]> Creatis software - bbtk.git/blob - kernel/src/bbtkBlackBox.cxx
re indent
[bbtk.git] / kernel / src / bbtkBlackBox.cxx
1 /*=========================================================================                                                                               
2   Program:   bbtk
3   Module:    $RCSfile: bbtkBlackBox.cxx,v $
4   Language:  C++
5   Date:      $Date: 2011/07/22 17:42:50 $
6   Version:   $Revision: 1.54 $
7 =========================================================================*/
8
9 /* ---------------------------------------------------------------------
10
11 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
12 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
13 *
14 *  This software is governed by the CeCILL-B license under French law and 
15 *  abiding by the rules of distribution of free software. You can  use, 
16 *  modify and/ or redistribute the software under the terms of the CeCILL-B 
17 *  license as circulated by CEA, CNRS and INRIA at the following URL 
18 *  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html 
19 *  or in the file LICENSE.txt.
20 *
21 *  As a counterpart to the access to the source code and  rights to copy,
22 *  modify and redistribute granted by the license, users are provided only
23 *  with a limited warranty  and the software's author,  the holder of the
24 *  economic rights,  and the successive licensors  have only  limited
25 *  liability. 
26 *
27 *  The fact that you are presently reading this means that you have had
28 *  knowledge of the CeCILL-B license and that you accept its terms.
29 * ------------------------------------------------------------------------ */                                                                         
30
31 /**
32  *  \file 
33  *  \brief Class bbtk::BlackBox : abstract black-box interface. 
34  */
35 #include "bbtkBlackBox.h"
36 #include "bbtkPackage.h"
37 #include "bbtkMessageManager.h"
38 #include "bbtkFactory.h"
39 #include "bbtkBlackBoxOutputConnector.h"
40
41 #include "bbtkConfigurationFile.h"
42 #include "bbtkWxBlackBox.h"
43 #include "bbtkWx.h"
44
45 #include <fstream>
46 //#include <vector>
47
48
49 namespace bbtk
50 {
51   static bool bbmgSomeBoxExecuting = false;
52   static bool bbmgFreezeExecution = false;
53   static std::set<BlackBox::WeakPointer> bbmgExecutionList;
54
55   //=========================================================================
56
57   BlackBox::Deleter::Deleter()
58   {
59   }
60   //=========================================================================
61   
62   //=========================================================================
63   int BlackBox::Deleter::Delete(Object* p)
64   {
65     BlackBox* b = dynamic_cast<BlackBox*>(p);
66     if (!b)
67       {
68         bbtkInternalError("BlackBox::Deleter::Delete("<<p->GetObjectName()
69                           <<"["<<p<<"]) : "
70                           <<"dynamic cast to BlackBox* failed !");
71       }
72     std::string name = p->GetObjectName();//b->bbGetNameWithParent();
73     bbtkDebugMessage("object",2,"##> BlackBox::Deleter(\""<<name<<"\")"<<std::endl);
74
75
76     BlackBoxDescriptor::WeakPointer desc = b->bbGetDescriptor();
77     bbtkDebugMessage("object",2,"##> BlackBox::Deleter(\""<<name<<"\") : deleting black box"<<std::endl);
78     
79     int refs = b->bbDelete();
80
81     bbtkDebugMessage("object",2,"##> BlackBox::Deleter(\""<<name<<"\") : releasing descriptor"<<std::endl);
82     
83     if (!desc.expired()) 
84       {
85         Package::WeakPointer pack = desc.lock()->GetPackage();
86         if (!pack.expired()) 
87           {
88             Package::ReleaseBlackBoxDescriptor(pack,desc);
89           }
90         else 
91           {
92             bbtkDebugMessage("object",2,"##> BlackBox::Deleter(\""<<name<<"\") : descriptor package expired (was not held by a package and the box was the last instance)"<<std::endl);
93           }
94       }
95     else
96       {
97         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);
98       }
99     bbtkDebugMessage("object",2,"<## BlackBox::Deleter(\""<<name<<"\")"<<std::endl);
100     return refs;
101   }
102   //=========================================================================
103
104   //=========================================================================
105   BlackBox::BlackBox(const std::string &name) 
106     : 
107     //    bbmStatus(MODIFIED), 
108     bbmInitialized(false),
109     bbmExecuting(false),
110     bbmName(name),
111     bbmBoxProcessMode("Pipeline"),
112     bbmParent()
113     
114   {
115           //JCP 02-11-09
116          // bbmBoxProcessMode = "Pipeline";     
117 //std::cout<<"JCP BlackBox::BlackBox(const std::string &name) name=" <<name
118 //                <<"bbmBoxProcessMode="<<bbmBoxProcessMode<<std::endl;
119     bbtkBlackBoxDebugMessage("object",4,"==> BlackBox::BlackBox(\""
120                      <<name<<"\")"<<std::endl);
121     bbtkBlackBoxDebugMessage("object",4,"<== BlackBox::BlackBox(\""
122                      <<name<<"\")"<<std::endl);
123   }
124   //=========================================================================
125
126   //=========================================================================
127   BlackBox::BlackBox(const BlackBox&)
128   {}
129
130   //=========================================================================
131   BlackBox::BlackBox(BlackBox& from, const std::string &name) 
132     :
133     //    bbmStatus(from.bbmStatus), 
134     bbmInitialized(false),
135     bbmExecuting(false),
136     bbmName(name), 
137     bbmBoxProcessMode(from.bbmBoxProcessMode),
138     bbmParent()
139     
140   {
141           //JCP 02-11-09
142           //bbmBoxProcessMode = from.bbmBoxProcessMode;
143           //std::cout<<"JCP BlackBox::BlackBox(const std::string &name) name=" <<name
144                 //  <<"bbmBoxProcessMode="<<bbmBoxProcessMode<<std::endl;
145     bbtkBlackBoxDebugMessage("object",4,"==> BlackBox::BlackBox("
146                      <<from.bbGetFullName()<<",\""
147                      <<name<<"\")"<<std::endl);
148     bbtkBlackBoxDebugMessage("object",4,"<== BlackBox::BlackBox("
149                      <<from.bbGetFullName()<<",\""
150                      <<name<<"\")"<<std::endl);
151   }
152   //=========================================================================
153
154
155   //=========================================================================
156   BlackBox::~BlackBox()
157   {
158     bbtkBlackBoxDebugMessage("object",4,"==> BlackBox::~BlackBox() ["<<bbmName
159                      <<"]"<<std::endl);
160     this->bbDesallocateConnectors();
161     bbtkBlackBoxDebugMessage("object",4,"<== BlackBox::~BlackBox() ["<<bbmName
162                      <<"]"<<std::endl);
163   }
164   //=========================================================================
165
166
167
168   //=========================================================================
169   std::string BlackBox::bbGetFullName() const
170   { 
171     return this->bbGetNameWithParent()+"<"+this->bbGetDescriptor()->GetTypeName()+">";
172   }
173   //=========================================================================
174      
175
176
177   //=========================================================================
178   std::string BlackBox::bbGetNameWithParent() const
179   {
180     if (bbmParent.lock()) 
181       {
182         return bbmParent.lock()->bbGetNameWithParent() + ":" + bbmName;
183       }
184     else 
185       {
186         return bbmName;
187       }
188   } 
189   //=========================================================================
190
191   //=========================================================================
192   void BlackBox::bbGetHelp(bool full) const
193   {
194     bbGetDescriptor()->GetHelp(full); 
195   }
196   //=========================================================================
197
198
199   //=========================================================================
200   bool BlackBox::bbHasInput(const std::string& name) const
201   {
202     bbtkBlackBoxDebugMessage("kernel",8,
203                         "BlackBox::bbHasInput(\""
204                         <<name<<"\")"
205                         <<std::endl);
206     bool r = ( bbGetDescriptor()->GetInputDescriptorMap().find(name)
207                != bbGetDescriptor()->GetInputDescriptorMap().end());
208     bbtkDebugDecTab("kernel",8);
209     return r;
210   }
211   //=========================================================================
212
213
214   //=========================================================================  
215   bool BlackBox::bbHasOutput(const std::string& name) const
216   {
217     bbtkBlackBoxDebugMessage("kernel",8,"BlackBox::bbHasOutput(\""
218                              <<name<<"\")"
219                              <<std::endl);
220     bool r = ( bbGetDescriptor()->GetOutputDescriptorMap().find(name)
221                != bbGetDescriptor()->GetOutputDescriptorMap().end());
222     bbtkDebugDecTab("kernel",8);
223     return r;
224   }
225   //=========================================================================
226
227
228   //=========================================================================  
229   TypeInfo BlackBox::bbGetOutputType( const std::string &name ) const 
230   {
231     bbtkBlackBoxDebugMessage("kernel",8,
232                              "BlackBox::bbGetOutputType(\""
233                              <<name<<"\")"
234                              <<std::endl);
235     TypeInfo r = bbGetDescriptor()->GetOutputDescriptor(name)->GetTypeInfo();
236     bbtkDebugDecTab("kernel",8); 
237     return r;
238   }
239   //=========================================================================
240
241   //=========================================================================
242   TypeInfo BlackBox::bbGetInputType( const std::string &name ) const
243   {
244     bbtkBlackBoxDebugMessage("kernel",8,
245                              "BlackBox::bbGetInputType(\""
246                              <<name<<"\")"
247                              <<std::endl);
248     TypeInfo r = bbGetDescriptor()->GetInputDescriptor(name)->GetTypeInfo();
249     bbtkDebugDecTab("kernel",8);
250     return r;
251   }
252   //=========================================================================
253
254
255   //=========================================================================
256   void BlackBox::bbAllocateConnectors()
257   {  
258     bbtkBlackBoxDebugMessage("kernel",8,
259                         "BlackBox::bbAllocateConnectors()"
260                         <<std::endl);                                   
261
262     MakeBlackBoxPointer(this,true);
263
264     const BlackBoxDescriptor::InputDescriptorMapType& imap 
265       = bbGetDescriptor()->GetInputDescriptorMap(); 
266     BlackBoxDescriptor::InputDescriptorMapType::const_iterator i;       
267     for ( i = imap.begin(); i != imap.end(); ++i )                      
268       {                                                                 
269         bbtkBlackBoxDebugMessage("kernel",8,"* Allocate \""<<i->first<<"\""<<std::endl);
270         bbGetInputConnectorMap()[i->second->GetName()] 
271           = new BlackBoxInputConnector(GetThisPointer<BlackBox>());
272       }                                                                 
273     const BlackBoxDescriptor::OutputDescriptorMapType& omap 
274       = bbGetDescriptor()->GetOutputDescriptorMap();                   
275     BlackBoxDescriptor::OutputDescriptorMapType::const_iterator o; 
276     for ( o = omap.begin(); o != omap.end(); ++o )
277       {                                                 
278         bbtkBlackBoxDebugMessage("kernel",8,"* Allocate \""<<o->first<<"\""<<std::endl);
279         bbGetOutputConnectorMap()[o->second->GetName()] 
280           = new BlackBoxOutputConnector(GetThisPointer<BlackBox>());
281       }
282   }
283   //=========================================================================
284
285
286   //=========================================================================
287   void BlackBox::bbDesallocateConnectors()
288   {
289     bbtkBlackBoxDebugMessage("kernel",8,
290                         "BlackBox::bbDesallocateConnectors()"
291                         <<std::endl);                                   
292
293     InputConnectorMapType::const_iterator i;
294     for ( i = bbGetInputConnectorMap().begin();
295           i != bbGetInputConnectorMap().end(); ++i )                   
296       {                                                                 
297         bbtkBlackBoxDebugMessage("kernel",8,"* Delete \""<<i->first<<"\""<<std::endl);
298         delete (i->second);
299       }                                                                 
300     OutputConnectorMapType::const_iterator o;   
301     for ( o = bbGetOutputConnectorMap().begin(); 
302           o != bbGetOutputConnectorMap().end(); ++o )                   
303       {                                                                 
304         bbtkBlackBoxDebugMessage("kernel",8,"* Delete \""<<o->first<<"\""<<std::endl);         
305         delete (o->second);
306       }                                                                 
307    
308     bbtkDebugDecTab("kernel",8);
309   }
310   //=========================================================================
311
312
313   //=========================================================================
314   void BlackBox::bbCopyIOValues(BlackBox& from)
315   {
316     bbtkBlackBoxDebugMessage("kernel",1,
317                              "BlackBox::bbCopyIOValues("
318                              <<from.bbGetFullName()<<")"
319                              <<std::endl);
320     // copies the input values
321     const BlackBoxDescriptor::InputDescriptorMapType& imap 
322       = bbGetDescriptor()->GetInputDescriptorMap(); 
323     BlackBoxDescriptor::InputDescriptorMapType::const_iterator i;       
324     for ( i = imap.begin(); i != imap.end(); ++i )                      
325       {         
326         if (! i->second->GetCopyConstruct() ) continue;
327         std::string input = i->second->GetName();
328         bbtkBlackBoxDebugMessage("kernel",2,"* Copying input "<<input<<std::endl);
329         this->bbSetInput(input, from.bbGetInput(input) );
330       }                                                                 
331     // copies the output values
332     const BlackBoxDescriptor::OutputDescriptorMapType& omap 
333       = bbGetDescriptor()->GetOutputDescriptorMap();                   
334     BlackBoxDescriptor::OutputDescriptorMapType::const_iterator o; 
335     for ( o = omap.begin(); o != omap.end(); ++o )
336       {                                                 
337         if (! o->second->GetCopyConstruct() ) continue;
338         std::string output = o->second->GetName();
339         bbtkBlackBoxDebugMessage("kernel",2,"* Copying output "<<output<<std::endl);
340         this->bbSetOutput(output, from.bbGetOutput(output) );
341       }
342
343     bbtkDebugDecTab("kernel",9);
344   }
345   //=========================================================================
346
347
348
349   //=========================================================================
350   bool BlackBox::bbCanReact() const 
351   { 
352     return ( bbGlobalGetSomeBoxExecuting() 
353 #ifdef USE_WXWIDGETS
354              || Wx::IsSomeWindowAlive() 
355 #endif
356              );
357   }
358   //=========================================================================
359
360
361
362   //=========================================================================
363   BlackBox::BoxProcessModeValue BlackBox::bbGetBoxProcessModeValue() const
364   {
365     const std::string& p = bbmBoxProcessMode;
366     if ( (p == "0") ||
367          (p == "P") || (p == "p") ||
368          (p == "Pipeline") || (p == "pipeline") ) return bbPipeline;
369     if ( (p == "1") ||
370          (p == "A") || (p == "a") ||
371          (p == "Always") || (p == "always") ) return bbAlways;
372     if ( (p == "2") ||
373          (p == "R") || (p == "r") ||
374          (p == "Reactive") || (p == "reactive") ) 
375                 return bbReactive;
376     /*
377     if ( (p == "3") ||
378          (p == "F") || (p == "f") ||
379          (p == "Flash") || (p == "flash") ) return Flash;
380     */
381     bbtkError(bbGetFullName()<<" : BoxProcessMode value '"<<p
382               <<"' unknown. Possible values : "
383               <<"'0'/'P'/'p'/'Pipeline'/'pipeline' | "
384               <<"'1'/'A'/'a'/'Always'/'always' | "
385               <<"'2'/'R'/'r'/'Reactive'/'reactive'"
386               //      <<"'3'/'F'/'f'/'Flash'/'flash'"
387               <<std::endl);
388   }
389   //=========================================================================
390   
391   //=========================================================================
392   bool  BlackBox::bbBoxProcessModeIsReactive() const
393   {
394     return (bbGetBoxProcessModeValue() == bbReactive);
395   }
396   //=========================================================================
397
398   //=========================================================================
399   bool  BlackBox::bbBoxProcessModeIsAlways() const
400   {
401     return (bbGetBoxProcessModeValue() == bbAlways);
402   }
403   //=========================================================================
404
405
406
407
408   //=========================================================================
409   void BlackBox::bbAddOutputObserver(const std::string& output, 
410                                    OutputChangeCallbackType f)
411   {
412     bbGetOutputConnector(output).AddChangeObserver(f);
413   }  
414   //=========================================================================
415
416   //=========================================================================
417   void BlackBox::bbRemoveOutputObserver(const std::string& output_name, 
418                                       OutputChangeCallbackType f)
419   {
420     bbtkError("BlackBox::RemoveChangeObserver NOT IMPLEMENTED");
421   }
422   //=========================================================================
423
424
425   //=========================================================================
426   void BlackBox::bbSetStatusAndPropagate(BlackBoxInputConnector* c,
427                                          IOStatus s)
428   {
429     bbtkBlackBoxDebugMessage("change",5,
430                              "=> BlackBox::bbSetStatusAndPropagate(input,"
431                              <<GetIOStatusString(s)<<")"
432                              <<std::endl);
433
434     if (s==UPTODATE) bbtkError("bbSetStatusAndPropagate with status UPTODATE!");
435     c->SetStatus(s);
436
437     // Flash reaction
438     /*
439     if (bbGetBoxProcessModeValue() == Flash)
440       {
441         this->bbExecute();
442       }
443     */
444
445     OutputConnectorMapType::const_iterator o;   
446     for ( o = bbGetOutputConnectorMap().begin(); 
447           o != bbGetOutputConnectorMap().end(); ++o )                   
448       {                                                                 
449         if (o->second->GetStatus()==UPTODATE) 
450           {
451             o->second->SetStatus(OUTOFDATE);
452             o->second->SignalChange(GetThisPointer<BlackBox>(),o->first); 
453           }
454         }                                                               
455     
456     if (  ( bbBoxProcessModeIsReactive()
457            || (c==bbGetInputConnectorMap().find("BoxExecute")->second))
458            && (bbCanReact() ) )
459       {
460         bbtkBlackBoxDebugMessage("change",2,
461                          "-> Execution triggered by Reactive mode or BoxExecute input change"<<std::endl);
462         bbGlobalAddToExecutionList( GetThisPointer<BlackBox>() );
463       }    
464     bbtkBlackBoxDebugMessage("change",5,
465                              "<= BlackBox::bbSetStatusAndPropagate(input)"
466                              <<std::endl);
467   }
468   //=========================================================================
469
470
471   //=========================================================================  
472   void BlackBox::bbSignalOutputModification(bool reaction)
473   {
474     bbtkBlackBoxDebugMessage("change",5,
475                              "=> BlackBox::bbSignalOutputModification("
476                              <<reaction<<")"
477                              <<"]"<<std::endl);
478
479     OutputConnectorMapType::iterator i;
480     for ( i  = bbGetOutputConnectorMap().begin(); 
481           i != bbGetOutputConnectorMap().end(); ++i) 
482       {
483         //      std::cout << "Stat = "
484         //<<GetIOStatusString(i->second->GetStatus())
485         //                <<std::endl;
486         // LG : CANNOT SIGNAL ONLY WHEN UPTODATE 
487         // See bbtkSampleOutputObserver
488         //      if (i->second->GetStatus()==UPTODATE) 
489         //        {
490             i->second->SignalChange(GetThisPointer<BlackBox>(),i->first); 
491             //    }
492       } // for
493
494     if (reaction) bbGlobalProcessExecutionList();
495
496     bbtkBlackBoxDebugMessage("change",5,
497                              "<= BlackBox::bbSignalOutputModification()"
498                              <<std::endl);
499   }  
500   //=========================================================================   
501
502
503   //=========================================================================  
504   void BlackBox::bbSignalOutputModification(const std::string& output,
505                                             bool reaction)
506   {
507     bbtkBlackBoxDebugMessage("change",5,
508                              "=> BlackBox::bbSignalOutputModification("
509                              <<output<<","<<reaction<<")"
510                              <<std::endl);
511     
512     OutputConnectorMapType::iterator i = 
513       bbGetOutputConnectorMap().find(output);
514
515
516     if ( i == bbGetOutputConnectorMap().end() ) 
517         {
518           bbtkError("BlackBox["<<bbGetFullName()<<"]::bbSignalOutputModification("<<output<<") : unknown output");
519         }
520
521     //    if (i->second->GetStatus()==UPTODATE) 
522     //      {
523         i->second->SignalChange(GetThisPointer<BlackBox>(),i->first); 
524         // Has to notify the output "BoxChange" also
525         if (output != "BoxChange") 
526           {
527             i = bbGetOutputConnectorMap().find("BoxChange");
528             if ( i != bbGetOutputConnectorMap().end() ) 
529               {
530                 i->second->SignalChange(GetThisPointer<BlackBox>(),i->first); 
531               }
532           }
533         if (reaction) bbGlobalProcessExecutionList();
534         //      }
535
536         bbtkBlackBoxDebugMessage("change",5,
537                              "<= BlackBox::bbSignalOutputModification("
538                              <<output<<")"
539                              <<std::endl);
540   }  
541   //=========================================================================   
542   //=========================================================================  
543   void BlackBox::bbSignalOutputModification(const std::vector<std::string>& output,
544         bool reaction)
545   {
546     bbtkBlackBoxDebugMessage("change",5,
547                         "=> BlackBox::bbSignalOutputModification(vector of outputs)"
548 <<std::endl);
549     OutputConnectorMapType::iterator i;
550     std::vector<std::string>::const_iterator o;
551     bool changed = false;
552     for (o=output.begin();o!=output.end();++o) 
553       {
554         // the output "BoxChange" must be signaled **AFTER** all others
555         if (*o == "BoxChange") continue;
556         // Look for the connector
557         i = bbGetOutputConnectorMap().find(*o);
558         if ( i == bbGetOutputConnectorMap().end() ) 
559           {
560             bbtkError("BlackBox["<<bbGetFullName()<<"]::bbSignalOutputModification("<<*o<<") : unknown output");
561           }
562
563         //      if (i->second->GetStatus()==UPTODATE)
564         //        {
565             i->second->SignalChange(GetThisPointer<BlackBox>(),i->first); 
566             changed = true;
567             //  }
568       }
569     // Has to notify the output "BoxChange" also
570     i = bbGetOutputConnectorMap().find("BoxChange");
571     if ( changed && (i != bbGetOutputConnectorMap().end())) 
572       {
573         // if (i->second->GetStatus()==UPTODATE) 
574         //        {
575             i->second->SignalChange(GetThisPointer<BlackBox>(),i->first); 
576             if (reaction) bbGlobalProcessExecutionList();
577             //  }
578       }
579
580     bbtkBlackBoxDebugMessage("change",5,
581                              "<= BlackBox::bbSignalOutputModification(vector of outputs)"
582                              <<std::endl);
583   }  
584   //=========================================================================   
585
586
587
588
589
590
591
592   //=========================================================================
593   /// Main processing method of the box.
594   void BlackBox::bbExecute(bool force)
595   {
596     bbtkBlackBoxDebugMessage("process",2,
597                              "=> BlackBox::bbExecute("<<(int)force<<")"
598                              <<std::endl);
599  
600     // If already executing : return
601     /*
602     if (bbGetExecuting()) 
603       {
604         bbtkBlackBoxDebugMessage("process",2,
605                          " -> already executing : abort"<<std::endl);
606         return;
607       }
608     */
609
610     // If execution frozen : return
611     if (bbGlobalGetFreezeExecution()) 
612       {
613         bbtkBlackBoxDebugMessage("process",2,
614                          " -> FreezeExecution global flag is 'true' : abort execution"<<std::endl);
615       }
616
617     BBTK_BUSY_CURSOR;
618
619     // If force is true then update is triggered even if the box is UPTODATE
620     //    if (force) bbSetModifiedStatus();
621
622     // Calls the main recursive execution method 
623     bbRecursiveExecute(Connection::Pointer());
624
625     bbtkBlackBoxDebugMessage("process",2,
626                              "<= BlackBox::bbExecute()"
627                              <<std::endl);
628   }
629   //=========================================================================
630
631   //=========================================================================
632   void BlackBox::bbInitializeProcessing()
633   {
634     if (!bbmInitialized) 
635       {
636         bbtkBlackBoxDebugMessage("process",2,"** Initialize processing"
637                                  <<std::endl);
638         this->bbRecursiveInitializeProcessing();
639         bbmInitialized = true;
640       }
641   }
642   //=========================================================================
643
644   //=========================================================================
645   void BlackBox::bbFinalizeProcessing()
646   {
647     if (bbmInitialized) 
648       {
649         bbtkBlackBoxDebugMessage("process",2,"** Finalize processing"
650                                  <<std::endl);
651         this->bbRecursiveFinalizeProcessing();
652         bbmInitialized = false;
653       }
654   }
655   //=========================================================================
656
657   
658   //=========================================================================
659   void BlackBox::bbRecursiveExecute( Connection::Pointer caller )
660   {
661     bbtkBlackBoxDebugMessage("process",3,
662                         "=> BlackBox::bbRecursiveExecute("
663                         <<(caller?caller->GetFullName():"0")<<")"
664                         <<std::endl);
665
666     // If already executing : return
667     if (bbGetExecuting()) 
668       {
669         bbtkBlackBoxDebugMessage("process",3,
670                          " -> already executing : abort"<<std::endl);
671         return; 
672       }
673     
674     // If not initialized do it
675     bbInitializeProcessing();
676
677     bbSetExecuting(true);
678     bool wasExecuting = bbGlobalGetSomeBoxExecuting();
679     bbGlobalSetSomeBoxExecuting(true);
680     
681     // Creates the window if the black box has one
682     this->bbCreateWindow();
683     
684     // Updates its inputs
685     IOStatus s = bbUpdateInputs();
686     
687     if ( (s != UPTODATE) ||
688          bbBoxProcessModeIsAlways() )
689       {
690           // Displays the window (WxBlackbox)
691           //    bbShowWindow(caller);
692
693           // Actual processing (virtual)
694           this->bbProcess();
695         
696         
697           // Update the I/O statuses
698           bbComputePostProcessStatus();
699       }
700     else 
701       {
702         // Test output status...
703         OutputConnectorMapType::iterator o;
704         for ( o = bbGetOutputConnectorMap().begin(); 
705               o!= bbGetOutputConnectorMap().end(); ++o) 
706           {
707             if (o->second->GetStatus() != UPTODATE)
708               {
709                 bbtkWarning("BlackBox::bbRecursiveExecute: "
710                             <<"all inputs are Up-to-date but output '"
711                             <<o->first<<"' is Out-of-date ???");
712               }
713           }
714         
715         bbtkBlackBoxDebugMessage("process",3," -> Up-to-date : nothing to do"
716                          <<std::endl);
717       }
718
719     // Shows the window if the black box has one
720     this->bbShowWindow(); 
721
722           
723     bbtkBlackBoxDebugMessage("process",3,
724             "<= BlackBox::bbRecursiveExecute()"
725             <<std::endl);
726
727     bbSetExecuting(false);
728     bbGlobalSetSomeBoxExecuting(wasExecuting);
729
730     return;
731   }
732   //=========================================================================
733   
734    
735
736
737
738   //=========================================================================
739   IOStatus BlackBox::bbUpdateInputs()
740   {
741     bbtkBlackBoxDebugMessage("process",4,
742                         "=> BlackBox::bbUpdateInputs()"
743                         <<std::endl);   
744
745     IOStatus s = UPTODATE;
746
747     InputConnectorMapType::iterator i;
748     for ( i = bbGetInputConnectorMap().begin(); 
749           i!= bbGetInputConnectorMap().end(); ++i) 
750       {
751         //      if (i->first=="WinHide") continue;
752         // If input type is Void : no recurse
753         //if (  bbGetDescriptor()->GetInputDescriptor(i->first)->GetTypeInfo() 
754         //      == typeid(Void) ) 
755         //  continue;
756         bbtkBlackBoxDebugMessage("change",2,
757                             "Input '"<<i->first
758                             <<"': status before update = '"
759                             <<GetIOStatusString(i->second->GetStatus())
760                             <<"'"<<std::endl);
761         i->second->RecursiveExecute();
762         IOStatus t = i->second->GetStatus();
763         if (t > s) s = t;
764         bbtkBlackBoxDebugMessage("change",2,
765                                  "Input '"<<i->first
766                                  <<"': status before process = '"
767                                  <<GetIOStatusString(i->second->GetStatus())
768                                  <<"'"<<std::endl);
769       }
770     
771     bbtkBlackBoxDebugMessage("process",4,
772                         "<= BlackBox::bbUpdateInputs()"
773                         <<std::endl);
774     return s;
775   }
776   //=========================================================================
777
778   //==================================================================
779    void BlackBox::bbComputePostProcessStatus()
780   {
781     bbtkBlackBoxDebugMessage("process",4,
782                         "=> BlackBox::bbComputePostProcessStatus()"
783                         <<std::endl);   
784
785     IOStatus new_output_status = UPTODATE;
786     if (bbBoxProcessModeIsAlways()) new_output_status = OUTOFDATE;
787
788     // Update the input statuses
789     InputConnectorMapType::iterator i;
790     for ( i = bbGetInputConnectorMap().begin(); 
791           i!= bbGetInputConnectorMap().end(); ++i) 
792       {
793         IOStatus t = i->second->GetStatus();
794         if (t == OUTOFDATE) new_output_status = OUTOFDATE;
795         // A previously MODIFIED status turns to UPTODATE
796         if (t==MODIFIED) i->second->SetStatus(UPTODATE);
797         bbtkBlackBoxDebugMessage("change",2,
798                          "Input '"<<i->first<<"' : "
799                          << GetIOStatusString(t) << " -> "
800                          << GetIOStatusString(i->second->GetStatus())
801                          << std::endl);
802       }
803     bbtkBlackBoxDebugMessage("change",2,
804                              "New output status : "
805                              << GetIOStatusString(new_output_status)
806                              <<std::endl);
807     // Update the output statuses
808     OutputConnectorMapType::iterator o;
809     for ( o = bbGetOutputConnectorMap().begin(); 
810           o!= bbGetOutputConnectorMap().end(); ++o) 
811       {
812         o->second->SetStatus(new_output_status);
813       }
814
815     bbtkBlackBoxDebugMessage("process",4,
816                         "<= BlackBox::bbComputePostProcessStatus()"
817                         <<std::endl);
818   }
819   //==================================================================
820
821   //=========================================================================
822   void BlackBox::bbConnectInput( const std::string& name, Connection* c)
823   {
824     bbtkBlackBoxDebugMessage("connection",2,
825                         "==> BlackBox::bbConnectInput(\""
826                         <<name<<"\","<<c->GetFullName()<<")"
827                         <<std::endl);       
828
829     InputConnectorMapType::iterator i = bbGetInputConnectorMap().find(name);
830     if (i==bbGetInputConnectorMap().end())
831       {
832         bbtkError("no input called '"<<name<<"'");
833       }
834     i->second->SetConnection(c);
835     // The input *MUST* be set OUTOFDATE to update its input on next execution
836     bbSetStatusAndPropagate(i->second,OUTOFDATE);
837
838     bbtkBlackBoxDebugMessage("connection",2,
839                         "<== BlackBox::bbConnectInput(\""
840                         <<name<<"\","<<c->GetFullName()<<")"
841                         <<std::endl);
842   }
843   //=========================================================================
844
845
846   //=========================================================================  
847   void BlackBox::bbConnectOutput( const std::string& name, Connection* c)
848   {
849     bbtkBlackBoxDebugMessage("connection",2,
850                              "==> BlackBox::bbConnectOutput(\""<<name<<"\","
851                              <<c->GetFullName()<<")"
852                              <<std::endl);       
853
854     OutputConnectorMapType::iterator i = bbGetOutputConnectorMap().find(name);
855     if (i==bbGetOutputConnectorMap().end())
856       {
857         bbtkError("no output called '"<<name<<"'");
858       }
859     i->second->SetConnection(c);
860
861     bbtkBlackBoxDebugMessage("connection",2,
862                              "<== BlackBox::bbConnectOutput(\""<<name<<"\","
863                              <<c->GetFullName()<<")"
864                              <<std::endl);
865   }
866   //=========================================================================
867
868
869   //=========================================================================
870    void BlackBox::bbDisconnectInput( const std::string& name, Connection* c)
871   {
872
873     bbtkBlackBoxDebugMessage("connection",2,
874                      "==> BlackBox::bbDisconnectInput(\""<<name
875                      <<"\","<<c->GetFullName()<<")"
876                      <<std::endl);
877     if (!c) 
878       {
879
880         bbtkBlackBoxDebugMessage("connection",2,"c==0"<<std::endl);     
881         return;
882       }
883
884     InputConnectorMapType::iterator i = bbGetInputConnectorMap().find(name);
885     if (i==bbGetInputConnectorMap().end())
886       {
887         bbtkError("no input called '"<<name<<"'");
888       }
889     i->second->UnsetConnection(c);
890
891     bbtkBlackBoxDebugMessage("connection",2,
892                      "<== BlackBox::bbDisconnectInput(\""<<name
893                      <<"\","<<c->GetFullName()<<")"
894                      <<std::endl);      
895
896   }
897   //=========================================================================
898
899
900   //=========================================================================
901    void BlackBox::bbDisconnectOutput( const std::string& name, Connection* c)
902   {
903     bbtkBlackBoxDebugMessage("connection",2,
904                      "==> BlackBox::bbDisconnectOutput(\""<<name
905                      <<"\","<<c->GetFullName()<<")"
906                      <<std::endl);       
907     if (!c) 
908       {
909
910         bbtkBlackBoxDebugMessage("connection",2,"c==0"<<std::endl);     
911         return;
912       }
913
914     OutputConnectorMapType::iterator i = bbGetOutputConnectorMap().find(name);
915     if (i==bbGetOutputConnectorMap().end())
916       {
917         bbtkError("no output called '"<<name<<"'");
918       }
919     i->second->UnsetConnection(c);
920
921     bbtkBlackBoxDebugMessage("connection",2,
922                      "<== BlackBox::bbDisconnectOutput(\""<<name
923                      <<"\","<<c->GetFullName()<<")"
924                      <<std::endl);       
925   } 
926   //=========================================================================
927  
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950   //=========================================================================
951   void BlackBox::bbWriteDotInputOutputName(FILE *ff,bool inputoutput,int detail, int level)
952   {
953     fprintf(ff,"%s%p",bbGetTypeName().c_str(),this);
954   }
955   //=========================================================================
956
957
958   //=========================================================================
959   std::string BlackBox::bbGetOutputAsString( const std::string &output ) 
960   {
961     std::string v;
962     // Looks for the adaptor
963     if (bbGetOutputType(output).name() != typeid(std::string).name() ) 
964       {
965         // Look for factory 
966         Package::Pointer p = bbGetDescriptor()->GetPackage();
967         if ((p != 0) && ( ! p->GetFactorySet().empty() ) )
968           {
969             Factory::Pointer f = p->GetFactorySet().begin()->lock();
970             BlackBox::Pointer a;
971             try
972               {
973                 a = f->NewAdaptor(  
974                                   bbGetOutputType(output),
975                                   typeid(std::string),
976                                   "");
977               } catch (bbtk::Exception e) 
978               {
979               }
980             if (a){
981               //                        bbUpdate();
982               a->bbSetInput("In",bbGetOutput(output));
983               a->bbExecute();
984               v = a->bbGetOutput("Out").unsafe_get<std::string>() ;
985             } else {
986               v="? (no adaptor found)";
987             }
988           }
989         else 
990           {
991             v="? (no factory found)";
992           }
993       } 
994     else 
995       {
996         //         bbUpdate();
997         v = bbGetOutput(output).unsafe_get<std::string>() ;
998       }
999     return v;
1000   }
1001   //=========================================================================
1002
1003   //=========================================================================
1004   std::string BlackBox::bbGetInputAsString( const std::string &input ) 
1005   {
1006     std::string v;
1007     // Looks for the adaptor
1008     if (bbGetInputType(input) != typeid(std::string)) 
1009       {
1010         // Look for factory 
1011         Package::Pointer p = bbGetDescriptor()->GetPackage();
1012         if ((p != 0) && ( ! p->GetFactorySet().empty() ) )
1013           {
1014             Factory::Pointer f = p->GetFactorySet().begin()->lock();
1015             BlackBox::Pointer a;
1016             try
1017               {
1018                 a = f->NewAdaptor(  
1019                                bbGetInputType(input),
1020                                typeid(std::string),
1021                                "");
1022               }catch (bbtk::Exception e) 
1023               {
1024               }
1025             if (a)
1026               {
1027                 //                      bbUpdate();
1028                 a->bbSetInput("In",bbGetInput(input));
1029                 a->bbExecute();
1030                 v = a->bbGetOutput("Out").unsafe_get<std::string>() ;
1031               } 
1032             else 
1033               {
1034                 v="? (no adaptor found)";
1035               }
1036           } 
1037         else 
1038           {
1039             v="? (no factory found)";
1040           }
1041       }
1042     else 
1043       {
1044         v = bbGetInput(input).unsafe_get<std::string>() ;
1045       }
1046     return v;
1047   }
1048   //=======================================================================
1049
1050   //=======================================================================
1051   // Replaces substrings "<" by "["
1052   void SubsBrackets ( std::string& s )
1053   {
1054     //   std::cout << "BEFORE=["<<s<<"]"<<std::endl;
1055     std::string ss("<");
1056     std::string::size_type pos = 0;
1057     pos = s.find(ss,0);
1058     std::string cr("[");
1059     while ( pos != std::string::npos )
1060       {
1061         //      std::cout << "*** find one "<<std::endl;
1062         s.replace(pos,1,cr.c_str(),1);
1063         pos = s.find(ss, pos);
1064       } 
1065     ss = ">";
1066     pos = 0;
1067     pos = s.find(ss,0);
1068     cr = "]";
1069     while ( pos != std::string::npos )
1070       {
1071         //      std::cout << "*** find one "<<std::endl;
1072         s.replace(pos,1,cr.c_str(),1);
1073         pos = s.find(ss, pos);
1074       } 
1075     ss = ",";
1076     pos = 0;
1077     pos = s.find(ss,0);
1078     cr = "-";
1079     while ( pos != std::string::npos )
1080       {
1081         //      std::cout << "*** find one "<<std::endl;
1082         s.replace(pos,1,cr.c_str(),1);
1083         pos = s.find(ss, pos);
1084       }     //    std::cout << "AFTER=["<<s<<"]"<<std::endl;
1085   }
1086   //=======================================================================
1087
1088   //=========================================================================
1089   /// Write Graphviz-dot description in file
1090   void BlackBox::bbWriteDotFileBlackBox(FILE *ff,
1091                                         BlackBox::Pointer parentblackbox, 
1092                                         int detail, int level,
1093                                         bool instanceOrtype,
1094                                         bool relative_link )
1095
1096   { 
1097     InputConnectorMapType::iterator i;
1098     // label
1099     std::string labelStr;
1100     std::string valueStr("");
1101
1102         if (detail==0) {
1103                 labelStr = bbGetName() ; 
1104 //EED 18 Fev 2008
1105                 labelStr = labelStr + "\\n[" +this->bbGetDescriptor()->GetPackage()->GetName()+"::"+ bbGetTypeName() + "]";
1106         } else {
1107                 labelStr = bbGetName();
1108                 labelStr = labelStr + "   [" +this->bbGetDescriptor()->GetPackage()->GetName()+"::"+ bbGetTypeName() + "]  ";
1109     }
1110
1111     SubsBrackets(labelStr);
1112     if (detail==1)
1113       {
1114         labelStr = labelStr + " | {{ "; 
1115         std::string tempStrTypeName;
1116         bool tmp; 
1117         tmp=false;
1118         for ( i = mInputConnectorMap.begin(); i != mInputConnectorMap.end(); ++i ) 
1119           {
1120             if (tmp==true)
1121               {
1122                 labelStr=labelStr+" | ";
1123               }
1124             tmp=true;
1125             if (instanceOrtype==true)
1126               {
1127                 valueStr = this->bbGetInputAsString(i->first) + " = ";
1128               } 
1129             const BlackBoxInputDescriptor* id = bbGetDescriptor()->GetInputDescriptor(i->first);
1130             tempStrTypeName=id->GetTypeName();
1131             SubsBrackets(tempStrTypeName);
1132             std::string Name(i->first);
1133             SubsBrackets(Name);
1134             labelStr=labelStr + "<"+i->first.c_str()+"> "  + valueStr +  Name.c_str() + "  [" + tempStrTypeName.c_str() + "]";
1135           }
1136         labelStr=labelStr+ " } | {";
1137         tmp = false;
1138         OutputConnectorMapType::iterator ii;
1139         for ( ii = mOutputConnectorMap.begin(); ii != mOutputConnectorMap.end(); ++ii ) 
1140         {
1141            if (tmp==true)
1142            {
1143                    labelStr=labelStr+" | ";
1144            }
1145            tmp = true;
1146            if (instanceOrtype==true)
1147            {
1148                    valueStr = this->bbGetOutputAsString(ii->first) + " = ";
1149            }
1150            const BlackBoxOutputDescriptor* id = bbGetDescriptor()->GetOutputDescriptor(ii->first); 
1151            tempStrTypeName=id->GetTypeName();
1152            SubsBrackets(tempStrTypeName);
1153            std::string Name(ii->first);
1154            SubsBrackets(Name);
1155            labelStr=labelStr+"<"+ii->first.c_str()+"> " + valueStr + Name.c_str() + "  ["+tempStrTypeName+"]";
1156         }
1157         labelStr = labelStr+ "      } }" ;
1158 } // detail
1159
1160     fprintf(ff,"  " );
1161     bbWriteDotInputOutputName(ff,true,detail,level);
1162     std::string tmp ( bbGetTypeName() );
1163     SubsBrackets(tmp);
1164     std::string url;
1165     if (relative_link) 
1166       url = this->bbGetDescriptor()->GetPackage()->GetDocRelativeURL() + "#" + tmp;
1167     else 
1168       url = this->bbGetDescriptor()->GetPackage()->GetDocURL() + "#" + tmp;
1169   
1170     fprintf( ff , " [shape=record, URL=\"%s\",label=\"%s\"]%s\n",url.c_str(),labelStr.c_str(),";" );
1171     //    std::cout  << labelStr << std::endl;
1172
1173     // Relation Input
1174     if (GetThisPointer<BlackBox>()!=parentblackbox){
1175       for ( i = mInputConnectorMap.begin(); i != mInputConnectorMap.end(); ++i ) 
1176         {
1177           if (i->second)
1178             {
1179               Connection* con = i->second->GetConnection();
1180               if (con!=NULL){
1181                 BlackBox::Pointer a=con->GetOriginalBlackBoxFrom();
1182                 BlackBox::Pointer b=con->GetOriginalBlackBoxTo();
1183                 fprintf(ff,"  ");
1184                 a->bbWriteDotInputOutputName(ff,false,detail,level);
1185                 if (detail==1)
1186                   {
1187                     fprintf(ff,":%s",con->GetOriginalBlackBoxFromOutput().c_str());
1188                   }
1189                 fprintf(ff,"->");
1190                 b->bbWriteDotInputOutputName(ff,true,detail,level);
1191                 if (detail==1)
1192                   {
1193                     fprintf(ff,":%s",con->GetOriginalBlackBoxToInput().c_str());
1194                   }
1195                 fprintf(ff,"%s\n",";");
1196               }  // if con
1197             } // if second
1198         } // for
1199     } // if parentblackbox
1200   }
1201   //=========================================================================
1202
1203
1204
1205
1206   //=========================================================================
1207   void BlackBox::bbPrintHelp(BlackBox::Pointer parentblackbox, 
1208                                  int detail, int level
1209                                  /*,Factory *factory*/ )
1210   {
1211      
1212     if (this->bbGetDescriptor()->GetPackage()) 
1213       {
1214              bbtkBlackBoxMessage("help",1,"Black Box '"<<bbGetName()<<"' <"<<
1215                     this->bbGetDescriptor()->GetPackage()->GetName()
1216                     <<"::"<<this->bbGetDescriptor()->GetTypeName()<<">"<<std::endl);
1217       }
1218     else 
1219       {
1220              bbtkBlackBoxMessage("help",1,"Black Box <::"<<this->bbGetDescriptor()->GetTypeName()<<">"<<std::endl);
1221       }
1222     /*
1223     if (bbIsUpToDate())
1224       {
1225              bbtkBlackBoxMessage("help",1,"Up-to-date ["<<mMaxInputChangeTime<<","
1226                     <<mMinOutputChangeTime<<"]"<<std::endl);
1227       }
1228     else 
1229       {
1230              bbtkBlackBoxMessage("help",1,"Out-of-date ["<<mMaxInputChangeTime<<","
1231                     <<mMinOutputChangeTime<<"]"<<std::endl);
1232       }
1233     */
1234     //    bbtkBlackBoxMessage("help",1," "<<GetDescription()<<std::endl);
1235     //    bbtkBlackBoxMessage("help",1," By : "<<GetAuthor()<<std::endl);
1236
1237     std::vector<std::string> iname;
1238     std::vector<std::string> ivalue;
1239     std::vector<std::string> iconn;
1240     std::vector<std::string> istatus;
1241
1242     InputConnectorMapType::iterator i;
1243     unsigned int namelmax = 0;
1244     unsigned int valuelmax = 0;
1245     //   unsigned int connlmax = 0;
1246     for ( i = mInputConnectorMap.begin(); i != mInputConnectorMap.end(); ++i ) 
1247     {
1248            iname.push_back(i->first);
1249            if (iname.back().size()>namelmax) namelmax = iname.back().size();
1250            ivalue.push_back(bbGetInputAsString(i->first));
1251            if (ivalue.back().size()>valuelmax) valuelmax = ivalue.back().size();
1252            std::string s("");
1253            Connection* con = i->second->GetConnection();
1254            if (con!=0){
1255               s = con->GetOriginalBlackBoxFrom()->bbGetName();
1256               s += ".";
1257               s += con->GetOriginalBlackBoxFromOutput();
1258            }  // if con
1259            iconn.push_back(s);
1260            istatus.push_back(GetIOStatusString(i->second->GetStatus()));
1261     }
1262     OutputConnectorMapType::iterator o;
1263     std::vector<std::string> oname;
1264     std::vector<std::string> ovalue;
1265     std::vector<std::vector<std::string> > oconn;
1266     std::vector<std::string> ostatus;
1267     for ( o = mOutputConnectorMap.begin(); o != mOutputConnectorMap.end(); ++o ) 
1268     {
1269            oname.push_back(o->first);
1270            if (oname.back().size()>namelmax)
1271           namelmax = oname.back().size();
1272            ovalue.push_back(bbGetOutputAsString(o->first));
1273            if (ovalue.back().size()>valuelmax) 
1274           valuelmax = ovalue.back().size();
1275            std::vector<std::string> ss;
1276            const std::vector<Connection*>& con 
1277                                     = o->second->GetConnectionVector();
1278            std::vector<Connection*>::const_iterator c;
1279            for (c=con.begin();c!=con.end();++c) 
1280            {
1281                std::string s;
1282                s = (*c)->GetOriginalBlackBoxTo()->bbGetName();
1283                s += ".";
1284                s += (*c)->GetOriginalBlackBoxToInput();
1285                ss.push_back(s);
1286             }  // if con
1287             oconn.push_back(ss);
1288             ostatus.push_back(GetIOStatusString(o->second->GetStatus()));
1289     }
1290
1291     if (iname.size()) 
1292       bbtkBlackBoxMessage("help",1," * Inputs : "<<std::endl);
1293     else 
1294       bbtkBlackBoxMessage("help",1," * No inputs"<<std::endl);
1295
1296     std::vector<std::string>::iterator i1,i2,i3,i4;
1297     for (i1=iname.begin(),i2=ivalue.begin(),i3=iconn.begin(),i4=istatus.begin();
1298              i1!=iname.end(),i2!=ivalue.end(),i3!=iconn.end(),i4!=istatus.end();
1299            ++i1,++i2,++i3,++i4)
1300      {
1301             std::string name(*i1);
1302             name += "'";
1303             name.append(1+namelmax-name.size(),' ');
1304             std::string value(*i2);
1305             value += "'";
1306             value.append(1+valuelmax-value.size(),' ');
1307             if (i3->size()) 
1308               bbtkBlackBoxMessage("help",1,"    '"<<name<<" = '"<<value<<" <-- '" <<*i3<<"'");
1309             else 
1310               bbtkBlackBoxMessage("help",1,"    '"<<name<<" = '"<<value);
1311             bbtkBlackBoxMessage("help",1," ["<<*i4<<"]"<<std::endl);
1312      }
1313
1314     if (oname.size()) 
1315        bbtkBlackBoxMessage("help",1," * Outputs : "<<std::endl);
1316     else 
1317        bbtkBlackBoxMessage("help",1," * No outputs"<<std::endl);
1318
1319     std::vector<std::vector<std::string> >::iterator i5;
1320
1321     for (i1=oname.begin(),i2=ovalue.begin(),i5=oconn.begin(),i4=ostatus.begin();
1322              i1!=oname.end(),i2!=ovalue.end(),i5!=oconn.end(),i4!=ostatus.end();
1323            ++i1,++i2,++i4,++i5)
1324     {
1325             std::string name(*i1);
1326             name += "'";
1327             name.append(1+namelmax-name.size(),' ');
1328             std::string value(*i2);
1329             value += "'";
1330             value.append(1+valuelmax-value.size(),' ');
1331             if (!(*i5).size())
1332               bbtkBlackBoxMessage("help",1,"    '"<<name<<" = '"<<value);
1333             else 
1334             {
1335                std::string pref = "    '"+name+" = '"+value;
1336                for (i3=i5->begin();i3!=i5->end();++i3)
1337                {
1338                       bbtkBlackBoxMessage("help",1,pref<<" --> '"<<*i3<<"'");
1339                       pref.replace(0,pref.size(),pref.size(),' ');
1340                }
1341             }
1342             bbtkBlackBoxMessage("help",1," ["<<*i4<<"]"<<std::endl);
1343     }
1344
1345    }
1346   //=========================================================================
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365   static bool bbmgGlobalProcessingExecutionList = false;
1366
1367   //=========================================================================
1368    void BlackBox::bbGlobalProcessExecutionList()
1369    {   
1370      bbtkDebugMessage("process",3,
1371                       "=> BlackBox::bbGlobalProcessExecutionList()"
1372                       <<std::endl);    
1373      if (bbmgGlobalProcessingExecutionList) 
1374        {
1375          bbtkDebugMessage("process",3,"BlackBox::bbGlobalProcessExecutionList() reentered !");
1376          return;
1377        }
1378      bbmgGlobalProcessingExecutionList = true;
1379
1380      std::set<BlackBox::WeakPointer>::iterator i; 
1381      while (bbmgExecutionList.size()>0)
1382        {
1383          i = bbmgExecutionList.begin();
1384          BlackBox::WeakPointer p = *i;
1385          bbmgExecutionList.erase(i);
1386          if (p.lock())
1387            {
1388              bbtkDebugMessage("process",4,
1389                               " -> Executing '"<<
1390                               p.lock()->bbGetName()<<"'"<<std::endl);
1391              p.lock()->bbExecute(true);
1392            }
1393          else 
1394            {
1395              bbtkGlobalError("Strange error in BlackBox::bbGlobalProcessExecutionList() : Weak bb pointer in bbmgExecutionList is no more valid...");
1396            }
1397        }
1398      
1399      bbmgExecutionList.clear();
1400      bbtkDebugMessage("process",3,
1401                          "<= BlackBox::bbGlobalProcessExecutionList()"
1402                          <<std::endl);     
1403      
1404      bbmgGlobalProcessingExecutionList = false;
1405      
1406    }
1407   //=========================================================================
1408
1409     bool BlackBox::bbGlobalGetSomeBoxExecuting()
1410         { 
1411                 return bbmgSomeBoxExecuting; 
1412         }
1413
1414     void BlackBox::bbGlobalSetSomeBoxExecuting(bool b) 
1415         { 
1416                 bbmgSomeBoxExecuting = b; 
1417         }
1418
1419     void BlackBox::bbGlobalSetFreezeExecution(bool b) 
1420         { 
1421                 bbmgFreezeExecution = b;
1422         }
1423
1424     bool BlackBox::bbGlobalGetFreezeExecution() 
1425         { 
1426                 return bbmgFreezeExecution; 
1427         }
1428
1429   void BlackBox::bbGlobalAddToExecutionList( BlackBox::Pointer b )
1430   {  
1431     bbtkDebugMessage("process",3,"* bbGlobalAddToExecutionList("<<b->bbGetName()<<")"<<std::endl);
1432     if (bbmgGlobalProcessingExecutionList) 
1433       {
1434         bbtkDebugMessage("process",3,"bbGlobalAddToExecutionList called inside bbGlobalProcessExecutionList !");
1435       }
1436     bbmgExecutionList.insert(b); 
1437   } 
1438
1439
1440    //=========================================================================
1441
1442   //=========================================================================
1443   void BlackBox::Check(bool recursive)
1444   {
1445     bbtkBlackBoxMessage("debug",1,"*** Checking"
1446                         <<" ... OK"<<std::endl);
1447   }
1448   //=========================================================================
1449
1450
1451
1452
1453 }  // EO namespace bbtk
1454
1455 // EOF
1456