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