]> Creatis software - bbtk.git/blob - kernel/src/bbtkBlackBox.cxx
b7a7ec78f4ee6d3d71be5de580d38085f24954c3
[bbtk.git] / kernel / src / bbtkBlackBox.cxx
1 /*=========================================================================                                                                               
2   Program:   bbtk
3   Module:    $RCSfile: bbtkBlackBox.cxx,v $
4   Language:  C++
5   Date:      $Date: 2008/12/08 12:53:45 $
6   Version:   $Revision: 1.32 $
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     if (s==UPTODATE) bbtkError("bbSetStatusAndPropagate with status UPTODATE!");
576     c->SetStatus(s);
577     OutputConnectorMapType::const_iterator o;   
578     for ( o = bbGetOutputConnectorMap().begin(); 
579           o != bbGetOutputConnectorMap().end(); ++o )                   
580       {                                                                 
581         //      bbSetStatusAndPropagate(o->second, OUTOFDATE);
582         if (o->second->GetStatus()==UPTODATE) 
583           {
584             o->second->SetStatus(OUTOFDATE);
585             o->second->SignalChange(GetThisPointer<BlackBox>(),o->first); 
586           }
587       }                                                                 
588     
589     if ( ( bbBoxProcessModeIsReactive()  ||
590            (c==bbGetInputConnectorMap().find("BoxExecute")->second))
591          && (bbCanReact() ) )
592       {
593         bbtkDebugMessage("modified",2,
594                          "-> Execution triggered by Reactive mode or BoxExecute input change"<<std::endl);
595         bbGlobalAddToExecutionList( GetThisPointer<BlackBox>() );
596       }    
597   }
598   //=========================================================================
599
600   //=========================================================================
601   void BlackBox::bbSetStatusAndPropagate(BlackBoxOutputConnector* c,
602                                          IOStatus s)
603   {
604     bbtkError("bbSetStatusAndPropagate(BlackBoxOutputConnector* c,IOStatus s)");
605     /*
606     if (i->GetStatus()==UPTODATE) 
607       {
608         i->second->SetStatus(s);
609         i->second->SignalChange(GetThisPointer<BlackBox>(),i->first); 
610       }
611     */
612   }
613   //=========================================================================
614  
615
616  ///  Signals that the BlackBox has been modified
617   /*
618   void BlackBox::bbSetModifiedStatus(BlackBoxInputConnector* c)
619   {
620     bbtkDebugMessage("modified",1,
621                      "==> BlackBox::bbSetModifiedStatus("<<c<<") ["
622                      <<bbGetFullName()<<"]"<<std::endl);
623     
624     if ( (c==bbGetInputConnectorMap().find("WinHide")->second) )
625       //         && (bbCanReact()))
626       {
627         bbtkDebugMessage("modified",2,
628                          "-> Hide triggered by WinHide input change"
629                          <<std::endl);
630         this->bbHideWindow();
631         this->bbSetStatus(MODIFIED); 
632         return;
633       }
634     if ( (c==bbGetInputConnectorMap().find("WinClose")->second) )
635       //         && (bbCanReact()))
636       {
637         bbtkDebugMessage("modified",2,
638                          "-> Close triggered by WinClose input change"
639                          <<std::endl);
640         this->bbHideWindow();
641         this->bbSetStatus(MODIFIED); 
642         return;
643       }
644     
645     if ( ( bbBoxProcessModeIsReactive()  ||
646            (c==bbGetInputConnectorMap().find("BoxExecute")->second))
647          && (bbCanReact() ) )
648       {
649         bbtkDebugMessage("modified",2,
650                          "-> Execution triggered by Reactive mode or BoxExecute input change"<<std::endl);
651         this->bbSetStatus(MODIFIED); 
652         bbGlobalAddToExecutionList( GetThisPointer<BlackBox>() );
653       }
654     
655     //else if ( bbGetStatus() == MODIFIED ) //! this->bbIsUptodate()) 
656      // { 
657 //      bbtkDebugMessage("modified",2,"-> Already modified"<<std::endl);
658 //      return;
659  //     }
660    
661     else 
662       {
663         bbtkDebugMessage("modified",2,"-> Status set to modified"<<std::endl);
664         this->bbSetStatus(MODIFIED); 
665       }
666  
667     this->bbSignalOutputModification(false);
668
669   bbtkDebugMessageDec("process",5,
670                         "<= BlackBox::bbSetModifiedStatus("<<c<<") ["
671                         <<bbGetFullName()<<"]"<<std::endl);
672   }  
673 */
674   //=========================================================================
675
676   //=========================================================================  
677   void BlackBox::bbSignalOutputModification(bool reaction)
678   {
679     bbtkDebugMessageInc("process",5,
680                         "=> BlackBox::bbSignalOutputModification("
681                         <<reaction<<") ["
682                         <<bbGetFullName()<<"]"<<std::endl);
683     
684     OutputConnectorMapType::iterator i;
685     for ( i  = bbGetOutputConnectorMap().begin(); 
686           i != bbGetOutputConnectorMap().end(); ++i) 
687       {
688         if (i->second->GetStatus()==UPTODATE) 
689           {
690             //      i->second->SetStatus(MODIFIED);
691             i->second->SignalChange(GetThisPointer<BlackBox>(),i->first); 
692           }
693       } 
694
695     if (reaction) bbGlobalProcessExecutionList();
696
697     bbtkDebugMessageDec("process",5,
698                         "<= BlackBox::bbSignalOutputModification() ["
699                         <<bbGetFullName()<<"]"<<std::endl);
700     
701   }  
702   //=========================================================================   
703   //=========================================================================  
704   void BlackBox::bbSignalOutputModification(const std::string& output,
705                                             bool reaction)
706   {
707     bbtkDebugMessageInc("process",5,
708                         "=> BlackBox::bbSignalOutputModification("
709                         <<output<<","<<reaction<<") ["
710                         <<bbGetFullName()<<"]"<<std::endl);
711     
712     OutputConnectorMapType::iterator i = 
713       bbGetOutputConnectorMap().find(output);
714
715
716     if ( i == bbGetOutputConnectorMap().end() ) 
717         {
718           bbtkError("BlackBox["<<bbGetFullName()<<"]::bbSignalOutputModification("<<output<<") : unknown output");
719         }
720
721     if (i->second->GetStatus()==UPTODATE) 
722       {
723         //      i->second->SetStatus(MODIFIED);
724         i->second->SignalChange(GetThisPointer<BlackBox>(),i->first); 
725         // Has to notify the output "BoxChange" also
726         if (output != "BoxChange") 
727           {
728             i = bbGetOutputConnectorMap().find("BoxChange");
729             if ( i != bbGetOutputConnectorMap().end() ) 
730               {
731                 //              i->second->SetStatus(MODIFIED);
732                 i->second->SignalChange(GetThisPointer<BlackBox>(),i->first); 
733               }
734           }
735         if (reaction) bbGlobalProcessExecutionList();
736       }
737
738     bbtkDebugMessageDec("process",5,
739                         "<= BlackBox::bbSignalOutputModification("
740                         <<output<<") ["
741                         <<bbGetFullName()<<"]"<<std::endl);
742     
743   }  
744   //=========================================================================   
745   //=========================================================================  
746   void BlackBox::bbSignalOutputModification(const std::vector<std::string>& output,
747         bool reaction)
748   {
749     bbtkDebugMessageInc("process",5,
750                         "=> BlackBox::bbSignalOutputModification(vector of outputs) ["
751                         <<bbGetFullName()<<"]"<<std::endl);
752     OutputConnectorMapType::iterator i;
753     std::vector<std::string>::const_iterator o;
754     bool changed = false;
755     for (o=output.begin();o!=output.end();++o) 
756       {
757         // the output "BoxChange" must be signaled **AFTER** all others
758         if (*o == "BoxChange") continue;
759         // Look for the connector
760         i = bbGetOutputConnectorMap().find(*o);
761         if ( i == bbGetOutputConnectorMap().end() ) 
762           {
763             bbtkError("BlackBox["<<bbGetFullName()<<"]::bbSignalOutputModification("<<*o<<") : unknown output");
764           }
765         // Already OUTOFDATE : noting to do
766         if (i->second->GetStatus()==UPTODATE)
767           {
768             //  i->second->SetStatus(MODIFIED);
769             i->second->SignalChange(GetThisPointer<BlackBox>(),i->first); 
770             changed = true;
771           }
772       }
773     // Has to notify the output "BoxChange" also
774     i = bbGetOutputConnectorMap().find("BoxChange");
775     if ( changed && (i != bbGetOutputConnectorMap().end())) 
776       {
777         // Already OUTOFDATE : noting to do
778         if (i->second->GetStatus()==UPTODATE) 
779           {
780             //  i->second->SetStatus(MODIFIED);
781             i->second->SignalChange(GetThisPointer<BlackBox>(),i->first); 
782             if (reaction) bbGlobalProcessExecutionList();
783           }
784       }
785
786     bbtkDebugMessageDec("process",5,
787                         "<= BlackBox::bbSignalOutputModification(vector of outputs) ["
788                         <<bbGetFullName()<<"]"<<std::endl);
789
790   }  
791   //=========================================================================   
792
793   //=========================================================================
794   /// Updates the BlackBox inputs
795   /// Calls BackwardUpdate on all BlackBoxInputConnector
796   /// \returns The maximum of final IOStatus after each input update
797   IOStatus BlackBox::bbUpdateInputs()
798   {
799     bbtkDebugMessageInc("process",4,
800                         "=> BlackBox::bbUpdateInputs() ["
801                         <<bbGetFullName()<<"]"
802                         <<std::endl);   
803
804     IOStatus s = UPTODATE;
805
806     InputConnectorMapType::iterator i;
807     for ( i = bbGetInputConnectorMap().begin(); 
808           i!= bbGetInputConnectorMap().end(); ++i) 
809       {
810         //      if (i->first=="WinHide") continue;
811         // If input type is Void : no recurse
812         //if (  bbGetDescriptor()->GetInputDescriptor(i->first)->GetTypeInfo() 
813         //      == typeid(Void) ) 
814         //  continue;
815         i->second->BackwardUpdate();
816         IOStatus t = i->second->GetStatus();
817         if (t > s) s = t;
818       }
819     
820     bbtkDebugMessageDec("process",4,
821                         "<= BlackBox::bbUpdateInputs() ["
822                         <<bbGetFullName()<<"]"
823                         <<std::endl);   
824     
825     
826     return s;
827   }
828   //=========================================================================
829
830   //==================================================================
831   /// Computes the final IOStatus of inputs and outputs after processing
832   void BlackBox::bbComputePostProcessStatus()
833   {
834     IOStatus new_output_status = UPTODATE;
835     if (bbBoxProcessModeIsAlways()) new_output_status = OUTOFDATE;
836
837     // Update the input statuses
838     InputConnectorMapType::iterator i;
839     for ( i = bbGetInputConnectorMap().begin(); 
840           i!= bbGetInputConnectorMap().end(); ++i) 
841       {
842         IOStatus t = i->second->GetStatus();
843         if (t == OUTOFDATE) new_output_status = OUTOFDATE;
844         // A previously MODIFIED status turns to UPTODATE
845         if (t==MODIFIED) i->second->SetStatus(UPTODATE);
846       }
847
848     // Update the output statuses
849     OutputConnectorMapType::iterator o;
850     for ( o = bbGetOutputConnectorMap().begin(); 
851           o!= bbGetOutputConnectorMap().end(); ++o) 
852       {
853         o->second->SetStatus(new_output_status);
854       }
855   }
856   //==================================================================
857
858   //=========================================================================
859   /// Connects the input <name> to the connection c
860   void BlackBox::bbConnectInput( const std::string& name, Connection* c)
861   {
862     bbtkDebugMessage("connection",2,
863                         "==> BlackBox::bbConnectInput(\""
864                         <<name<<"\","<<c->GetFullName()<<") ["
865                         <<bbGetFullName()<<"]"
866                         <<std::endl);       
867
868
869     InputConnectorMapType::iterator i = bbGetInputConnectorMap().find(name);
870     if (i==bbGetInputConnectorMap().end())
871       {
872         bbtkError("no input called '"<<name<<"'");
873       }
874     i->second->SetConnection(c);
875
876     // Check the status of the from.output of c 
877     // to set the new status of the input
878     IOStatus s = MODIFIED;
879     if ( c->GetBlackBoxFrom()->bbGetOutputConnector(c->GetBlackBoxFromOutput()).GetStatus() == OUTOFDATE ) 
880       s = OUTOFDATE;
881     bbSetStatusAndPropagate(i->second,s);
882     
883     bbtkDebugMessage("connection",2,
884                         "<== BlackBox::bbConnectInput(\""
885                         <<name<<"\","<<c->GetFullName()<<") ["
886                         <<bbGetFullName()<<"]"
887                         <<std::endl);       
888
889   }
890   //=========================================================================
891
892
893   //=========================================================================  
894   /// Connects the output <name> to the connection c
895   void BlackBox::bbConnectOutput( const std::string& name, Connection* c)
896   {
897     bbtkDebugMessage("connection",2,
898                      "==> BlackBox::bbConnectOutput(\""<<name<<"\","
899                      <<c->GetFullName()<<") ["
900                      <<bbGetFullName()<<"]"<<std::endl);       
901     
902     OutputConnectorMapType::iterator i = bbGetOutputConnectorMap().find(name);
903     if (i==bbGetOutputConnectorMap().end())
904       {
905         bbtkError("no output called '"<<name<<"'");
906       }
907     i->second->SetConnection(c);
908
909     bbtkDebugMessage("connection",2,
910                      "<== BlackBox::bbConnectOutput(\""<<name<<"\","
911                      <<c->GetFullName()<<") ["
912                      <<bbGetFullName()<<"]"<<std::endl);       
913
914   }
915   //=========================================================================
916
917
918   //=========================================================================
919   /// Disconnects the input <name> from the connection c
920   void BlackBox::bbDisconnectInput( const std::string& name, Connection* c)
921   {
922
923     bbtkDebugMessage("connection",2,
924                      "==> BlackBox::bbDisconnectInput(\""<<name
925                      <<"\","<<c->GetFullName()<<") ["
926                      <<bbGetFullName()<<"]"
927                      <<std::endl);      
928
929     if (!c) 
930       {
931
932         bbtkDebugMessage("connection",2,"c==0"<<std::endl);     
933         return;
934       }
935
936     InputConnectorMapType::iterator i = bbGetInputConnectorMap().find(name);
937     if (i==bbGetInputConnectorMap().end())
938       {
939         bbtkError("no input called '"<<name<<"'");
940       }
941     i->second->UnsetConnection(c);
942
943     bbtkDebugMessage("connection",2,
944                      "<== BlackBox::bbDisconnectInput(\""<<name
945                      <<"\","<<c->GetFullName()<<") ["
946                      <<bbGetFullName()<<"]"
947                      <<std::endl);      
948
949   }
950   //=========================================================================
951
952
953   //=========================================================================
954   /// Disconnects the output <name> from the connection c
955   void BlackBox::bbDisconnectOutput( const std::string& name, Connection* c)
956   {
957     bbtkDebugMessage("connection",2,
958                      "==> BlackBox::bbDisconnectOutput(\""<<name
959                      <<"\","<<c->GetFullName()<<") ["
960                      <<bbGetFullName()<<"]"
961                      <<std::endl);       
962     if (!c) 
963       {
964
965         bbtkDebugMessage("connection",2,"c==0"<<std::endl);     
966         return;
967       }
968
969     OutputConnectorMapType::iterator i = bbGetOutputConnectorMap().find(name);
970     if (i==bbGetOutputConnectorMap().end())
971       {
972         bbtkError("no output called '"<<name<<"'");
973       }
974     i->second->UnsetConnection(c);
975
976     bbtkDebugMessage("connection",2,
977                      "<== BlackBox::bbDisconnectOutput(\""<<name
978                      <<"\","<<c->GetFullName()<<") ["
979                      <<bbGetFullName()<<"]"
980                      <<std::endl);       
981   } 
982   //=========================================================================
983  
984
985   //=========================================================================
986   /// Virtual
987   void BlackBox::bbWriteDotInputOutputName(FILE *ff,bool inputoutput,int detail, int level)
988   {
989     fprintf(ff,"%s%p",bbGetTypeName().c_str(),this);
990   }
991   //=========================================================================
992
993
994   //=========================================================================
995   std::string BlackBox::bbGetOutputAsString( const std::string &output ) 
996   {
997     std::string v;
998     // Looks for the adaptor
999     if (bbGetOutputType(output).name() != typeid(std::string).name() ) 
1000       {
1001         // Look for factory 
1002         Package::Pointer p = bbGetDescriptor()->GetPackage();
1003         if ((p != 0) && ( ! p->GetFactorySet().empty() ) )
1004           {
1005             Factory::Pointer f = p->GetFactorySet().begin()->lock();
1006             BlackBox::Pointer a;
1007             try
1008               {
1009                 a = f->NewAdaptor(  
1010                                   bbGetOutputType(output),
1011                                   typeid(std::string),
1012                                   "");
1013               } catch (bbtk::Exception e) 
1014               {
1015               }
1016             if (a){
1017               //                        bbUpdate();
1018               a->bbSetInput("In",bbGetOutput(output));
1019               a->bbExecute();
1020               v = a->bbGetOutput("Out").unsafe_get<std::string>() ;
1021             } else {
1022               v="? (no adaptor found)";
1023             }
1024           }
1025         else 
1026           {
1027             v="? (no factory found)";
1028           }
1029       } 
1030     else 
1031       {
1032         //         bbUpdate();
1033         v = bbGetOutput(output).unsafe_get<std::string>() ;
1034       }
1035     return v;
1036   }
1037   //=========================================================================
1038
1039   //=========================================================================
1040   std::string BlackBox::bbGetInputAsString( const std::string &input ) 
1041   {
1042     std::string v;
1043     // Looks for the adaptor
1044     if (bbGetInputType(input) != typeid(std::string)) 
1045       {
1046         // Look for factory 
1047         Package::Pointer p = bbGetDescriptor()->GetPackage();
1048         if ((p != 0) && ( ! p->GetFactorySet().empty() ) )
1049           {
1050             Factory::Pointer f = p->GetFactorySet().begin()->lock();
1051             BlackBox::Pointer a;
1052             try
1053               {
1054                 a = f->NewAdaptor(  
1055                                bbGetInputType(input),
1056                                typeid(std::string),
1057                                "");
1058               }catch (bbtk::Exception e) 
1059               {
1060               }
1061             if (a)
1062               {
1063                 //                      bbUpdate();
1064                 a->bbSetInput("In",bbGetInput(input));
1065                 a->bbExecute();
1066                 v = a->bbGetOutput("Out").unsafe_get<std::string>() ;
1067               } 
1068             else 
1069               {
1070                 v="? (no adaptor found)";
1071               }
1072           } 
1073         else 
1074           {
1075             v="? (no factory found)";
1076           }
1077       }
1078     else 
1079       {
1080         v = bbGetInput(input).unsafe_get<std::string>() ;
1081       }
1082     return v;
1083   }
1084   //=======================================================================
1085
1086   //=======================================================================
1087   // Replaces substrings "<" by "["
1088   void SubsBrackets ( std::string& s )
1089   {
1090     //   std::cout << "BEFORE=["<<s<<"]"<<std::endl;
1091     std::string ss("<");
1092     std::string::size_type pos = 0;
1093     pos = s.find(ss,0);
1094     std::string cr("[");
1095     while ( pos != std::string::npos )
1096       {
1097         //      std::cout << "*** find one "<<std::endl;
1098         s.replace(pos,1,cr.c_str(),1);
1099         pos = s.find(ss, pos);
1100       } 
1101     ss = ">";
1102     pos = 0;
1103     pos = s.find(ss,0);
1104     cr = "]";
1105     while ( pos != std::string::npos )
1106       {
1107         //      std::cout << "*** find one "<<std::endl;
1108         s.replace(pos,1,cr.c_str(),1);
1109         pos = s.find(ss, pos);
1110       } 
1111     ss = ",";
1112     pos = 0;
1113     pos = s.find(ss,0);
1114     cr = "-";
1115     while ( pos != std::string::npos )
1116       {
1117         //      std::cout << "*** find one "<<std::endl;
1118         s.replace(pos,1,cr.c_str(),1);
1119         pos = s.find(ss, pos);
1120       }     //    std::cout << "AFTER=["<<s<<"]"<<std::endl;
1121   }
1122   //=======================================================================
1123
1124   //=========================================================================
1125   /// Write Graphviz-dot description in file
1126   void BlackBox::bbWriteDotFileBlackBox(FILE *ff,
1127                                         BlackBox::Pointer parentblackbox, 
1128                                         int detail, int level,
1129                                         bool instanceOrtype,
1130                                         bool relative_link )
1131
1132   { 
1133     InputConnectorMapType::iterator i;
1134     // label
1135     std::string labelStr;
1136     std::string valueStr("");
1137
1138         if (detail==0) {
1139                 labelStr = bbGetName() ; 
1140 //EED 18 Fev 2008
1141                 labelStr = labelStr + "\\n[" +this->bbGetDescriptor()->GetPackage()->GetName()+"::"+ bbGetTypeName() + "]";
1142         } else {
1143                 labelStr = bbGetName();
1144                 labelStr = labelStr + "   [" +this->bbGetDescriptor()->GetPackage()->GetName()+"::"+ bbGetTypeName() + "]  ";
1145     }
1146
1147     SubsBrackets(labelStr);
1148     if (detail==1)
1149       {
1150         labelStr = labelStr + " | {{ "; 
1151         std::string tempStrTypeName;
1152         bool tmp; 
1153         tmp=false;
1154         for ( i = mInputConnectorMap.begin(); i != mInputConnectorMap.end(); ++i ) 
1155           {
1156             if (tmp==true)
1157               {
1158                 labelStr=labelStr+" | ";
1159               }
1160             tmp=true;
1161             if (instanceOrtype==true)
1162               {
1163                 valueStr = this->bbGetInputAsString(i->first) + " = ";
1164               } 
1165             const BlackBoxInputDescriptor* id = bbGetDescriptor()->GetInputDescriptor(i->first);
1166             tempStrTypeName=id->GetTypeName();
1167             SubsBrackets(tempStrTypeName);
1168             std::string Name(i->first);
1169             SubsBrackets(Name);
1170             labelStr=labelStr + "<"+i->first.c_str()+"> "  + valueStr +  Name.c_str() + "  [" + tempStrTypeName.c_str() + "]";
1171           }
1172         labelStr=labelStr+ " } | {";
1173         tmp = false;
1174         OutputConnectorMapType::iterator ii;
1175         for ( ii = mOutputConnectorMap.begin(); ii != mOutputConnectorMap.end(); ++ii ) 
1176         {
1177            if (tmp==true)
1178            {
1179                    labelStr=labelStr+" | ";
1180            }
1181            tmp = true;
1182            if (instanceOrtype==true)
1183            {
1184                    valueStr = this->bbGetOutputAsString(ii->first) + " = ";
1185            }
1186            const BlackBoxOutputDescriptor* id = bbGetDescriptor()->GetOutputDescriptor(ii->first); 
1187            tempStrTypeName=id->GetTypeName();
1188            SubsBrackets(tempStrTypeName);
1189             std::string Name(ii->first);
1190             SubsBrackets(Name);
1191            labelStr=labelStr+"<"+ii->first.c_str()+"> " + valueStr + Name.c_str() + "  ["+tempStrTypeName+"]";
1192         }
1193         labelStr = labelStr+ "      } }" ;
1194 } // detail
1195
1196     fprintf(ff,"  " );
1197     bbWriteDotInputOutputName(ff,true,detail,level);
1198     std::string tmp ( bbGetTypeName() );
1199     SubsBrackets(tmp);
1200     std::string url;
1201     if (relative_link) 
1202       url = this->bbGetDescriptor()->GetPackage()->GetDocRelativeURL() + "#" + tmp;
1203     else 
1204       url = this->bbGetDescriptor()->GetPackage()->GetDocURL() + "#" + tmp;
1205   
1206     fprintf( ff , " [shape=record, URL=\"%s\",label=\"%s\"]%s\n",url.c_str(),labelStr.c_str(),";" );
1207     //    std::cout  << labelStr << std::endl;
1208
1209     // Relation Input
1210     if (GetThisPointer<BlackBox>()!=parentblackbox){
1211       for ( i = mInputConnectorMap.begin(); i != mInputConnectorMap.end(); ++i ) 
1212         {
1213           if (i->second)
1214             {
1215               Connection* con = i->second->GetConnection();
1216               if (con!=NULL){
1217                 BlackBox::Pointer a=con->GetOriginalBlackBoxFrom();
1218                 BlackBox::Pointer b=con->GetOriginalBlackBoxTo();
1219                 fprintf(ff,"  ");
1220                 a->bbWriteDotInputOutputName(ff,false,detail,level);
1221                 if (detail==1)
1222                   {
1223                     fprintf(ff,":%s",con->GetOriginalBlackBoxFromOutput().c_str());
1224                   }
1225                 fprintf(ff,"->");
1226                 b->bbWriteDotInputOutputName(ff,true,detail,level);
1227                 if (detail==1)
1228                   {
1229                     fprintf(ff,":%s",con->GetOriginalBlackBoxToInput().c_str());
1230                   }
1231                 fprintf(ff,"%s\n",";");
1232               }  // if con
1233             } // if second
1234         } // for
1235     } // if parentblackbox
1236   }
1237   //=========================================================================
1238
1239
1240
1241
1242   //=========================================================================
1243   void BlackBox::bbShowRelations(BlackBox::Pointer parentblackbox, 
1244                                  int detail, int level
1245                                  /*,Factory *factory*/ )
1246   {
1247      
1248     if (this->bbGetDescriptor()->GetPackage()) 
1249       {
1250         bbtkMessage("Help",1,"Black Box '"<<bbGetName()<<"' <"<<
1251                     this->bbGetDescriptor()->GetPackage()->GetName()
1252                     <<"::"<<this->bbGetDescriptor()->GetTypeName()<<">"<<std::endl);
1253       }
1254     else 
1255       {
1256         bbtkMessage("Help",1,"Black Box <::"<<this->bbGetDescriptor()->GetTypeName()<<">"<<std::endl);
1257       }
1258     /*
1259     if (bbIsUpToDate())
1260       {
1261         bbtkMessage("Help",1,"Up-to-date ["<<mMaxInputChangeTime<<","
1262                     <<mMinOutputChangeTime<<"]"<<std::endl);
1263       }
1264     else 
1265       {
1266         bbtkMessage("Help",1,"Out-of-date ["<<mMaxInputChangeTime<<","
1267                     <<mMinOutputChangeTime<<"]"<<std::endl);
1268       }
1269     */
1270     //    bbtkMessage("Help",1," "<<GetDescription()<<std::endl);
1271     //    bbtkMessage("Help",1," By : "<<GetAuthor()<<std::endl);
1272
1273     std::vector<std::string> iname;
1274     std::vector<std::string> ivalue;
1275     std::vector<std::string> iconn;
1276     std::vector<std::string> istatus;
1277
1278     InputConnectorMapType::iterator i;
1279     unsigned int namelmax = 0;
1280     unsigned int valuelmax = 0;
1281     //   unsigned int connlmax = 0;
1282     for ( i = mInputConnectorMap.begin(); i != mInputConnectorMap.end(); ++i ) 
1283       {
1284         iname.push_back(i->first);
1285         if (iname.back().size()>namelmax) namelmax = iname.back().size();
1286         ivalue.push_back(bbGetInputAsString(i->first));
1287         if (ivalue.back().size()>valuelmax) valuelmax = ivalue.back().size();
1288         std::string s("");
1289         Connection* con = i->second->GetConnection();
1290         if (con!=0){
1291           s = con->GetOriginalBlackBoxFrom()->bbGetName();
1292           s += ".";
1293           s += con->GetOriginalBlackBoxFromOutput();
1294         }  // if con
1295         iconn.push_back(s);
1296         istatus.push_back(GetIOStatusString(i->second->GetStatus()));
1297       }
1298     OutputConnectorMapType::iterator o;
1299     std::vector<std::string> oname;
1300     std::vector<std::string> ovalue;
1301     std::vector<std::vector<std::string> > oconn;
1302     std::vector<std::string> ostatus;
1303     for ( o = mOutputConnectorMap.begin(); o != mOutputConnectorMap.end(); ++o ) 
1304       {
1305         oname.push_back(o->first);
1306         if (oname.back().size()>namelmax) namelmax = oname.back().size();
1307         ovalue.push_back(bbGetOutputAsString(o->first));
1308         if (ovalue.back().size()>valuelmax) valuelmax = ovalue.back().size();
1309         std::vector<std::string> ss;
1310         const std::vector<Connection*>& con 
1311           = o->second->GetConnectionVector();
1312         std::vector<Connection*>::const_iterator c;
1313         for (c=con.begin();c!=con.end();++c) 
1314           {
1315             std::string s;
1316             s = (*c)->GetOriginalBlackBoxTo()->bbGetName();
1317             s += ".";
1318             s += (*c)->GetOriginalBlackBoxToInput();
1319             ss.push_back(s);
1320         }  // if con
1321         oconn.push_back(ss);
1322         ostatus.push_back(GetIOStatusString(o->second->GetStatus()));
1323       }
1324
1325     if (iname.size()) 
1326       bbtkMessage("Help",1," * Inputs : "<<std::endl);
1327     else 
1328       bbtkMessage("Help",1," * No inputs"<<std::endl);
1329
1330     std::vector<std::string>::iterator i1,i2,i3,i4;
1331     for (i1=iname.begin(),i2=ivalue.begin(),i3=iconn.begin(),i4=istatus.begin();
1332          i1!=iname.end(),i2!=ivalue.end(),i3!=iconn.end(),i4!=istatus.end();
1333          ++i1,++i2,++i3,++i4)
1334       {
1335         std::string name(*i1);
1336         name += "'";
1337         name.append(1+namelmax-name.size(),' ');
1338         std::string value(*i2);
1339         value += "'";
1340         value.append(1+valuelmax-value.size(),' ');
1341         if (i3->size()) 
1342           bbtkMessage("Help",1,"    '"<<name<<" = '"<<value<<" <-- '"
1343                       <<*i3<<"'");
1344         else 
1345           bbtkMessage("Help",1,"    '"<<name<<" = '"<<value);
1346         bbtkMessage("Help",1," ["<<*i4<<"]"<<std::endl);
1347       }
1348
1349     if (oname.size()) 
1350       bbtkMessage("Help",1," * Outputs : "<<std::endl);
1351     else 
1352       bbtkMessage("Help",1," * No outputs"<<std::endl);
1353
1354     std::vector<std::vector<std::string> >::iterator i5;
1355
1356     for (i1=oname.begin(),i2=ovalue.begin(),i5=oconn.begin(),i4=ostatus.begin();
1357          i1!=oname.end(),i2!=ovalue.end(),i5!=oconn.end(),i4!=ostatus.end();
1358          ++i1,++i2,++i4,++i5)
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 (!(*i5).size())
1367           bbtkMessage("Help",1,"    '"<<name<<" = '"<<value);
1368         else 
1369           {
1370             std::string pref = "    '"+name+" = '"+value;
1371             for (i3=i5->begin();i3!=i5->end();++i3)
1372               {
1373                 bbtkMessage("Help",1,pref<<" --> '"<<*i3<<"'");
1374                 pref.replace(0,pref.size(),pref.size(),' ');
1375               }
1376           }
1377         bbtkMessage("Help",1," ["<<*i4<<"]"<<std::endl);
1378       }
1379
1380    }
1381   //=========================================================================
1382
1383   static bool bbmgGlobalProcessingExecutionList = false;
1384
1385   //=========================================================================
1386    void BlackBox::bbGlobalProcessExecutionList()
1387    {   
1388      bbtkDebugMessageInc("process",3,
1389                          "=> BlackBox::bbGlobalProcessExecutionList()"
1390                          <<std::endl);    
1391      if (bbmgGlobalProcessingExecutionList) 
1392        {
1393          bbtkDebugMessage("process",3,"BlackBox::bbGlobalProcessExecutionList() reentered !");
1394          return;
1395        }
1396      bbmgGlobalProcessingExecutionList = true;
1397
1398      std::set<BlackBox::WeakPointer>::iterator i; 
1399      while (bbmgExecutionList.size()>0)
1400        {
1401          i = bbmgExecutionList.begin();
1402          BlackBox::WeakPointer p = *i;
1403          bbmgExecutionList.erase(i);
1404          if (p.lock())
1405            {
1406              bbtkDebugMessage("process",4,
1407                               " -> Executing "<<
1408                               p.lock()->bbGetFullName()<<std::endl);
1409              p.lock()->bbExecute(true);
1410            }
1411          else 
1412            {
1413              bbtkGlobalError("Strange error in BlackBox::bbGlobalProcessExecutionList() : Weak bb pointer in bbmgExecutionList is no more valid...");
1414            }
1415        }
1416      
1417      bbmgExecutionList.clear();
1418      bbtkDebugMessageDec("process",3,
1419                          "<= BlackBox::bbGlobalProcessExecutionList()"
1420                          <<std::endl);     
1421      
1422      bbmgGlobalProcessingExecutionList = false;
1423      
1424    }
1425   //=========================================================================
1426
1427     bool BlackBox::bbGlobalGetSomeBoxExecuting()
1428         { 
1429                 return bbmgSomeBoxExecuting; 
1430         }
1431
1432     void BlackBox::bbGlobalSetSomeBoxExecuting(bool b) 
1433         { 
1434                 bbmgSomeBoxExecuting = b; 
1435         }
1436
1437     void BlackBox::bbGlobalSetFreezeExecution(bool b) 
1438         { 
1439                 bbmgFreezeExecution = b;
1440         }
1441
1442     bool BlackBox::bbGlobalGetFreezeExecution() 
1443         { 
1444                 return bbmgFreezeExecution; 
1445         }
1446
1447   void BlackBox::bbGlobalAddToExecutionList( BlackBox::Pointer b )
1448   {  
1449     bbtkDebugMessage("process",3,"* bbGlobalAddToExecutionList("<<b->bbGetFullName()<<")"<<std::endl);
1450     if (bbmgGlobalProcessingExecutionList) 
1451       {
1452         bbtkDebugMessage("process",3,"bbGlobalAddToExecutionList called inside bbGlobalProcessExecutionList !");
1453       }
1454     bbmgExecutionList.insert(b); 
1455   } 
1456
1457
1458    //=========================================================================
1459
1460   //=========================================================================
1461   void BlackBox::Check(bool recursive)
1462   {
1463     bbtkMessage("debug",1,"*** Checking Black Box "<<(void*)this<<" ["<<bbGetFullName()
1464                 <<"] ... OK"<<std::endl);
1465   }
1466   //=========================================================================
1467
1468   void BlackBox::bbUserOnShowWidget(std::string nameInput)
1469   {
1470           bbtk::BlackBoxInputConnector *cc;
1471           cc = this->bbGetInputConnectorMap().find( nameInput.c_str() )->second;
1472           if (cc->GetConnection()!=NULL) 
1473           {
1474                   cc->GetConnection()->GetBlackBoxFrom()->bbUserOnShow();
1475           }
1476   }
1477
1478
1479
1480 }  // EO namespace bbtk
1481
1482 // EOF
1483