]> Creatis software - bbtk.git/commitdiff
MagicBox : support of data synchronization + various related fixes
authorguigues <guigues>
Mon, 30 Mar 2009 14:42:16 +0000 (14:42 +0000)
committerguigues <guigues>
Mon, 30 Mar 2009 14:42:16 +0000 (14:42 +0000)
kernel/src/bbtkAny.h
kernel/src/bbtkBlackBox.cxx
kernel/src/bbtkConnection.cxx
kernel/src/bbtkConnection.h
kernel/src/bbtkExecuter.cxx
packages/std/src/bbstdMagicBox.cxx
packages/std/src/bbstdMagicBox.h
packages/wx/bbs/appli/exampleSynchronizeWidgets.bbs [new file with mode: 0644]
packages/wx/src/bbwxSlider.cxx

index 9fbc9e732c088bfa6ea21d7bd1faa32626f75b50..a343e79c5632a811a66a2535a416a4856686a422 100644 (file)
@@ -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
index 0206b2924369b54871e9eba5df07b74a59de64c4..8be7d01d0e3a283d659957fcf63f6284a8dbb7ba 100644 (file)
@@ -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 '"<<p
              <<"' unknown. Possible values : "
              <<"'0'/'P'/'p'/'Pipeline'/'pipeline' | "
              <<"'1'/'A'/'a'/'Always'/'always' | "
-             <<"'2'/'R'/'r'/'Reactive'/'reactive'"<<std::endl);
+             <<"'2'/'R'/'r'/'Reactive'/'reactive'"
+             //      <<"'3'/'F'/'f'/'Flash'/'flash'"
+             <<std::endl);
   }
   //=========================================================================
   
@@ -546,6 +553,15 @@ namespace bbtk
 
     if (s==UPTODATE) bbtkError("bbSetStatusAndPropagate with status UPTODATE!");
     c->SetStatus(s);
+
+    // Flash reaction
+    /*
+    if (bbGetBoxProcessModeValue() == Flash)
+      {
+       this->bbExecute();
+      }
+    */
+
     OutputConnectorMapType::const_iterator o;  
     for ( o = bbGetOutputConnectorMap().begin(); 
          o != bbGetOutputConnectorMap().end(); ++o )                   
index bc6b3b1c001561de5335fb3311f7d027118dea5f..37c0eb6be1448122aacd7f025324e4f973e34329 100644 (file)
@@ -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 '"
-                       <<GetFullName()
-                       <<"' : '"<<from->bbGetName()<<"."<<output
+           bbtkWarning("Connection: '"<<from->bbGetName()<<"."<<output
                        <<"' is of type <"
                        <<HumanTypeName<Data>()
                        <<"> : type compatibility with '"
@@ -345,6 +343,18 @@ Connection::Connection(BlackBox::Pointer from, const std::string& output,
                     "===> Connection::RecursiveExecute() ["
                     <<GetFullName()<<"]"<<std::endl);
 
+    /*
+    // If box from already executing : nothing to do
+    if (mFrom->bbGetExecuting()) 
+      {
+       bbtkDebugMessage("process",3,
+                        " -> "<<mFrom->bbGetName()
+                        <<" already executing : abort"<<std::endl);
+       return; 
+
+      }
+    */
+
     mFrom->bbRecursiveExecute(GetThisPointer<Connection>());
 
     TransferData();
@@ -407,8 +417,14 @@ Connection::Connection(BlackBox::Pointer from, const std::string& output,
                         <<HumanTypeName(mTo->bbGetInputType(mInput))
                         <<">"<<std::endl);
        
+       // 0) If from any contents void : nothing to do 
+       if (mFrom->bbGetOutput(mOutput).type() == typeid(void)) 
+         {
+           bbtkDebugMessage("data",3,
+                            " -> Source is void : nothing to transfer!"<<std::endl);
+         }
        // 1) Test strict type matching between any content and target
-       if (mFrom->bbGetOutput(mOutput)
+       else if (mFrom->bbGetOutput(mOutput)
            .contains( mTo->bbGetInputType(mInput) ) )
          {
            bbtkDebugMessage("data",3,
index 391385abea6ff7df7fea174e5416ed70a951d40a..6c81d9e280b4b49e210828044740c8842c9f3f17 100644 (file)
@@ -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:
index 84273c0815cc85404d6c1fe180218b37f3a15241..41ca9b6f13dd52dc0731551d68d832b179b078ea 100644 (file)
@@ -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<bbtk::thing>) )&&
+        ( b->bbGetInputType(input) != typeid(std::string) ) )
       {
        BlackBox::Pointer a =
           GetFactory()->NewAdaptor(typeid(std::string),
index 0d3e476c3a1855a188eb6610f71f35584534af45..fe601be58f205e9d0c8e289d9af17f3e60265822 100644 (file)
@@ -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 $
 =========================================================================*/
 
 /* ---------------------------------------------------------------------
 
 #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,"
+                       <<GetIOStatusString(s)<<") ["
+                       <<bbGetFullName()<<"]"<<std::endl);
+   if (mCanSet)
+      {
+       if (c->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);
   
index ffd86dea3ae581cc7c9862dda5430398f4e754b4..de0e443e99d9108a7864e5898e943ad32142de56 100644 (file)
@@ -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 $
 =========================================================================*/
 
 /* ---------------------------------------------------------------------
 
 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()"<<std::endl);
+      bbtkDebugMessage("data",9,"MagicBoxSetfunctor::Set("<<
+                      bbtk::HumanTypeName(d.type())<<
+                      ")"<<std::endl);
       (((MagicBox*)o)->*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,bbtk::Data,bbtk::Data>        \
+    (&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,bbtk::Data,bbtk::Data>
     (&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 (file)
index 0000000..1a46524
--- /dev/null
@@ -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
+
index 16192ccb0dd0c74d94322d440f14057ebac73044..adb884da0dabb4f671b06ddc7342b3a3b615e805 100644 (file)
@@ -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 "<<bbGetName()<<" input="
+                    <<bbGetInputIn()<<std::endl);
+   
     bbSetOutputOut( bbGetInputIn() );
+    if (bbGetOutputWidget()!=0)
+      {
+       ((SliderWidget*)bbGetOutputWidget())->SetValue(bbGetInputIn());
+      }
   }
 
   void Slider::CreateWidget(wxWindow* parent)