]> Creatis software - bbtk.git/blob - kernel/src/bbtkBlackBox.cxx
no message
[bbtk.git] / kernel / src / bbtkBlackBox.cxx
1 /*=========================================================================                                                                               
2   Program:   bbtk
3   Module:    $RCSfile: bbtkBlackBox.cxx,v $
4   Language:  C++
5   Date:      $Date: 2011/07/02 08:00:34 $
6   Version:   $Revision: 1.53 $
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
353     return ( bbGlobalGetSomeBoxExecuting() 
354 #ifdef USE_WXWIDGETS
355              || Wx::IsSomeWindowAlive() 
356 #endif
357              );
358   }
359   //=========================================================================
360
361
362
363   //=========================================================================
364   BlackBox::BoxProcessModeValue BlackBox::bbGetBoxProcessModeValue() const
365   {
366     const std::string& p = bbmBoxProcessMode;
367     if ( (p == "0") ||
368          (p == "P") || (p == "p") ||
369          (p == "Pipeline") || (p == "pipeline") ) return bbPipeline;
370     if ( (p == "1") ||
371          (p == "A") || (p == "a") ||
372          (p == "Always") || (p == "always") ) return bbAlways;
373     if ( (p == "2") ||
374          (p == "R") || (p == "r") ||
375          (p == "Reactive") || (p == "reactive") ) 
376                 return bbReactive;
377     /*
378     if ( (p == "3") ||
379          (p == "F") || (p == "f") ||
380          (p == "Flash") || (p == "flash") ) return Flash;
381     */
382     bbtkError(bbGetFullName()<<" : BoxProcessMode value '"<<p
383               <<"' unknown. Possible values : "
384               <<"'0'/'P'/'p'/'Pipeline'/'pipeline' | "
385               <<"'1'/'A'/'a'/'Always'/'always' | "
386               <<"'2'/'R'/'r'/'Reactive'/'reactive'"
387               //      <<"'3'/'F'/'f'/'Flash'/'flash'"
388               <<std::endl);
389   }
390   //=========================================================================
391   
392   //=========================================================================
393   bool  BlackBox::bbBoxProcessModeIsReactive() const
394   {
395     return (bbGetBoxProcessModeValue() == bbReactive);
396   }
397   //=========================================================================
398
399   //=========================================================================
400   bool  BlackBox::bbBoxProcessModeIsAlways() const
401   {
402     return (bbGetBoxProcessModeValue() == bbAlways);
403   }
404   //=========================================================================
405
406
407
408
409   //=========================================================================
410   void BlackBox::bbAddOutputObserver(const std::string& output, 
411                                    OutputChangeCallbackType f)
412   {
413     bbGetOutputConnector(output).AddChangeObserver(f);
414   }  
415   //=========================================================================
416
417   //=========================================================================
418   void BlackBox::bbRemoveOutputObserver(const std::string& output_name, 
419                                       OutputChangeCallbackType f)
420   {
421     bbtkError("BlackBox::RemoveChangeObserver NOT IMPLEMENTED");
422   }
423   //=========================================================================
424
425
426   //=========================================================================
427   void BlackBox::bbSetStatusAndPropagate(BlackBoxInputConnector* c,
428                                          IOStatus s)
429   {
430     bbtkBlackBoxDebugMessage("change",5,
431                              "=> BlackBox::bbSetStatusAndPropagate(input,"
432                              <<GetIOStatusString(s)<<")"
433                              <<std::endl);
434
435     if (s==UPTODATE) bbtkError("bbSetStatusAndPropagate with status UPTODATE!");
436     c->SetStatus(s);
437
438     // Flash reaction
439     /*
440     if (bbGetBoxProcessModeValue() == Flash)
441       {
442         this->bbExecute();
443       }
444     */
445
446     OutputConnectorMapType::const_iterator o;   
447     for ( o = bbGetOutputConnectorMap().begin(); 
448           o != bbGetOutputConnectorMap().end(); ++o )                   
449       {                                                                 
450         if (o->second->GetStatus()==UPTODATE) 
451           {
452             o->second->SetStatus(OUTOFDATE);
453             o->second->SignalChange(GetThisPointer<BlackBox>(),o->first); 
454           }
455         }                                                               
456     
457           
458     if ( ( bbBoxProcessModeIsReactive()  || (c==bbGetInputConnectorMap().find("BoxExecute")->second))
459          && (bbCanReact() ) )
460       {
461         bbtkBlackBoxDebugMessage("change",2,
462                          "-> Execution triggered by Reactive mode or BoxExecute input change"<<std::endl);
463         bbGlobalAddToExecutionList( GetThisPointer<BlackBox>() );
464       }    
465     bbtkBlackBoxDebugMessage("change",5,
466                              "<= BlackBox::bbSetStatusAndPropagate(input)"
467                              <<std::endl);
468   }
469   //=========================================================================
470
471
472   //=========================================================================  
473   void BlackBox::bbSignalOutputModification(bool reaction)
474   {
475     bbtkBlackBoxDebugMessage("change",5,
476                              "=> BlackBox::bbSignalOutputModification("
477                              <<reaction<<")"
478                              <<"]"<<std::endl);
479
480           
481     OutputConnectorMapType::iterator i;
482     for ( i  = bbGetOutputConnectorMap().begin(); 
483           i != bbGetOutputConnectorMap().end(); ++i) 
484       {
485         //      std::cout << "Stat = "
486         //<<GetIOStatusString(i->second->GetStatus())
487         //                <<std::endl;
488         // LG : CANNOT SIGNAL ONLY WHEN UPTODATE 
489         // See bbtkSampleOutputObserver
490         //      if (i->second->GetStatus()==UPTODATE) 
491         //        {
492             i->second->SignalChange(GetThisPointer<BlackBox>(),i->first); 
493             //    }
494       } // for
495
496     if (reaction) 
497         { 
498                 bbGlobalProcessExecutionList();
499         }  
500
501     bbtkBlackBoxDebugMessage("change",5,
502                              "<= BlackBox::bbSignalOutputModification()"
503                              <<std::endl);
504   }  
505   //=========================================================================   
506         
507         
508         
509   //=========================================================================  
510   void BlackBox::bbSignalOutputModification(const std::string& output,
511                                             bool reaction)
512   {
513     bbtkBlackBoxDebugMessage("change",5,
514                              "=> BlackBox::bbSignalOutputModification("
515                              <<output<<","<<reaction<<")"
516                              <<std::endl);
517     
518     OutputConnectorMapType::iterator i = 
519       bbGetOutputConnectorMap().find(output);
520
521
522     if ( i == bbGetOutputConnectorMap().end() ) 
523         {
524           bbtkError("BlackBox["<<bbGetFullName()<<"]::bbSignalOutputModification("<<output<<") : unknown output");
525         }
526
527     //    if (i->second->GetStatus()==UPTODATE) 
528     //      {
529         i->second->SignalChange(GetThisPointer<BlackBox>(),i->first); 
530         // Has to notify the output "BoxChange" also
531         if (output != "BoxChange") 
532           {
533             i = bbGetOutputConnectorMap().find("BoxChange");
534             if ( i != bbGetOutputConnectorMap().end() ) 
535               {
536                 i->second->SignalChange(GetThisPointer<BlackBox>(),i->first); 
537               }
538           }
539         if (reaction) bbGlobalProcessExecutionList();
540         //      }
541
542         bbtkBlackBoxDebugMessage("change",5,
543                              "<= BlackBox::bbSignalOutputModification("
544                              <<output<<")"
545                              <<std::endl);
546   }  
547   //=========================================================================   
548   //=========================================================================  
549   void BlackBox::bbSignalOutputModification(const std::vector<std::string>& output,
550         bool reaction)
551   {
552     bbtkBlackBoxDebugMessage("change",5,
553                         "=> BlackBox::bbSignalOutputModification(vector of outputs)"
554 <<std::endl);
555     OutputConnectorMapType::iterator i;
556     std::vector<std::string>::const_iterator o;
557     bool changed = false;
558     for (o=output.begin();o!=output.end();++o) 
559       {
560         // the output "BoxChange" must be signaled **AFTER** all others
561         if (*o == "BoxChange") continue;
562         // Look for the connector
563         i = bbGetOutputConnectorMap().find(*o);
564         if ( i == bbGetOutputConnectorMap().end() ) 
565           {
566             bbtkError("BlackBox["<<bbGetFullName()<<"]::bbSignalOutputModification("<<*o<<") : unknown output");
567           }
568
569         //      if (i->second->GetStatus()==UPTODATE)
570         //        {
571             i->second->SignalChange(GetThisPointer<BlackBox>(),i->first); 
572             changed = true;
573             //  }
574       }
575     // Has to notify the output "BoxChange" also
576     i = bbGetOutputConnectorMap().find("BoxChange");
577     if ( changed && (i != bbGetOutputConnectorMap().end())) 
578       {
579         // if (i->second->GetStatus()==UPTODATE) 
580         //        {
581             i->second->SignalChange(GetThisPointer<BlackBox>(),i->first); 
582             if (reaction) bbGlobalProcessExecutionList();
583             //  }
584       }
585
586     bbtkBlackBoxDebugMessage("change",5,
587                              "<= BlackBox::bbSignalOutputModification(vector of outputs)"
588                              <<std::endl);
589   }  
590   //=========================================================================   
591
592
593
594
595
596
597
598   //=========================================================================
599   /// Main processing method of the box.
600   void BlackBox::bbExecute(bool force)
601   {
602     bbtkBlackBoxDebugMessage("process",2,
603                              "=> BlackBox::bbExecute("<<(int)force<<")"
604                              <<std::endl);
605  
606     // If already executing : return
607     /*
608     if (bbGetExecuting()) 
609       {
610         bbtkBlackBoxDebugMessage("process",2,
611                          " -> already executing : abort"<<std::endl);
612         return;
613       }
614     */
615
616     // If execution frozen : return
617     if (bbGlobalGetFreezeExecution()) 
618       {
619         bbtkBlackBoxDebugMessage("process",2,
620                          " -> FreezeExecution global flag is 'true' : abort execution"<<std::endl);
621       }
622
623     BBTK_BUSY_CURSOR;
624
625     // If force is true then update is triggered even if the box is UPTODATE
626     //    if (force) bbSetModifiedStatus();
627
628     // Calls the main recursive execution method 
629     bbRecursiveExecute(Connection::Pointer());
630
631     bbtkBlackBoxDebugMessage("process",2,
632                              "<= BlackBox::bbExecute()"
633                              <<std::endl);
634   }
635   //=========================================================================
636
637   //=========================================================================
638   void BlackBox::bbInitializeProcessing()
639   {
640     if (!bbmInitialized) 
641       {
642         bbtkBlackBoxDebugMessage("process",2,"** Initialize processing"
643                                  <<std::endl);
644         this->bbRecursiveInitializeProcessing();
645         bbmInitialized = true;
646       }
647   }
648   //=========================================================================
649
650   //=========================================================================
651   void BlackBox::bbFinalizeProcessing()
652   {
653     if (bbmInitialized) 
654       {
655         bbtkBlackBoxDebugMessage("process",2,"** Finalize processing"
656                                  <<std::endl);
657         this->bbRecursiveFinalizeProcessing();
658         bbmInitialized = false;
659       }
660   }
661   //=========================================================================
662
663   
664   //=========================================================================
665   void BlackBox::bbRecursiveExecute( Connection::Pointer caller )
666   {
667     bbtkBlackBoxDebugMessage("process",3,
668                         "=> BlackBox::bbRecursiveExecute("
669                         <<(caller?caller->GetFullName():"0")<<")"
670                         <<std::endl);
671
672     // If already executing : return
673     if (bbGetExecuting()) 
674       {
675         bbtkBlackBoxDebugMessage("process",3,
676                          " -> already executing : abort"<<std::endl);
677         return; 
678       }
679     
680     // If not initialized do it
681     bbInitializeProcessing();
682
683     bbSetExecuting(true);
684     bool wasExecuting = bbGlobalGetSomeBoxExecuting();
685     bbGlobalSetSomeBoxExecuting(true);
686     
687     // Creates the window if the black box has one
688     this->bbCreateWindow();
689     
690     // Updates its inputs
691     IOStatus s = bbUpdateInputs();
692     
693     if ( (s != UPTODATE) ||
694          bbBoxProcessModeIsAlways() )
695       {
696           // Displays the window (WxBlackbox)
697           //    bbShowWindow(caller);
698
699           // Actual processing (virtual)
700           this->bbProcess();
701         
702         
703           // Update the I/O statuses
704           bbComputePostProcessStatus();
705       }
706     else 
707       {
708         // Test output status...
709         OutputConnectorMapType::iterator o;
710         for ( o = bbGetOutputConnectorMap().begin(); 
711               o!= bbGetOutputConnectorMap().end(); ++o) 
712           {
713             if (o->second->GetStatus() != UPTODATE)
714               {
715                 bbtkWarning("BlackBox::bbRecursiveExecute: "
716                             <<"all inputs are Up-to-date but output '"
717                             <<o->first<<"' is Out-of-date ???");
718               }
719           }
720         
721         bbtkBlackBoxDebugMessage("process",3," -> Up-to-date : nothing to do"
722                          <<std::endl);
723       }
724
725     // Shows the window if the black box has one
726     this->bbShowWindow(); 
727
728           
729     bbtkBlackBoxDebugMessage("process",3,
730             "<= BlackBox::bbRecursiveExecute()"
731             <<std::endl);
732
733     bbSetExecuting(false);
734     bbGlobalSetSomeBoxExecuting(wasExecuting);
735
736     return;
737   }
738   //=========================================================================
739   
740    
741
742
743
744   //=========================================================================
745   IOStatus BlackBox::bbUpdateInputs()
746   {
747     bbtkBlackBoxDebugMessage("process",4,
748                         "=> BlackBox::bbUpdateInputs()"
749                         <<std::endl);   
750
751     IOStatus s = UPTODATE;
752
753     InputConnectorMapType::iterator i;
754     for ( i = bbGetInputConnectorMap().begin(); 
755           i!= bbGetInputConnectorMap().end(); ++i) 
756       {
757         //      if (i->first=="WinHide") continue;
758         // If input type is Void : no recurse
759         //if (  bbGetDescriptor()->GetInputDescriptor(i->first)->GetTypeInfo() 
760         //      == typeid(Void) ) 
761         //  continue;
762         bbtkBlackBoxDebugMessage("change",2,
763                             "Input '"<<i->first
764                             <<"': status before update = '"
765                             <<GetIOStatusString(i->second->GetStatus())
766                             <<"'"<<std::endl);
767         i->second->RecursiveExecute();
768         IOStatus t = i->second->GetStatus();
769         if (t > s) s = t;
770         bbtkBlackBoxDebugMessage("change",2,
771                                  "Input '"<<i->first
772                                  <<"': status before process = '"
773                                  <<GetIOStatusString(i->second->GetStatus())
774                                  <<"'"<<std::endl);
775       }
776     
777     bbtkBlackBoxDebugMessage("process",4,
778                         "<= BlackBox::bbUpdateInputs()"
779                         <<std::endl);
780     return s;
781   }
782   //=========================================================================
783
784   //==================================================================
785    void BlackBox::bbComputePostProcessStatus()
786   {
787     bbtkBlackBoxDebugMessage("process",4,
788                         "=> BlackBox::bbComputePostProcessStatus()"
789                         <<std::endl);   
790
791     IOStatus new_output_status = UPTODATE;
792     if (bbBoxProcessModeIsAlways()) new_output_status = OUTOFDATE;
793
794     // Update the input statuses
795     InputConnectorMapType::iterator i;
796     for ( i = bbGetInputConnectorMap().begin(); 
797           i!= bbGetInputConnectorMap().end(); ++i) 
798       {
799         IOStatus t = i->second->GetStatus();
800         if (t == OUTOFDATE) new_output_status = OUTOFDATE;
801         // A previously MODIFIED status turns to UPTODATE
802         if (t==MODIFIED) i->second->SetStatus(UPTODATE);
803         bbtkBlackBoxDebugMessage("change",2,
804                          "Input '"<<i->first<<"' : "
805                          << GetIOStatusString(t) << " -> "
806                          << GetIOStatusString(i->second->GetStatus())
807                          << std::endl);
808       }
809     bbtkBlackBoxDebugMessage("change",2,
810                              "New output status : "
811                              << GetIOStatusString(new_output_status)
812                              <<std::endl);
813     // Update the output statuses
814     OutputConnectorMapType::iterator o;
815     for ( o = bbGetOutputConnectorMap().begin(); 
816           o!= bbGetOutputConnectorMap().end(); ++o) 
817       {
818         o->second->SetStatus(new_output_status);
819       }
820
821     bbtkBlackBoxDebugMessage("process",4,
822                         "<= BlackBox::bbComputePostProcessStatus()"
823                         <<std::endl);
824   }
825   //==================================================================
826
827   //=========================================================================
828   void BlackBox::bbConnectInput( const std::string& name, Connection* c)
829   {
830     bbtkBlackBoxDebugMessage("connection",2,
831                         "==> BlackBox::bbConnectInput(\""
832                         <<name<<"\","<<c->GetFullName()<<")"
833                         <<std::endl);       
834
835     InputConnectorMapType::iterator i = bbGetInputConnectorMap().find(name);
836     if (i==bbGetInputConnectorMap().end())
837       {
838         bbtkError("no input called '"<<name<<"'");
839       }
840     i->second->SetConnection(c);
841     // The input *MUST* be set OUTOFDATE to update its input on next execution
842     bbSetStatusAndPropagate(i->second,OUTOFDATE);
843
844     bbtkBlackBoxDebugMessage("connection",2,
845                         "<== BlackBox::bbConnectInput(\""
846                         <<name<<"\","<<c->GetFullName()<<")"
847                         <<std::endl);
848   }
849   //=========================================================================
850
851
852   //=========================================================================  
853   void BlackBox::bbConnectOutput( const std::string& name, Connection* c)
854   {
855     bbtkBlackBoxDebugMessage("connection",2,
856                              "==> BlackBox::bbConnectOutput(\""<<name<<"\","
857                              <<c->GetFullName()<<")"
858                              <<std::endl);       
859
860     OutputConnectorMapType::iterator i = bbGetOutputConnectorMap().find(name);
861     if (i==bbGetOutputConnectorMap().end())
862       {
863         bbtkError("no output called '"<<name<<"'");
864       }
865     i->second->SetConnection(c);
866
867     bbtkBlackBoxDebugMessage("connection",2,
868                              "<== BlackBox::bbConnectOutput(\""<<name<<"\","
869                              <<c->GetFullName()<<")"
870                              <<std::endl);
871   }
872   //=========================================================================
873
874
875   //=========================================================================
876    void BlackBox::bbDisconnectInput( const std::string& name, Connection* c)
877   {
878
879     bbtkBlackBoxDebugMessage("connection",2,
880                      "==> BlackBox::bbDisconnectInput(\""<<name
881                      <<"\","<<c->GetFullName()<<")"
882                      <<std::endl);
883     if (!c) 
884       {
885
886         bbtkBlackBoxDebugMessage("connection",2,"c==0"<<std::endl);     
887         return;
888       }
889
890     InputConnectorMapType::iterator i = bbGetInputConnectorMap().find(name);
891     if (i==bbGetInputConnectorMap().end())
892       {
893         bbtkError("no input called '"<<name<<"'");
894       }
895     i->second->UnsetConnection(c);
896
897     bbtkBlackBoxDebugMessage("connection",2,
898                      "<== BlackBox::bbDisconnectInput(\""<<name
899                      <<"\","<<c->GetFullName()<<")"
900                      <<std::endl);      
901
902   }
903   //=========================================================================
904
905
906   //=========================================================================
907    void BlackBox::bbDisconnectOutput( const std::string& name, Connection* c)
908   {
909     bbtkBlackBoxDebugMessage("connection",2,
910                      "==> BlackBox::bbDisconnectOutput(\""<<name
911                      <<"\","<<c->GetFullName()<<")"
912                      <<std::endl);       
913     if (!c) 
914       {
915
916         bbtkBlackBoxDebugMessage("connection",2,"c==0"<<std::endl);     
917         return;
918       }
919
920     OutputConnectorMapType::iterator i = bbGetOutputConnectorMap().find(name);
921     if (i==bbGetOutputConnectorMap().end())
922       {
923         bbtkError("no output called '"<<name<<"'");
924       }
925     i->second->UnsetConnection(c);
926
927     bbtkBlackBoxDebugMessage("connection",2,
928                      "<== BlackBox::bbDisconnectOutput(\""<<name
929                      <<"\","<<c->GetFullName()<<")"
930                      <<std::endl);       
931   } 
932   //=========================================================================
933  
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956   //=========================================================================
957   void BlackBox::bbWriteDotInputOutputName(FILE *ff,bool inputoutput,int detail, int level)
958   {
959     fprintf(ff,"%s%p",bbGetTypeName().c_str(),this);
960   }
961   //=========================================================================
962
963
964   //=========================================================================
965   std::string BlackBox::bbGetOutputAsString( const std::string &output ) 
966   {
967     std::string v;
968     // Looks for the adaptor
969     if (bbGetOutputType(output).name() != typeid(std::string).name() ) 
970       {
971         // Look for factory 
972         Package::Pointer p = bbGetDescriptor()->GetPackage();
973         if ((p != 0) && ( ! p->GetFactorySet().empty() ) )
974           {
975             Factory::Pointer f = p->GetFactorySet().begin()->lock();
976             BlackBox::Pointer a;
977             try
978               {
979                 a = f->NewAdaptor(  
980                                   bbGetOutputType(output),
981                                   typeid(std::string),
982                                   "");
983               } catch (bbtk::Exception e) 
984               {
985               }
986             if (a){
987               //                        bbUpdate();
988               a->bbSetInput("In",bbGetOutput(output));
989               a->bbExecute();
990               v = a->bbGetOutput("Out").unsafe_get<std::string>() ;
991             } else {
992               v="? (no adaptor found)";
993             }
994           }
995         else 
996           {
997             v="? (no factory found)";
998           }
999       } 
1000     else 
1001       {
1002         //         bbUpdate();
1003         v = bbGetOutput(output).unsafe_get<std::string>() ;
1004       }
1005     return v;
1006   }
1007   //=========================================================================
1008
1009   //=========================================================================
1010   std::string BlackBox::bbGetInputAsString( const std::string &input ) 
1011   {
1012     std::string v;
1013     // Looks for the adaptor
1014     if (bbGetInputType(input) != typeid(std::string)) 
1015       {
1016         // Look for factory 
1017         Package::Pointer p = bbGetDescriptor()->GetPackage();
1018         if ((p != 0) && ( ! p->GetFactorySet().empty() ) )
1019           {
1020             Factory::Pointer f = p->GetFactorySet().begin()->lock();
1021             BlackBox::Pointer a;
1022             try
1023               {
1024                 a = f->NewAdaptor(  
1025                                bbGetInputType(input),
1026                                typeid(std::string),
1027                                "");
1028               }catch (bbtk::Exception e) 
1029               {
1030               }
1031             if (a)
1032               {
1033                 //                      bbUpdate();
1034                 a->bbSetInput("In",bbGetInput(input));
1035                 a->bbExecute();
1036                 v = a->bbGetOutput("Out").unsafe_get<std::string>() ;
1037               } 
1038             else 
1039               {
1040                 v="? (no adaptor found)";
1041               }
1042           } 
1043         else 
1044           {
1045             v="? (no factory found)";
1046           }
1047       }
1048     else 
1049       {
1050         v = bbGetInput(input).unsafe_get<std::string>() ;
1051       }
1052     return v;
1053   }
1054   //=======================================================================
1055
1056   //=======================================================================
1057   // Replaces substrings "<" by "["
1058   void SubsBrackets ( std::string& s )
1059   {
1060     //   std::cout << "BEFORE=["<<s<<"]"<<std::endl;
1061     std::string ss("<");
1062     std::string::size_type pos = 0;
1063     pos = s.find(ss,0);
1064     std::string cr("[");
1065     while ( pos != std::string::npos )
1066       {
1067         //      std::cout << "*** find one "<<std::endl;
1068         s.replace(pos,1,cr.c_str(),1);
1069         pos = s.find(ss, pos);
1070       } 
1071     ss = ">";
1072     pos = 0;
1073     pos = s.find(ss,0);
1074     cr = "]";
1075     while ( pos != std::string::npos )
1076       {
1077         //      std::cout << "*** find one "<<std::endl;
1078         s.replace(pos,1,cr.c_str(),1);
1079         pos = s.find(ss, pos);
1080       } 
1081     ss = ",";
1082     pos = 0;
1083     pos = s.find(ss,0);
1084     cr = "-";
1085     while ( pos != std::string::npos )
1086       {
1087         //      std::cout << "*** find one "<<std::endl;
1088         s.replace(pos,1,cr.c_str(),1);
1089         pos = s.find(ss, pos);
1090       }     //    std::cout << "AFTER=["<<s<<"]"<<std::endl;
1091   }
1092   //=======================================================================
1093
1094   //=========================================================================
1095   /// Write Graphviz-dot description in file
1096   void BlackBox::bbWriteDotFileBlackBox(FILE *ff,
1097                                         BlackBox::Pointer parentblackbox, 
1098                                         int detail, int level,
1099                                         bool instanceOrtype,
1100                                         bool relative_link )
1101
1102   { 
1103     InputConnectorMapType::iterator i;
1104     // label
1105     std::string labelStr;
1106     std::string valueStr("");
1107
1108         if (detail==0) {
1109                 labelStr = bbGetName() ; 
1110 //EED 18 Fev 2008
1111                 labelStr = labelStr + "\\n[" +this->bbGetDescriptor()->GetPackage()->GetName()+"::"+ bbGetTypeName() + "]";
1112         } else {
1113                 labelStr = bbGetName();
1114                 labelStr = labelStr + "   [" +this->bbGetDescriptor()->GetPackage()->GetName()+"::"+ bbGetTypeName() + "]  ";
1115     }
1116
1117     SubsBrackets(labelStr);
1118     if (detail==1)
1119       {
1120         labelStr = labelStr + " | {{ "; 
1121         std::string tempStrTypeName;
1122         bool tmp; 
1123         tmp=false;
1124         for ( i = mInputConnectorMap.begin(); i != mInputConnectorMap.end(); ++i ) 
1125           {
1126             if (tmp==true)
1127               {
1128                 labelStr=labelStr+" | ";
1129               }
1130             tmp=true;
1131             if (instanceOrtype==true)
1132               {
1133                 valueStr = this->bbGetInputAsString(i->first) + " = ";
1134               } 
1135             const BlackBoxInputDescriptor* id = bbGetDescriptor()->GetInputDescriptor(i->first);
1136             tempStrTypeName=id->GetTypeName();
1137             SubsBrackets(tempStrTypeName);
1138             std::string Name(i->first);
1139             SubsBrackets(Name);
1140             labelStr=labelStr + "<"+i->first.c_str()+"> "  + valueStr +  Name.c_str() + "  [" + tempStrTypeName.c_str() + "]";
1141           }
1142         labelStr=labelStr+ " } | {";
1143         tmp = false;
1144         OutputConnectorMapType::iterator ii;
1145         for ( ii = mOutputConnectorMap.begin(); ii != mOutputConnectorMap.end(); ++ii ) 
1146         {
1147            if (tmp==true)
1148            {
1149                    labelStr=labelStr+" | ";
1150            }
1151            tmp = true;
1152            if (instanceOrtype==true)
1153            {
1154                    valueStr = this->bbGetOutputAsString(ii->first) + " = ";
1155            }
1156            const BlackBoxOutputDescriptor* id = bbGetDescriptor()->GetOutputDescriptor(ii->first); 
1157            tempStrTypeName=id->GetTypeName();
1158            SubsBrackets(tempStrTypeName);
1159             std::string Name(ii->first);
1160             SubsBrackets(Name);
1161            labelStr=labelStr+"<"+ii->first.c_str()+"> " + valueStr + Name.c_str() + "  ["+tempStrTypeName+"]";
1162         }
1163         labelStr = labelStr+ "      } }" ;
1164 } // detail
1165
1166     fprintf(ff,"  " );
1167     bbWriteDotInputOutputName(ff,true,detail,level);
1168     std::string tmp ( bbGetTypeName() );
1169     SubsBrackets(tmp);
1170     std::string url;
1171     if (relative_link) 
1172       url = this->bbGetDescriptor()->GetPackage()->GetDocRelativeURL() + "#" + tmp;
1173     else 
1174       url = this->bbGetDescriptor()->GetPackage()->GetDocURL() + "#" + tmp;
1175   
1176     fprintf( ff , " [shape=record, URL=\"%s\",label=\"%s\"]%s\n",url.c_str(),labelStr.c_str(),";" );
1177     //    std::cout  << labelStr << std::endl;
1178
1179     // Relation Input
1180     if (GetThisPointer<BlackBox>()!=parentblackbox){
1181       for ( i = mInputConnectorMap.begin(); i != mInputConnectorMap.end(); ++i ) 
1182         {
1183           if (i->second)
1184             {
1185               Connection* con = i->second->GetConnection();
1186               if (con!=NULL){
1187                 BlackBox::Pointer a=con->GetOriginalBlackBoxFrom();
1188                 BlackBox::Pointer b=con->GetOriginalBlackBoxTo();
1189                 fprintf(ff,"  ");
1190                 a->bbWriteDotInputOutputName(ff,false,detail,level);
1191                 if (detail==1)
1192                   {
1193                     fprintf(ff,":%s",con->GetOriginalBlackBoxFromOutput().c_str());
1194                   }
1195                 fprintf(ff,"->");
1196                 b->bbWriteDotInputOutputName(ff,true,detail,level);
1197                 if (detail==1)
1198                   {
1199                     fprintf(ff,":%s",con->GetOriginalBlackBoxToInput().c_str());
1200                   }
1201                 fprintf(ff,"%s\n",";");
1202               }  // if con
1203             } // if second
1204         } // for
1205     } // if parentblackbox
1206   }
1207   //=========================================================================
1208
1209
1210
1211
1212   //=========================================================================
1213   void BlackBox::bbPrintHelp(BlackBox::Pointer parentblackbox, 
1214                                  int detail, int level
1215                                  /*,Factory *factory*/ )
1216   {
1217      
1218     if (this->bbGetDescriptor()->GetPackage()) 
1219       {
1220         bbtkBlackBoxMessage("help",1,"Black Box '"<<bbGetName()<<"' <"<<
1221                     this->bbGetDescriptor()->GetPackage()->GetName()
1222                     <<"::"<<this->bbGetDescriptor()->GetTypeName()<<">"<<std::endl);
1223       }
1224     else 
1225       {
1226         bbtkBlackBoxMessage("help",1,"Black Box <::"<<this->bbGetDescriptor()->GetTypeName()<<">"<<std::endl);
1227       }
1228     /*
1229     if (bbIsUpToDate())
1230       {
1231         bbtkBlackBoxMessage("help",1,"Up-to-date ["<<mMaxInputChangeTime<<","
1232                     <<mMinOutputChangeTime<<"]"<<std::endl);
1233       }
1234     else 
1235       {
1236         bbtkBlackBoxMessage("help",1,"Out-of-date ["<<mMaxInputChangeTime<<","
1237                     <<mMinOutputChangeTime<<"]"<<std::endl);
1238       }
1239     */
1240     //    bbtkBlackBoxMessage("help",1," "<<GetDescription()<<std::endl);
1241     //    bbtkBlackBoxMessage("help",1," By : "<<GetAuthor()<<std::endl);
1242
1243     std::vector<std::string> iname;
1244     std::vector<std::string> ivalue;
1245     std::vector<std::string> iconn;
1246     std::vector<std::string> istatus;
1247
1248     InputConnectorMapType::iterator i;
1249     unsigned int namelmax = 0;
1250     unsigned int valuelmax = 0;
1251     //   unsigned int connlmax = 0;
1252     for ( i = mInputConnectorMap.begin(); i != mInputConnectorMap.end(); ++i ) 
1253       {
1254         iname.push_back(i->first);
1255         if (iname.back().size()>namelmax) namelmax = iname.back().size();
1256         ivalue.push_back(bbGetInputAsString(i->first));
1257         if (ivalue.back().size()>valuelmax) valuelmax = ivalue.back().size();
1258         std::string s("");
1259         Connection* con = i->second->GetConnection();
1260         if (con!=0){
1261           s = con->GetOriginalBlackBoxFrom()->bbGetName();
1262           s += ".";
1263           s += con->GetOriginalBlackBoxFromOutput();
1264         }  // if con
1265         iconn.push_back(s);
1266         istatus.push_back(GetIOStatusString(i->second->GetStatus()));
1267       }
1268     OutputConnectorMapType::iterator o;
1269     std::vector<std::string> oname;
1270     std::vector<std::string> ovalue;
1271     std::vector<std::vector<std::string> > oconn;
1272     std::vector<std::string> ostatus;
1273     for ( o = mOutputConnectorMap.begin(); o != mOutputConnectorMap.end(); ++o ) 
1274       {
1275         oname.push_back(o->first);
1276         if (oname.back().size()>namelmax) namelmax = oname.back().size();
1277         ovalue.push_back(bbGetOutputAsString(o->first));
1278         if (ovalue.back().size()>valuelmax) valuelmax = ovalue.back().size();
1279         std::vector<std::string> ss;
1280         const std::vector<Connection*>& con 
1281           = o->second->GetConnectionVector();
1282         std::vector<Connection*>::const_iterator c;
1283         for (c=con.begin();c!=con.end();++c) 
1284           {
1285             std::string s;
1286             s = (*c)->GetOriginalBlackBoxTo()->bbGetName();
1287             s += ".";
1288             s += (*c)->GetOriginalBlackBoxToInput();
1289             ss.push_back(s);
1290         }  // if con
1291         oconn.push_back(ss);
1292         ostatus.push_back(GetIOStatusString(o->second->GetStatus()));
1293       }
1294
1295     if (iname.size()) 
1296       bbtkBlackBoxMessage("help",1," * Inputs : "<<std::endl);
1297     else 
1298       bbtkBlackBoxMessage("help",1," * No inputs"<<std::endl);
1299
1300     std::vector<std::string>::iterator i1,i2,i3,i4;
1301     for (i1=iname.begin(),i2=ivalue.begin(),i3=iconn.begin(),i4=istatus.begin();
1302          i1!=iname.end(),i2!=ivalue.end(),i3!=iconn.end(),i4!=istatus.end();
1303          ++i1,++i2,++i3,++i4)
1304       {
1305         std::string name(*i1);
1306         name += "'";
1307         name.append(1+namelmax-name.size(),' ');
1308         std::string value(*i2);
1309         value += "'";
1310         value.append(1+valuelmax-value.size(),' ');
1311         if (i3->size()) 
1312           bbtkBlackBoxMessage("help",1,"    '"<<name<<" = '"<<value<<" <-- '"
1313                       <<*i3<<"'");
1314         else 
1315           bbtkBlackBoxMessage("help",1,"    '"<<name<<" = '"<<value);
1316         bbtkBlackBoxMessage("help",1," ["<<*i4<<"]"<<std::endl);
1317       }
1318
1319     if (oname.size()) 
1320       bbtkBlackBoxMessage("help",1," * Outputs : "<<std::endl);
1321     else 
1322       bbtkBlackBoxMessage("help",1," * No outputs"<<std::endl);
1323
1324     std::vector<std::vector<std::string> >::iterator i5;
1325
1326     for (i1=oname.begin(),i2=ovalue.begin(),i5=oconn.begin(),i4=ostatus.begin();
1327          i1!=oname.end(),i2!=ovalue.end(),i5!=oconn.end(),i4!=ostatus.end();
1328          ++i1,++i2,++i4,++i5)
1329       {
1330         std::string name(*i1);
1331         name += "'";
1332         name.append(1+namelmax-name.size(),' ');
1333         std::string value(*i2);
1334         value += "'";
1335         value.append(1+valuelmax-value.size(),' ');
1336         if (!(*i5).size())
1337           bbtkBlackBoxMessage("help",1,"    '"<<name<<" = '"<<value);
1338         else 
1339           {
1340             std::string pref = "    '"+name+" = '"+value;
1341             for (i3=i5->begin();i3!=i5->end();++i3)
1342               {
1343                 bbtkBlackBoxMessage("help",1,pref<<" --> '"<<*i3<<"'");
1344                 pref.replace(0,pref.size(),pref.size(),' ');
1345               }
1346           }
1347         bbtkBlackBoxMessage("help",1," ["<<*i4<<"]"<<std::endl);
1348       }
1349
1350    }
1351   //=========================================================================
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370   static bool bbmgGlobalProcessingExecutionList = false;
1371
1372   //=========================================================================
1373    void BlackBox::bbGlobalProcessExecutionList()
1374    {   
1375      bbtkDebugMessage("process",3,
1376                       "=> BlackBox::bbGlobalProcessExecutionList()"
1377                       <<std::endl);    
1378      if (bbmgGlobalProcessingExecutionList) 
1379        {
1380          bbtkDebugMessage("process",3,"BlackBox::bbGlobalProcessExecutionList() reentered !");
1381          return;
1382        }
1383      bbmgGlobalProcessingExecutionList = true;
1384
1385      std::set<BlackBox::WeakPointer>::iterator i; 
1386      while (bbmgExecutionList.size()>0)
1387        {
1388          i = bbmgExecutionList.begin();
1389          BlackBox::WeakPointer p = *i;
1390          bbmgExecutionList.erase(i);
1391          if (p.lock())
1392            {
1393              bbtkDebugMessage("process",4,
1394                               " -> Executing '"<<
1395                               p.lock()->bbGetName()<<"'"<<std::endl);
1396              p.lock()->bbExecute(true);
1397            }
1398          else 
1399            {
1400              bbtkGlobalError("Strange error in BlackBox::bbGlobalProcessExecutionList() : Weak bb pointer in bbmgExecutionList is no more valid...");
1401            }
1402        }
1403      
1404      bbmgExecutionList.clear();
1405      bbtkDebugMessage("process",3,
1406                          "<= BlackBox::bbGlobalProcessExecutionList()"
1407                          <<std::endl);     
1408      
1409      bbmgGlobalProcessingExecutionList = false;
1410      
1411    }
1412   //=========================================================================
1413
1414     bool BlackBox::bbGlobalGetSomeBoxExecuting()
1415         { 
1416                 return bbmgSomeBoxExecuting; 
1417         }
1418
1419     void BlackBox::bbGlobalSetSomeBoxExecuting(bool b) 
1420         { 
1421                 bbmgSomeBoxExecuting = b; 
1422         }
1423
1424     void BlackBox::bbGlobalSetFreezeExecution(bool b) 
1425         { 
1426                 bbmgFreezeExecution = b;
1427         }
1428
1429     bool BlackBox::bbGlobalGetFreezeExecution() 
1430         { 
1431                 return bbmgFreezeExecution; 
1432         }
1433
1434   void BlackBox::bbGlobalAddToExecutionList( BlackBox::Pointer b )
1435   {  
1436     bbtkDebugMessage("process",3,"* bbGlobalAddToExecutionList("<<b->bbGetName()<<")"<<std::endl);
1437     if (bbmgGlobalProcessingExecutionList) 
1438       {
1439         bbtkDebugMessage("process",3,"bbGlobalAddToExecutionList called inside bbGlobalProcessExecutionList !");
1440       }
1441     bbmgExecutionList.insert(b); 
1442   } 
1443
1444
1445    //=========================================================================
1446
1447   //=========================================================================
1448   void BlackBox::Check(bool recursive)
1449   {
1450     bbtkBlackBoxMessage("debug",1,"*** Checking"
1451                         <<" ... OK"<<std::endl);
1452   }
1453   //=========================================================================
1454
1455
1456
1457
1458 }  // EO namespace bbtk
1459
1460 // EOF
1461