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