]> Creatis software - bbtk.git/blobdiff - kernel/src/bbtkBlackBox.cxx
bbAlways vs Always (to avoid troubles with X11 at compile time)
[bbtk.git] / kernel / src / bbtkBlackBox.cxx
index 795d8d490e6ac45e6425f081e6308d37108782ec..35bda120cdf1aebc80a2d43cdc83e8dcecc1e9cf 100644 (file)
@@ -2,8 +2,8 @@
   Program:   bbtk
   Module:    $RCSfile: bbtkBlackBox.cxx,v $
   Language:  C++
-  Date:      $Date: 2009/05/28 08:12:05 $
-  Version:   $Revision: 1.46 $
+  Date:      $Date: 2011/03/03 14:33:13 $
+  Version:   $Revision: 1.51 $
 =========================================================================*/
 
 /* ---------------------------------------------------------------------
@@ -48,8 +48,6 @@
 
 namespace bbtk
 {
-
-
   static bool bbmgSomeBoxExecuting = false;
   static bool bbmgFreezeExecution = false;
   static std::set<BlackBox::WeakPointer> bbmgExecutionList;
@@ -114,6 +112,10 @@ namespace bbtk
     bbmParent()
     
   {
+         //JCP 02-11-09
+        // bbmBoxProcessMode = "Pipeline";     
+//std::cout<<"JCP BlackBox::BlackBox(const std::string &name) name=" <<name
+//               <<"bbmBoxProcessMode="<<bbmBoxProcessMode<<std::endl;
     bbtkBlackBoxDebugMessage("object",4,"==> BlackBox::BlackBox(\""
                     <<name<<"\")"<<std::endl);
     bbtkBlackBoxDebugMessage("object",4,"<== BlackBox::BlackBox(\""
@@ -136,6 +138,10 @@ namespace bbtk
     bbmParent()
     
   {
+         //JCP 02-11-09
+         //bbmBoxProcessMode = from.bbmBoxProcessMode;
+         //std::cout<<"JCP BlackBox::BlackBox(const std::string &name) name=" <<name
+               //  <<"bbmBoxProcessMode="<<bbmBoxProcessMode<<std::endl;
     bbtkBlackBoxDebugMessage("object",4,"==> BlackBox::BlackBox("
                     <<from.bbGetFullName()<<",\""
                     <<name<<"\")"<<std::endl);
@@ -169,7 +175,6 @@ namespace bbtk
 
 
   //=========================================================================
-  /// Returns the name with the name of the parent prepended if any
   std::string BlackBox::bbGetNameWithParent() const
   {
     if (bbmParent.lock()) 
@@ -184,7 +189,6 @@ namespace bbtk
   //=========================================================================
 
   //=========================================================================
-  /// Prints the Help on the BlackBox type 
   void BlackBox::bbGetHelp(bool full) const
   {
     bbGetDescriptor()->GetHelp(full); 
@@ -193,7 +197,6 @@ namespace bbtk
 
 
   //=========================================================================
-  /// Returns true if the UserBlackBox has an input of name name
   bool BlackBox::bbHasInput(const std::string& name) const
   {
     bbtkBlackBoxDebugMessage("kernel",8,
@@ -209,7 +212,6 @@ namespace bbtk
 
 
   //=========================================================================  
-  /// Returns true if the UserBlackBox has an output of name name
   bool BlackBox::bbHasOutput(const std::string& name) const
   {
     bbtkBlackBoxDebugMessage("kernel",8,"BlackBox::bbHasOutput(\""
@@ -224,7 +226,6 @@ namespace bbtk
 
 
   //=========================================================================  
-  ///  Gets the output type of a given name
   TypeInfo BlackBox::bbGetOutputType( const std::string &name ) const 
   {
     bbtkBlackBoxDebugMessage("kernel",8,
@@ -238,7 +239,6 @@ namespace bbtk
   //=========================================================================
 
   //=========================================================================
-  ///  Gets the input type of a given name
   TypeInfo BlackBox::bbGetInputType( const std::string &name ) const
   {
     bbtkBlackBoxDebugMessage("kernel",8,
@@ -253,7 +253,6 @@ namespace bbtk
 
 
   //=========================================================================
-  /// Allocates the i/o connectors of the black box
   void BlackBox::bbAllocateConnectors()
   {  
     bbtkBlackBoxDebugMessage("kernel",8,
@@ -280,13 +279,11 @@ namespace bbtk
        bbGetOutputConnectorMap()[o->second->GetName()] 
          = new BlackBoxOutputConnector(GetThisPointer<BlackBox>());
       }
-
   }
   //=========================================================================
 
 
   //=========================================================================
-  /// Desallocates the i/o connectors of the black box
   void BlackBox::bbDesallocateConnectors()
   {
     bbtkBlackBoxDebugMessage("kernel",8,
@@ -308,14 +305,12 @@ namespace bbtk
        delete (o->second);
       }                                                                        
    
-    bbtkDebugDecTab("kernel",8);  
-
+    bbtkDebugDecTab("kernel",8);
   }
   //=========================================================================
 
 
   //=========================================================================
-  /// Copies the input / output values from another box
   void BlackBox::bbCopyIOValues(BlackBox& from)
   {
     bbtkBlackBoxDebugMessage("kernel",1,
@@ -346,7 +341,6 @@ namespace bbtk
       }
 
     bbtkDebugDecTab("kernel",9);
-
   }
   //=========================================================================
 
@@ -359,38 +353,26 @@ namespace bbtk
 #ifdef USE_WXWIDGETS
             || Wx::IsSomeWindowAlive() 
 #endif
-            ); 
+            );
   }
   //=========================================================================
 
 
 
-  //=========================================================================
-  /// User overloadable destruction method of a black box
-  void BlackBox::bbUserDelete() 
-  {   
-    bbtkBlackBoxDebugMessage("process",5,
-                            "=> BlackBox::bbUserDelete()"
-                            <<" : not overloaded; using standard deletion"
-                            <<std::endl);
-    delete this;
-  }
-  //=========================================================================
-
-
   //=========================================================================
   BlackBox::BoxProcessModeValue BlackBox::bbGetBoxProcessModeValue() const
   {
     const std::string& p = bbmBoxProcessMode;
     if ( (p == "0") ||
         (p == "P") || (p == "p") ||
-        (p == "Pipeline") || (p == "pipeline") ) return Pipeline;
+        (p == "Pipeline") || (p == "pipeline") ) return bbPipeline;
     if ( (p == "1") ||
         (p == "A") || (p == "a") ||
-        (p == "Always") || (p == "always") ) return Always;
+        (p == "Always") || (p == "always") ) return bbAlways;
     if ( (p == "2") ||
         (p == "R") || (p == "r") ||
-        (p == "Reactive") || (p == "reactive") ) return Reactive;
+        (p == "Reactive") || (p == "reactive") ) 
+               return bbReactive;
     /*
     if ( (p == "3") ||
         (p == "F") || (p == "f") ||
@@ -409,14 +391,14 @@ namespace bbtk
   //=========================================================================
   bool  BlackBox::bbBoxProcessModeIsReactive() const
   {
-    return (bbGetBoxProcessModeValue() == Reactive);
+    return (bbGetBoxProcessModeValue() == BlackBox::Reactive);
   }
   //=========================================================================
 
   //=========================================================================
   bool  BlackBox::bbBoxProcessModeIsAlways() const
   {
-    return (bbGetBoxProcessModeValue() == Always);
+    return (bbGetBoxProcessModeValue() == BlackBox::Always);
   }
   //=========================================================================
 
@@ -440,117 +422,7 @@ namespace bbtk
   //=========================================================================
 
 
-  /*
   //=========================================================================
-  ///  Sets the ChangeTime of input 
-  void BlackBox::bbSetInputChangeTime(BlackBoxInputConnector* c, 
-                                     const ChangeTime& t)
-  {
-    bbtkBlackBoxDebugMessage("change",1,
-                    "==> BlackBox::bbSetInputChangeTime("<<c<<","<<t<<") ["
-                    <<bbGetFullName()<<"]"<<std::endl);
-    
-    // If new time is greater than old one
-    if ( c->SetChangeTime(t) ) 
-      {
-       bool was_up_to_date = bbIsUpToDate();
-       // If new time is greater than the old max time of inputs
-       if ( mMaxInputChangeTime.Set(t) ) 
-         {
-           // If the box turned out-of-date
-           if ( was_up_to_date && bbIsOutOfDate() )
-             {
-               // 
-               if ( ( bbBoxProcessModeIsReactive()  ||
-                      (c==bbGetInputConnectorMap().find("BoxExecute")->second))
-                    && (bbCanReact() ) )
-                 {
-                   bbtkBlackBoxDebugMessage("change",2,
-                                    "an input of "
-                                    <<bbGetFullName()
-                                    <<" changed and box is in Reactive mode or BoxExecute input changed : adding it to the global execution list"
-                                    <<std::endl);
-                   bbGlobalAddToExecutionList( GetThisPointer<BlackBox>() );
-                 }
-               // Have to propagate the modification to aval boxes
-               OutputConnectorMapType::iterator i;
-               for (i = bbGetOutputConnectorMap().begin();
-                    i != bbGetOutputConnectorMap().end();
-                    ++i)
-                 {
-                   i->second->SetChangeTime(t);
-                 }
-               // update the MinOutputChangeTime
-               mMinOutputChangeTime.Set(t);
-             }
-         }
-      }
-  }
-  //=========================================================================
-
- //=========================================================================
-  ///  Sets the ChangeTime of output 
-  void BlackBox::bbSetOutputChangeTime(BlackBoxOutputConnector* c, 
-                                      const ChangeTime& t)
-  {
-    bbtkBlackBoxDebugMessage("change",1,
-                    "==> BlackBox::bbSetOutputChangeTime("<<c<<","<<t<<") ["
-                    <<bbGetFullName()<<"]"<<std::endl);
-    
-    //ChangeTime old = 
-    c->SetChangeTime(t);
-    // c->GetChangeTime() = t;
-    //    bbUpdateMinOutputChangeTime(t);
-    // propagate
-    
-  }
-  //=========================================================================
-  */
-
-  /*
-  //=========================================================================
-  void BlackBox::bbUpdateMaxInputChangeTime(const ChangeTime& t)
-  {    
-
-    
-    if ( t > mMaxInputChangeTime ) 
-      {
-       mMaxInputChangeTime = t;
-       if ( mMinOutputChangeTime > mMaxInputChangeTime )
-         {
-           
-         }
-      }
-    
-  }
-  //=========================================================================
-
-  //=========================================================================
-  void bbUpdateMinOutputChangeTime(const ChangeTime& t)
-  {
-    ChangeTime old = mMinOutputChangeTime;
-    mMinOutputChangeTime = MAXLONG;
-    OutputConnectorMapType::iterator i;
-    for (i = bbGetOutputConnectorMap.begin();
-        i != bbGetOutputConnectorMap.end();
-        ++i)
-      {
-       if (i->second->GetChangeTime() < mMinOutputChangeTime)
-         mMinOutputChangeTime = i->second->GetChangeTime();
-      }
-    if ( mMinOutputChangeTime < old )
-      {
-      }
-   
-  }
-  //=========================================================================
-  */
-
-  //=========================================================================
-  /// Signals that the BlackBox has been modified through 
-  /// the input connector c
-  /// and propagates it downward
-  /// ** NOT USER INTENDED **
   void BlackBox::bbSetStatusAndPropagate(BlackBoxInputConnector* c,
                                         IOStatus s)
   {
@@ -579,7 +451,7 @@ namespace bbtk
            o->second->SetStatus(OUTOFDATE);
            o->second->SignalChange(GetThisPointer<BlackBox>(),o->first); 
          }
-      }                                                                        
+       }                                                               
     
     if ( ( bbBoxProcessModeIsReactive()  ||
           (c==bbGetInputConnectorMap().find("BoxExecute")->second))
@@ -603,7 +475,7 @@ namespace bbtk
                             "=> BlackBox::bbSignalOutputModification("
                             <<reaction<<")"
                             <<"]"<<std::endl);
-    
+
     OutputConnectorMapType::iterator i;
     for ( i  = bbGetOutputConnectorMap().begin(); 
          i != bbGetOutputConnectorMap().end(); ++i) 
@@ -624,7 +496,6 @@ namespace bbtk
     bbtkBlackBoxDebugMessage("change",5,
                             "<= BlackBox::bbSignalOutputModification()"
                             <<std::endl);
-    
   }  
   //=========================================================================   
   //=========================================================================  
@@ -664,7 +535,6 @@ namespace bbtk
                             "<= BlackBox::bbSignalOutputModification("
                             <<output<<")"
                             <<std::endl);
-    
   }  
   //=========================================================================   
   //=========================================================================  
@@ -708,7 +578,6 @@ namespace bbtk
     bbtkBlackBoxDebugMessage("change",5,
                             "<= BlackBox::bbSignalOutputModification(vector of outputs)"
                             <<std::endl);
-
   }  
   //=========================================================================   
 
@@ -785,7 +654,6 @@ namespace bbtk
 
   
   //=========================================================================
-  /// Main recursive processing method of the box.
   void BlackBox::bbRecursiveExecute( Connection::Pointer caller )
   {
     bbtkBlackBoxDebugMessage("process",3,
@@ -857,8 +725,7 @@ namespace bbtk
     bbSetExecuting(false);
     bbGlobalSetSomeBoxExecuting(wasExecuting);
 
-    return; 
-
+    return;
   }
   //=========================================================================
   
@@ -867,9 +734,6 @@ namespace bbtk
 
 
   //=========================================================================
-  /// Updates the BlackBox inputs
-  /// Calls RecursiveExecute on all BlackBoxInputConnector
-  /// \returns The maximum of final IOStatus after each input update
   IOStatus BlackBox::bbUpdateInputs()
   {
     bbtkBlackBoxDebugMessage("process",4,
@@ -904,16 +768,13 @@ namespace bbtk
     
     bbtkBlackBoxDebugMessage("process",4,
                        "<= BlackBox::bbUpdateInputs()"
-                       <<std::endl);   
-    
-    
+                       <<std::endl);
     return s;
   }
   //=========================================================================
 
   //==================================================================
-  /// Computes the final IOStatus of inputs and outputs after processing
-  void BlackBox::bbComputePostProcessStatus()
+   void BlackBox::bbComputePostProcessStatus()
   {
     bbtkBlackBoxDebugMessage("process",4,
                        "=> BlackBox::bbComputePostProcessStatus()"
@@ -951,13 +812,11 @@ namespace bbtk
 
     bbtkBlackBoxDebugMessage("process",4,
                        "<= BlackBox::bbComputePostProcessStatus()"
-                       <<std::endl);   
-
+                       <<std::endl);
   }
   //==================================================================
 
   //=========================================================================
-  /// Connects the input <name> to the connection c
   void BlackBox::bbConnectInput( const std::string& name, Connection* c)
   {
     bbtkBlackBoxDebugMessage("connection",2,
@@ -965,7 +824,6 @@ namespace bbtk
                        <<name<<"\","<<c->GetFullName()<<")"
                        <<std::endl);       
 
-
     InputConnectorMapType::iterator i = bbGetInputConnectorMap().find(name);
     if (i==bbGetInputConnectorMap().end())
       {
@@ -974,25 +832,23 @@ namespace bbtk
     i->second->SetConnection(c);
     // The input *MUST* be set OUTOFDATE to update its input on next execution
     bbSetStatusAndPropagate(i->second,OUTOFDATE);
-    
+
     bbtkBlackBoxDebugMessage("connection",2,
                        "<== BlackBox::bbConnectInput(\""
                        <<name<<"\","<<c->GetFullName()<<")"
-                       <<std::endl);       
-
+                       <<std::endl);
   }
   //=========================================================================
 
 
   //=========================================================================  
-  /// Connects the output <name> to the connection c
   void BlackBox::bbConnectOutput( const std::string& name, Connection* c)
   {
     bbtkBlackBoxDebugMessage("connection",2,
                             "==> BlackBox::bbConnectOutput(\""<<name<<"\","
                             <<c->GetFullName()<<")"
                             <<std::endl);       
-    
+
     OutputConnectorMapType::iterator i = bbGetOutputConnectorMap().find(name);
     if (i==bbGetOutputConnectorMap().end())
       {
@@ -1003,22 +859,19 @@ namespace bbtk
     bbtkBlackBoxDebugMessage("connection",2,
                             "<== BlackBox::bbConnectOutput(\""<<name<<"\","
                             <<c->GetFullName()<<")"
-                            <<std::endl);       
-
+                            <<std::endl);
   }
   //=========================================================================
 
 
   //=========================================================================
-  /// Disconnects the input <name> from the connection c
-  void BlackBox::bbDisconnectInput( const std::string& name, Connection* c)
+   void BlackBox::bbDisconnectInput( const std::string& name, Connection* c)
   {
 
     bbtkBlackBoxDebugMessage("connection",2,
                     "==> BlackBox::bbDisconnectInput(\""<<name
                     <<"\","<<c->GetFullName()<<")"
-                    <<std::endl);      
-
+                    <<std::endl);
     if (!c) 
       {
 
@@ -1043,8 +896,7 @@ namespace bbtk
 
 
   //=========================================================================
-  /// Disconnects the output <name> from the connection c
-  void BlackBox::bbDisconnectOutput( const std::string& name, Connection* c)
+   void BlackBox::bbDisconnectOutput( const std::string& name, Connection* c)
   {
     bbtkBlackBoxDebugMessage("connection",2,
                     "==> BlackBox::bbDisconnectOutput(\""<<name
@@ -1072,8 +924,28 @@ namespace bbtk
   //=========================================================================
  
 
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
   //=========================================================================
-  /// Virtual
   void BlackBox::bbWriteDotInputOutputName(FILE *ff,bool inputoutput,int detail, int level)
   {
     fprintf(ff,"%s%p",bbGetTypeName().c_str(),this);
@@ -1330,35 +1202,35 @@ namespace bbtk
 
 
   //=========================================================================
-  void BlackBox::bbShowRelations(BlackBox::Pointer parentblackbox, 
+  void BlackBox::bbPrintHelp(BlackBox::Pointer parentblackbox, 
                                 int detail, int level
                                 /*,Factory *factory*/ )
   {
      
     if (this->bbGetDescriptor()->GetPackage()) 
       {
-       bbtkBlackBoxMessage("Help",1,"Black Box '"<<bbGetName()<<"' <"<<
+       bbtkBlackBoxMessage("help",1,"Black Box '"<<bbGetName()<<"' <"<<
                    this->bbGetDescriptor()->GetPackage()->GetName()
                    <<"::"<<this->bbGetDescriptor()->GetTypeName()<<">"<<std::endl);
       }
     else 
       {
-       bbtkBlackBoxMessage("Help",1,"Black Box <::"<<this->bbGetDescriptor()->GetTypeName()<<">"<<std::endl);
+       bbtkBlackBoxMessage("help",1,"Black Box <::"<<this->bbGetDescriptor()->GetTypeName()<<">"<<std::endl);
       }
     /*
     if (bbIsUpToDate())
       {
-       bbtkBlackBoxMessage("Help",1,"Up-to-date ["<<mMaxInputChangeTime<<","
+       bbtkBlackBoxMessage("help",1,"Up-to-date ["<<mMaxInputChangeTime<<","
                    <<mMinOutputChangeTime<<"]"<<std::endl);
       }
     else 
       {
-       bbtkBlackBoxMessage("Help",1,"Out-of-date ["<<mMaxInputChangeTime<<","
+       bbtkBlackBoxMessage("help",1,"Out-of-date ["<<mMaxInputChangeTime<<","
                    <<mMinOutputChangeTime<<"]"<<std::endl);
       }
     */
-    //    bbtkBlackBoxMessage("Help",1," "<<GetDescription()<<std::endl);
-    //    bbtkBlackBoxMessage("Help",1," By : "<<GetAuthor()<<std::endl);
+    //    bbtkBlackBoxMessage("help",1," "<<GetDescription()<<std::endl);
+    //    bbtkBlackBoxMessage("help",1," By : "<<GetAuthor()<<std::endl);
 
     std::vector<std::string> iname;
     std::vector<std::string> ivalue;
@@ -1413,9 +1285,9 @@ namespace bbtk
       }
 
     if (iname.size()) 
-      bbtkBlackBoxMessage("Help",1," * Inputs : "<<std::endl);
+      bbtkBlackBoxMessage("help",1," * Inputs : "<<std::endl);
     else 
-      bbtkBlackBoxMessage("Help",1," * No inputs"<<std::endl);
+      bbtkBlackBoxMessage("help",1," * No inputs"<<std::endl);
 
     std::vector<std::string>::iterator i1,i2,i3,i4;
     for (i1=iname.begin(),i2=ivalue.begin(),i3=iconn.begin(),i4=istatus.begin();
@@ -1429,17 +1301,17 @@ namespace bbtk
        value += "'";
        value.append(1+valuelmax-value.size(),' ');
        if (i3->size()) 
-         bbtkBlackBoxMessage("Help",1,"    '"<<name<<" = '"<<value<<" <-- '"
+         bbtkBlackBoxMessage("help",1,"    '"<<name<<" = '"<<value<<" <-- '"
                      <<*i3<<"'");
        else 
-         bbtkBlackBoxMessage("Help",1,"    '"<<name<<" = '"<<value);
-       bbtkBlackBoxMessage("Help",1," ["<<*i4<<"]"<<std::endl);
+         bbtkBlackBoxMessage("help",1,"    '"<<name<<" = '"<<value);
+       bbtkBlackBoxMessage("help",1," ["<<*i4<<"]"<<std::endl);
       }
 
     if (oname.size()) 
-      bbtkBlackBoxMessage("Help",1," * Outputs : "<<std::endl);
+      bbtkBlackBoxMessage("help",1," * Outputs : "<<std::endl);
     else 
-      bbtkBlackBoxMessage("Help",1," * No outputs"<<std::endl);
+      bbtkBlackBoxMessage("help",1," * No outputs"<<std::endl);
 
     std::vector<std::vector<std::string> >::iterator i5;
 
@@ -1454,22 +1326,39 @@ namespace bbtk
        value += "'";
        value.append(1+valuelmax-value.size(),' ');
        if (!(*i5).size())
-         bbtkBlackBoxMessage("Help",1,"    '"<<name<<" = '"<<value);
+         bbtkBlackBoxMessage("help",1,"    '"<<name<<" = '"<<value);
        else 
          {
            std::string pref = "    '"+name+" = '"+value;
            for (i3=i5->begin();i3!=i5->end();++i3)
              {
-               bbtkBlackBoxMessage("Help",1,pref<<" --> '"<<*i3<<"'");
+               bbtkBlackBoxMessage("help",1,pref<<" --> '"<<*i3<<"'");
                pref.replace(0,pref.size(),pref.size(),' ');
              }
          }
-       bbtkBlackBoxMessage("Help",1," ["<<*i4<<"]"<<std::endl);
+       bbtkBlackBoxMessage("help",1," ["<<*i4<<"]"<<std::endl);
       }
 
    }
   //=========================================================================
 
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
   static bool bbmgGlobalProcessingExecutionList = false;
 
   //=========================================================================