]> Creatis software - bbtk.git/blobdiff - kernel/src/bbtkBlackBox.cxx
New widget pipeline : progressing ...
[bbtk.git] / kernel / src / bbtkBlackBox.cxx
index edca10ce191024bd2a961e6013ba11534e5a1349..ddfc3ed9576598ad5b150716c67dbec7ccafe65e 100644 (file)
@@ -1,21 +1,32 @@
-/*=========================================================================
-                                                                                
-Program:   bbtk
-Module:    $RCSfile: bbtkBlackBox.cxx,v $
-Language:  C++
-Date:      $Date: 2008/04/24 10:11:27 $
-Version:   $Revision: 1.16 $
-                                                                                
-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/11/25 11:17:13 $
+  Version:   $Revision: 1.29 $
 =========================================================================*/
 
+/* ---------------------------------------------------------------------
+
+* 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()
 
@@ -139,10 +157,16 @@ namespace bbtk
   void BlackBox::bbExecute(bool force)
   {
     bbtkDebugMessageInc("process",2,
-                       "=> BlackBox::bbExecute() ["
+                       "=> 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()) 
@@ -151,14 +175,14 @@ namespace bbtk
                         " -> 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",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) );
       }
 
@@ -431,6 +457,16 @@ namespace bbtk
        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))
@@ -441,11 +477,13 @@ namespace bbtk
        this->bbSetStatus(MODIFIED); 
         bbGlobalAddToExecutionList( GetThisPointer<BlackBox>() );
       }
+    /*
     else if ( bbGetStatus() == MODIFIED ) //! this->bbIsUptodate()) 
       { 
        bbtkDebugMessage("modified",2,"-> Already modified"<<std::endl);
        return;
       }
+    */
     else 
       {
        bbtkDebugMessage("modified",2,"-> Status set to modified"<<std::endl);
@@ -1004,7 +1042,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,22 +1138,38 @@ namespace bbtk
    }
   //=========================================================================
 
+  static bool bbmgGlobalProcessingExecutionList = false;
 
   //=========================================================================
    void BlackBox::bbGlobalProcessExecutionList()
    {   
      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",4,
-                         " -> 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();
@@ -1123,6 +1177,7 @@ namespace bbtk
                         "<= BlackBox::bbGlobalProcessExecutionList()"
                         <<std::endl);     
      
+     bbmgGlobalProcessingExecutionList = false;
      
    }
   //=========================================================================
@@ -1148,18 +1203,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 +1223,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