From a35973b128a2f7130b619a2a11a35cfd418b21b6 Mon Sep 17 00:00:00 2001 From: guigues Date: Mon, 30 Mar 2009 14:42:16 +0000 Subject: [PATCH] MagicBox : support of data synchronization + various related fixes --- kernel/src/bbtkAny.h | 6 +- kernel/src/bbtkBlackBox.cxx | 22 +++++- kernel/src/bbtkConnection.cxx | 28 ++++++-- kernel/src/bbtkConnection.h | 6 +- kernel/src/bbtkExecuter.cxx | 7 +- packages/std/src/bbstdMagicBox.cxx | 32 ++++++++- packages/std/src/bbstdMagicBox.h | 70 +++++++++++++++---- .../bbs/appli/exampleSynchronizeWidgets.bbs | 36 ++++++++++ packages/wx/src/bbwxSlider.cxx | 13 +++- 9 files changed, 186 insertions(+), 34 deletions(-) create mode 100644 packages/wx/bbs/appli/exampleSynchronizeWidgets.bbs diff --git a/kernel/src/bbtkAny.h b/kernel/src/bbtkAny.h index 9fbc9e7..a343e79 100644 --- a/kernel/src/bbtkAny.h +++ b/kernel/src/bbtkAny.h @@ -2,8 +2,8 @@ Program: bbtk Module: $RCSfile: bbtkAny.h,v $ Language: C++ - Date: $Date: 2009/01/07 13:08:19 $ - Version: $Revision: 1.6 $ + Date: $Date: 2009/03/30 14:42:16 $ + Version: $Revision: 1.7 $ =========================================================================*/ /* --------------------------------------------------------------------- @@ -333,7 +333,7 @@ namespace bbtk /// Returns true iff the contained type is a pointer inline bool contains_pointer() { - return content->is_pointer() ; + return content ? content->is_pointer() : false; } /// Returns true iff the contained type is t diff --git a/kernel/src/bbtkBlackBox.cxx b/kernel/src/bbtkBlackBox.cxx index 0206b29..8be7d01 100644 --- a/kernel/src/bbtkBlackBox.cxx +++ b/kernel/src/bbtkBlackBox.cxx @@ -2,8 +2,8 @@ Program: bbtk Module: $RCSfile: bbtkBlackBox.cxx,v $ Language: C++ - Date: $Date: 2009/03/23 13:06:41 $ - Version: $Revision: 1.40 $ + Date: $Date: 2009/03/30 14:42:16 $ + Version: $Revision: 1.41 $ =========================================================================*/ /* --------------------------------------------------------------------- @@ -383,11 +383,18 @@ namespace bbtk if ( (p == "2") || (p == "R") || (p == "r") || (p == "Reactive") || (p == "reactive") ) return Reactive; + /* + if ( (p == "3") || + (p == "F") || (p == "f") || + (p == "Flash") || (p == "flash") ) return Flash; + */ bbtkError(bbGetFullName()<<" : BoxProcessMode value '"<

SetStatus(s); + + // Flash reaction + /* + if (bbGetBoxProcessModeValue() == Flash) + { + this->bbExecute(); + } + */ + OutputConnectorMapType::const_iterator o; for ( o = bbGetOutputConnectorMap().begin(); o != bbGetOutputConnectorMap().end(); ++o ) diff --git a/kernel/src/bbtkConnection.cxx b/kernel/src/bbtkConnection.cxx index bc6b3b1..37c0eb6 100644 --- a/kernel/src/bbtkConnection.cxx +++ b/kernel/src/bbtkConnection.cxx @@ -2,8 +2,8 @@ Program: bbtk Module: $RCSfile: bbtkConnection.cxx,v $ Language: C++ - Date: $Date: 2008/12/11 09:50:35 $ - Version: $Revision: 1.19 $ + Date: $Date: 2009/03/30 14:42:16 $ + Version: $Revision: 1.20 $ =========================================================================*/ /* --------------------------------------------------------------------- @@ -116,9 +116,7 @@ Connection::Connection(BlackBox::Pointer from, const std::string& output, { if ( from->bbGetOutputType(output) == typeid(Data) ) { - bbtkWarning("Connection '" - <bbGetName()<<"."<bbGetName()<<"."<() <<"> : type compatibility with '" @@ -345,6 +343,18 @@ Connection::Connection(BlackBox::Pointer from, const std::string& output, "===> Connection::RecursiveExecute() [" <bbGetExecuting()) + { + bbtkDebugMessage("process",3, + " -> "<bbGetName() + <<" already executing : abort"<bbRecursiveExecute(GetThisPointer()); TransferData(); @@ -407,8 +417,14 @@ Connection::Connection(BlackBox::Pointer from, const std::string& output, <bbGetInputType(mInput)) <<">"<bbGetOutput(mOutput).type() == typeid(void)) + { + bbtkDebugMessage("data",3, + " -> Source is void : nothing to transfer!"<bbGetOutput(mOutput) + else if (mFrom->bbGetOutput(mOutput) .contains( mTo->bbGetInputType(mInput) ) ) { bbtkDebugMessage("data",3, diff --git a/kernel/src/bbtkConnection.h b/kernel/src/bbtkConnection.h index 391385a..6c81d9e 100644 --- a/kernel/src/bbtkConnection.h +++ b/kernel/src/bbtkConnection.h @@ -2,8 +2,8 @@ Program: bbtk Module: $RCSfile: bbtkConnection.h,v $ Language: C++ - Date: $Date: 2008/12/11 09:50:35 $ - Version: $Revision: 1.11 $ + Date: $Date: 2009/03/30 14:42:16 $ + Version: $Revision: 1.12 $ =========================================================================*/ /* --------------------------------------------------------------------- @@ -166,7 +166,7 @@ namespace bbtk /// Sets the members but does not test compatibility (used by bbtk::AdaptiveConnection) // Connection(BlackBox* from, const std::string& output, // BlackBox* to, const std::string& input, int ); - + public: void TransferData(); private: diff --git a/kernel/src/bbtkExecuter.cxx b/kernel/src/bbtkExecuter.cxx index 84273c0..41ca9b6 100644 --- a/kernel/src/bbtkExecuter.cxx +++ b/kernel/src/bbtkExecuter.cxx @@ -2,8 +2,8 @@ Program: bbtk Module: $RCSfile: bbtkExecuter.cxx,v $ Language: C++ - Date: $Date: 2009/01/27 14:22:56 $ - Version: $Revision: 1.27 $ + Date: $Date: 2009/03/30 14:42:16 $ + Version: $Revision: 1.28 $ =========================================================================*/ /* --------------------------------------------------------------------- @@ -397,7 +397,8 @@ namespace bbtk BlackBox::Pointer b = GetCurrentDescriptor()->GetPrototype()->bbGetBlackBox(box); // Looks for the adaptor - if ( b->bbGetInputType(input) != typeid(std::string) ) + if ( ( b->bbGetInputType(input) != typeid(bbtk::any) )&& + ( b->bbGetInputType(input) != typeid(std::string) ) ) { BlackBox::Pointer a = GetFactory()->NewAdaptor(typeid(std::string), diff --git a/packages/std/src/bbstdMagicBox.cxx b/packages/std/src/bbstdMagicBox.cxx index 0d3e476..fe601be 100644 --- a/packages/std/src/bbstdMagicBox.cxx +++ b/packages/std/src/bbstdMagicBox.cxx @@ -2,8 +2,8 @@ Program: bbtk Module: $RCSfile: bbstdMagicBox.cxx,v $ Language: C++ - Date: $Date: 2008/10/17 08:18:26 $ - Version: $Revision: 1.5 $ + Date: $Date: 2009/03/30 14:42:23 $ + Version: $Revision: 1.6 $ =========================================================================*/ /* --------------------------------------------------------------------- @@ -31,9 +31,37 @@ #include "bbstdMagicBox.h" #include "bbstdPackage.h" +#include "bbtkBlackBoxOutputConnector.h" +using namespace bbtk; + namespace bbstd { + void MagicBox::bbSetStatusAndPropagate(bbtk::BlackBoxInputConnector* c, + bbtk::IOStatus s) + { + bbtkDebugMessageInc("change",5, + "=> MagicBox::bbSetStatusAndPropagate(input," + <IsConnected()) + { + std::string do_input = c->GetConnection()->GetBlackBoxToInput(); + c->GetConnection()->TransferData(); + bbSetOutputOut( bbGetInput(do_input) ); + } + mCanSet = false; + } + BlackBox::bbSetStatusAndPropagate(c,s); + } + + void MagicBox::DoProcess() + { + mCanSet = true; + } + BBTK_ADD_BLACK_BOX_TO_PACKAGE(std,MagicBox); BBTK_BLACK_BOX_IMPLEMENTATION(MagicBox,bbtk::AtomicBlackBox); diff --git a/packages/std/src/bbstdMagicBox.h b/packages/std/src/bbstdMagicBox.h index ffd86de..de0e443 100644 --- a/packages/std/src/bbstdMagicBox.h +++ b/packages/std/src/bbstdMagicBox.h @@ -2,8 +2,8 @@ Program: bbtk Module: $RCSfile: bbstdMagicBox.h,v $ Language: C++ - Date: $Date: 2008/12/12 08:55:21 $ - Version: $Revision: 1.10 $ + Date: $Date: 2009/03/30 14:42:23 $ + Version: $Revision: 1.11 $ =========================================================================*/ /* --------------------------------------------------------------------- @@ -37,24 +37,47 @@ namespace bbstd { +#define BBTK_MB_DECLARE_INPUT(NAME,TYPE) \ + protected: \ + TYPE bbmInput##NAME; \ +public: \ + TYPE bbGetInput##NAME () \ + { return bbmInput##NAME; } \ + void bbSetInput##NAME (TYPE d) \ + { bbmInput##NAME = d; \ + if (mCanSet) { bbSetOutputOut(d); mCanSet = false; } } + //================================================================== class bbstd_EXPORT MagicBox : public bbtk::AtomicBlackBox { BBTK_BLACK_BOX_INTERFACE(MagicBox,bbtk::AtomicBlackBox); - BBTK_DECLARE_INPUT(In,bbtk::Data); + BBTK_MB_DECLARE_INPUT(In,bbtk::Data); + BBTK_MB_DECLARE_INPUT(In1,bbtk::Data); + BBTK_MB_DECLARE_INPUT(In2,bbtk::Data); + BBTK_MB_DECLARE_INPUT(In3,bbtk::Data); + BBTK_MB_DECLARE_INPUT(In4,bbtk::Data); + BBTK_MB_DECLARE_INPUT(In5,bbtk::Data); + BBTK_MB_DECLARE_INPUT(In6,bbtk::Data); + BBTK_MB_DECLARE_INPUT(In7,bbtk::Data); + BBTK_MB_DECLARE_INPUT(In8,bbtk::Data); + BBTK_MB_DECLARE_INPUT(In9,bbtk::Data); BBTK_DECLARE_OUTPUT(Out,bbtk::Data); BBTK_PROCESS(DoProcess); - void DoProcess() { bbSetOutputOut( bbGetInputIn() ); } - + void DoProcess(); protected: // virtual void bbUserConstructor(); - - }; + virtual void bbSetStatusAndPropagate(bbtk::BlackBoxInputConnector* c, + bbtk::IOStatus s); + bool mCanSet; + virtual void bbUserConstructor() { mCanSet = true; } + + }; //================================================================== - +#undef BBTK_MB_DECLARE_INPUT + //================================================================== // We have to create a particular SetFunctor for MagicBox because // its input is of type bbtk::Data (i.e. any) and : @@ -78,7 +101,9 @@ namespace bbstd /// Concrete application of the Set method of object o void Set(bbtk::AtomicBlackBox* o, const bbtk::Data& d) { - bbtkDebugMessage("Data",9,"MagicBoxSetfunctor::Set()"<*mSetMethodPointer)(d); } @@ -93,21 +118,42 @@ namespace bbstd SetMethodPointerType mSetMethodPointer; }; //=========================================================================== - + +#define MAGIC_BOX_INPUT(NAME) \ + AddInputDescriptor \ + (new bbtk::AtomicBlackBoxInputDescriptor \ + (typeid(MagicBoxDescriptor), \ + #NAME,"Input data","", \ + new bbtk::AtomicBlackBoxTGetFunctor \ + (&MagicBox::bbGetInput ## NAME), \ + new MagicBoxSetFunctor (&MagicBox::bbSetInput ## NAME) ) ); //=========================================================================== BBTK_BEGIN_DESCRIBE_BLACK_BOX(MagicBox,bbtk::AtomicBlackBox); BBTK_NAME("MagicBox"); BBTK_AUTHOR("laurent.guigues@creatis.insa-lyon.fr"); BBTK_CATEGORY("misc"); - BBTK_DESCRIPTION("Takes *any kind* of data and copies it to its output. Is a magic box as any box output can be plugged into it and its output can be plugged into any other box input (dynamic type checking, see below), hence it can be put between **any** two boxes. Type matching between its output and the input of the box(es) to which it is connected is made at *run-time*. The pipeline will be executed if the data types : i) match exactly ii) can be transformed by an adaptor iii) are related pointers, i.e. if the output pointer can be upcasted (static_cast) or downcasted (dynamic_cast) to an input type pointer (see the bbtk::any output connection rule in the guide for details). Important uses of the MagicBox are : 1) performing run-time pointer cast, either upward or backward an object hierarchy 2) perform data adaptation (adaptor creation) at run-time vs. pipeline creation time."); - AddInputDescriptor + BBTK_DESCRIPTION("Takes *any kind* of data and copies it to its output. Is a magic box as any box output can be plugged into it and its output can be plugged into any other box input (dynamic type checking, see below), hence it can be put between **any** two boxes. Type matching between its output and the input of the box(es) to which it is connected is made at *run-time*. The pipeline will be executed if the data types : i) match exactly ii) can be transformed by an adaptor iii) are related pointers, i.e. if the output pointer can be upcasted (static_cast) or downcasted (dynamic_cast) to an input type pointer (see the bbtk::any output connection rule in the guide for details). Important uses of the MagicBox are : 1) performing run-time pointer cast, either upward or backward an object hierarchy 2) perform data adaptation (adaptor creation) at run-time vs. pipeline creation time. Any has now 9 more inputs and the value of the output is the value of the lower index input which has changed. This functionality is used to implement a memory which can be written by different boxes. The current value of the memory (the output) is that of the last input which has changed, i.e. has 'written' the memory. It is used for example for synchronization issues between boxes."); + MAGIC_BOX_INPUT(In) + MAGIC_BOX_INPUT(In1) + MAGIC_BOX_INPUT(In2) + MAGIC_BOX_INPUT(In3) + MAGIC_BOX_INPUT(In4) + MAGIC_BOX_INPUT(In5) + MAGIC_BOX_INPUT(In6) + MAGIC_BOX_INPUT(In7) + MAGIC_BOX_INPUT(In8) + MAGIC_BOX_INPUT(In9) + + /* + AddInputDescriptor (new bbtk::AtomicBlackBoxInputDescriptor (typeid(MagicBoxDescriptor), "In","Input data","", new bbtk::AtomicBlackBoxTGetFunctor (&MagicBox::bbGetInputIn), new MagicBoxSetFunctor (&MagicBox::bbSetInputIn) ) ); + */ AddOutputDescriptor (new bbtk::AtomicBlackBoxOutputDescriptor (typeid(MagicBoxDescriptor), diff --git a/packages/wx/bbs/appli/exampleSynchronizeWidgets.bbs b/packages/wx/bbs/appli/exampleSynchronizeWidgets.bbs new file mode 100644 index 0000000..1a46524 --- /dev/null +++ b/packages/wx/bbs/appli/exampleSynchronizeWidgets.bbs @@ -0,0 +1,36 @@ +description "Show how to synchronize multiple sliders (when one changes all the others are updated)" +author "laurent.guigues@creatis.insa-lyon.fr" +category "example" + +load wx +load std + +new Slider slider1 +new Slider slider2 +new Slider slider3 +new Slider slider4 +new LayoutLine layout +new MagicBox position + +set position.In 20 +set position.BoxProcessMode Reactive + +connect slider1.Out position.In1 +connect slider2.Out position.In2 +connect slider3.Out position.In3 +connect slider4.Out position.In4 +connect position.Out slider1.In +connect position.Out slider2.In +connect position.Out slider3.In +connect position.Out slider4.In + +connect slider1.Widget layout.Widget1 +connect slider2.Widget layout.Widget2 +connect slider3.Widget layout.Widget3 +connect slider4.Widget layout.Widget4 + +//message process 3 +//message change 1 +//message data 1 +exec layout + diff --git a/packages/wx/src/bbwxSlider.cxx b/packages/wx/src/bbwxSlider.cxx index 16192cc..adb884d 100644 --- a/packages/wx/src/bbwxSlider.cxx +++ b/packages/wx/src/bbwxSlider.cxx @@ -2,8 +2,8 @@ Program: bbtk Module: $RCSfile: bbwxSlider.cxx,v $ Language: C++ - Date: $Date: 2009/03/19 08:08:14 $ - Version: $Revision: 1.20 $ + Date: $Date: 2009/03/30 14:42:28 $ + Version: $Revision: 1.21 $ =========================================================================*/ /* --------------------------------------------------------------------- @@ -74,6 +74,7 @@ namespace bbwx void OnResolutionOfSlider(wxScrollEvent& event); // Accessors + void SetValue(int v) { mwxSlider->SetValue(v); } int GetValue() { return mwxSlider->GetValue(); } void SetRange(int min, int max); // Update the texts which display the min/max/current values of the slider @@ -412,7 +413,15 @@ namespace bbwx //-------------------------------------------------------------------------- void Slider::Process() { + bbtkDebugMessage("process",3, + "Slider "<