]> Creatis software - bbtk.git/blobdiff - kernel/src/bbtkBlackBox.cxx
Try to display planes (from Image Planes)
[bbtk.git] / kernel / src / bbtkBlackBox.cxx
index 1f59e6bdae6f18d99f17e15b88f01f8f70784ef6..5fc7d01babe0b9224cb59e7b194a34e24e9aafe7 100644 (file)
@@ -1,21 +1,32 @@
-/*=========================================================================
-                                                                                
-Program:   bbtk
-Module:    $RCSfile: bbtkBlackBox.cxx,v $
-Language:  C++
-Date:      $Date: 2008/04/22 14:30:25 $
-Version:   $Revision: 1.14 $
-                                                                                
-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: bbtkBlackBox.cxx,v $
+  Language:  C++
+  Date:      $Date: 2008/12/03 09:34:37 $
+  Version:   $Revision: 1.30 $
 =========================================================================*/
 
+/* ---------------------------------------------------------------------
+
+* Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
+* Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
+*
+*  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.
+* ------------------------------------------------------------------------ */                                                                         
 
 /**
  *  \file 
@@ -39,7 +50,7 @@ namespace bbtk
 
   static bool bbmgSomeBoxExecuting = false;
   static bool bbmgFreezeExecution = false;
-  static std::set<BlackBox::Pointer> bbmgExecutionList;
+  static std::set<BlackBox::WeakPointer> bbmgExecutionList;
 
   //=========================================================================
   BlackBox::Deleter::Deleter()
@@ -65,7 +76,7 @@ namespace bbtk
     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()) 
@@ -90,11 +101,13 @@ namespace bbtk
 
   //=========================================================================
   BlackBox::BlackBox(const std::string &name) 
-    : bbmName(name), 
-      bbmStatus(MODIFIED), 
-      bbmBoxProcessMode("Pipeline"),
-      bbmParent()
-
+    : 
+    bbmStatus(MODIFIED), 
+    bbmExecuting(false),
+    bbmName(name),
+    bbmBoxProcessMode("Pipeline"),
+    bbmParent()
+    
   {
     bbtkDebugMessage("object",4,"==> BlackBox::BlackBox(\""
                     <<name<<"\")"<<std::endl);
@@ -103,11 +116,16 @@ namespace bbtk
   }
   //=========================================================================
 
+  //=========================================================================
+  BlackBox::BlackBox(const BlackBox&)
+  {}
 
   //=========================================================================
   BlackBox::BlackBox(BlackBox& from, const std::string &name) 
-    : bbmName(name), 
+    :
       bbmStatus(from.bbmStatus), 
+      bbmExecuting(false),
+      bbmName(name), 
       bbmBoxProcessMode(from.bbmBoxProcessMode),
       bbmParent()
 
@@ -138,28 +156,34 @@ namespace bbtk
   /// Main processing method of the box.
   void BlackBox::bbExecute(bool force)
   {
-    bbtkDebugMessageInc("Process",1,
-                       "=> BlackBox::bbExecute() ["
+    bbtkDebugMessageInc("process",2,
+                       "=> BlackBox::bbExecute("<<(int)force<<") ["
                        <<bbGetFullName()<<"]"<<std::endl);
  
-    Wx::BeginBusyCursor();
+    // If already executing : return
+    if (bbGetExecuting()) 
+      {
+       bbtkDebugMessage("process",2,
+                        " -> already executing : bailing out"<<std::endl);
+       return;
+      }
 
     // If execution frozen : return
     if (bbGlobalGetFreezeExecution()) 
       {
-       bbtkDebugMessage("Process",1,
+       bbtkDebugMessage("process",2,
                         " -> FreezeExecution global flag is 'true' : abort execution"<<std::endl);
       }
 
+    BBTK_BUSY_CURSOR;
+
     // If force is true then update is triggered even if the box is UPTODATE
     if (force) bbSetModifiedStatus();
 
     // Calls the main recursive update method 
     bbBackwardUpdate(Connection::Pointer());
 
-    Wx::EndBusyCursor();
-
-    bbtkDebugMessageDec("Process",1,
+    bbtkDebugMessageDec("process",2,
                        "<= BlackBox::bbExecute() ["
                        <<bbGetFullName()<<"]"<<std::endl);
   }
@@ -319,7 +343,7 @@ namespace bbtk
   /// Copies the input / output values from another box
   void BlackBox::bbCopyIOValues(BlackBox& from)
   {
-    bbtkDebugMessageInc("Kernel",9,
+    bbtkDebugMessageInc("Kernel",1,
                        "BlackBox::bbCopyIOValues("
                        <<from.bbGetFullName()<<") ["
                        <<bbGetFullName()<<"]"<<std::endl);
@@ -331,6 +355,7 @@ namespace bbtk
       {                
        if (! i->second->GetCopyConstruct() ) continue;
        std::string input = i->second->GetName();
+       bbtkDebugMessage("Kernel",2,"* Copying input "<<input<<std::endl);
        this->bbSetInput(input, from.bbGetInput(input) );
       }                                                                        
     // copies the output values
@@ -341,6 +366,7 @@ namespace bbtk
       {                                                        
        if (! o->second->GetCopyConstruct() ) continue;
        std::string output = o->second->GetName();
+       bbtkDebugMessage("Kernel",2,"* Copying output "<<output<<std::endl);
        this->bbSetOutput(output, from.bbGetOutput(output) );
       }
 
@@ -368,7 +394,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"
@@ -417,55 +443,68 @@ 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( 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); 
+       std::cout << "Status set to modified" <<std::endl;
       }
  
     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);
     
@@ -486,7 +525,7 @@ namespace bbtk
 
     if (reaction) bbGlobalProcessExecutionList();
 
-    bbtkDebugMessageDec("Process",5,
+    bbtkDebugMessageDec("process",5,
                        "<= BlackBox::bbSignalOutputModification() ["
                        <<bbGetFullName()<<"]"<<std::endl);
     
@@ -496,7 +535,7 @@ namespace bbtk
   void BlackBox::bbSignalOutputModification(const std::string& output,
        bool reaction)
   {
-    bbtkDebugMessageInc("Process",5,
+    bbtkDebugMessageInc("process",5,
                        "=> BlackBox::bbSignalOutputModification("
                        <<output<<") ["
                        <<bbGetFullName()<<"]"<<std::endl);
@@ -518,7 +557,7 @@ namespace bbtk
       }
   if (reaction) bbGlobalProcessExecutionList();
 
-  bbtkDebugMessageDec("Process",5,
+  bbtkDebugMessageDec("process",5,
                       "<= BlackBox::bbSignalOutputModification("
                       <<output<<") ["
                       <<bbGetFullName()<<"]"<<std::endl);
@@ -529,7 +568,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;
@@ -554,7 +593,7 @@ namespace bbtk
       }
   if (reaction) bbGlobalProcessExecutionList();
 
-   bbtkDebugMessageDec("Process",5,
+   bbtkDebugMessageDec("process",5,
                       "<= BlackBox::bbSignalOutputModification(vector of outputs) ["
                        <<bbGetFullName()<<"]"<<std::endl);
 
@@ -567,7 +606,7 @@ namespace bbtk
   ///          else MODIFIED 
   IOStatus BlackBox::bbUpdateInputs(bool excludeParent)
   {
-    bbtkDebugMessageInc("Process",4,
+    bbtkDebugMessageInc("process",4,
                        "=> BlackBox::bbUpdateInputs() ["
                        <<bbGetFullName()<<"]"
                        <<std::endl);   
@@ -589,7 +628,7 @@ namespace bbtk
        if (t==MODIFIED) s = MODIFIED;
       }
     
-   bbtkDebugMessageDec("Process",4,
+   bbtkDebugMessageDec("process",4,
                        "<= BlackBox::bbUpdateInputs() ["
                        <<bbGetFullName()<<"]"
                        <<std::endl);   
@@ -1004,7 +1043,7 @@ namespace bbtk
     InputConnectorMapType::iterator i;
     unsigned int namelmax = 0;
     unsigned int valuelmax = 0;
-    unsigned int connlmax = 0;
+    //   unsigned int connlmax = 0;
     for ( i = mInputConnectorMap.begin(); i != mInputConnectorMap.end(); ++i ) 
       {
        iname.push_back(i->first);
@@ -1100,29 +1139,46 @@ namespace bbtk
    }
   //=========================================================================
 
+  static bool bbmgGlobalProcessingExecutionList = false;
 
   //=========================================================================
    void BlackBox::bbGlobalProcessExecutionList()
    {   
-     bbtkDebugMessageInc("Process",1,
+     bbtkDebugMessageInc("process",3,
                         "=> BlackBox::bbGlobalProcessExecutionList()"
-                        <<std::endl);     
-     
-     std::set<BlackBox::Pointer>::iterator i;
-     for (i=bbmgExecutionList.begin();
-         i!=bbmgExecutionList.end();
-         ++i)
+                        <<std::endl);    
+     if (bbmgGlobalProcessingExecutionList) 
+       {
+        bbtkDebugMessage("process",3,"BlackBox::bbGlobalProcessExecutionList() reentered !");
+        return;
+       }
+     bbmgGlobalProcessingExecutionList = true;
+
+     std::set<BlackBox::WeakPointer>::iterator i; 
+     while (bbmgExecutionList.size()>0)
        {
-        bbtkDebugMessage("Process",2,
-                         " -> Executing "<<(*i)->bbGetFullName()<<std::endl);
-        (*i)->bbExecute(true);
+        i = bbmgExecutionList.begin();
+        BlackBox::WeakPointer p = *i;
+        bbmgExecutionList.erase(i);
+        if (p.lock())
+          {
+            bbtkDebugMessage("process",4,
+                             " -> Executing "<<
+                             p.lock()->bbGetFullName()<<std::endl);
+            p.lock()->bbExecute(true);
+          }
+        else 
+          {
+            bbtkGlobalError("Strange error in BlackBox::bbGlobalProcessExecutionList() : Weak bb pointer in bbmgExecutionList is no more valid...");
+          }
        }
      
      bbmgExecutionList.clear();
-     bbtkDebugMessageDec("Process",1,
+     bbtkDebugMessageDec("process",3,
                         "<= BlackBox::bbGlobalProcessExecutionList()"
                         <<std::endl);     
      
+     bbmgGlobalProcessingExecutionList = false;
      
    }
   //=========================================================================
@@ -1148,18 +1204,16 @@ namespace bbtk
        }
 
   void BlackBox::bbGlobalAddToExecutionList( BlackBox::Pointer b )
-       {  
-               bbmgExecutionList.insert(b); 
-       } 
+  {  
+    bbtkDebugMessage("process",3,"* bbGlobalAddToExecutionList("<<b->bbGetFullName()<<")"<<std::endl);
+    if (bbmgGlobalProcessingExecutionList) 
+      {
+       bbtkDebugMessage("process",3,"bbGlobalAddToExecutionList called inside bbGlobalProcessExecutionList !");
+      }
+    bbmgExecutionList.insert(b); 
+  } 
 
 
-  //=========================================================================
-  // Static members initialization
-/*EED
-  bool BlackBox::bbmgSomeBoxExecuting = false;
-  bool BlackBox::bbmgFreezeExecution = false;
-  std::set<BlackBox*> BlackBox::bbmgExecutionList;
-*/
    //=========================================================================
 
   //=========================================================================
@@ -1170,6 +1224,16 @@ namespace bbtk
   }
   //=========================================================================
 
+  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