]> Creatis software - bbtk.git/blobdiff - kernel/src/bbtkBlackBox.cxx
*** empty log message ***
[bbtk.git] / kernel / src / bbtkBlackBox.cxx
index 1c980b724347e203b128f68531361b2f0ec09f6d..d2137752f2e8aee1d3084543d6c786427e001b71 100644 (file)
@@ -3,8 +3,8 @@
 Program:   bbtk
 Module:    $RCSfile: bbtkBlackBox.cxx,v $
 Language:  C++
-Date:      $Date: 2008/02/18 10:41:02 $
-Version:   $Revision: 1.4 $
+Date:      $Date: 2008/06/19 09:46:41 $
+Version:   $Revision: 1.21 $
                                                                                 
 Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
 l'Image). All rights reserved. See doc/license.txt or
@@ -35,24 +35,90 @@ PURPOSE.  See the above copyright notices for more information.
 
 namespace bbtk
 {
+
+
+  static bool bbmgSomeBoxExecuting = false;
+  static bool bbmgFreezeExecution = false;
+  static std::set<BlackBox::Pointer> bbmgExecutionList;
+
+  //=========================================================================
+  BlackBox::Deleter::Deleter()
+  {
+  }
+  //=========================================================================
+  
+  //=========================================================================
+  void BlackBox::Deleter::Delete(Object* p)
+  {
+    BlackBox* b = dynamic_cast<BlackBox*>(p);
+    if (!b)
+      {
+       bbtkInternalError("BlackBox::Deleter::Delete("<<p->GetObjectName()
+                         <<"["<<p<<"]) : "
+                         <<"dynamic cast to BlackBox* failed !");
+      }
+    std::string name = p->GetObjectName();//b->bbGetNameWithParent();
+    bbtkDebugMessage("object",2,"##> BlackBox::Deleter(\""<<name<<"\")"<<std::endl);
+
+
+    BlackBoxDescriptor::WeakPointer desc = b->bbGetDescriptor();
+    bbtkDebugMessage("object",2,"##> BlackBox::Deleter(\""<<name<<"\") : deleting black box"<<std::endl);
+    
+    b->bbDelete();
+
+    bbtkDebugMessage("object",2,"##> BlackBox::Deleter(\""<<name<<"\") : releasing descriptor ["<<desc.lock()<<"]"<<std::endl);
+    
+    if (!desc.expired()) 
+      {
+       Package::WeakPointer pack = desc.lock()->GetPackage();
+       if (!pack.expired()) 
+         {
+           Package::ReleaseBlackBoxDescriptor(pack,desc);
+         }
+       else 
+         {
+           bbtkDebugMessage("object",2,"##> BlackBox::Deleter(\""<<name<<"\") : descriptor package expired (was not held by a package and the box was the last instance)"<<std::endl);
+         }
+      }
+    else
+      {
+       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);
+  }
+  //=========================================================================
+
   //=========================================================================
   BlackBox::BlackBox(const std::string &name) 
-    : bbmName(name), bbmStatus(MODIFIED), 
-      bbmBoxProcessMode("Pipeline"),bbmParent(NULL)
+    : bbmName(name), 
+      bbmStatus(MODIFIED), 
+      bbmBoxProcessMode("Pipeline"),
+      bbmParent()
+
   {
-    bbtkDebugMessage("Kernel",7,"BlackBox::BlackBox(\""
+    bbtkDebugMessage("object",4,"==> BlackBox::BlackBox(\""
+                    <<name<<"\")"<<std::endl);
+    bbtkDebugMessage("object",4,"<== BlackBox::BlackBox(\""
                     <<name<<"\")"<<std::endl);
   }
   //=========================================================================
 
+  //=========================================================================
+  BlackBox::BlackBox(const BlackBox&)
+  {}
 
   //=========================================================================
   BlackBox::BlackBox(BlackBox& from, const std::string &name) 
     : bbmName(name), 
       bbmStatus(from.bbmStatus), 
-      bbmBoxProcessMode(from.bbmBoxProcessMode),bbmParent(NULL)
+      bbmBoxProcessMode(from.bbmBoxProcessMode),
+      bbmParent()
+
   {
-    bbtkDebugMessage("Kernel",7,"BlackBox::BlackBox("
+    bbtkDebugMessage("object",4,"==> BlackBox::BlackBox("
+                    <<from.bbGetFullName()<<",\""
+                    <<name<<"\")"<<std::endl);
+    bbtkDebugMessage("object",4,"<== BlackBox::BlackBox("
                     <<from.bbGetFullName()<<",\""
                     <<name<<"\")"<<std::endl);
   }
@@ -62,21 +128,11 @@ namespace bbtk
   //=========================================================================
   BlackBox::~BlackBox()
   {
-    //    std::cout << "EED BlackBox::~BlackBox 01 [" << bbGetName()<<"]\n";
-    bbtkDebugMessageInc("Kernel",7,"BlackBox::~BlackBox()"<<std::endl);
+    bbtkDebugMessage("object",4,"==> BlackBox::~BlackBox() ["<<bbmName
+                    <<"]"<<std::endl);
     this->bbDesallocateConnectors();
-    //printf("EED BlackBox::~BlackBox 02 \n");
-    bbtkDebugDecTab("Kernel",7);
-  }
-  //=========================================================================
-
-  //=========================================================================
-  /// Destruction method of a black box
-  void BlackBox::bbDelete()
-  {
-    bbtkDebugMessage("Kernel",5,"BlackBox::bbDelete() ["
-                    <<bbGetFullName()<<"]"<<std::endl);    
-    this->bbUserDelete();
+    bbtkDebugMessage("object",4,"<== BlackBox::~BlackBox() ["<<bbmName
+                    <<"]"<<std::endl);
   }
   //=========================================================================
 
@@ -85,16 +141,17 @@ namespace bbtk
   /// Main processing method of the box.
   void BlackBox::bbExecute(bool force)
   {
-    bbtkDebugMessageInc("Process",1,
+    bbtkDebugMessageInc("process",2,
                        "=> BlackBox::bbExecute() ["
                        <<bbGetFullName()<<"]"<<std::endl);
-
-    Wx::BeginBusyCursor();
+       wxBusyCursor wait;
+    //EED Wx::BeginBusyCursor();
 
     // If execution frozen : return
     if (bbGlobalGetFreezeExecution()) 
       {
-       bbtkDebugMessage("Process",1,
+       bbtkDebugMessage("process",2,
                         " -> FreezeExecution global flag is 'true' : abort execution"<<std::endl);
       }
 
@@ -102,11 +159,11 @@ namespace bbtk
     if (force) bbSetModifiedStatus();
 
     // Calls the main recursive update method 
-    bbBackwardUpdate(0);
+    bbBackwardUpdate(Connection::Pointer());
 
-    Wx::EndBusyCursor();
+    //EED Wx::EndBusyCursor();
 
-    bbtkDebugMessageDec("Process",1,
+    bbtkDebugMessageDec("process",2,
                        "<= BlackBox::bbExecute() ["
                        <<bbGetFullName()<<"]"<<std::endl);
   }
@@ -115,7 +172,7 @@ namespace bbtk
   //=========================================================================
   std::string BlackBox::bbGetFullName() const
   { 
-    return bbGetNameWithParent()+"<"+this->bbGetDescriptor()->GetTypeName()+">";
+    return this->bbGetNameWithParent()+"<"+this->bbGetDescriptor()->GetTypeName()+">";
   }
   //=========================================================================
      
@@ -125,9 +182,9 @@ namespace bbtk
   /// Returns the name with the name of the parent prepended if any
   std::string BlackBox::bbGetNameWithParent() const
   {
-    if (bbmParent) 
+    if (bbmParent.lock()
       {
-       return bbmParent->bbGetNameWithParent() + ":" + bbmName;
+       return bbmParent.lock()->bbGetNameWithParent() + ":" + bbmName;
       }
     else 
       {
@@ -217,7 +274,7 @@ namespace bbtk
       {                                                                        
        bbtkDebugMessage("Kernel",8,"* Allocate \""<<i->first<<"\""<<std::endl);
        bbGetInputConnectorMap()[i->second->GetName()] 
-         = new BlackBoxInputConnector(this);
+         = new BlackBoxInputConnector(GetThisPointer<BlackBox>());
       }                                                                        
     const BlackBoxDescriptor::OutputDescriptorMapType& omap 
       = bbGetDescriptor()->GetOutputDescriptorMap();                  
@@ -315,7 +372,7 @@ namespace bbtk
   /// User overloadable destruction method of a black box
   void BlackBox::bbUserDelete() 
   {   
-    bbtkDebugMessage("Process",5,
+    bbtkDebugMessage("process",5,
                     "=> BlackBox::bbUserDelete() ["
                     <<bbGetFullName()<<"]"
                     <<" : not overloaded; using standard deletion"
@@ -364,55 +421,65 @@ namespace bbtk
   ///  Signals that the BlackBox has been modified
   void BlackBox::bbSetModifiedStatus(BlackBoxInputConnector* c)
   {
-    bbtkDebugMessageInc("Process",5,
-                       "=> BlackBox::bbSetModifiedStatus("<<c<<") ["
-                       <<bbGetFullName()<<"]"<<std::endl);
-   
+    bbtkDebugMessage("modified",1,
+                    "==> BlackBox::bbSetModifiedStatus("<<c<<") ["
+                    <<bbGetFullName()<<"]"<<std::endl);
+    
     if ( (c==bbGetInputConnectorMap().find("WinHide")->second) )
-        //      && (bbCanReact()))
+      //        && (bbCanReact()))
       {
-       bbtkDebugMessage("Process",9,
+       bbtkDebugMessage("modified",2,
                         "-> Hide triggered by WinHide input change"
                         <<std::endl);
        this->bbHideWindow();
        this->bbSetStatus(MODIFIED); 
        return;
       }
+    if ( (c==bbGetInputConnectorMap().find("WinClose")->second) )
+      //        && (bbCanReact()))
+      {
+       bbtkDebugMessage("modified",2,
+                        "-> Close triggered by WinClose input change"
+                        <<std::endl);
+       this->bbHideWindow();
+       this->bbSetStatus(MODIFIED); 
+       return;
+      }
+    
     if ( ( bbBoxProcessModeIsReactive()  ||
           (c==bbGetInputConnectorMap().find("BoxExecute")->second))
         && (bbCanReact() ) )
       {
-       bbtkDebugMessage("Process",9,
+       bbtkDebugMessage("modified",2,
                         "-> Execution triggered by Reactive mode or BoxExecute input change"<<std::endl);
        this->bbSetStatus(MODIFIED); 
-        bbGlobalAddToExecutionList( this );
+        bbGlobalAddToExecutionList( GetThisPointer<BlackBox>() );
       }
     else if ( bbGetStatus() == MODIFIED ) //! this->bbIsUptodate()) 
       { 
-       bbtkDebugMessage("Process",5,"-> Already modified"<<std::endl);
-       bbtkDebugDecTab("Process",5);
+       bbtkDebugMessage("modified",2,"-> Already modified"<<std::endl);
        return;
       }
     else 
       {
-       bbtkDebugMessage("Process",5,"-> Status set to modified"<<std::endl);
-       bbtkDebugDecTab("Process",5);
+       bbtkDebugMessage("modified",2,"-> Status set to modified"<<std::endl);
        this->bbSetStatus(MODIFIED); 
       }
  
     this->bbSignalOutputModification(false);
 
-   bbtkDebugMessageDec("Process",5,
+    /* 
+  bbtkDebugMessageDec("process",5,
                        "<= BlackBox::bbSetModifiedStatus("<<c<<") ["
                        <<bbGetFullName()<<"]"<<std::endl);
+    */
   }  
   //=========================================================================
 
   //=========================================================================  
   void BlackBox::bbSignalOutputModification(bool reaction)
   {
-    bbtkDebugMessageInc("Process",5,
+    bbtkDebugMessageInc("process",5,
                        "=> BlackBox::bbSignalOutputModification() ["
                        <<bbGetFullName()<<"]"<<std::endl);
     
@@ -433,7 +500,7 @@ namespace bbtk
 
     if (reaction) bbGlobalProcessExecutionList();
 
-    bbtkDebugMessageDec("Process",5,
+    bbtkDebugMessageDec("process",5,
                        "<= BlackBox::bbSignalOutputModification() ["
                        <<bbGetFullName()<<"]"<<std::endl);
     
@@ -443,7 +510,7 @@ namespace bbtk
   void BlackBox::bbSignalOutputModification(const std::string& output,
        bool reaction)
   {
-    bbtkDebugMessageInc("Process",5,
+    bbtkDebugMessageInc("process",5,
                        "=> BlackBox::bbSignalOutputModification("
                        <<output<<") ["
                        <<bbGetFullName()<<"]"<<std::endl);
@@ -465,10 +532,10 @@ namespace bbtk
       }
   if (reaction) bbGlobalProcessExecutionList();
 
-    bbtkDebugMessageDec("Process",5,
-                       "<= BlackBox::bbSignalOutputModification("
-                       <<output<<") ["
-                       <<bbGetFullName()<<"]"<<std::endl);
+  bbtkDebugMessageDec("process",5,
+                      "<= BlackBox::bbSignalOutputModification("
+                      <<output<<") ["
+                      <<bbGetFullName()<<"]"<<std::endl);
 
   }  
   //=========================================================================   
@@ -476,7 +543,7 @@ namespace bbtk
   void BlackBox::bbSignalOutputModification(const std::vector<std::string>& output,
        bool reaction)
   {
-    bbtkDebugMessageInc("Process",5,
+    bbtkDebugMessageInc("process",5,
                        "=> BlackBox::bbSignalOutputModification(vector of outputs) ["
                        <<bbGetFullName()<<"]"<<std::endl);
     OutputConnectorMapType::iterator i;
@@ -501,7 +568,7 @@ namespace bbtk
       }
   if (reaction) bbGlobalProcessExecutionList();
 
-   bbtkDebugMessageDec("Process",5,
+   bbtkDebugMessageDec("process",5,
                       "<= BlackBox::bbSignalOutputModification(vector of outputs) ["
                        <<bbGetFullName()<<"]"<<std::endl);
 
@@ -514,13 +581,13 @@ namespace bbtk
   ///          else MODIFIED 
   IOStatus BlackBox::bbUpdateInputs(bool excludeParent)
   {
-    bbtkDebugMessageInc("Process",4,
+    bbtkDebugMessageInc("process",4,
                        "=> BlackBox::bbUpdateInputs() ["
                        <<bbGetFullName()<<"]"
                        <<std::endl);   
 
     IOStatus s = UPTODATE;
-    
+
     InputConnectorMapType::iterator i;
     for ( i = bbGetInputConnectorMap().begin(); 
          i!= bbGetInputConnectorMap().end(); ++i) 
@@ -536,7 +603,7 @@ namespace bbtk
        if (t==MODIFIED) s = MODIFIED;
       }
     
-   bbtkDebugMessageDec("Process",4,
+   bbtkDebugMessageDec("process",4,
                        "<= BlackBox::bbUpdateInputs() ["
                        <<bbGetFullName()<<"]"
                        <<std::endl);   
@@ -551,10 +618,13 @@ namespace bbtk
   /// Connects the input <name> to the connection c
   void BlackBox::bbConnectInput( const std::string& name, Connection* c)
   {
-    bbtkDebugMessageInc("Kernel",7,
-                       "BlackBox::bbConnectInput(\""<<name<<"\","<<c<<") ["
+    bbtkDebugMessage("connection",2,
+                       "==> BlackBox::bbConnectInput(\""
+                       <<name<<"\","<<c->GetFullName()<<") ["
                        <<bbGetFullName()<<"]"
                        <<std::endl);       
+
+
     InputConnectorMapType::iterator i = bbGetInputConnectorMap().find(name);
     if (i==bbGetInputConnectorMap().end())
       {
@@ -562,9 +632,13 @@ namespace bbtk
       }
     i->second->SetConnection(c);
     
+    bbtkDebugMessage("connection",2,
+                       "<== BlackBox::bbConnectInput(\""
+                       <<name<<"\","<<c->GetFullName()<<") ["
+                       <<bbGetFullName()<<"]"
+                       <<std::endl);       
     //  bbSetModifiedStatus();
 
-    bbtkDebugDecTab("Kernel",7);
   }
   //=========================================================================
 
@@ -573,10 +647,11 @@ namespace bbtk
   /// Connects the output <name> to the connection c
   void BlackBox::bbConnectOutput( const std::string& name, Connection* c)
   {
-    bbtkDebugMessageInc("Kernel",7,
-                       "BlackBox::bbConnectOutput(\""<<name<<"\","<<c<<") ["
-                       <<bbGetFullName()<<"]"<<std::endl);       
-
+    bbtkDebugMessage("connection",2,
+                    "==> BlackBox::bbConnectOutput(\""<<name<<"\","
+                    <<c->GetFullName()<<") ["
+                    <<bbGetFullName()<<"]"<<std::endl);       
+    
     OutputConnectorMapType::iterator i = bbGetOutputConnectorMap().find(name);
     if (i==bbGetOutputConnectorMap().end())
       {
@@ -584,7 +659,11 @@ namespace bbtk
       }
     i->second->SetConnection(c);
 
-    bbtkDebugDecTab("Kernel",7);
+    bbtkDebugMessage("connection",2,
+                    "<== BlackBox::bbConnectOutput(\""<<name<<"\","
+                    <<c->GetFullName()<<") ["
+                    <<bbGetFullName()<<"]"<<std::endl);       
+
   }
   //=========================================================================
 
@@ -593,11 +672,19 @@ namespace bbtk
   /// Disconnects the input <name> from the connection c
   void BlackBox::bbDisconnectInput( const std::string& name, Connection* c)
   {
-    bbtkDebugMessageInc("Kernel",7,
-                       "BlackBox::bbDisconnectInput(\""<<name
-                       <<"\","<<c<<") ["
-                       <<bbGetFullName()<<"]"
-                       <<std::endl);      
+
+    bbtkDebugMessage("connection",2,
+                    "==> BlackBox::bbDisconnectInput(\""<<name
+                    <<"\","<<c->GetFullName()<<") ["
+                    <<bbGetFullName()<<"]"
+                    <<std::endl);      
+
+    if (!c) 
+      {
+
+       bbtkDebugMessage("connection",2,"c==0"<<std::endl);     
+       return;
+      }
 
     InputConnectorMapType::iterator i = bbGetInputConnectorMap().find(name);
     if (i==bbGetInputConnectorMap().end())
@@ -606,7 +693,12 @@ namespace bbtk
       }
     i->second->UnsetConnection(c);
 
-    bbtkDebugDecTab("Kernel",7);
+    bbtkDebugMessage("connection",2,
+                    "<== BlackBox::bbDisconnectInput(\""<<name
+                    <<"\","<<c->GetFullName()<<") ["
+                    <<bbGetFullName()<<"]"
+                    <<std::endl);      
+
   }
   //=========================================================================
 
@@ -615,11 +707,17 @@ namespace bbtk
   /// Disconnects the output <name> from the connection c
   void BlackBox::bbDisconnectOutput( const std::string& name, Connection* c)
   {
-    bbtkDebugMessageInc("Kernel",7,
-                       "BlackBox::bbDisconnectOutput(\""<<name
-                       <<"\","<<c<<") ["
-                       <<bbGetFullName()<<"]"
-                       <<std::endl);       
+    bbtkDebugMessage("connection",2,
+                    "==> BlackBox::bbDisconnectOutput(\""<<name
+                    <<"\","<<c->GetFullName()<<") ["
+                    <<bbGetFullName()<<"]"
+                    <<std::endl);       
+    if (!c) 
+      {
+
+       bbtkDebugMessage("connection",2,"c==0"<<std::endl);     
+       return;
+      }
 
     OutputConnectorMapType::iterator i = bbGetOutputConnectorMap().find(name);
     if (i==bbGetOutputConnectorMap().end())
@@ -628,7 +726,11 @@ namespace bbtk
       }
     i->second->UnsetConnection(c);
 
-    bbtkDebugDecTab("Kernel",7);
+    bbtkDebugMessage("connection",2,
+                    "<== BlackBox::bbDisconnectOutput(\""<<name
+                    <<"\","<<c->GetFullName()<<") ["
+                    <<bbGetFullName()<<"]"
+                    <<std::endl);       
   } 
   //=========================================================================
  
@@ -649,28 +751,40 @@ namespace bbtk
     // Looks for the adaptor
     if (bbGetOutputType(output).name() != typeid(std::string).name() ) 
       {
-       BlackBox* a = 0;
-       try
+       // Look for factory 
+       Package::Pointer p = bbGetDescriptor()->GetPackage();
+       if ((p != 0) && ( ! p->GetFactorySet().empty() ) )
          {
-           a = NewAdaptor(  
-                          bbGetOutputType(output),
-                          typeid(std::string),
-                          "");
-         } catch (bbtk::Exception e) 
+           Factory::Pointer f = p->GetFactorySet().begin()->lock();
+           BlackBox::Pointer a;
+           try
+             {
+               a = f->NewAdaptor(  
+                                 bbGetOutputType(output),
+                                 typeid(std::string),
+                                 "");
+             } catch (bbtk::Exception e) 
+             {
+             }
+           if (a){
+             //                        bbUpdate();
+             a->bbSetInput("In",bbGetOutput(output));
+             a->bbExecute();
+             v = a->bbGetOutput("Out").unsafe_get<std::string>() ;
+           } else {
+             v="? (no adaptor found)";
+           }
+         }
+       else 
          {
+           v="? (no factory found)";
          }
-       if (a!=NULL){
-         //                    bbUpdate();
-         a->bbSetInput("In",bbGetOutput(output));
-         a->bbExecute();
-         v = a->bbGetOutput("Out").unsafe_get<std::string>() ;
-       } else {
-         v="? (no adaptor found)";
-       }
-      } else {
-      //         bbUpdate();
-      v = bbGetOutput(output).unsafe_get<std::string>() ;
-    }
+      } 
+    else 
+      {
+       //         bbUpdate();
+       v = bbGetOutput(output).unsafe_get<std::string>() ;
+      }
     return v;
   }
   //=========================================================================
@@ -682,28 +796,38 @@ namespace bbtk
     // Looks for the adaptor
     if (bbGetInputType(input) != typeid(std::string)) 
       {
-       BlackBox* a = 0;
-       try
-         {
-           a = NewAdaptor(  
-                          bbGetInputType(input),
-                          typeid(std::string),
-                          "");
-         }catch (bbtk::Exception e) 
-         {
-         }
-       if (a!=NULL)
+       // Look for factory 
+       Package::Pointer p = bbGetDescriptor()->GetPackage();
+       if ((p != 0) && ( ! p->GetFactorySet().empty() ) )
          {
-           //                  bbUpdate();
-           a->bbSetInput("In",bbGetInput(input));
-           a->bbExecute();
-           v = a->bbGetOutput("Out").unsafe_get<std::string>() ;
+           Factory::Pointer f = p->GetFactorySet().begin()->lock();
+           BlackBox::Pointer a;
+           try
+             {
+               a = f->NewAdaptor(  
+                              bbGetInputType(input),
+                              typeid(std::string),
+                              "");
+             }catch (bbtk::Exception e) 
+             {
+             }
+           if (a)
+             {
+               //                      bbUpdate();
+               a->bbSetInput("In",bbGetInput(input));
+               a->bbExecute();
+               v = a->bbGetOutput("Out").unsafe_get<std::string>() ;
+             } 
+           else 
+             {
+               v="? (no adaptor found)";
+             }
          } 
        else 
          {
-           v="? (no adaptor found)";
+           v="? (no factory found)";
          }
-      } 
+      }
     else 
       {
        v = bbGetInput(input).unsafe_get<std::string>() ;
@@ -753,7 +877,7 @@ namespace bbtk
   //=========================================================================
   /// Write Graphviz-dot description in file
   void BlackBox::bbWriteDotFileBlackBox(FILE *ff,
-                                       BlackBox *parentblackbox, 
+                                       BlackBox::Pointer parentblackbox, 
                                        int detail, int level,
                                        bool instanceOrtype,
                                        bool relative_link )
@@ -836,26 +960,26 @@ namespace bbtk
     //    std::cout  << labelStr << std::endl;
 
     // Relation Input
-    if (this!=parentblackbox){
+    if (GetThisPointer<BlackBox>()!=parentblackbox){
       for ( i = mInputConnectorMap.begin(); i != mInputConnectorMap.end(); ++i ) 
        {
          if (i->second)
            {
              Connection* con = i->second->GetConnection();
              if (con!=NULL){
-               BlackBox *a=con->GetBlackBoxFrom();
-               BlackBox *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
@@ -869,7 +993,7 @@ namespace bbtk
 
 
   //=========================================================================
-  void BlackBox::bbShowRelations(BlackBox *parentblackbox, 
+  void BlackBox::bbShowRelations(BlackBox::Pointer parentblackbox, 
                                 int detail, int level
                                 /*,Factory *factory*/ )
   {
@@ -904,9 +1028,9 @@ namespace bbtk
        std::string s("");
        Connection* con = i->second->GetConnection();
        if (con!=0){
-         s = con->GetBlackBoxFrom()->bbGetName();
+         s = con->GetOriginalBlackBoxFrom()->bbGetName();
          s += ".";
-         s += con->GetBlackBoxFromOutput();
+         s += con->GetOriginalBlackBoxFromOutput();
        }  // if con
        iconn.push_back(s);
       }
@@ -921,14 +1045,15 @@ namespace bbtk
        ovalue.push_back(bbGetOutputAsString(o->first));
        if (ovalue.back().size()>valuelmax) valuelmax = ovalue.back().size();
        std::vector<std::string> ss;
-       const std::vector<Connection*>& con = o->second->GetConnectionVector();
+       const std::vector<Connection*>& con 
+         = o->second->GetConnectionVector();
        std::vector<Connection*>::const_iterator c;
        for (c=con.begin();c!=con.end();++c) 
          {
            std::string s;
-           s = (*c)->GetBlackBoxTo()->bbGetName();
+           s = (*c)->GetOriginalBlackBoxTo()->bbGetName();
            s += ".";
-           s += (*c)->GetBlackBoxToInput();
+           s += (*c)->GetOriginalBlackBoxToInput();
            ss.push_back(s);
        }  // if con
        oconn.push_back(ss);
@@ -993,22 +1118,22 @@ namespace bbtk
   //=========================================================================
    void BlackBox::bbGlobalProcessExecutionList()
    {   
-     bbtkDebugMessageInc("Process",1,
+     bbtkDebugMessageInc("process",3,
                         "=> BlackBox::bbGlobalProcessExecutionList()"
                         <<std::endl);     
      
-     std::set<BlackBox*>::iterator i;
+     std::set<BlackBox::Pointer>::iterator i;
      for (i=bbmgExecutionList.begin();
          i!=bbmgExecutionList.end();
          ++i)
        {
-        bbtkDebugMessage("Process",2,
+        bbtkDebugMessage("process",4,
                          " -> Executing "<<(*i)->bbGetFullName()<<std::endl);
         (*i)->bbExecute(true);
        }
      
      bbmgExecutionList.clear();
-     bbtkDebugMessageDec("Process",1,
+     bbtkDebugMessageDec("process",3,
                         "<= BlackBox::bbGlobalProcessExecutionList()"
                         <<std::endl);     
      
@@ -1016,13 +1141,53 @@ namespace bbtk
    }
   //=========================================================================
 
-  //=========================================================================
-  // Static members initialization
-  bool BlackBox::bbmgSomeBoxExecuting = false;
-  bool BlackBox::bbmgFreezeExecution = false;
-  std::set<BlackBox*> BlackBox::bbmgExecutionList;
+    bool BlackBox::bbGlobalGetSomeBoxExecuting()
+       { 
+               return bbmgSomeBoxExecuting; 
+       }
+
+    void BlackBox::bbGlobalSetSomeBoxExecuting(bool b) 
+       { 
+               bbmgSomeBoxExecuting = b; 
+       }
+
+    void BlackBox::bbGlobalSetFreezeExecution(bool b) 
+       { 
+               bbmgFreezeExecution = b;
+       }
+
+    bool BlackBox::bbGlobalGetFreezeExecution() 
+       { 
+               return bbmgFreezeExecution; 
+       }
+
+  void BlackBox::bbGlobalAddToExecutionList( BlackBox::Pointer b )
+       {  
+               bbmgExecutionList.insert(b); 
+       } 
+
+
    //=========================================================================
 
+  //=========================================================================
+  void BlackBox::Check(bool recursive)
+  {
+    bbtkMessage("debug",1,"*** Checking Black Box "<<(void*)this<<" ["<<bbGetFullName()
+               <<"] ... OK"<<std::endl);
+  }
+  //=========================================================================
+
+  void BlackBox::bbUserOnShowWidget(std::string nameInput)
+  {
+         bbtk::BlackBoxInputConnector *cc;
+         cc = this->bbGetInputConnectorMap().find( nameInput.c_str() )->second;
+         if (cc->GetConnection()!=NULL) 
+         {
+                 cc->GetConnection()->GetBlackBoxFrom()->bbUserOnShow();
+         }
+  }
+
+
 
 }  // EO namespace bbtk