]> Creatis software - bbtk.git/blobdiff - kernel/src/bbtkBlackBox.cxx
MagicBox : support of data synchronization + various related fixes
[bbtk.git] / kernel / src / bbtkBlackBox.cxx
index 1ff72d10bdb6f49542d099ca5faf82c2fe784240..8be7d01d0e3a283d659957fcf63f6284a8dbb7ba 100644 (file)
@@ -2,8 +2,8 @@
   Program:   bbtk
   Module:    $RCSfile: bbtkBlackBox.cxx,v $
   Language:  C++
-  Date:      $Date: 2008/12/09 13:45:13 $
-  Version:   $Revision: 1.35 $
+  Date:      $Date: 2009/03/30 14:42:16 $
+  Version:   $Revision: 1.41 $
 =========================================================================*/
 
 /* ---------------------------------------------------------------------
@@ -54,6 +54,7 @@ namespace bbtk
   static std::set<BlackBox::WeakPointer> bbmgExecutionList;
 
   //=========================================================================
+
   BlackBox::Deleter::Deleter()
   {
   }
@@ -78,7 +79,7 @@ namespace bbtk
     
     b->bbDelete();
 
-    bbtkDebugMessage("object",2,"##> BlackBox::Deleter(\""<<name<<"\") : releasing descriptor ["<<desc.lock()<<"]"<<std::endl);
+    bbtkDebugMessage("object",2,"##> BlackBox::Deleter(\""<<name<<"\") : releasing descriptor"<<std::endl);
     
     if (!desc.expired()) 
       {
@@ -153,42 +154,6 @@ namespace bbtk
   //=========================================================================
 
 
-  //=========================================================================
-  /// Main processing method of the box.
-  void BlackBox::bbExecute(bool force)
-  {
-    bbtkDebugMessageInc("process",2,
-                       "=> BlackBox::bbExecute("<<(int)force<<") ["
-                       <<bbGetFullName()<<"]"<<std::endl);
-    // If already executing : return
-    if (bbGetExecuting()) 
-      {
-       bbtkDebugMessage("process",2,
-                        " -> already executing : bailing out"<<std::endl);
-       return;
-      }
-
-    // If execution frozen : return
-    if (bbGlobalGetFreezeExecution()) 
-      {
-       bbtkDebugMessage("process",2,
-                        " -> FreezeExecution global flag is 'true' : abort execution"<<std::endl);
-      }
-
-    BBTK_BUSY_CURSOR;
-
-    // If force is true then update is triggered even if the box is UPTODATE
-    //    if (force) bbSetModifiedStatus();
-
-    // Calls the main recursive update method 
-    bbBackwardUpdate(Connection::Pointer());
-
-    bbtkDebugMessageDec("process",2,
-                       "<= BlackBox::bbExecute() ["
-                       <<bbGetFullName()<<"]"<<std::endl);
-  }
-  //=========================================================================
 
   //=========================================================================
   std::string BlackBox::bbGetFullName() const
@@ -382,7 +347,7 @@ namespace bbtk
   bool BlackBox::bbCanReact() const 
   { 
     return ( bbGlobalGetSomeBoxExecuting() 
-#ifdef _USE_WXWIDGETS_
+#ifdef USE_WXWIDGETS
             || Wx::IsSomeWindowAlive() 
 #endif
             ); 
@@ -418,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);
   }
   //=========================================================================
   
@@ -444,16 +416,18 @@ namespace bbtk
 
 
   //=========================================================================
-  void BlackBox::AddChangeObserver(const std::string& output_name
+  void BlackBox::bbAddOutputObserver(const std::string& output
                                   OutputChangeCallbackType f)
   {
+    bbGetOutputConnector(output).AddChangeObserver(f);
   }  
   //=========================================================================
 
   //=========================================================================
-  void BlackBox::RemoveChangeObserver(const std::string& output_name, 
+  void BlackBox::bbRemoveOutputObserver(const std::string& output_name, 
                                      OutputChangeCallbackType f)
   {
+    bbtkError("BlackBox::RemoveChangeObserver NOT IMPLEMENTED");
   }
   //=========================================================================
 
@@ -579,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 )                   
@@ -617,10 +600,15 @@ namespace bbtk
     for ( i  = bbGetOutputConnectorMap().begin(); 
          i != bbGetOutputConnectorMap().end(); ++i) 
       {
-       if (i->second->GetStatus()==UPTODATE) 
-         {
+       //      std::cout << "Stat = "
+       //<<GetIOStatusString(i->second->GetStatus())
+       //                <<std::endl;
+       // LG : CANNOT SIGNAL ONLY WHEN UPTODATE 
+       // See bbtkSampleOutputObserver
+       //      if (i->second->GetStatus()==UPTODATE) 
+       //        {
            i->second->SignalChange(GetThisPointer<BlackBox>(),i->first); 
-         }
+           //    }
       } 
 
     if (reaction) bbGlobalProcessExecutionList();
@@ -649,8 +637,8 @@ namespace bbtk
          bbtkError("BlackBox["<<bbGetFullName()<<"]::bbSignalOutputModification("<<output<<") : unknown output");
        }
 
-    if (i->second->GetStatus()==UPTODATE) 
-      {
+    //    if (i->second->GetStatus()==UPTODATE) 
+    //      {
        i->second->SignalChange(GetThisPointer<BlackBox>(),i->first); 
        // Has to notify the output "BoxChange" also
        if (output != "BoxChange") 
@@ -662,7 +650,7 @@ namespace bbtk
              }
          }
        if (reaction) bbGlobalProcessExecutionList();
-      }
+       //      }
 
     bbtkDebugMessageDec("change",5,
                        "<= BlackBox::bbSignalOutputModification("
@@ -691,23 +679,22 @@ namespace bbtk
          {
            bbtkError("BlackBox["<<bbGetFullName()<<"]::bbSignalOutputModification("<<*o<<") : unknown output");
          }
-       // Already OUTOFDATE : noting to do
-       if (i->second->GetStatus()==UPTODATE)
-         {
+
+       //      if (i->second->GetStatus()==UPTODATE)
+       //        {
            i->second->SignalChange(GetThisPointer<BlackBox>(),i->first); 
            changed = true;
-         }
+           //  }
       }
     // Has to notify the output "BoxChange" also
     i = bbGetOutputConnectorMap().find("BoxChange");
     if ( changed && (i != bbGetOutputConnectorMap().end())) 
       {
-       // Already OUTOFDATE : noting to do
-       if (i->second->GetStatus()==UPTODATE) 
-         {
+       // if (i->second->GetStatus()==UPTODATE) 
+       //        {
            i->second->SignalChange(GetThisPointer<BlackBox>(),i->first); 
            if (reaction) bbGlobalProcessExecutionList();
-         }
+           //  }
       }
 
     bbtkDebugMessageDec("change",5,
@@ -717,9 +704,133 @@ namespace bbtk
   }  
   //=========================================================================   
 
+
+
+
+
+
+
+  //=========================================================================
+  /// Main processing method of the box.
+  void BlackBox::bbExecute(bool force)
+  {
+    bbtkDebugMessageInc("process",2,
+                       "=> BlackBox::bbExecute("<<(int)force<<") ["
+                       <<bbGetFullName()<<"]"<<std::endl);
+    // If already executing : return
+    /*
+    if (bbGetExecuting()) 
+      {
+       bbtkDebugMessage("process",2,
+                        " -> already executing : abort"<<std::endl);
+       return;
+      }
+    */
+
+    // If execution frozen : return
+    if (bbGlobalGetFreezeExecution()) 
+      {
+       bbtkDebugMessage("process",2,
+                        " -> FreezeExecution global flag is 'true' : abort execution"<<std::endl);
+      }
+
+    BBTK_BUSY_CURSOR;
+
+    // If force is true then update is triggered even if the box is UPTODATE
+    //    if (force) bbSetModifiedStatus();
+
+    // Calls the main recursive execution method 
+    bbRecursiveExecute(Connection::Pointer());
+
+    bbtkDebugMessageDec("process",2,
+                       "<= BlackBox::bbExecute() ["
+                       <<bbGetFullName()<<"]"<<std::endl);
+  }
+  //=========================================================================
+
+
+  //=========================================================================
+  /// Main recursive processing method of the box.
+  void BlackBox::bbRecursiveExecute( Connection::Pointer caller )
+  {
+    bbtkDebugMessageInc("process",3,
+                       "=> BlackBox::bbRecursiveExecute("
+                       <<(caller?caller->GetFullName():"0")<<") ["
+                       <<bbGetFullName()<<"]"<<std::endl);
+
+    // If already executing : return
+    if (bbGetExecuting()) 
+      {
+       bbtkDebugMessage("process",3,
+                        " -> already executing : abort"<<std::endl);
+       return; 
+      }
+
+    bbSetExecuting(true);
+    bool wasExecuting = bbGlobalGetSomeBoxExecuting();
+    bbGlobalSetSomeBoxExecuting(true);
+
+       this->bbCreateWidget();
+
+    // Updates its inputs
+    IOStatus s = bbUpdateInputs();
+    
+    if ( (s != UPTODATE) ||
+        bbBoxProcessModeIsAlways() )
+      {
+         // Displays the window (WxBlackbox)
+         //    bbShowWindow(caller);
+
+         // Actual processing (virtual)
+         this->bbProcess();
+       
+       
+         // Update the I/O statuses
+         bbComputePostProcessStatus();
+      }
+    else 
+      {
+       // Test output status...
+       OutputConnectorMapType::iterator o;
+       for ( o = bbGetOutputConnectorMap().begin(); 
+             o!= bbGetOutputConnectorMap().end(); ++o) 
+         {
+           if (o->second->GetStatus() != UPTODATE)
+             {
+               bbtkWarning("BlackBox::bbRecursiveExecute ["
+                           <<bbGetFullName()
+                           <<"] : all inputs are Up-to-date but output '"
+                           <<o->first<<"' is Out-of-date ???");
+             }
+         }
+       
+        bbtkDebugMessage("process",3," -> Up-to-date : nothing to do"
+                        <<std::endl);
+      }
+
+         this->bbShowWidget(); 
+
+         
+    bbtkDebugMessage("process",3,
+            "<= BlackBox::bbRecursiveExecute() ["
+            <<bbGetFullName()<<"]"<<std::endl);
+
+    bbSetExecuting(false);
+    bbGlobalSetSomeBoxExecuting(wasExecuting);
+
+    return; 
+
+  }
+  //=========================================================================
+  
+   
+
+
+
   //=========================================================================
   /// Updates the BlackBox inputs
-  /// Calls BackwardUpdate on all BlackBoxInputConnector
+  /// Calls RecursiveExecute on all BlackBoxInputConnector
   /// \returns The maximum of final IOStatus after each input update
   IOStatus BlackBox::bbUpdateInputs()
   {
@@ -745,7 +856,7 @@ namespace bbtk
                            <<" status before update = '"
                            <<GetIOStatusString(i->second->GetStatus())
                            <<"'"<<std::endl);
-       i->second->BackwardUpdate();
+       i->second->RecursiveExecute();
        IOStatus t = i->second->GetStatus();
        if (t > s) s = t;
        bbtkDebugMessageDec("change",2,