]> Creatis software - bbtk.git/blobdiff - kernel/src/bbtkComplexBlackBox.cxx
*** empty log message ***
[bbtk.git] / kernel / src / bbtkComplexBlackBox.cxx
index 012a03f24c743a67d2bb440c32cd45d21d3cecc0..dbd76efd197b83a0a697152a58ce75743c09934e 100644 (file)
@@ -3,8 +3,8 @@
 Program:   bbtk
 Module:    $RCSfile: bbtkComplexBlackBox.cxx,v $
 Language:  C++
-Date:      $Date: 2008/04/08 06:59:29 $
-Version:   $Revision: 1.8 $
+Date:      $Date: 2008/04/09 11:16:57 $
+Version:   $Revision: 1.9 $
                                                                                 
 Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
 l'Image). All rights reserved. See Doc/License.txt or
@@ -77,14 +77,15 @@ namespace bbtk
        bbtkDebugMessageInc("Kernel",9,"* Cloning \""<<
                            (*j)->GetFullName()<<"\""<<std::endl);
 
-       BlackBox* bbfrom = bbGetBlackBox( (*j)->GetBlackBoxFrom()->bbGetName() );
-       BlackBox* bbto = bbGetBlackBox( (*j)->GetBlackBoxTo()->bbGetName() );
+       BlackBox* bbfrom = bbGetBlackBox( (*j)->GetOriginalBlackBoxFrom()->bbGetName() );
+       BlackBox* bbto = bbGetBlackBox( (*j)->GetOriginalBlackBoxTo()->bbGetName() );
        Connection* c = mDescriptor->GetFactory()-> 
          NewConnection( bbfrom, 
-                        (*j)->GetBlackBoxFromOutput(), 
+                        (*j)->GetOriginalBlackBoxFromOutput(), 
                         bbto, 
-                        (*j)->GetBlackBoxToInput() );
+                        (*j)->GetOriginalBlackBoxToInput() );
        
+
        bbAddConnection(c);
 
        bbtkDebugDecTab("Kernel",9);
@@ -100,15 +101,15 @@ namespace bbtk
   ///  Destructor
   ComplexBlackBox::~ComplexBlackBox()
   {
-    bbtkDebugMessageInc("Kernel",9,
+    bbtkDebugMessageInc("Kernel",1,
                        "ComplexBlackBox::~ComplexBlackBox() ["
                        <<bbGetFullName()<<"]"<<std::endl);
     
-    bbtkDebugMessageInc("Kernel",9,"* Delete Connections"<<std::endl);
+    bbtkDebugMessageInc("Kernel",1,"* Delete Connections"<<std::endl);
     ConnectionListType::iterator j;
     for ( j = mConnectionList.begin(); j != mConnectionList.end(); ++j ) 
       {
-       bbtkDebugMessageInc("Kernel",9,"* Delete \""<<
+       bbtkDebugMessageInc("Kernel",1,"* Delete \""<<
                            (*j)->GetFullName()<<"\""<<std::endl);
        delete *j;
        bbtkDebugDecTab("Kernel",9);
@@ -116,21 +117,21 @@ namespace bbtk
     bbtkDebugDecTab("Kernel",9);
 
     
-    bbtkDebugMessageInc("Kernel",9,"* Delete Black Boxes"<<std::endl);
+    bbtkDebugMessageInc("Kernel",1,"* Delete Black Boxes"<<std::endl);
     BlackBoxMapType::iterator i;
     for ( i = mBlackBoxMap.begin(); i != mBlackBoxMap.end(); ++i ) 
       {
-       bbtkDebugMessageInc("Kernel",9,"* Delete \""<<i->first<<"\""<<std::endl);
+       bbtkDebugMessageInc("Kernel",1,"* Delete \""<<i->first<<"\""<<std::endl);
        i->second->bbDelete();
-       bbtkDebugDecTab("Kernel",9);
+       bbtkDebugDecTab("Kernel",1);
       }
-    bbtkDebugDecTab("Kernel",9);
-    //    bbtkDebugMessage("Kernel",9,"EO ComplexBlackBox::~ComplexBlackBox  ["
-    //              <<bbGetFullName()<<"]"<<std::endl);
-
+    bbtkDebugDecTab("Kernel",1);
+    
+    bbtkDebugMessage("Kernel",1,"EO ComplexBlackBox::~ComplexBlackBox  ["
+                    <<bbGetFullName()<<"]"<<std::endl);
     
     this->bbDesallocateConnectors();
-    bbtkDebugDecTab("Kernel",9);   
+    bbtkDebugDecTab("Kernel",1);   
   } 
   //=======================================================================
 
@@ -215,7 +216,8 @@ namespace bbtk
                        <<bbGetFullName()<<"]"<<std::endl);
     
     ComplexBlackBox* CBB = new ComplexBlackBox(*this,name);
-    
+    bbGetDescriptor()->Reference();           
+
     bbtkDebugDecTab("Kernel",9);   
 
     return CBB;
@@ -300,7 +302,8 @@ namespace bbtk
                        "ComplexBlackBox::bbBackwardUpdate("
                        <<(caller?caller->GetFullName():"0")<<") ["
                        <<bbGetFullName()<<"]"<<std::endl);
-
+    bbtkInternalError("ComplexBlackBox::bbBackwardUpdate should never be called !");
+    /*
     if (caller==0)
       {
        bbtkInternalError("ComplexBlackBox::bbBackwardUpdate called with caller=0");
@@ -336,10 +339,11 @@ namespace bbtk
        //      std::cout << "tmpout = "<<d->GetOutput()<<std::endl;
        //      caller->SetBlackBoxFromOutput(d->GetOutput());
        //
-       Connection newcaller(*caller);
-       newcaller.SetBlackBoxFromOutput(d->GetOutput());
-       IOStatus s1 = b->bbBackwardUpdate(&newcaller);
-       newcaller.Clear();
+       //Connection newcaller(*caller);
+       //newcaller.SetBlackBoxFromOutput(d->GetOutput());
+       //IOStatus s1 = b->bbBackwardUpdate(&newcaller);
+       IOStatus s1 = b->bbBackwardUpdate(caller);
+       //newcaller.Clear();
        // restore old output
        //      caller->SetBlackBoxFromOutput(oldout);
 
@@ -357,6 +361,8 @@ namespace bbtk
     bbSetExecuting(false);
 
     return s;
+    */
+    return UPTODATE;
   }
   //==================================================================
 
@@ -458,6 +464,57 @@ namespace bbtk
   }
   //==================================================================
 
+  //=========================================================================
+  /// Connects the input <name> to the connection c
+  void ComplexBlackBox::bbConnectInput( const std::string& name, Connection* c)
+  {
+    bbtkDebugMessageInc("Kernel",7,
+                       "ComplexBlackBox::bbConnectInput(\""
+                       <<name<<"\","<<c<<") ["
+                       <<bbGetFullName()<<"]"
+                       <<std::endl);       
+
+   ComplexBlackBoxInputDescriptor* d = (ComplexBlackBoxInputDescriptor*)
+      bbGetDescriptor()->GetInputDescriptor(name);
+
+   BlackBox* t = bbGetBlackBox(d->GetTarget());
+   c->SetBlackBoxTo(t);
+   c->SetBlackBoxToInput(d->GetInput());
+   t->bbConnectInput(d->GetInput(),c);
+
+   bbtkMessage("Debug",1,"ComplexBlackBox["<<bbGetFullName()<<"]::bbConnectInput : "
+              <<c->GetFullName()<<std::endl);
+
+    bbtkDebugDecTab("Kernel",7);
+  }
+  //=========================================================================
+
+
+  //=========================================================================  
+  /// Connects the output <name> to the connection c
+  void ComplexBlackBox::bbConnectOutput( const std::string& name, Connection* c)
+  {
+    bbtkDebugMessageInc("Kernel",7,
+                       "ComplexBlackBox::bbConnectOutput(\""
+                       <<name<<"\","<<c<<") ["
+                       <<bbGetFullName()<<"]"<<std::endl);       
+
+   ComplexBlackBoxOutputDescriptor* d = (ComplexBlackBoxOutputDescriptor*)
+      bbGetDescriptor()->GetOutputDescriptor(name);
+
+   BlackBox* t = bbGetBlackBox(d->GetTarget());
+   c->SetBlackBoxFrom(t);
+   c->SetBlackBoxFromOutput(d->GetOutput());
+   t->bbConnectOutput(d->GetOutput(),c);
+  
+   bbtkMessage("Debug",1,"ComplexBlackBox["<<bbGetFullName()<<"]::bbConnectOutput : "
+              <<c->GetFullName()<<std::endl);
+
+    bbtkDebugDecTab("Kernel",7);
+  }
+  //=========================================================================
+
+
   //==================================================================
   /// Adds the black box to the complex box
   void ComplexBlackBox::bbAddBlackBox( BlackBox* b)
@@ -977,4 +1034,28 @@ namespace bbtk
   }
   //=======================================================================
   */
+
+  //=======================================================================
+  void ComplexBlackBox::Check(bool recursive)
+  {
+     bbtkMessage("Debug",1,"**** Checking Complex Black Box "<<(void*)this
+                <<" ["<<bbGetFullName()<<"]"<<std::endl);
+     
+     BlackBoxMapType::const_iterator i;
+     for ( i = mBlackBoxMap.begin(); i != mBlackBoxMap.end(); ++i ) 
+       {
+        i->second->Check(recursive);
+       }
+     ConnectionListType::const_iterator j;
+     for ( j = mConnectionList.begin(); 
+          j != mConnectionList.end(); ++j ) 
+       {
+        (*j)->Check();
+       }
+     bbtkMessage("Debug",1,"**** Checking Complex Black Box "<<(void*)this
+                <<" ["<<bbGetFullName()<<"] ... OK"<<std::endl);
+  
+  }
+  //=======================================================================
+
 }