]> Creatis software - bbtk.git/blobdiff - kernel/src/bbtkBlackBox.cxx
*** empty log message ***
[bbtk.git] / kernel / src / bbtkBlackBox.cxx
index 914bf145ea291edd1b8f1518cbfdec773018da0b..fbf94a0f6e694b477c591038a85eeb197ac8b6d3 100644 (file)
@@ -2,8 +2,8 @@
   Program:   bbtk
   Module:    $RCSfile: bbtkBlackBox.cxx,v $
   Language:  C++
-  Date:      $Date: 2008/12/11 09:50:35 $
-  Version:   $Revision: 1.37 $
+  Date:      $Date: 2009/05/18 10:45:40 $
+  Version:   $Revision: 1.45 $
 =========================================================================*/
 
 /* ---------------------------------------------------------------------
@@ -40,6 +40,7 @@
 
 #include "bbtkConfigurationFile.h"
 #include "bbtkWxBlackBox.h"
+#include "bbtkWx.h"
 
 #include <fstream>
 //#include <vector>
@@ -54,13 +55,14 @@ namespace bbtk
   static std::set<BlackBox::WeakPointer> bbmgExecutionList;
 
   //=========================================================================
+
   BlackBox::Deleter::Deleter()
   {
   }
   //=========================================================================
   
   //=========================================================================
-  void BlackBox::Deleter::Delete(Object* p)
+  int BlackBox::Deleter::Delete(Object* p)
   {
     BlackBox* b = dynamic_cast<BlackBox*>(p);
     if (!b)
@@ -76,9 +78,9 @@ namespace bbtk
     BlackBoxDescriptor::WeakPointer desc = b->bbGetDescriptor();
     bbtkDebugMessage("object",2,"##> BlackBox::Deleter(\""<<name<<"\") : deleting black box"<<std::endl);
     
-    b->bbDelete();
+    int refs = 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()) 
       {
@@ -97,6 +99,7 @@ namespace bbtk
        bbtkDebugMessage("object",2,"##> BlackBox::Deleter(\""<<name<<"\") : descriptor expired : nothing to do (was not held by a package or the box is a complex black box prototype)"<<std::endl);
       }
     bbtkDebugMessage("object",2,"<## BlackBox::Deleter(\""<<name<<"\")"<<std::endl);
+    return refs;
   }
   //=========================================================================
 
@@ -104,6 +107,7 @@ namespace bbtk
   BlackBox::BlackBox(const std::string &name) 
     : 
     //    bbmStatus(MODIFIED), 
+    bbmInitialized(false),
     bbmExecuting(false),
     bbmName(name),
     bbmBoxProcessMode("Pipeline"),
@@ -125,11 +129,12 @@ namespace bbtk
   BlackBox::BlackBox(BlackBox& from, const std::string &name) 
     :
     //    bbmStatus(from.bbmStatus), 
-      bbmExecuting(false),
-      bbmName(name), 
-      bbmBoxProcessMode(from.bbmBoxProcessMode),
-      bbmParent()
-
+    bbmInitialized(false),
+    bbmExecuting(false),
+    bbmName(name), 
+    bbmBoxProcessMode(from.bbmBoxProcessMode),
+    bbmParent()
+    
   {
     bbtkDebugMessage("object",4,"==> BlackBox::BlackBox("
                     <<from.bbGetFullName()<<",\""
@@ -346,7 +351,7 @@ namespace bbtk
   bool BlackBox::bbCanReact() const 
   { 
     return ( bbGlobalGetSomeBoxExecuting() 
-#ifdef _USE_WXWIDGETS_
+#ifdef USE_WXWIDGETS
             || Wx::IsSomeWindowAlive() 
 #endif
             ); 
@@ -382,11 +387,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);
   }
   //=========================================================================
   
@@ -545,6 +557,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 )                   
@@ -732,7 +753,32 @@ namespace bbtk
   }
   //=========================================================================
 
+  //=========================================================================
+  void BlackBox::bbInitializeProcessing()
+  {
+    std::cout << "INIT BEFORE TEST"<<bbGetFullName()<<std::endl;
+    if (!bbmInitialized) 
+      {
+       std::cout << "INIT "<<bbGetFullName()<<std::endl;
+       this->bbRecursiveInitializeProcessing();
+       bbmInitialized = true;
+      }
+  }
+  //=========================================================================
+
+  //=========================================================================
+  void BlackBox::bbFinalizeProcessing()
+  {
+    if (bbmInitialized) 
+      {
+       std::cout << "FINI "<<bbGetFullName()<<std::endl;
+       this->bbRecursiveFinalizeProcessing();
+       bbmInitialized = false;
+      }
+  }
+  //=========================================================================
 
+  
   //=========================================================================
   /// Main recursive processing method of the box.
   void BlackBox::bbRecursiveExecute( Connection::Pointer caller )
@@ -749,26 +795,32 @@ namespace bbtk
                         " -> already executing : abort"<<std::endl);
        return; 
       }
+    
+    // If not initialized do it
+    bbInitializeProcessing();
 
     bbSetExecuting(true);
     bool wasExecuting = bbGlobalGetSomeBoxExecuting();
     bbGlobalSetSomeBoxExecuting(true);
-
+    
+    // Creates the window if the black box has one
+    this->bbCreateWindow();
+    
     // Updates its inputs
     IOStatus s = bbUpdateInputs();
     
     if ( (s != UPTODATE) ||
         bbBoxProcessModeIsAlways() )
       {
-       // Displays the window (WxBlackbox)
-       //      bbShowWindow(caller);
+         // Displays the window (WxBlackbox)
+         //    bbShowWindow(caller);
 
-       // Actual processing (virtual)
-       this->bbProcess();
+         // Actual processing (virtual)
+         this->bbProcess();
        
        
-       // Update the I/O statuses
-       bbComputePostProcessStatus();
+         // Update the I/O statuses
+         bbComputePostProcessStatus();
       }
     else 
       {
@@ -790,6 +842,10 @@ namespace bbtk
                         <<std::endl);
       }
 
+    // Shows the window if the black box has one
+    this->bbShowWindow(); 
+
+         
     bbtkDebugMessage("process",3,
             "<= BlackBox::bbRecursiveExecute() ["
             <<bbGetFullName()<<"]"<<std::endl);