Boost logo

Boost-Commit :

From: stipe_at_[hidden]
Date: 2007-12-24 00:18:57


Author: srajko
Date: 2007-12-24 00:18:55 EST (Mon, 24 Dec 2007)
New Revision: 42273
URL: http://svn.boost.org/trac/boost/changeset/42273

Log:
GUI well on its way
Added:
   sandbox/SOC/2007/signals/boost/dataflow/blueprint/component_bank.hpp (contents, props changed)
   sandbox/SOC/2007/signals/libs/dataflow/example/fltk_gui/BlueprintBank.cpp (contents, props changed)
   sandbox/SOC/2007/signals/libs/dataflow/example/fltk_gui/BlueprintBank.hpp (contents, props changed)
   sandbox/SOC/2007/signals/libs/dataflow/example/fltk_gui/BlueprintComponent.cpp (contents, props changed)
   sandbox/SOC/2007/signals/libs/dataflow/example/fltk_gui/BlueprintComponent.hpp (contents, props changed)
   sandbox/SOC/2007/signals/libs/dataflow/example/fltk_gui/BlueprintWindow.cpp (contents, props changed)
   sandbox/SOC/2007/signals/libs/dataflow/example/fltk_gui/BlueprintWindow.hpp (contents, props changed)
Text files modified:
   sandbox/SOC/2007/signals/boost/dataflow/blueprint/binary_operation.hpp | 2
   sandbox/SOC/2007/signals/boost/dataflow/blueprint/component.hpp | 32 ++++++++++++++
   sandbox/SOC/2007/signals/boost/dataflow/blueprint/network.hpp | 83 ++++++++++++++++++++++++++-------------
   sandbox/SOC/2007/signals/boost/switch.hpp | 4
   sandbox/SOC/2007/signals/libs/dataflow/build/xcodeide/signal_network.xcodeproj/project.pbxproj | 16 +++++++
   sandbox/SOC/2007/signals/libs/dataflow/example/blueprint/blueprint_example.cpp | 21 ++++++++-
   sandbox/SOC/2007/signals/libs/dataflow/example/fltk_gui/Jamfile.v2 | 2
   sandbox/SOC/2007/signals/libs/dataflow/example/fltk_gui/fltk_gui_example.cpp | 61 +++++++++++++++++++++++++----
   8 files changed, 173 insertions(+), 48 deletions(-)

Modified: sandbox/SOC/2007/signals/boost/dataflow/blueprint/binary_operation.hpp
==============================================================================
--- sandbox/SOC/2007/signals/boost/dataflow/blueprint/binary_operation.hpp (original)
+++ sandbox/SOC/2007/signals/boost/dataflow/blueprint/binary_operation.hpp 2007-12-24 00:18:55 EST (Mon, 24 Dec 2007)
@@ -55,7 +55,7 @@
     return shared_ptr<binary_operation<Operation> >();
 }
 
-void extract(port & producer, port & consumer)
+inline void extract(port & producer, port & consumer)
 {
     get_binary_operation<operations::extract>(producer, consumer)->invoke(producer, consumer);
 }

Modified: sandbox/SOC/2007/signals/boost/dataflow/blueprint/component.hpp
==============================================================================
--- sandbox/SOC/2007/signals/boost/dataflow/blueprint/component.hpp (original)
+++ sandbox/SOC/2007/signals/boost/dataflow/blueprint/component.hpp 2007-12-24 00:18:55 EST (Mon, 24 Dec 2007)
@@ -23,6 +23,7 @@
 {
 public:
     virtual void invoke()=0;
+ virtual bool is_invocable()=0;
     virtual size_t num_ports() const=0;
     virtual port & get_port(int port_num)=0;
     
@@ -30,6 +31,31 @@
     virtual ~component() {};
 };
 
+namespace detail
+{
+ template<typename T, typename Tag, typename Enable=void>
+ struct try_invoke
+ {
+ void operator()(T &) const
+ {
+ throw std::exception();
+ }
+ };
+
+ template<typename T, typename Tag>
+ struct try_invoke<
+ T, Tag,
+ typename enable_if<
+ is_component_operable<T, operations::invoke, Tag>
+ >::type >
+ {
+ void operator()(T &c) const
+ {
+ component_operation<operations::invoke, Tag>(c);
+ }
+ };
+}
+
 template<typename Component, typename Tag=default_tag>
 class component_t : public component
 {
@@ -42,8 +68,12 @@
     
     void invoke()
     {
- component_operation<operations::invoke, Tag>(c);
+ detail::try_invoke<Component, Tag>()(c);
     }
+ virtual bool is_invocable()
+ {
+ return is_component_operable<Component, operations::invoke, Tag>::type::value;
+ };
     size_t num_ports() const
     {
         return mpl::size<typename traits_of<Component, Tag>::type::ports>::value;

Added: sandbox/SOC/2007/signals/boost/dataflow/blueprint/component_bank.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2007/signals/boost/dataflow/blueprint/component_bank.hpp 2007-12-24 00:18:55 EST (Mon, 24 Dec 2007)
@@ -0,0 +1,82 @@
+// Copyright Stjepan Rajko 2007. Use, modification and
+// distribution is subject to the Boost Software License, Version
+// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+#ifndef BOOST_DATAFLOW_BLUEPRINT_COMPONENT_BANK_HPP
+#define BOOST_DATAFLOW_BLUEPRINT_COMPONENT_BANK_HPP
+
+#include <boost/dataflow/blueprint/component.hpp>
+
+#include <boost/bind.hpp>
+#include <boost/function.hpp>
+#include <boost/functional/factory.hpp>
+
+#include <map>
+#include <memory>
+
+namespace boost { namespace dataflow { namespace blueprint {
+
+template<typename Map>
+class key_iterator
+ : public boost::iterator_adaptor<
+ key_iterator<Map> // Derived
+ , typename Map::const_iterator
+ , const typename Map::key_type // Value
+ , boost::use_default
+ >
+{
+public:
+ key_iterator()
+ : key_iterator::iterator_adaptor_() {}
+
+ explicit key_iterator(typename Map::const_iterator it)
+ : key_iterator::iterator_adaptor_(it) {}
+
+ typename key_iterator::reference dereference() const
+ {
+ return key_iterator::base_reference()->first;
+ }
+
+ private:
+ friend class boost::iterator_core_access;
+};
+
+class component_bank
+{
+ typedef std::map<std::string, boost::function<component * ()> > map_type;
+public:
+ typedef key_iterator<map_type> iterator;
+
+ std::auto_ptr<component> make(const std::string &key)
+ {
+ std::auto_ptr<component> ret(m_components[key]());
+ return ret;
+ }
+ key_iterator<map_type> begin()
+ { return key_iterator<map_type>(m_components.begin()); }
+ key_iterator<map_type> end()
+ { return key_iterator<map_type>(m_components.end()); }
+protected:
+ map_type m_components;
+};
+
+template<typename Tag>
+class tag_component_bank : public component_bank
+{
+public:
+ template<typename T>
+ void add_component(const std::string &s)
+ {
+ m_components[s] = boost::factory<component_t<T, Tag> *>();
+ }
+ template<typename T, typename T0>
+ void add_component(const std::string &s, const T0 &t0)
+ {
+ m_components[s] = boost::bind(boost::factory<component_t<T, Tag> *>(), t0);
+ }
+};
+
+} } } // namespace boost::dataflow::blueprint
+
+#endif // BOOST_DATAFLOW_BLUEPRINT_COMPONENT_BANK_HPP
\ No newline at end of file

Modified: sandbox/SOC/2007/signals/boost/dataflow/blueprint/network.hpp
==============================================================================
--- sandbox/SOC/2007/signals/boost/dataflow/blueprint/network.hpp (original)
+++ sandbox/SOC/2007/signals/boost/dataflow/blueprint/network.hpp 2007-12-24 00:18:55 EST (Mon, 24 Dec 2007)
@@ -16,7 +16,6 @@
 
 namespace boost { namespace dataflow { namespace blueprint {
 
-template<typename Tag>
 class network
 {
     struct node_t
@@ -32,8 +31,8 @@
 public:
     typedef boost::adjacency_list<
         boost::vecS, boost::vecS, boost::bidirectionalS, node_t, edge_t> graph_type;
- typedef typename graph_type::vertex_descriptor component_type;
- typedef typename graph_type::edge_descriptor connection_type;
+ typedef graph_type::vertex_descriptor component_type;
+ typedef graph_type::edge_descriptor connection_type;
 private:
     struct vc
     {
@@ -68,32 +67,19 @@
         copy_graph(n.g, g, vertex_copy(vc(n.g, g)).edge_copy(ec(n.g, g)));
     }
     
- template<typename Component>
- component_type add_component()
- {
- typename graph_type::vertex_descriptor v = add_vertex(g);
- g[v].ptr.reset(new component_t<Component, Tag>());
- return v;
- }
- template<typename Component, typename T0>
- component_type add_component(const T0 &t0)
+ component_type add_component(std::auto_ptr<component> c)
     {
- typename graph_type::vertex_descriptor v = add_vertex(g);
- g[v].ptr.reset(new component_t<Component, Tag>(t0));
+ graph_type::vertex_descriptor v = add_vertex(g);
+ g[v].ptr = c;
         return v;
     }
- template<typename Mechanism, typename ProducerPort, typename ConsumerPort>
- void add_connection(component_type p, int p_port, component_type c, int c_port)
- {
- add_connection_(p, p_port, c, c_port, new binary_operation_t<operations::connect, Mechanism, ProducerPort, ConsumerPort>());
- }
- void add_connection(component_type p, int p_port, component_type c, int c_port)
+ void add_connection(component_type p, int p_port, component_type c, int c_port, bool instantiate=false)
     {
         if (!are_connectable(p, p_port, c, c_port))
             throw(std::exception());
 
         add_connection_(p, p_port, c, c_port,
- get_binary_operation<operations::connect>(get_port(p, p_port), get_port(c, c_port)));
+ get_binary_operation<operations::connect>(get_port(p, p_port), get_port(c, c_port)), instantiate);
     }
     bool are_connectable(component_type p, int p_port, component_type c, int c_port)
     {
@@ -101,11 +87,9 @@
     }
     void connect()
     {
- typename graph_type::edge_iterator it;
+ graph_type::edge_iterator it;
         for (it = edges(g).first; it!=edges(g).second; it++)
- g[*it].ptr->invoke(
- g[source(*it, g)].ptr->get_port(g[*it].producer_port),
- g[target(*it, g)].ptr->get_port(g[*it].consumer_port));
+ connect_(*it);
     }
     component &operator[](component_type c)
     {
@@ -120,18 +104,59 @@
         return g;
     }
     
-private:
+protected:
     void add_connection_(component_type p, int p_port, component_type c, int c_port,
- boost::shared_ptr<binary_operation<operations::connect> >)
+ boost::shared_ptr<binary_operation<operations::connect> >, bool instantiate)
     {
- typename graph_type::edge_descriptor e = add_edge(p, c, g).first;
+ graph_type::edge_descriptor e = add_edge(p, c, g).first;
         g[e].ptr = get_binary_operation<operations::connect>(get_port(p, p_port), get_port(c, c_port));
         g[e].producer_port = p_port;
- g[e].consumer_port = c_port;
+ g[e].consumer_port = c_port;
+ if (instantiate)
+ connect_(e);
+ }
+ void connect_(graph_type::edge_descriptor e)
+ {
+ g[e].ptr->invoke(
+ g[source(e, g)].ptr->get_port(g[e].producer_port),
+ g[target(e, g)].ptr->get_port(g[e].consumer_port));
     }
     graph_type g;
 };
 
+template<typename Tag>
+class tag_network : public network
+{
+public:
+ tag_network() {}
+ tag_network(const network &n)
+ : network(n)
+ {}
+
+ template<typename Component>
+ component_type add_component()
+ {
+ typename graph_type::vertex_descriptor v = add_vertex(g);
+ g[v].ptr.reset(new component_t<Component, Tag>());
+ return v;
+ }
+ using network::add_component;
+ template<typename Component, typename T0>
+ component_type add_component(const T0 &t0)
+ {
+ typename graph_type::vertex_descriptor v = add_vertex(g);
+ g[v].ptr.reset(new component_t<Component, Tag>(t0));
+ return v;
+ }
+ using network::add_connection;
+
+ template<typename Mechanism, typename ProducerPort, typename ConsumerPort>
+ void add_connection(component_type p, int p_port, component_type c, int c_port, bool instantiate=false)
+ {
+ add_connection_(p, p_port, c, c_port, new binary_operation_t<ProducerPort, ConsumerPort, operations::connect, Tag>(), instantiate);
+ }
+};
+
 } } } // namespace boost::dataflow::blueprint
 
 #endif // BOOST_DATAFLOW_BLUEPRINT_NETWORK_HPP
\ No newline at end of file

Modified: sandbox/SOC/2007/signals/boost/switch.hpp
==============================================================================
--- sandbox/SOC/2007/signals/boost/switch.hpp (original)
+++ sandbox/SOC/2007/signals/boost/switch.hpp 2007-12-24 00:18:55 EST (Mon, 24 Dec 2007)
@@ -50,13 +50,13 @@
 // default is supplied.
 
 template<class R>
-R forced_return(R* r = 0) {
+inline R forced_return(R* r = 0) {
     return(*r);
 }
 
 // Thanks to Stjepan Rajko for catching this.
 template<>
-void forced_return<void>(void*) {}
+inline void forced_return<void>(void*) {}
 
 template<class R>
 struct throw_exception {

Modified: sandbox/SOC/2007/signals/libs/dataflow/build/xcodeide/signal_network.xcodeproj/project.pbxproj
==============================================================================
--- sandbox/SOC/2007/signals/libs/dataflow/build/xcodeide/signal_network.xcodeproj/project.pbxproj (original)
+++ sandbox/SOC/2007/signals/libs/dataflow/build/xcodeide/signal_network.xcodeproj/project.pbxproj 2007-12-24 00:18:55 EST (Mon, 24 Dec 2007)
@@ -99,6 +99,13 @@
                 084482560CA0B37200B88137 /* operators.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = operators.hpp; sourceTree = "<group>"; };
                 084B11CE0D08EB2C00491E27 /* forwardable.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = forwardable.hpp; sourceTree = "<group>"; };
                 084D2E6E0CE7DFE900E861FA /* gil_example.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = gil_example.cpp; sourceTree = "<group>"; };
+ 08622E2E0D1EE4A70068A238 /* component_bank.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = component_bank.hpp; sourceTree = "<group>"; };
+ 086231CB0D1F422F0068A238 /* BlueprintWindow.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = BlueprintWindow.hpp; sourceTree = "<group>"; };
+ 086231CD0D1F42650068A238 /* BlueprintBank.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = BlueprintBank.hpp; sourceTree = "<group>"; };
+ 086231CE0D1F42650068A238 /* BlueprintBank.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = BlueprintBank.cpp; sourceTree = "<group>"; };
+ 086231CF0D1F42A10068A238 /* BlueprintComponent.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = BlueprintComponent.hpp; sourceTree = "<group>"; };
+ 086231D00D1F42A10068A238 /* BlueprintComponent.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = BlueprintComponent.cpp; sourceTree = "<group>"; };
+ 086231D10D1F42B60068A238 /* BlueprintWindow.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = BlueprintWindow.cpp; sourceTree = "<group>"; };
                 08668C4E0C19A16300ACB19A /* simple_distributed_example.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = simple_distributed_example.cpp; sourceTree = "<group>"; };
                 08668C4F0C19A16300ACB19A /* Jamfile.v2 */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text; path = Jamfile.v2; sourceTree = "<group>"; };
                 08B9D4190CC3D0790050F10B /* test_binary_op.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = test_binary_op.cpp; sourceTree = "<group>"; };
@@ -348,6 +355,12 @@
                         children = (
                                 08D2C7330D1DDE5C008388D7 /* Jamfile.v2 */,
                                 08D2C7390D1DDEB8008388D7 /* fltk_gui_example.cpp */,
+ 086231CB0D1F422F0068A238 /* BlueprintWindow.hpp */,
+ 086231D10D1F42B60068A238 /* BlueprintWindow.cpp */,
+ 086231CD0D1F42650068A238 /* BlueprintBank.hpp */,
+ 086231CE0D1F42650068A238 /* BlueprintBank.cpp */,
+ 086231CF0D1F42A10068A238 /* BlueprintComponent.hpp */,
+ 086231D00D1F42A10068A238 /* BlueprintComponent.cpp */,
                         );
                         path = fltk_gui;
                         sourceTree = "<group>";
@@ -551,6 +564,7 @@
                                 08256FE60CEBDFEC003EC1B4 /* network.hpp */,
                                 08F346EC0D0CFE9700A037A3 /* vector_port_t.hpp */,
                                 08F244EA0D1B682D00EC9B03 /* keyed_port_t.hpp */,
+ 08622E2E0D1EE4A70068A238 /* component_bank.hpp */,
                         );
                         path = blueprint;
                         sourceTree = "<group>";
@@ -845,7 +859,7 @@
                         );
                         runOnlyForDeploymentPostprocessing = 0;
                         shellPath = /bin/sh;
- shellScript = "cd ../../doc\nbjam --v2 --toolset=darwin release";
+ shellScript = "style=`echo $BUILD_STYLE | sed 'y/DR/dr/'` \ncd ../../doc\nbjam --v2 --toolset=darwin $style";
                 };
                 08FD5E6E0C1BA8BC00F00877 /* ShellScript */ = {
                         isa = PBXShellScriptBuildPhase;

Modified: sandbox/SOC/2007/signals/libs/dataflow/example/blueprint/blueprint_example.cpp
==============================================================================
--- sandbox/SOC/2007/signals/libs/dataflow/example/blueprint/blueprint_example.cpp (original)
+++ sandbox/SOC/2007/signals/libs/dataflow/example/blueprint/blueprint_example.cpp 2007-12-24 00:18:55 EST (Mon, 24 Dec 2007)
@@ -7,6 +7,7 @@
 
 #include <iostream>
 
+#include <boost/dataflow/blueprint/component_bank.hpp>
 #include <boost/dataflow/blueprint/network.hpp>
 #include <boost/dataflow/blueprint/binary_operation_t.hpp>
 #include <boost/dataflow/blueprint/port_t.hpp>
@@ -23,12 +24,24 @@
 
 using namespace boost;
 
+class example_bank : public blueprint::tag_component_bank<df::signals::tag>
+{
+public:
+ example_bank()
+ {
+ add_component<signals::storage<void(int)> >("storage_int");
+ add_component<signals::storage<void(float)> >("storage_float_100_1", 100.1f);
+ add_component<signals::storage<void(float)> >("storage_float_0", 0.0f);
+ }
+};
+
 class blueprint_example
 {
- typedef blueprint::network<df::signals::tag> network_type;
+ typedef blueprint::tag_network<df::signals::tag> network_type;
 
     // The network.
     network_type network;
+ example_bank bank;
 
     // The components (graph indices).
     network_type::component_type source, sink, source_float, sink_float;
@@ -39,11 +52,11 @@
         // Add the components to the network.
         source = network.add_component<signals::storage<void(int)> >(100),
         sink = network.add_component<signals::storage<void(int)> >(0),
- source_float = network.add_component<signals::storage<void(float)> >(100.1f),
- sink_float = network.add_component<signals::storage<void(float)> >(0.0f);
+ source_float = network.add_component(bank.make("storage_float_100_1"));
+ sink_float = network.add_component(bank.make("storage_float_0"));
     }
     void run()
- {
+ {
         // Print some runtime port info
         std::cout << "Printing runtime info about all of the components:" << std::endl << std::endl;
         print_port_info("source", source);

Added: sandbox/SOC/2007/signals/libs/dataflow/example/fltk_gui/BlueprintBank.cpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2007/signals/libs/dataflow/example/fltk_gui/BlueprintBank.cpp 2007-12-24 00:18:55 EST (Mon, 24 Dec 2007)
@@ -0,0 +1,31 @@
+// Copyright 2007 Stjepan Rajko.
+// Distributed under the Boost Software License, Version 1.0. (See
+// accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+#include "BlueprintBank.hpp"
+#include "BlueprintWindow.hpp"
+#include <fltk/Button.h>
+
+namespace boost { namespace dataflow { namespace fltk_gui {
+
+void BlueprintBank::button_callback(fltk::Widget* widget, void*b)
+{
+ BlueprintBank *bank= static_cast<BlueprintBank *>(b);
+ bank->m_blueprint->add_component(bank->m_bank.make(widget->label()), widget->label());
+}
+
+void BlueprintBank::rearrange()
+{
+ clear();
+ int y = 0;
+ for(blueprint::component_bank::iterator it= m_bank.begin(); it!=m_bank.end(); it++)
+ {
+ fltk::Button *button = new fltk::Button(0, y, 100, 100, it->c_str());
+ y += 100;
+ button->callback((fltk::Callback *)&button_callback, this);
+ add(button);
+ }
+}
+
+} } }

Added: sandbox/SOC/2007/signals/libs/dataflow/example/fltk_gui/BlueprintBank.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2007/signals/libs/dataflow/example/fltk_gui/BlueprintBank.hpp 2007-12-24 00:18:55 EST (Mon, 24 Dec 2007)
@@ -0,0 +1,45 @@
+// Copyright 2007 Stjepan Rajko.
+// Distributed under the Boost Software License, Version 1.0. (See
+// accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+
+#ifndef BLUEPRINT_COMPONENT_BANK_HPP
+#define BLUEPRINT_COMPONENT_BANK_HPP
+
+#include <boost/dataflow/blueprint/component_bank.hpp>
+
+#include <fltk/window.h>
+
+namespace boost { namespace dataflow { namespace fltk_gui {
+
+class BlueprintWindow;
+
+class BlueprintBank : public fltk::Window
+{
+public:
+ BlueprintBank(int w, int h, const char *label = 0)
+ : fltk::Window(w, h, label)
+ {}
+ BlueprintBank(int x, int y, int w, int h, const char *label = 0, bool begin=false)
+ : fltk::Window(x, y, w, h, label, begin)
+ {}
+ void set_bank(const blueprint::component_bank &bank)
+ {
+ m_bank = bank;
+ rearrange();
+ }
+ void set_blueprint(BlueprintWindow &blueprint)
+ {
+ m_blueprint = &blueprint;
+ }
+ static void button_callback(fltk::Widget* widget, void*b);
+private:
+ void rearrange();
+ BlueprintWindow * m_blueprint;
+ blueprint::component_bank m_bank;
+};
+
+} } }
+
+#endif
\ No newline at end of file

Added: sandbox/SOC/2007/signals/libs/dataflow/example/fltk_gui/BlueprintComponent.cpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2007/signals/libs/dataflow/example/fltk_gui/BlueprintComponent.cpp 2007-12-24 00:18:55 EST (Mon, 24 Dec 2007)
@@ -0,0 +1,96 @@
+// Copyright 2007 Stjepan Rajko.
+// Distributed under the Boost Software License, Version 1.0. (See
+// accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+#include "BlueprintComponent.hpp"
+#include <fltk/events.h>
+
+namespace boost { namespace dataflow { namespace fltk_gui {
+
+class BlueprintComponentCore : public fltk::Button
+{
+public:
+ BlueprintComponentCore(int x, int y, int w, int h, bool invocable)
+ : fltk::Button(x, y, w, h, invocable ? "invoke" : 0)
+ , m_dragged(false)
+ , m_invocable(invocable)
+ {
+ callback((fltk::Callback *)on_push, this);
+
+ }
+ int handle(int event);
+private:
+ static void on_push(fltk::Widget *widget, BlueprintComponentCore *core)
+ {
+ if (core->m_invocable)
+ core->component().invoke();
+ }
+ BlueprintComponent &component()
+ { return *static_cast<BlueprintComponent *>(parent()); }
+ int push_x, push_y;
+ bool m_dragged;
+ bool m_invocable;
+};
+
+int BlueprintComponentCore::handle(int event)
+{
+ switch (event)
+ {
+ case fltk::DRAG:
+ parent()->position(parent()->x() + fltk::event_x_root() - push_x, parent()->y() + fltk::event_y_root() - push_y);
+ case fltk::PUSH:
+ push_x = fltk::event_x_root();
+ push_y = fltk::event_y_root();
+ m_dragged = event==fltk::DRAG;
+ return fltk::Button::handle(event);
+ case fltk::RELEASE:
+ if (!m_dragged)
+ return fltk::Button::handle(event);
+ }
+ return fltk::Button::handle(event);
+}
+
+int BlueprintComponentPort::handle(int event)
+{
+ switch(event)
+ {
+ case fltk::DND_RELEASE:
+ return blueprint().register_drop(this);;
+ case fltk::DND_ENTER:
+ return 1;
+ case fltk::PASTE:
+ blueprint().connect_dragged_with(this);
+ return 1;
+ case fltk::DRAG:
+ fltk::copy("port", 4);
+ blueprint().register_drag(this);
+ fltk::dnd();
+ }
+ return fltk::Button::handle(event);
+}
+
+BlueprintComponent::BlueprintComponent(int x, int y, int w, int h, const char *label, blueprint::component &c, id_type id)
+ : fltk::Group(x, y, w, h)
+ , m_component(c), m_id(id)
+{
+ copy_label(label);
+ add(new BlueprintComponentCore(20, 20, 60, 60, c.is_invocable()));
+
+ int y_left = 20;
+ int y_right = 20;
+
+ for (size_t i=0; i<c.num_ports(); i++)
+ if (c.get_port(i).traits().category().is<ports::producer>())
+ {
+ add(new BlueprintComponentPort(80, y_right, 20, 20, "@->", i));
+ y_right+=20;
+ }
+ else
+ {
+ add(new BlueprintComponentPort(0, y_left, 20, 20, "@>", i));
+ y_left+=20;
+ }
+}
+
+} } }

Added: sandbox/SOC/2007/signals/libs/dataflow/example/fltk_gui/BlueprintComponent.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2007/signals/libs/dataflow/example/fltk_gui/BlueprintComponent.hpp 2007-12-24 00:18:55 EST (Mon, 24 Dec 2007)
@@ -0,0 +1,45 @@
+// Copyright 2007 Stjepan Rajko.
+// Distributed under the Boost Software License, Version 1.0. (See
+// accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+#ifndef BLUEPRINT_COMPONENT_HPP
+#define BLUEPRINT_COMPONENT_HPP
+
+#include <fltk/Button.h>
+#include "BlueprintWindow.hpp"
+
+namespace boost { namespace dataflow { namespace fltk_gui {
+
+class BlueprintComponent : public fltk::Group
+{
+ typedef blueprint::network::component_type id_type;
+public:
+ BlueprintComponent(int x, int y, int w, int h, const char *label, blueprint::component &c, id_type id);
+ void invoke() {m_component.invoke();}
+ id_type id() {return m_id;}
+private:
+ blueprint::component &m_component;
+ std::string m_name;
+ id_type m_id;
+};
+
+class BlueprintComponentPort : public fltk::Button
+{
+public:
+ BlueprintComponentPort(int x, int y, int w, int h, const char *label, size_t id)
+ : fltk::Button(x, y, w, h, label), m_id(id)
+ {}
+ int handle(int event);
+ BlueprintComponent &component()
+ { return *static_cast<BlueprintComponent *>(parent()); }
+ size_t id() {return m_id;}
+private:
+ BlueprintWindow &blueprint()
+ { return *static_cast<BlueprintWindow *>(parent()->parent()); }
+ size_t m_id;
+};
+
+} } }
+
+#endif
\ No newline at end of file

Added: sandbox/SOC/2007/signals/libs/dataflow/example/fltk_gui/BlueprintWindow.cpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2007/signals/libs/dataflow/example/fltk_gui/BlueprintWindow.cpp 2007-12-24 00:18:55 EST (Mon, 24 Dec 2007)
@@ -0,0 +1,44 @@
+// Copyright 2007 Stjepan Rajko.
+// Distributed under the Boost Software License, Version 1.0. (See
+// accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+#include "BlueprintWindow.hpp"
+#include "BlueprintComponent.hpp"
+//#include <fltk/MenuBar.hpp>
+
+namespace boost { namespace dataflow { namespace fltk_gui {
+
+BlueprintWindow::BlueprintWindow(int width, int height, const char *label)
+ : fltk::Window(width, height)
+{
+ copy_label(label);
+ begin();
+/* fltk::MenuBar menubar(0,0,width,25);
+ menubar.callback(callback);
+ menubar.begin();
+ fltk::ItemGroup file("&Blueprint");
+ file.begin();
+ Item* o = new Item("Instantiate connections");
+ file.end();
+ end();*/
+}
+
+void BlueprintWindow::add_component(std::auto_ptr<blueprint::component> c, const std::string &name)
+{
+ BlueprintComponent *bc = new BlueprintComponent(100, 100, 100, 100, name.c_str(), *c, m_network.add_component(c));
+ add(bc);
+ redraw();
+}
+
+bool BlueprintWindow::register_drop(BlueprintComponentPort *port)
+{
+ return m_network.are_connectable(m_dragged->component().id(), m_dragged->id(), port->component().id(), port->id());
+}
+
+void BlueprintWindow::connect_dragged_with(BlueprintComponentPort *port)
+{
+ m_network.add_connection(m_dragged->component().id(), m_dragged->id(), port->component().id(), port->id(), true);
+}
+
+} } }
\ No newline at end of file

Added: sandbox/SOC/2007/signals/libs/dataflow/example/fltk_gui/BlueprintWindow.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2007/signals/libs/dataflow/example/fltk_gui/BlueprintWindow.hpp 2007-12-24 00:18:55 EST (Mon, 24 Dec 2007)
@@ -0,0 +1,37 @@
+// Copyright 2007 Stjepan Rajko.
+// Distributed under the Boost Software License, Version 1.0. (See
+// accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+#ifndef BLUEPRINT_WINDOW_HPP
+#define BLUEPRINT_WINDOW_HPP
+
+#include <fltk/Window.h>
+
+#include <boost/dataflow/blueprint/network.hpp>
+#include <boost/dataflow/signals/runtime_support.hpp>
+
+namespace boost { namespace dataflow { namespace fltk_gui {
+
+class BlueprintComponent;
+class BlueprintComponentPort;
+
+class BlueprintWindow : public fltk::Window
+{
+public:
+ BlueprintWindow(int width, int height, const char *label = 0);
+ void add_component(std::auto_ptr<blueprint::component> c, const std::string &name);
+ void register_drag(BlueprintComponentPort *port)
+ {
+ m_dragged = port;
+ }
+ bool register_drop(BlueprintComponentPort *port);
+ void connect_dragged_with(BlueprintComponentPort *port);
+private:
+ blueprint::network m_network;
+ std::vector<BlueprintComponent *> m_components;
+ BlueprintComponentPort *m_dragged;
+};
+
+} } }
+#endif
\ No newline at end of file

Modified: sandbox/SOC/2007/signals/libs/dataflow/example/fltk_gui/Jamfile.v2
==============================================================================
--- sandbox/SOC/2007/signals/libs/dataflow/example/fltk_gui/Jamfile.v2 (original)
+++ sandbox/SOC/2007/signals/libs/dataflow/example/fltk_gui/Jamfile.v2 2007-12-24 00:18:55 EST (Mon, 24 Dec 2007)
@@ -14,4 +14,4 @@
       <toolset>darwin:<linkflags>"-framework Carbon"
     ;
 
-exe fltk_gui_example : fltk_gui_example.cpp ;
+exe fltk_gui_example : fltk_gui_example.cpp BlueprintWindow.cpp BlueprintBank.cpp BlueprintComponent.cpp ;

Modified: sandbox/SOC/2007/signals/libs/dataflow/example/fltk_gui/fltk_gui_example.cpp
==============================================================================
--- sandbox/SOC/2007/signals/libs/dataflow/example/fltk_gui/fltk_gui_example.cpp (original)
+++ sandbox/SOC/2007/signals/libs/dataflow/example/fltk_gui/fltk_gui_example.cpp 2007-12-24 00:18:55 EST (Mon, 24 Dec 2007)
@@ -3,28 +3,71 @@
 // accompanying file LICENSE_1_0.txt or copy at
 // http://www.boost.org/LICENSE_1_0.txt)
 
-#include <fltk/Window.h>
+
+#include "BlueprintWindow.hpp"
+#include "BlueprintBank.hpp"
 #include <fltk/run.h>
-#include <boost/dataflow/blueprint/network.hpp>
+#include <fltk/Button.h>
+#include <fltk/ValueOutput.h>
+
+#include <boost/dataflow/signals/component/storage.hpp>
+#include <boost/dataflow/signals/runtime_support.hpp>
 
 #include <memory>
 
-class BlueprintWindow : public fltk::Window
+namespace blueprint=boost::dataflow::blueprint;
+namespace signals=boost::signals;
+namespace df=boost::dataflow;
+
+class valuator : public boost::signals::filter<valuator, void(int), boost::mpl::vector<void(int)> >
 {
- BlueprintWindow(int width, int height, const char *label = 0)
- : fltk::Window(width, height, label)
- {}
+public:
+ valuator(const valuator &)
+ {
+ m_window.reset(new fltk::Window(200, 200, "Valuator output"));
+ m_window->add(output = new fltk::ValueOutput(50, 50, 100, 100));
+ m_window->show();
+ }
+ valuator()
+ {
+ m_window.reset(new fltk::Window(200, 200, "Valuator output"));
+ m_window->add(output = new fltk::ValueOutput(50, 50, 100, 100));
+ m_window->show();
+ }
+ void operator()(int x)
+ {
+ output->value(x);
+ }
+public:
+ std::auto_ptr<fltk::Window> m_window;
+ fltk::ValueOutput *output;
 };
 
-class BlueprintComponent : public fltk::Group
+class example_bank : public blueprint::tag_component_bank<df::signals::tag>
 {
-
+public:
+ example_bank()
+ {
+ add_component<signals::storage<void(int)> >("storage_int", 100);
+ add_component<valuator>("valuator");
+ }
 };
 
 int main()
 {
- std::auto_ptr<fltk::Window> window(new fltk::Window(100, 100));
+ //fltk::Button::default_style->box_ = fltk::RSHADOW_BOX;
+ //fltk::Button::default_style->buttonbox_ = fltk::RSHADOW_BOX;
+ fltk::Button::default_style->buttoncolor_ = fltk::color(0, 0, 255);
+ fltk::Window::default_style->color_ = fltk::GRAY75;
+ using namespace boost::dataflow::fltk_gui;
+
+ std::auto_ptr<df::fltk_gui::BlueprintWindow> window(new df::fltk_gui::BlueprintWindow(800, 600, "Blueprint"));
+ std::auto_ptr<BlueprintBank> bank(new BlueprintBank(100, 600, "Components"));
+
+ bank->set_bank(example_bank());
+ bank->set_blueprint(*window);
     
+ bank->show();
     window->show();
     
     fltk::run();


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk