]> Creatis software - bbtk.git/blobdiff - kernel/src/bbtkComplexBlackBox.cxx
#3512 clean bbs2 python version
[bbtk.git] / kernel / src / bbtkComplexBlackBox.cxx
index f692435687233e6a03f5e17e4d707929ef96f449..c07ba9f383b74ef805b56f208243c17ce8aadb51 100644 (file)
@@ -1,29 +1,48 @@
+/*
+ # ---------------------------------------------------------------------
+ #
+ # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
+ #                        pour la SantÈ)
+ # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
+ # Previous Authors : Laurent Guigues, Jean-Pierre Roux
+ # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
+ #
+ #  This software is governed by the CeCILL-B license under French law and
+ #  abiding by the rules of distribution of free software. You can  use,
+ #  modify and/ or redistribute the software under the terms of the CeCILL-B
+ #  license as circulated by CEA, CNRS and INRIA at the following URL
+ #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
+ #  or in the file LICENSE.txt.
+ #
+ #  As a counterpart to the access to the source code and  rights to copy,
+ #  modify and redistribute granted by the license, users are provided only
+ #  with a limited warranty  and the software's author,  the holder of the
+ #  economic rights,  and the successive licensors  have only  limited
+ #  liability.
+ #
+ #  The fact that you are presently reading this means that you have had
+ #  knowledge of the CeCILL-B license and that you accept its terms.
+ # ------------------------------------------------------------------------ */
+
+
 /*=========================================================================
-                                                                                
-Program:   bbtk
-Module:    $RCSfile: bbtkComplexBlackBox.cxx,v $
-Language:  C++
-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
-http://www.creatis.insa-lyon.fr/Public/bbtk/License.html for details.
-                                                                                
-This software is distributed WITHOUT ANY WARRANTY; without even
-the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
-PURPOSE.  See the above copyright notices for more information.
-                                                                               
+  Program:   bbtk
+  Module:    $RCSfile: bbtkComplexBlackBox.cxx,v $
+  Language:  C++
+  Date:      $Date: 2012/11/16 08:49:01 $
+  Version:   $Revision: 1.33 $
 =========================================================================*/
 
 
+
 /**
  *  \file 
  *  \brief class bbtk::ComplexBlackBox : user defined complex black boxes
  */
 #include "bbtkComplexBlackBox.h"
-#include "bbtkBlackBoxDescriptor.h"
-#include "bbtkFactory.h"
+#include "bbtkWx.h"
+//#include "bbtkBlackBoxDescriptor.h"
+//#include "bbtkFactory.h"
 #include "bbtkConfigurationFile.h"
 
 namespace bbtk
@@ -34,12 +53,9 @@ namespace bbtk
   ComplexBlackBox::Pointer ComplexBlackBox::New(const std::string& name,
                                                ComplexBlackBoxDescriptor::Pointer desc)
   {
-    bbtkDebugMessage("object",1,"##> ComplexBlackBox::New('"<<name<<"','"<<
-                    desc->GetTypeName()<<"')" <<bbtkendl);
-    ComplexBlackBox::Pointer p = 
-      MakeBlackBoxPointer(new ComplexBlackBox(name,desc));
-    bbtkDebugMessage("object",2,"<## ComplexBlackBox::New('"<<name<<"','"<<
-                    desc->GetTypeName()<<"')" <<bbtkendl);
+    bbtkDebugMessage("object",1,"##> ComplexBlackBox::New('"<<name<<"','"<< desc->GetTypeName()<<"')" <<bbtkendl);
+    ComplexBlackBox::Pointer p = MakeBlackBoxPointer(new ComplexBlackBox(name,desc));
+    bbtkDebugMessage("object",2,"<## ComplexBlackBox::New('"<<name<<"','"<< desc->GetTypeName()<<"')" <<bbtkendl);
     return p;
   }
   //==========================================================================
@@ -53,12 +69,12 @@ namespace bbtk
     mLockedDescriptor(desc),
     mDescriptor(desc)
   {
-    bbtkDebugMessage("object",3,
-                    "##> ComplexBlackBox::ComplexBlackBox(\""
+    bbtkBlackBoxDebugMessage("object",3,
+                    "##> ComplexBlackBox(\""
                     <<name<<"\")"<<std::endl);
     bbAllocateConnectors();
-    bbtkDebugMessage("object",3,
-                    "<## ComplexBlackBox::ComplexBlackBox(\""
+    bbtkBlackBoxDebugMessage("object",3,
+                    "<## ComplexBlackBox(\""
                     <<name<<"\")"<<std::endl);
   }
   //=======================================================================
@@ -74,11 +90,11 @@ namespace bbtk
       mDescriptor(from.mDescriptor),
      mExecutionList(from.mExecutionList)    
   {
-    bbtkDebugMessage("object",3,
-                       "##> ComplexBlackBox::ComplexBlackBox(\""
+    bbtkBlackBoxDebugMessage("object",3,
+                       "##> ComplexBlackBox(\""
                        <<from.bbGetName()<<"\",\""
                        <<name<<"\")"<<std::endl);
-    bbtkDebugMessage("object",4,"  * Cloning Black Boxes"<<std::endl);
+    bbtkBlackBoxDebugMessage("object",4,"  * Cloning Black Boxes"<<std::endl);
 
     // We have to make the shared_ptr on this because it is used 
     // in bbUnsafeAddBlackBox !
@@ -87,16 +103,16 @@ namespace bbtk
     BlackBoxMapType::const_iterator i;
     for ( i = from.mBlackBoxMap.begin(); i != from.mBlackBoxMap.end(); ++i ) 
       {
-       bbtkDebugMessageInc("object",5,"    * Cloning \""<<i->first<<"\""<<std::endl);
+       bbtkBlackBoxDebugMessage("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);
+    bbtkBlackBoxDebugMessage("object",4,"  * Cloning Connections"<<std::endl);
     ConnectionListType::const_iterator j;
     for ( j = from.mConnectionList.begin(); j != from.mConnectionList.end(); ++j ) 
       {
-       bbtkDebugMessage("object",5,"    * Cloning \""<<
+       bbtkBlackBoxDebugMessage("object",5,"    * Cloning \""<<
                         (*j)->GetFullName()<<"\""<<std::endl);
 
        BlackBox::Pointer bbfrom = bbGetBlackBox( (*j)->GetOriginalBlackBoxFrom()->bbGetName() );
@@ -114,8 +130,8 @@ namespace bbtk
       }
 
     bbAllocateConnectors();
-    bbtkDebugMessage("object",3,
-                       "<## ComplexBlackBox::ComplexBlackBox(\""
+    bbtkBlackBoxDebugMessage("object",3,
+                       "<## ComplexBlackBox(\""
                        <<from.bbGetName()<<"\",\""
                        <<name<<"\")"<<std::endl);
   }
@@ -125,34 +141,47 @@ namespace bbtk
   ///  Destructor
   ComplexBlackBox::~ComplexBlackBox()
   {
-    bbtkDebugMessage("object",3,
-                    "==> ComplexBlackBox::~ComplexBlackBox() ["
-                    <<bbGetName()<<"]"<<std::endl);
+    bbtkBlackBoxDebugMessage("object",3,
+                            "==> ~ComplexBlackBox()"
+                            <<std::endl);
+    
+    Clear();
+    this->bbDesallocateConnectors();
 
-    bbtkDebugMessage("object",4,
+    bbtkBlackBoxDebugMessage("object",3,
+                            "<== ~ComplexBlackBox()"
+                            <<std::endl);
+  } 
+  //=======================================================================
+
+  //======================================================================= 
+  ///  Clear
+  void ComplexBlackBox::Clear()
+  {
+    bbtkBlackBoxDebugMessage("object",3,
+                    "==> ComplexBlackBox::Clear()"
+                    <<std::endl);
+
+    bbtkBlackBoxDebugMessage("object",4,
                     " -> Releasing connections"<<std::endl);
     mConnectionList.clear();
-    bbtkDebugMessage("object",4,
+    bbtkBlackBoxDebugMessage("object",4,
                     " -> Releasing boxes"<<std::endl);
     mBlackBoxMap.clear();
 
-    //    Clear();
-    this->bbDesallocateConnectors();
-
-    bbtkDebugMessage("object",3,
-                    "<== ComplexBlackBox::~ComplexBlackBox() ["
-                    <<bbGetName()<<"]"<<std::endl);
+    bbtkBlackBoxDebugMessage("object",3,
+                    "<== ComplexBlackBox::Clear()"
+                            <<std::endl);
   } 
   //=======================================================================
 
   //=========================================================================
   /// Allocates the i/o connectors of the black box
   void ComplexBlackBox::bbAllocateConnectors()
   {  
-    bbtkDebugMessageInc("Kernel",8,
-                       "ComplexBlackBox::bbAllocateConnectors() ["
-                       <<bbGetFullName()<<"]"
+    bbtkBlackBoxDebugMessage("kernel",8,
+                       "==> ComplexBlackBox::bbAllocateConnectors()"
                        <<std::endl);   
     
     // Input connectors
@@ -161,7 +190,7 @@ namespace bbtk
     BlackBoxDescriptor::InputDescriptorMapType::const_iterator i;      
     for ( i = imap.begin(); i != imap.end(); ++i )                     
       {                                                                        
-       bbtkDebugMessage("Kernel",8,"* Allocate \""<<i->first<<"\""<<std::endl);
+       bbtkBlackBoxDebugMessage("kernel",8,"* Allocate \""<<i->first<<"\""<<std::endl);
        // Redirect the connector to the internal box connector
        // Cast the BBInputDescriptor into a ComplexBBInputDescriptor
        ComplexBlackBoxInputDescriptor* d = 
@@ -180,7 +209,7 @@ namespace bbtk
     BlackBoxDescriptor::OutputDescriptorMapType::const_iterator o; 
     for ( o = omap.begin(); o != omap.end(); ++o )
       {                                                        
-       bbtkDebugMessage("Kernel",8,"* Allocate \""<<o->first<<"\""<<std::endl);
+       bbtkBlackBoxDebugMessage("kernel",8,"* Allocate \""<<o->first<<"\""<<std::endl);
        // Redirect the connector to the internal box connector
        // Cast the BBOutputDescriptor into a ComplexBBOutputDescriptor
        ComplexBlackBoxOutputDescriptor* d = 
@@ -192,9 +221,10 @@ namespace bbtk
 
        bbGetOutputConnectorMap()[o->second->GetName()] = c;
       }
-    
-    bbtkDebugDecTab("Kernel",8);  
-  }
+   bbtkBlackBoxDebugMessage("kernel",8,
+                       "<== ComplexBlackBox::bbAllocateConnectors()"
+                       <<std::endl);   
+   }
   //=========================================================================
 
 
@@ -202,8 +232,8 @@ namespace bbtk
   /// Desallocates the i/o connectors of the black box
   void ComplexBlackBox::bbDesallocateConnectors()
   {
-    bbtkDebugMessageInc("Kernel",8,
-                       "ComplexBlackBox::DesallocateConnectors()"
+    bbtkBlackBoxDebugMessage("kernel",8,
+                       "==> ComplexBlackBox::DesallocateConnectors()"
                        <<std::endl);                                   
 
     // The connectors have not been allocated by the complex box 
@@ -212,8 +242,11 @@ namespace bbtk
     // BlackBox::bbDesallocateConnectors delete the connectors
     bbGetInputConnectorMap().clear();
     bbGetOutputConnectorMap().clear();
-
-    bbtkDebugDecTab("Kernel",8);  
+    
+    bbtkBlackBoxDebugMessage("kernel",8,
+                            "<== ComplexBlackBox::DesallocateConnectors()"
+                            <<std::endl);                                      
+    
 
   }
   //=========================================================================
@@ -221,12 +254,15 @@ namespace bbtk
   //=======================================================================
   BlackBox::Pointer ComplexBlackBox::bbClone(const std::string& name)
   {
-    bbtkDebugMessageInc("Kernel",9,
-                       "ComplexBlackBox::bbClone(\""<<name<<"\") ["
-                       <<bbGetFullName()<<"]"<<std::endl);
+    bbtkBlackBoxDebugMessage("kernel",9,
+                       "==> ComplexBlackBox::bbClone(\""<<name<<"\")"
+                            <<std::endl);
     
     ComplexBlackBox* CBB = new ComplexBlackBox(*this,name);
-    return MakeBlackBoxPointer(CBB);
+    bbtkBlackBoxDebugMessage("kernel",9,
+                            "<== ComplexBlackBox::bbClone(\""<<name<<"\")"
+                            <<std::endl);
+     return MakeBlackBoxPointer(CBB);
   }
   //=======================================================================
 
@@ -235,12 +271,12 @@ namespace bbtk
   /// Executes the box so that its outputs are up-to-date on exit
   void ComplexBlackBox::bbExecute(bool force)
   {
-    bbtkDebugMessageInc("process",2,
-                       "=> ComplexBlackBox::bbExecute() ["
-                       <<bbGetFullName()<<"]"<<std::endl);
-
-
-    Wx::BeginBusyCursor();
+    bbtkBlackBoxDebugMessage("process",2,
+                            "**> ComplexBlackBox::bbExecute()"
+                            <<std::endl);
+    
+    
+    Wx::BusyCursor wait;
     
     if (mExecutionList.size() != 0) 
       {
@@ -250,7 +286,7 @@ namespace bbtk
             i!=mExecutionList.end();
             ++i) 
          {
-           bbtkDebugMessage("process",3," -> Executing '"<<*i<<"'"<<std::endl);
+           bbtkBlackBoxDebugMessage("process",3," -> Executing '"<<*i<<"'"<<std::endl);
            mBlackBoxMap[*i]->bbExecute(force);
          }
       }
@@ -262,109 +298,23 @@ namespace bbtk
            i->second->bbExecute(force);
          }
       } 
-
-    Wx::EndBusyCursor();
+    bbtkBlackBoxDebugMessage("process",2,
+                            "<** ComplexBlackBox::bbExecute()"
+                            <<std::endl);
     
-    
-  }
-  //==================================================================
-
-  //==================================================================
-  void ComplexBlackBox::bbSetModifiedStatus(BlackBoxInputConnector* c)
-  {
-    bbtkDebugMessage("modified",1,
-                       "==> ComplexBlackBox::bbSetModifiedStatus("
-                    <<c<<") ["<<bbGetFullName()<<"]"<<std::endl);
-
-    c->GetBlackBox()->bbSetModifiedStatus(c);
-
-    /*
-    bbtkDebugMessage("modified",1,
-                    "<== ComplexBlackBox::bbSetModifiedStatus("
-                    <<c<<") ["<<bbGetFullName()<<"]"<<std::endl);
-    */
   }
   //==================================================================
 
   //==================================================================
   void ComplexBlackBox::bbAddToExecutionList( const std::string& name )
   {
-        bbtkDebugMessageInc("Kernel",9,
+    bbtkBlackBoxDebugMessage("kernel",9,
                        "ComplexBlackBox::bbAddToExecutionList(\""
-                       <<name<<"\") ["
-                       <<bbGetFullName()<<"]"<<std::endl);
-
-       mExecutionList.push_back( name );
-
-     bbtkDebugDecTab("Kernel",9);   
-
-  }
-  //==================================================================
-
-  //==================================================================
-  IOStatus ComplexBlackBox::bbBackwardUpdate(Connection::Pointer caller)
-  {
-    bbtkDebugMessageInc("process",3,
-                       "==> ComplexBlackBox::bbBackwardUpdate("
-                       <<(caller?caller->GetFullName():"0")<<") ["
-                       <<bbGetFullName()<<"]"<<std::endl);
-    //    bbtkInternalError("ComplexBlackBox::bbBackwardUpdate should never be called !");
+                       <<name<<"\")"
+                            <<std::endl);
+    
+    mExecutionList.push_back( name );
     
-    if (caller==0)
-      {
-       bbtkInternalError("ComplexBlackBox::bbBackwardUpdate called with caller=0");
-      }
-
-    /*
-    std::cout << "CBB BUP : "<<caller->GetBlackBoxFrom()->bbGetFullName()
-             <<"."<<caller->GetBlackBoxFromOutput()<<"----"
-             <<caller->GetOriginalBlackBoxFrom()->bbGetFullName()
-             <<"."<<caller->GetOriginalBlackBoxFromOutput()<<std::endl;
-    */
-      
-
-
-    IOStatus s = UPTODATE;
-    const BlackBoxDescriptor::OutputDescriptorMapType& omap 
-      = bbGetDescriptor()->GetOutputDescriptorMap(); 
-    BlackBoxDescriptor::OutputDescriptorMapType::const_iterator i 
-      = omap.find(caller->GetBlackBoxFromOutput());
-    if (i!=omap.end())
-      {        
-       // Cast the BBOutputDescriptor into a ComplexBBOutputDescriptor
-       ComplexBlackBoxOutputDescriptor* d = 
-         (ComplexBlackBoxOutputDescriptor*)i->second;
-       // Get the internal box 
-       BlackBox::Pointer b = bbUnsafeGetBlackBox ( d->GetTarget() );
-       // Calls BackwardUpdate on it
-       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
-       
-       //      std::string oldout = caller->GetBlackBoxFromOutput();
-       //      std::cout << "oldout = "<<oldout<<std::endl;
-       //      std::cout << "tmpout = "<<d->GetOutput()<<std::endl;
-       //      caller->SetBlackBoxFromOutput(d->GetOutput());
-       //
-       //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);
-
-       // ??? STATUS OF CBBs ???
-       // ??? Here it is only the final status of the boxes connected to the output 
-       if (s1==MODIFIED) s=MODIFIED;
-      }
-    else 
-      {
-       bbtkError("Connection '"<<caller->GetFullName()<<"' does not point to a valid output of the complex box !");
-      }
-
-    return s;
     
   }
   //==================================================================
@@ -373,9 +323,9 @@ namespace bbtk
   //==================================================================
   Data ComplexBlackBox::bbGetOutput( const std::string &name )
   {
-    bbtkDebugMessageInc("Data",7,
-                       "ComplexBlackBox::bbGetOutput(\""<<name<<"\") ["
-                       <<bbGetFullName()<<"]"<<std::endl);
+    bbtkBlackBoxDebugMessage("data",7,
+                       "ComplexBlackBox::bbGetOutput(\""<<name<<"\")"
+                       <<std::endl);
 
     ComplexBlackBoxOutputDescriptor* d = 
       (ComplexBlackBoxOutputDescriptor*)
@@ -383,8 +333,6 @@ namespace bbtk
     
     Data p = bbGetBlackBox(d->GetTarget())->bbGetOutput(d->GetOutput());
 
-
-    bbtkDebugDecTab("Data",7);
     return p;
   }
   //==================================================================
@@ -393,9 +341,9 @@ namespace bbtk
   ///  Gets the input Data of a given name
   Data ComplexBlackBox::bbGetInput( const std::string &name ) 
   {
-    bbtkDebugMessageInc("Data",7,
-                       "ComplexBlackBox::bbGetInput(\""<<name<<"\") ["
-                       <<bbGetFullName()<<"]"<<std::endl);  
+    bbtkBlackBoxDebugMessage("data",7,
+                       "ComplexBlackBox::bbGetInput(\""<<name<<"\")"
+                            <<std::endl);  
 
     ComplexBlackBoxInputDescriptor* d = 
       (ComplexBlackBoxInputDescriptor*)
@@ -403,7 +351,6 @@ namespace bbtk
 
     Data p = bbGetBlackBox(d->GetTarget())->bbGetInput(d->GetInput());
 
-    bbtkDebugDecTab("Data",7);
     return p;
   }
   //==================================================================
@@ -412,9 +359,9 @@ namespace bbtk
   ///  Sets the data of the output called <name>
   void ComplexBlackBox::bbSetOutput( const std::string &name, Data data)
   {
-    bbtkDebugMessageInc("Data",7,
-                       "ComplexBlackBox::bbSetOutput(\""<<name<<"\",data) ["
-                       <<bbGetFullName()<<"]"<<std::endl); 
+    bbtkBlackBoxDebugMessage("data",7,
+                       "ComplexBlackBox::bbSetOutput(\""<<name<<"\",data)"
+                            <<std::endl); 
 
     ComplexBlackBoxOutputDescriptor* d = 
       (ComplexBlackBoxOutputDescriptor*)
@@ -422,7 +369,6 @@ namespace bbtk
     
     bbGetBlackBox(d->GetTarget())->bbSetOutput(d->GetOutput(),data);
 
-    bbtkDebugDecTab("Data",7);
   }
   //==================================================================
   
@@ -431,16 +377,15 @@ namespace bbtk
   void ComplexBlackBox::bbSetInput( const std::string &name, Data data,
                                    bool setModified)
   {
-    bbtkDebugMessageInc("Data",7,
-                       "ComplexBlackBox::bbSetInput(\""<<name<<"\",data) ["
-                       <<bbGetFullName()<<"]"<<std::endl);  
+    bbtkBlackBoxDebugMessage("data",7,
+                       "ComplexBlackBox::bbSetInput(\""<<name<<"\",data)"
+                            <<std::endl);  
 
     ComplexBlackBoxInputDescriptor* d = (ComplexBlackBoxInputDescriptor*)
       bbGetDescriptor()->GetInputDescriptor(name);
 
     bbGetBlackBox(d->GetTarget())->bbSetInput(d->GetInput(),data,setModified);
 
-    bbtkDebugDecTab("Data",7);
   }
   //==================================================================
 
@@ -451,10 +396,10 @@ namespace bbtk
                                                     void* data,
                                                     bool setModified)
   {
-    bbtkDebugMessageInc("Data",7,
+    bbtkBlackBoxDebugMessage("data",7,
                        "ComplexBlackBox::bbBruteForceSetInputPointer('"
-                       <<name<<"',"<<data<<") ["
-                       <<bbGetFullName()<<"]"<<std::endl);  
+                       <<name<<"',"<<data<<")"
+                            <<std::endl);  
 
     ComplexBlackBoxInputDescriptor* d = (ComplexBlackBoxInputDescriptor*)
       bbGetDescriptor()->GetInputDescriptor(name);
@@ -463,7 +408,6 @@ namespace bbtk
                                                               data,
                                                               setModified);
 
-    bbtkDebugDecTab("Data",7);
   }
   //==================================================================
 
@@ -471,10 +415,9 @@ namespace bbtk
   /// Connects the input <name> to the connection c
   void ComplexBlackBox::bbConnectInput( const std::string& name, Connection* c)
   {
-    bbtkDebugMessage("connection",2,
+    bbtkBlackBoxDebugMessage("connection",2,
                     "==> ComplexBlackBox::bbConnectInput(\""
-                    <<name<<"\","<<c->GetFullName()<<") ["
-                    <<bbGetFullName()<<"]"
+                    <<name<<"\","<<c->GetFullName()<<")"
                     <<std::endl);       
     
    ComplexBlackBoxInputDescriptor* d = (ComplexBlackBoxInputDescriptor*)
@@ -483,18 +426,17 @@ namespace bbtk
 
    BlackBox::Pointer t = bbGetBlackBox(d->GetTarget());
 
-   bbtkDebugMessage("connection",2," - Target = "<<d->GetTarget()<<" = "<<t->bbGetFullName()<<std::endl);
+   bbtkBlackBoxDebugMessage("connection",2," - Target = "<<d->GetTarget()<<" = "<<t->bbGetFullName()<<std::endl);
 
    c->SetBlackBoxTo(t);
    c->SetBlackBoxToInput(d->GetInput());
 
-   bbtkDebugMessage("connection",2," - New conn = "<<c->GetFullName()<<std::endl);
+   bbtkBlackBoxDebugMessage("connection",2," - New conn = "<<c->GetFullName()<<std::endl);
    t->bbConnectInput(d->GetInput(),c);
 
-   bbtkDebugMessage("connection",2,
+   bbtkBlackBoxDebugMessage("connection",2,
                     "<== ComplexBlackBox::bbConnectInput(\""
-                    <<name<<"\","<<c->GetFullName()<<") ["
-                    <<bbGetFullName()<<"]"
+                    <<name<<"\","<<c->GetFullName()<<")"
                     <<std::endl);       
   }
   //=========================================================================
@@ -504,29 +446,29 @@ namespace bbtk
   /// Connects the output <name> to the connection c
   void ComplexBlackBox::bbConnectOutput( const std::string& name, Connection* c)
   {
-    bbtkDebugMessage("connection",2,
+    bbtkBlackBoxDebugMessage("connection",2,
                     "==> ComplexBlackBox::bbConnectOutput(\""
-                    <<name<<"\","<<c->GetFullName()<<") ["
-                    <<bbGetFullName()<<"]"<<std::endl);       
+                    <<name<<"\","<<c->GetFullName()<<")"
+                            <<std::endl);       
 
    ComplexBlackBoxOutputDescriptor* d = (ComplexBlackBoxOutputDescriptor*)
       bbGetDescriptor()->GetOutputDescriptor(name);
 
    BlackBox::Pointer t = bbGetBlackBox(d->GetTarget());
  
-  bbtkDebugMessage("connection",2," - Target = "<<d->GetTarget()<<" = "<<t->bbGetFullName()<<std::endl);
+  bbtkBlackBoxDebugMessage("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);
+   bbtkBlackBoxDebugMessage("connection",2," - New conn = "<<c->GetFullName()<<std::endl);
 
    t->bbConnectOutput(d->GetOutput(),c);
   
-    bbtkDebugMessage("connection",2,
+    bbtkBlackBoxDebugMessage("connection",2,
                     "<== ComplexBlackBox::bbConnectOutput(\""
-                    <<name<<"\","<<c->GetFullName()<<") ["
-                    <<bbGetFullName()<<"]"<<std::endl);       
+                    <<name<<"\","<<c->GetFullName()<<")"
+                            <<std::endl);       
   }
   //=========================================================================
 
@@ -535,10 +477,10 @@ namespace bbtk
   /// Adds the black box to the complex box
   void ComplexBlackBox::bbAddBlackBox( BlackBox::Pointer b)
   {
-    bbtkDebugMessageInc("Kernel",7,
-                       "ComplexBlackBox::AddBlackBox(\""<<b->bbGetName()
-                       <<"\") ["
-                       <<bbGetFullName()<<"]"<<std::endl);  
+    bbtkBlackBoxDebugMessage("kernel",7,
+                            "ComplexBlackBox::AddBlackBox(\""<<b->bbGetName()
+                            <<"\")"
+                            <<std::endl);  
     
     if ( bbUnsafeGetBlackBox(b->bbGetName()) ) 
       {
@@ -548,7 +490,6 @@ namespace bbtk
     b->bbSetParent(GetThisPointer<ComplexBlackBox>());
     mBlackBoxMap[b->bbGetName()] = b;
 
-    bbtkDebugDecTab("Kernel",7);
   }
   //==================================================================
 
@@ -556,15 +497,14 @@ namespace bbtk
   /// Adds the black box to the complex box (unsafe)
   void ComplexBlackBox::bbUnsafeAddBlackBox( BlackBox::Pointer b)
   {
-    bbtkDebugMessageInc("Kernel",7,
+    bbtkBlackBoxDebugMessage("kernel",7,
                        "ComplexBlackBox::UnsafeAddBlackBox(\""<<b->bbGetName()
-                       <<"\") ["
-                       <<bbGetFullName()<<"]"<<std::endl);  
+                       <<"\")"
+                       <<std::endl);  
     
     b->bbSetParent(GetThisPointer<ComplexBlackBox>());
     mBlackBoxMap[b->bbGetName()] = b;
 
-    bbtkDebugDecTab("Kernel",7);
   }
   //==================================================================
 
@@ -573,9 +513,9 @@ namespace bbtk
   void ComplexBlackBox::bbRemoveBlackBox( const std::string& name, 
                                          bool remove_connections )
   {
-    bbtkDebugMessageInc("Kernel",7,
-                       "ComplexBlackBox::RemoveBlackBox(\""<<name<<"\") ["
-                       <<bbGetFullName()<<"]"<<std::endl);  
+    bbtkBlackBoxDebugMessage("kernel",7,
+                       "ComplexBlackBox::RemoveBlackBox(\""<<name<<"\")"
+                            <<std::endl);  
 
     BlackBoxMapType::iterator i = mBlackBoxMap.find(name);
     if ( i == mBlackBoxMap.end() ) 
@@ -604,7 +544,6 @@ namespace bbtk
     // Unload orphan dl packages 
     Package::UnLoadReleasedDynamicallyLoadedPackages();
 
-    bbtkDebugDecTab("Kernel",7);
   }
   //==================================================================
 
@@ -612,13 +551,12 @@ namespace bbtk
   /// Adds the connection to the complex box
   void ComplexBlackBox::bbAddConnection( Connection::Pointer c)
   {
-    bbtkDebugMessageInc("Kernel",7,
-                       "ComplexBlackBox::AddConnection(\""<<"..."<<"\") ["
-                       <<bbGetFullName()<<"]"<<std::endl);  
+    bbtkBlackBoxDebugMessage("kernel",7,
+                       "ComplexBlackBox::AddConnection(\""<<"..."<<"\")"
+                            <<std::endl);  
 
     mConnectionList.push_back(c);
 
-    bbtkDebugDecTab("Kernel",7);
   }
   //==================================================================
   //    void RemoveConnection( );
@@ -627,17 +565,14 @@ namespace bbtk
   /// Returns the black box with name <name>
   BlackBox::Pointer ComplexBlackBox::bbGetBlackBox( const std::string& name )
   {
-    bbtkDebugMessageInc("Kernel",9,
-                       "ComplexBlackBox::GetBlackBox(\""<<name<<"\") ["
-                       <<bbGetFullName()<<"]"<<std::endl);  
-
+    bbtkBlackBoxDebugMessage("kernel",9,
+                       "ComplexBlackBox::GetBlackBox(\""<<name<<"\")"
+                            <<std::endl);
     BlackBoxMapType::iterator i = mBlackBoxMap.find(name);
     if ( i == mBlackBoxMap.end() ) 
-      {
-       bbtkError("the black box \""<<name<<"\" does not exist");
-      }
-
-    bbtkDebugDecTab("Kernel",9);
+    {
+        bbtkError("the black box \""<<name<<"\" does not exist");
+    }
     return i->second;
   }
   //==================================================================
@@ -647,19 +582,16 @@ namespace bbtk
   /// if it does not exist but return a null pointer
   BlackBox::Pointer ComplexBlackBox::bbUnsafeGetBlackBox( const std::string& name )
   {
-    bbtkDebugMessageInc("Kernel",9,
-                       "ComplexBlackBox::UnsafeGetBlackBox(\""<<name<<"\") ["
-                       <<bbGetFullName()<<"]"
+    bbtkBlackBoxDebugMessage("kernel",9,
+                       "ComplexBlackBox::UnsafeGetBlackBox(\""<<name<<"\")"
                        <<std::endl);  
 
     BlackBoxMapType::iterator i = mBlackBoxMap.find(name);
     if ( i == mBlackBoxMap.end() ) 
       {
-       bbtkDebugDecTab("Kernel",9);
        return BlackBox::Pointer();
       }
 
-    bbtkDebugDecTab("Kernel",9);
     return i->second;
     
   }
@@ -668,18 +600,16 @@ namespace bbtk
   //==================================================================
   void ComplexBlackBox::bbPrintBlackBoxes()
   {
-    bbtkDebugMessageInc("Kernel",9,
-                       "ComplexBlackBox::PrintBlackBoxes() ["
-                       <<bbGetFullName()<<"]"
+    bbtkBlackBoxDebugMessage("kernel",9,
+                       "ComplexBlackBox::PrintBlackBoxes()"
                        <<std::endl);  
 
     BlackBoxMapType::iterator i;
     for ( i = mBlackBoxMap.begin(); i != mBlackBoxMap.end(); ++i ) 
       {
-       bbtkMessage("Help",1,i->second->bbGetFullName()<<std::endl);
+       bbtkMessage("help",1,i->second->bbGetFullName()<<std::endl);
       }
 
-    bbtkDebugDecTab("Kernel",9);
   }
   //==================================================================
 
@@ -741,7 +671,6 @@ namespace bbtk
                                            const std::string& output_dir,
                                            bool relative_link )
   {
-    
     std::string directory(output_dir);
 
     if (output_dir.length() == 0) 
@@ -763,10 +692,22 @@ namespace bbtk
     std::string filename_dot2  ("\""   + filename_dot  + "\"");
     
 
-    std::string command1 ("dot -T png -o "  
-                         + filename_png2  + " " + filename_dot2);
-    std::string command1a("dot -T cmap -o " 
-                         + filename_cmap2 + " " + filename_dot2);
+#ifdef WIN32
+       std::string currentexecpath("\"\"" + crea::System::GetDllAppPath("bbtk") +"\\dot_embedded\\dot\"");     
+       std::string command1 (currentexecpath + " -Tpng -o " + filename_png2  + " " + filename_dot2 + "\"");
+       std::string command1a(currentexecpath + " -T cmap -o " + filename_cmap2 + " " + filename_dot2 + "\"");          
+#else
+  #ifdef APPLE
+       std::string command1 ("dot -Tpng:quartz -o " + filename_png2  + " " + filename_dot2  );
+       std::string command1a("dot -T cmap -o " + filename_cmap2 + " " + filename_dot2 );
+  #else
+       std::string command1 ("dot -Tpng:cairo -o " + filename_png2  + " " + filename_dot2  );
+       std::string command1a("dot -T cmap -o " + filename_cmap2 + " " + filename_dot2 );
+  #endif
+#endif
+
+
+    
 
     // 1. Generating .dot file
     FILE *ff;
@@ -784,9 +725,11 @@ namespace bbtk
     fprintf(ff,"}\n");
     fclose(ff);
 
+       std::cout<<"JCP bbtkComplexBlackBox.cxx execute1="<<command1<<std::endl;
     // 2. Executing .dot file -> png
     system( command1.c_str() );   
     // 3. Executing .dot file -> cmap
+       std::cout<<"JCP bbtkComplexBlackBox.cxx execute2="<<command1a<<std::endl;
     system( command1a.c_str() );  
     
     // 4. HTML code insertion
@@ -800,14 +743,16 @@ namespace bbtk
     FILE *ff2;
     char c;
     ff2=fopen(filename_cmap.c_str(),"r");
-    while (!feof(ff2))
-    {
-          c=fgetc(ff2);
-          if (c!=-1)
-          {
-             (s) << c;
-          }
-    }
+       if (ff2!=NULL){
+               while (!feof(ff2))
+               {
+                       c=fgetc(ff2);
+                       if (c!=-1)
+                       {
+                               (s) << c;
+                       } // if 
+               } // while
+       } // if ff2
     (s) << "</map>\n\n";
     
     // End
@@ -1157,13 +1102,13 @@ namespace bbtk
     BlackBoxMapType::const_iterator i;
     for ( i = mBlackBoxMap.begin(); i != mBlackBoxMap.end(); ++i ) 
       {
-       s += i->second->GetObjectRecursiveSize();
+                                       s += i->second->GetObjectRecursiveSize();
       }
     ConnectionListType::const_iterator j;
     for ( j = mConnectionList.begin(); 
          j != mConnectionList.end(); ++j ) 
       {
-       s += (*j)->GetObjectRecursiveSize();
+                               s += (*j)->GetObjectRecursiveSize();
       }
     return s;
   }