]> Creatis software - bbtk.git/blobdiff - kernel/src/bbtkComplexBlackBox.cxx
*** empty log message ***
[bbtk.git] / kernel / src / bbtkComplexBlackBox.cxx
index 56fdb05c09bb5055c5d4aa9dabcec1ef4ee54c20..f692435687233e6a03f5e17e4d707929ef96f449 100644 (file)
@@ -3,8 +3,8 @@
 Program:   bbtk
 Module:    $RCSfile: bbtkComplexBlackBox.cxx,v $
 Language:  C++
-Date:      $Date: 2008/04/21 11:41:56 $
-Version:   $Revision: 1.11 $
+Date:      $Date: 2008/04/24 11:49:59 $
+Version:   $Revision: 1.19 $
                                                                                 
 Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
 l'Image). All rights reserved. See Doc/License.txt or
@@ -79,13 +79,17 @@ namespace bbtk
                        <<from.bbGetName()<<"\",\""
                        <<name<<"\")"<<std::endl);
     bbtkDebugMessage("object",4,"  * Cloning Black Boxes"<<std::endl);
+
+    // We have to make the shared_ptr on this because it is used 
+    // in bbUnsafeAddBlackBox !
+    MakeBlackBoxPointer(this,true);
+
     BlackBoxMapType::const_iterator i;
     for ( i = from.mBlackBoxMap.begin(); i != from.mBlackBoxMap.end(); ++i ) 
       {
        bbtkDebugMessageInc("object",5,"    * Cloning \""<<i->first<<"\""<<std::endl);
        BlackBox::Pointer B = i->second->bbClone(i->second->bbGetName());
        bbUnsafeAddBlackBox(B);
-       
       }
    
     bbtkDebugMessage("object",4,"  * Cloning Connections"<<std::endl);
@@ -132,16 +136,9 @@ namespace bbtk
                     " -> Releasing boxes"<<std::endl);
     mBlackBoxMap.clear();
 
-    /*    
     //    Clear();
     this->bbDesallocateConnectors();
-    if (mLockedDescriptor) 
-      {
-       bbtkMessage("object",3," --> Releasing descriptor"<<std::endl);
-       mLockedDescriptor.reset();                                      
-       if (!mDescriptor.expired()) BlackBoxDescriptor::Release(mDescriptor);
-      }
-    */
+
     bbtkDebugMessage("object",3,
                     "<== ComplexBlackBox::~ComplexBlackBox() ["
                     <<bbGetName()<<"]"<<std::endl);
@@ -157,7 +154,7 @@ namespace bbtk
                        "ComplexBlackBox::bbAllocateConnectors() ["
                        <<bbGetFullName()<<"]"
                        <<std::endl);   
-    /*
+    
     // Input connectors
     const BlackBoxDescriptor::InputDescriptorMapType& imap 
       = bbGetDescriptor()->GetInputDescriptorMap(); 
@@ -175,7 +172,6 @@ namespace bbtk
          ->bbGetInputConnectorMap()[ d->GetInput() ];
        
        bbGetInputConnectorMap()[i->second->GetName()] = c;
-//new BlackBoxInputConnector();
       }                                                                        
 
     // Output connectors
@@ -195,11 +191,8 @@ namespace bbtk
          ->bbGetOutputConnectorMap()[ d->GetOutput() ];
 
        bbGetOutputConnectorMap()[o->second->GetName()] = c;
-       //new BlackBoxOutputConnector();
       }
-
-*/
-
+    
     bbtkDebugDecTab("Kernel",8);  
   }
   //=========================================================================
@@ -217,11 +210,9 @@ namespace bbtk
     // but by the internal boxes. Hence **DO NOT** desallocate !
     // just clear the maps to avoid that 
     // BlackBox::bbDesallocateConnectors delete the connectors
-    /*
-   bbGetInputConnectorMap().clear();
+    bbGetInputConnectorMap().clear();
     bbGetOutputConnectorMap().clear();
-    */
+
     bbtkDebugDecTab("Kernel",8);  
 
   }
@@ -244,8 +235,8 @@ namespace bbtk
   /// Executes the box so that its outputs are up-to-date on exit
   void ComplexBlackBox::bbExecute(bool force)
   {
-    bbtkDebugMessageInc("Process",1,
-                       "ComplexBlackBox::bbExecute() ["
+    bbtkDebugMessageInc("process",2,
+                       "=> ComplexBlackBox::bbExecute() ["
                        <<bbGetFullName()<<"]"<<std::endl);
 
 
@@ -259,7 +250,7 @@ namespace bbtk
             i!=mExecutionList.end();
             ++i) 
          {
-           bbtkDebugMessage("Process",2," -> Executing '"<<*i<<"'"<<std::endl);
+           bbtkDebugMessage("process",3," -> Executing '"<<*i<<"'"<<std::endl);
            mBlackBoxMap[*i]->bbExecute(force);
          }
       }
@@ -274,8 +265,6 @@ namespace bbtk
 
     Wx::EndBusyCursor();
     
-
-    bbtkDebugDecTab("Process",1);
     
   }
   //==================================================================
@@ -283,15 +272,17 @@ namespace bbtk
   //==================================================================
   void ComplexBlackBox::bbSetModifiedStatus(BlackBoxInputConnector* c)
   {
-    bbtkDebugMessage("Process",3,
-                       "ComplexBlackBox::bbSetModifiedStatus("
+    bbtkDebugMessage("modified",1,
+                       "==> ComplexBlackBox::bbSetModifiedStatus("
                     <<c<<") ["<<bbGetFullName()<<"]"<<std::endl);
 
     c->GetBlackBox()->bbSetModifiedStatus(c);
 
-    bbtkDebugMessage("Process",3,
-                    "EO ComplexBlackBox::bbSetModifiedStatus("
+    /*
+    bbtkDebugMessage("modified",1,
+                    "<== ComplexBlackBox::bbSetModifiedStatus("
                     <<c<<") ["<<bbGetFullName()<<"]"<<std::endl);
+    */
   }
   //==================================================================
 
@@ -313,8 +304,8 @@ namespace bbtk
   //==================================================================
   IOStatus ComplexBlackBox::bbBackwardUpdate(Connection::Pointer caller)
   {
-    bbtkDebugMessageInc("Process",1,
-                       "ComplexBlackBox::bbBackwardUpdate("
+    bbtkDebugMessageInc("process",3,
+                       "==> ComplexBlackBox::bbBackwardUpdate("
                        <<(caller?caller->GetFullName():"0")<<") ["
                        <<bbGetFullName()<<"]"<<std::endl);
     //    bbtkInternalError("ComplexBlackBox::bbBackwardUpdate should never be called !");
@@ -324,12 +315,14 @@ namespace bbtk
        bbtkInternalError("ComplexBlackBox::bbBackwardUpdate called with caller=0");
       }
 
-    if (bbGetExecuting()) 
-      {
-       bbtkWarning(bbGetFullName()<<" : Cyclic execution stopped");
-       return UPTODATE;
-      }
-    bbSetExecuting(true);
+    /*
+    std::cout << "CBB BUP : "<<caller->GetBlackBoxFrom()->bbGetFullName()
+             <<"."<<caller->GetBlackBoxFromOutput()<<"----"
+             <<caller->GetOriginalBlackBoxFrom()->bbGetFullName()
+             <<"."<<caller->GetOriginalBlackBoxFromOutput()<<std::endl;
+    */
+      
+
 
     IOStatus s = UPTODATE;
     const BlackBoxDescriptor::OutputDescriptorMapType& omap 
@@ -344,7 +337,7 @@ namespace bbtk
        // Get the internal box 
        BlackBox::Pointer b = bbUnsafeGetBlackBox ( d->GetTarget() );
        // Calls BackwardUpdate on it
-       bbtkDebugMessageInc("Process",2,"Internal box connected to output : "<<d->GetTarget()<<std::endl);
+       bbtkDebugMessageInc("process",4,"Internal box connected to output : "<<d->GetTarget()<<std::endl);
        // Because internal box can also be a complex box we have to 
        // temporarily change the connection BlackBoxFromOutput to the 
        // mapped one
@@ -365,19 +358,14 @@ namespace bbtk
        // ??? STATUS OF CBBs ???
        // ??? Here it is only the final status of the boxes connected to the output 
        if (s1==MODIFIED) s=MODIFIED;
-       bbtkDebugDecTab("Process",2);
       }
     else 
       {
        bbtkError("Connection '"<<caller->GetFullName()<<"' does not point to a valid output of the complex box !");
       }
-    bbtkDebugDecTab("Process",1);
-
-    bbSetExecuting(false);
 
     return s;
     
-    //    return UPTODATE;
   }
   //==================================================================
 
@@ -481,52 +469,64 @@ namespace bbtk
 
   //=========================================================================
   /// Connects the input <name> to the connection c
-  void ComplexBlackBox::bbConnectInput( const std::string& name, Connection::Pointer c)
+  void ComplexBlackBox::bbConnectInput( const std::string& name, Connection* c)
   {
-    bbtkDebugMessageInc("Kernel",7,
-                       "ComplexBlackBox::bbConnectInput(\""
-                       <<name<<"\","<<c<<") ["
-                       <<bbGetFullName()<<"]"
-                       <<std::endl);       
-
+    bbtkDebugMessage("connection",2,
+                    "==> ComplexBlackBox::bbConnectInput(\""
+                    <<name<<"\","<<c->GetFullName()<<") ["
+                    <<bbGetFullName()<<"]"
+                    <<std::endl);       
+    
    ComplexBlackBoxInputDescriptor* d = (ComplexBlackBoxInputDescriptor*)
       bbGetDescriptor()->GetInputDescriptor(name);
 
+
    BlackBox::Pointer t = bbGetBlackBox(d->GetTarget());
+
+   bbtkDebugMessage("connection",2," - Target = "<<d->GetTarget()<<" = "<<t->bbGetFullName()<<std::endl);
+
    c->SetBlackBoxTo(t);
    c->SetBlackBoxToInput(d->GetInput());
-   t->bbConnectInput(d->GetInput(),c);
 
-   bbtkMessage("Debug",1,"ComplexBlackBox["<<bbGetFullName()<<"]::bbConnectInput : "
-              <<c->GetFullName()<<std::endl);
+   bbtkDebugMessage("connection",2," - New conn = "<<c->GetFullName()<<std::endl);
+   t->bbConnectInput(d->GetInput(),c);
 
-    bbtkDebugDecTab("Kernel",7);
+   bbtkDebugMessage("connection",2,
+                    "<== ComplexBlackBox::bbConnectInput(\""
+                    <<name<<"\","<<c->GetFullName()<<") ["
+                    <<bbGetFullName()<<"]"
+                    <<std::endl);       
   }
   //=========================================================================
 
 
   //=========================================================================  
   /// Connects the output <name> to the connection c
-  void ComplexBlackBox::bbConnectOutput( const std::string& name, Connection::Pointer c)
+  void ComplexBlackBox::bbConnectOutput( const std::string& name, Connection* c)
   {
-    bbtkDebugMessageInc("Kernel",7,
-                       "ComplexBlackBox::bbConnectOutput(\""
-                       <<name<<"\","<<c<<") ["
-                       <<bbGetFullName()<<"]"<<std::endl);       
+    bbtkDebugMessage("connection",2,
+                    "==> ComplexBlackBox::bbConnectOutput(\""
+                    <<name<<"\","<<c->GetFullName()<<") ["
+                    <<bbGetFullName()<<"]"<<std::endl);       
 
    ComplexBlackBoxOutputDescriptor* d = (ComplexBlackBoxOutputDescriptor*)
       bbGetDescriptor()->GetOutputDescriptor(name);
 
    BlackBox::Pointer t = bbGetBlackBox(d->GetTarget());
+  bbtkDebugMessage("connection",2," - Target = "<<d->GetTarget()<<" = "<<t->bbGetFullName()<<std::endl);
 
    c->SetBlackBoxFrom(t);
    c->SetBlackBoxFromOutput(d->GetOutput());
+
+   bbtkDebugMessage("connection",2," - New conn = "<<c->GetFullName()<<std::endl);
+
    t->bbConnectOutput(d->GetOutput(),c);
   
-   bbtkMessage("Debug",5,"ComplexBlackBox["<<bbGetFullName()<<"]::bbConnectOutput : "
-              <<c->GetFullName()<<std::endl);
-
-    bbtkDebugDecTab("Kernel",7);
+    bbtkDebugMessage("connection",2,
+                    "<== ComplexBlackBox::bbConnectOutput(\""
+                    <<name<<"\","<<c->GetFullName()<<") ["
+                    <<bbGetFullName()<<"]"<<std::endl);       
   }
   //=========================================================================
 
@@ -590,7 +590,7 @@ namespace bbtk
        for ( j = mConnectionList.begin(); 
              j != mConnectionList.end(); ++j ) 
          {
-           //(*j)->Check();
+           (*j)->Check();
          }
       }
     if (p.use_count()!=1) 
@@ -1032,21 +1032,21 @@ namespace bbtk
        {
          if (ii->second)
            {
-             Connection::Pointer con = ii->second->GetConnection();
+             Connection* con = ii->second->GetConnection();
              if (con!=NULL){
-               BlackBox::Pointer a=con->GetBlackBoxFrom();
-               BlackBox::Pointer b=con->GetBlackBoxTo();
+               BlackBox::Pointer a=con->GetOriginalBlackBoxFrom();
+               BlackBox::Pointer b=con->GetOriginalBlackBoxTo();
                fprintf(ff,"  ");
                a->bbWriteDotInputOutputName(ff,false,detail,level);
                if (detail==1)
                  {
-                   fprintf(ff,":%s",con->GetBlackBoxFromOutput().c_str());
+                   fprintf(ff,":%s",con->GetOriginalBlackBoxFromOutput().c_str());
                  }
                fprintf(ff,"->");
                b->bbWriteDotInputOutputName(ff,true,detail,level);
                if (detail==1)
                  {
-                   fprintf(ff,":%s",con->GetBlackBoxToInput().c_str());
+                   fprintf(ff,":%s",con->GetOriginalBlackBoxToInput().c_str());
                  }
                fprintf(ff,"%s\n",";");
              } // if con
@@ -1080,7 +1080,7 @@ namespace bbtk
   //=======================================================================
   void ComplexBlackBox::Check(bool recursive)
   {
-     bbtkMessage("Debug",1,"**** Checking Complex Black Box "<<(void*)this
+     bbtkMessage("debug",1,"**** Checking Complex Black Box "<<(void*)this
                 <<" ["<<bbGetFullName()<<"]"<<std::endl);
      
      BlackBoxMapType::const_iterator i;
@@ -1092,9 +1092,9 @@ namespace bbtk
      for ( j = mConnectionList.begin(); 
           j != mConnectionList.end(); ++j ) 
        {
-        //(*j)->Check();
+        (*j)->Check();
        }
-     bbtkMessage("Debug",1,"**** Checking Complex Black Box "<<(void*)this
+     bbtkMessage("debug",1,"**** Checking Complex Black Box "<<(void*)this
                 <<" ["<<bbGetFullName()<<"] ... OK"<<std::endl);
   
   }