]> Creatis software - bbtk.git/blobdiff - kernel/src/bbtkBlackBox.cxx
*** empty log message ***
[bbtk.git] / kernel / src / bbtkBlackBox.cxx
index 8be7d01d0e3a283d659957fcf63f6284a8dbb7ba..fbf94a0f6e694b477c591038a85eeb197ac8b6d3 100644 (file)
@@ -2,8 +2,8 @@
   Program:   bbtk
   Module:    $RCSfile: bbtkBlackBox.cxx,v $
   Language:  C++
-  Date:      $Date: 2009/03/30 14:42:16 $
-  Version:   $Revision: 1.41 $
+  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>
@@ -61,7 +62,7 @@ namespace bbtk
   //=========================================================================
   
   //=========================================================================
-  void BlackBox::Deleter::Delete(Object* p)
+  int BlackBox::Deleter::Delete(Object* p)
   {
     BlackBox* b = dynamic_cast<BlackBox*>(p);
     if (!b)
@@ -77,7 +78,7 @@ 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"<<std::endl);
     
@@ -98,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;
   }
   //=========================================================================
 
@@ -105,6 +107,7 @@ namespace bbtk
   BlackBox::BlackBox(const std::string &name) 
     : 
     //    bbmStatus(MODIFIED), 
+    bbmInitialized(false),
     bbmExecuting(false),
     bbmName(name),
     bbmBoxProcessMode("Pipeline"),
@@ -126,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()<<",\""
@@ -749,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 )
@@ -766,13 +795,17 @@ namespace bbtk
                         " -> already executing : abort"<<std::endl);
        return; 
       }
+    
+    // If not initialized do it
+    bbInitializeProcessing();
 
     bbSetExecuting(true);
     bool wasExecuting = bbGlobalGetSomeBoxExecuting();
     bbGlobalSetSomeBoxExecuting(true);
-
-       this->bbCreateWidget();
-
+    
+    // Creates the window if the black box has one
+    this->bbCreateWindow();
+    
     // Updates its inputs
     IOStatus s = bbUpdateInputs();
     
@@ -809,7 +842,8 @@ namespace bbtk
                         <<std::endl);
       }
 
-         this->bbShowWidget(); 
+    // Shows the window if the black box has one
+    this->bbShowWindow(); 
 
          
     bbtkDebugMessage("process",3,