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