1 /*=========================================================================
4 Module: $RCSfile: bbtkBlackBox.cxx,v $
6 Date: $Date: 2008/03/11 18:46:47 $
7 Version: $Revision: 1.7 $
9 Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10 l'Image). All rights reserved. See doc/license.txt or
11 http://www.creatis.insa-lyon.fr/Public/bbtk/License.html for details.
13 This software is distributed WITHOUT ANY WARRANTY; without even
14 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 PURPOSE. See the above copyright notices for more information.
17 =========================================================================*/
22 * \brief Class bbtk::BlackBox : abstract black-box interface.
24 #include "bbtkBlackBox.h"
25 #include "bbtkPackage.h"
26 #include "bbtkMessageManager.h"
27 #include "bbtkFactory.h"
29 #include "bbtkConfigurationFile.h"
30 #include "bbtkWxBlackBox.h"
40 static bool bbmgSomeBoxExecuting = false;
41 static bool bbmgFreezeExecution = false;
42 static std::set<BlackBox*> bbmgExecutionList;
45 //=========================================================================
46 BlackBox::BlackBox(const std::string &name)
47 : bbmName(name), bbmStatus(MODIFIED),
48 bbmBoxProcessMode("Pipeline"),bbmParent(NULL)
50 bbtkDebugMessage("Kernel",7,"BlackBox::BlackBox(\""
51 <<name<<"\")"<<std::endl);
53 //=========================================================================
56 //=========================================================================
57 BlackBox::BlackBox(BlackBox& from, const std::string &name)
59 bbmStatus(from.bbmStatus),
60 bbmBoxProcessMode(from.bbmBoxProcessMode),bbmParent(NULL)
62 bbtkDebugMessage("Kernel",7,"BlackBox::BlackBox("
63 <<from.bbGetFullName()<<",\""
64 <<name<<"\")"<<std::endl);
66 //=========================================================================
69 //=========================================================================
72 // std::cout << "EED BlackBox::~BlackBox 01 [" << bbGetName()<<"]\n";
73 bbtkDebugMessageInc("Kernel",7,"BlackBox::~BlackBox()"<<std::endl);
74 this->bbDesallocateConnectors();
75 //printf("EED BlackBox::~BlackBox 02 \n");
76 bbtkDebugDecTab("Kernel",7);
78 //=========================================================================
80 //=========================================================================
81 /// Destruction method of a black box
82 void BlackBox::bbDelete()
84 bbtkDebugMessage("Kernel",5,"BlackBox::bbDelete() ["
85 <<bbGetFullName()<<"]"<<std::endl);
88 //=========================================================================
91 //=========================================================================
92 /// Main processing method of the box.
93 void BlackBox::bbExecute(bool force)
95 bbtkDebugMessageInc("Process",1,
96 "=> BlackBox::bbExecute() ["
97 <<bbGetFullName()<<"]"<<std::endl);
99 Wx::BeginBusyCursor();
101 // If execution frozen : return
102 if (bbGlobalGetFreezeExecution())
104 bbtkDebugMessage("Process",1,
105 " -> FreezeExecution global flag is 'true' : abort execution"<<std::endl);
108 // If force is true then update is triggered even if the box is UPTODATE
109 if (force) bbSetModifiedStatus();
111 // Calls the main recursive update method
116 bbtkDebugMessageDec("Process",1,
117 "<= BlackBox::bbExecute() ["
118 <<bbGetFullName()<<"]"<<std::endl);
120 //=========================================================================
122 //=========================================================================
123 std::string BlackBox::bbGetFullName() const
125 return bbGetNameWithParent()+"<"+this->bbGetDescriptor()->GetTypeName()+">";
127 //=========================================================================
131 //=========================================================================
132 /// Returns the name with the name of the parent prepended if any
133 std::string BlackBox::bbGetNameWithParent() const
137 return bbmParent->bbGetNameWithParent() + ":" + bbmName;
144 //=========================================================================
146 //=========================================================================
147 /// Prints the Help on the BlackBox type
148 void BlackBox::bbGetHelp(bool full) const
150 bbGetDescriptor()->GetHelp(full);
152 //=========================================================================
155 //=========================================================================
156 /// Returns true if the UserBlackBox has an input of name name
157 bool BlackBox::bbHasInput(const std::string& name) const
159 bbtkDebugMessageInc("Kernel",8,
160 "BlackBox::bbHasInput(\""
161 <<name<<"\") ["<<bbGetFullName()<<"]"
163 bool r = ( bbGetDescriptor()->GetInputDescriptorMap().find(name)
164 != bbGetDescriptor()->GetInputDescriptorMap().end());
165 bbtkDebugDecTab("Kernel",8);
168 //=========================================================================
171 //=========================================================================
172 /// Returns true if the UserBlackBox has an output of name name
173 bool BlackBox::bbHasOutput(const std::string& name) const
175 bbtkDebugMessageInc("Kernel",8,"BlackBox::bbHasOutput(\""
176 <<name<<"\") ["<<bbGetFullName()<<"]"<<std::endl);
177 bool r = ( bbGetDescriptor()->GetOutputDescriptorMap().find(name)
178 != bbGetDescriptor()->GetOutputDescriptorMap().end());
179 bbtkDebugDecTab("Kernel",8);
182 //=========================================================================
185 //=========================================================================
186 /// Gets the output type of a given name
187 TypeInfo BlackBox::bbGetOutputType( const std::string &name ) const
189 bbtkDebugMessageInc("Kernel",8,
190 "BlackBox::bbGetOutputType(\""
191 <<name<<"\") ["<<bbGetFullName()<<"]"<<std::endl);
192 TypeInfo r = bbGetDescriptor()->GetOutputDescriptor(name)->GetTypeInfo();
193 bbtkDebugDecTab("Kernel",8);
196 //=========================================================================
198 //=========================================================================
199 /// Gets the input type of a given name
200 TypeInfo BlackBox::bbGetInputType( const std::string &name ) const
202 bbtkDebugMessageInc("Kernel",8,
203 "BlackBox::bbGetInputType(\""
204 <<name<<"\") ["<<bbGetFullName()<<"]"<<std::endl);
205 TypeInfo r = bbGetDescriptor()->GetInputDescriptor(name)->GetTypeInfo();
206 bbtkDebugDecTab("Kernel",8);
209 //=========================================================================
212 //=========================================================================
213 /// Allocates the i/o connectors of the black box
214 void BlackBox::bbAllocateConnectors()
216 bbtkDebugMessageInc("Kernel",8,
217 "BlackBox::bbAllocateConnectors() ["
218 <<bbGetFullName()<<"]"
220 const BlackBoxDescriptor::InputDescriptorMapType& imap
221 = bbGetDescriptor()->GetInputDescriptorMap();
222 BlackBoxDescriptor::InputDescriptorMapType::const_iterator i;
223 for ( i = imap.begin(); i != imap.end(); ++i )
225 bbtkDebugMessage("Kernel",8,"* Allocate \""<<i->first<<"\""<<std::endl);
226 bbGetInputConnectorMap()[i->second->GetName()]
227 = new BlackBoxInputConnector(this);
229 const BlackBoxDescriptor::OutputDescriptorMapType& omap
230 = bbGetDescriptor()->GetOutputDescriptorMap();
231 BlackBoxDescriptor::OutputDescriptorMapType::const_iterator o;
232 for ( o = omap.begin(); o != omap.end(); ++o )
234 bbtkDebugMessage("Kernel",8,"* Allocate \""<<o->first<<"\""<<std::endl);
235 bbGetOutputConnectorMap()[o->second->GetName()]
236 = new BlackBoxOutputConnector();
238 bbtkDebugDecTab("Kernel",8);
240 //=========================================================================
243 //=========================================================================
244 /// Desallocates the i/o connectors of the black box
245 void BlackBox::bbDesallocateConnectors()
247 bbtkDebugMessageInc("Kernel",8,
248 "BlackBox::bbDesallocateConnectors()"
251 InputConnectorMapType::const_iterator i;
252 for ( i = bbGetInputConnectorMap().begin();
253 i != bbGetInputConnectorMap().end(); ++i )
255 bbtkDebugMessage("Kernel",8,"* Delete \""<<i->first<<"\""<<std::endl);
258 OutputConnectorMapType::const_iterator o;
259 for ( o = bbGetOutputConnectorMap().begin();
260 o != bbGetOutputConnectorMap().end(); ++o )
262 bbtkDebugMessage("Kernel",8,"* Delete \""<<o->first<<"\""<<std::endl);
266 bbtkDebugDecTab("Kernel",8);
269 //=========================================================================
272 //=========================================================================
273 /// Copies the input / output values from another box
274 void BlackBox::bbCopyIOValues(BlackBox& from)
276 bbtkDebugMessageInc("Kernel",9,
277 "BlackBox::bbCopyIOValues("
278 <<from.bbGetFullName()<<") ["
279 <<bbGetFullName()<<"]"<<std::endl);
280 // copies the input values
281 const BlackBoxDescriptor::InputDescriptorMapType& imap
282 = bbGetDescriptor()->GetInputDescriptorMap();
283 BlackBoxDescriptor::InputDescriptorMapType::const_iterator i;
284 for ( i = imap.begin(); i != imap.end(); ++i )
286 if (! i->second->GetCopyConstruct() ) continue;
287 std::string input = i->second->GetName();
288 this->bbSetInput(input, from.bbGetInput(input) );
290 // copies the output values
291 const BlackBoxDescriptor::OutputDescriptorMapType& omap
292 = bbGetDescriptor()->GetOutputDescriptorMap();
293 BlackBoxDescriptor::OutputDescriptorMapType::const_iterator o;
294 for ( o = omap.begin(); o != omap.end(); ++o )
296 if (! o->second->GetCopyConstruct() ) continue;
297 std::string output = o->second->GetName();
298 this->bbSetOutput(output, from.bbGetOutput(output) );
301 bbtkDebugDecTab("Kernel",9);
304 //=========================================================================
308 //=========================================================================
309 bool BlackBox::bbCanReact() const
311 return ( bbGlobalGetSomeBoxExecuting()
312 #ifdef _USE_WXWIDGETS_
313 || Wx::IsSomeWindowAlive()
317 //=========================================================================
321 //=========================================================================
322 /// User overloadable destruction method of a black box
323 void BlackBox::bbUserDelete()
325 bbtkDebugMessage("Process",5,
326 "=> BlackBox::bbUserDelete() ["
327 <<bbGetFullName()<<"]"
328 <<" : not overloaded; using standard deletion"
332 //=========================================================================
335 //=========================================================================
336 BlackBox::BoxProcessModeValue BlackBox::bbGetBoxProcessModeValue() const
338 const std::string& p = bbmBoxProcessMode;
340 (p == "P") || (p == "p") ||
341 (p == "Pipeline") || (p == "pipeline") ) return Pipeline;
343 (p == "A") || (p == "a") ||
344 (p == "Always") || (p == "always") ) return Always;
346 (p == "R") || (p == "r") ||
347 (p == "Reactive") || (p == "reactive") ) return Reactive;
348 bbtkError(bbGetFullName()<<" : BoxProcessMode value '"<<p
349 <<"' unknown. Possible values : "
350 <<"'0'/'P'/'p'/'Pipeline'/'pipeline' | "
351 <<"'1'/'A'/'a'/'Always'/'always' | "
352 <<"'2'/'R'/'r'/'Reactive'/'reactive'"<<std::endl);
354 //=========================================================================
356 //=========================================================================
357 bool BlackBox::bbBoxProcessModeIsReactive() const
359 return (bbGetBoxProcessModeValue() == Reactive);
361 //=========================================================================
363 //=========================================================================
364 bool BlackBox::bbBoxProcessModeIsAlways() const
366 return (bbGetBoxProcessModeValue() == Always);
368 //=========================================================================
370 //=========================================================================
371 /// Signals that the BlackBox has been modified
372 void BlackBox::bbSetModifiedStatus(BlackBoxInputConnector* c)
374 bbtkDebugMessageInc("Process",5,
375 "=> BlackBox::bbSetModifiedStatus("<<c<<") ["
376 <<bbGetFullName()<<"]"<<std::endl);
378 if ( (c==bbGetInputConnectorMap().find("WinHide")->second) )
379 // && (bbCanReact()))
381 bbtkDebugMessage("Process",9,
382 "-> Hide triggered by WinHide input change"
384 this->bbHideWindow();
385 this->bbSetStatus(MODIFIED);
389 if ( ( bbBoxProcessModeIsReactive() ||
390 (c==bbGetInputConnectorMap().find("BoxExecute")->second))
393 bbtkDebugMessage("Process",9,
394 "-> Execution triggered by Reactive mode or BoxExecute input change"<<std::endl);
395 this->bbSetStatus(MODIFIED);
396 bbGlobalAddToExecutionList( this );
398 else if ( bbGetStatus() == MODIFIED ) //! this->bbIsUptodate())
400 bbtkDebugMessage("Process",5,"-> Already modified"<<std::endl);
401 bbtkDebugDecTab("Process",5);
406 bbtkDebugMessage("Process",5,"-> Status set to modified"<<std::endl);
407 bbtkDebugDecTab("Process",5);
408 this->bbSetStatus(MODIFIED);
411 this->bbSignalOutputModification(false);
413 bbtkDebugMessageDec("Process",5,
414 "<= BlackBox::bbSetModifiedStatus("<<c<<") ["
415 <<bbGetFullName()<<"]"<<std::endl);
417 //=========================================================================
419 //=========================================================================
420 void BlackBox::bbSignalOutputModification(bool reaction)
422 bbtkDebugMessageInc("Process",5,
423 "=> BlackBox::bbSignalOutputModification() ["
424 <<bbGetFullName()<<"]"<<std::endl);
426 OutputConnectorMapType::iterator change = bbGetOutputConnectorMap().end();
427 OutputConnectorMapType::iterator i;
428 for ( i = bbGetOutputConnectorMap().begin();
429 i != bbGetOutputConnectorMap().end(); ++i) {
430 /* if ( i->first == "BoxChange" )
436 i->second->SetModifiedStatus();
438 // if (change != bbGetOutputConnectorMap().end())
439 // change->second->SetModifiedStatus();
441 if (reaction) bbGlobalProcessExecutionList();
443 bbtkDebugMessageDec("Process",5,
444 "<= BlackBox::bbSignalOutputModification() ["
445 <<bbGetFullName()<<"]"<<std::endl);
448 //=========================================================================
449 //=========================================================================
450 void BlackBox::bbSignalOutputModification(const std::string& output,
453 bbtkDebugMessageInc("Process",5,
454 "=> BlackBox::bbSignalOutputModification("
456 <<bbGetFullName()<<"]"<<std::endl);
458 OutputConnectorMapType::iterator i = bbGetOutputConnectorMap().find(output);
459 if ( i == bbGetOutputConnectorMap().end() )
461 bbtkError("BlackBox["<<bbGetFullName()<<"]::bbSignalOutputModification("<<output<<") : unknown output");
463 i->second->SetModifiedStatus();
464 // Has to notify the output "BoxChange" also
465 if (output != "BoxChange")
467 i = bbGetOutputConnectorMap().find("BoxChange");
468 if ( i != bbGetOutputConnectorMap().end() )
470 i->second->SetModifiedStatus();
473 if (reaction) bbGlobalProcessExecutionList();
475 bbtkDebugMessageDec("Process",5,
476 "<= BlackBox::bbSignalOutputModification("
478 <<bbGetFullName()<<"]"<<std::endl);
481 //=========================================================================
482 //=========================================================================
483 void BlackBox::bbSignalOutputModification(const std::vector<std::string>& output,
486 bbtkDebugMessageInc("Process",5,
487 "=> BlackBox::bbSignalOutputModification(vector of outputs) ["
488 <<bbGetFullName()<<"]"<<std::endl);
489 OutputConnectorMapType::iterator i;
490 std::vector<std::string>::const_iterator o;
491 for (o=output.begin();o!=output.end();++o)
493 // the output "BoxChange" must be signaled **AFTER** all others
494 if (*o == "BoxChange") continue;
495 // Look for the connector
496 i = bbGetOutputConnectorMap().find(*o);
497 if ( i == bbGetOutputConnectorMap().end() )
499 bbtkError("BlackBox["<<bbGetFullName()<<"]::bbSignalOutputModification("<<*o<<") : unknown output");
501 i->second->SetModifiedStatus();
503 // Has to notify the output "BoxChange" also
504 i = bbGetOutputConnectorMap().find("BoxChange");
505 if ( i != bbGetOutputConnectorMap().end() )
507 i->second->SetModifiedStatus();
509 if (reaction) bbGlobalProcessExecutionList();
511 bbtkDebugMessageDec("Process",5,
512 "<= BlackBox::bbSignalOutputModification(vector of outputs) ["
513 <<bbGetFullName()<<"]"<<std::endl);
516 //=========================================================================
518 //=========================================================================
519 /// Updates the BlackBox inputs
520 /// \returns UPTODATE if all inputs are in UPTODATE status after update
522 IOStatus BlackBox::bbUpdateInputs(bool excludeParent)
524 bbtkDebugMessageInc("Process",4,
525 "=> BlackBox::bbUpdateInputs() ["
526 <<bbGetFullName()<<"]"
529 IOStatus s = UPTODATE;
531 InputConnectorMapType::iterator i;
532 for ( i = bbGetInputConnectorMap().begin();
533 i!= bbGetInputConnectorMap().end(); ++i)
535 if (excludeParent && (i->first=="WinParent")) continue;
536 if (i->first=="WinHide") continue;
537 // If input type is Void : no recurse
538 //if ( bbGetDescriptor()->GetInputDescriptor(i->first)->GetTypeInfo()
542 IOStatus t = i->second->BackwardUpdate();
543 if (t==MODIFIED) s = MODIFIED;
546 bbtkDebugMessageDec("Process",4,
547 "<= BlackBox::bbUpdateInputs() ["
548 <<bbGetFullName()<<"]"
554 //=========================================================================
557 //=========================================================================
558 /// Connects the input <name> to the connection c
559 void BlackBox::bbConnectInput( const std::string& name, Connection* c)
561 bbtkDebugMessageInc("Kernel",7,
562 "BlackBox::bbConnectInput(\""<<name<<"\","<<c<<") ["
563 <<bbGetFullName()<<"]"
565 InputConnectorMapType::iterator i = bbGetInputConnectorMap().find(name);
566 if (i==bbGetInputConnectorMap().end())
568 bbtkError("no input called '"<<name<<"'");
570 i->second->SetConnection(c);
572 // bbSetModifiedStatus();
574 bbtkDebugDecTab("Kernel",7);
576 //=========================================================================
579 //=========================================================================
580 /// Connects the output <name> to the connection c
581 void BlackBox::bbConnectOutput( const std::string& name, Connection* c)
583 bbtkDebugMessageInc("Kernel",7,
584 "BlackBox::bbConnectOutput(\""<<name<<"\","<<c<<") ["
585 <<bbGetFullName()<<"]"<<std::endl);
587 OutputConnectorMapType::iterator i = bbGetOutputConnectorMap().find(name);
588 if (i==bbGetOutputConnectorMap().end())
590 bbtkError("no output called '"<<name<<"'");
592 i->second->SetConnection(c);
594 bbtkDebugDecTab("Kernel",7);
596 //=========================================================================
599 //=========================================================================
600 /// Disconnects the input <name> from the connection c
601 void BlackBox::bbDisconnectInput( const std::string& name, Connection* c)
603 bbtkDebugMessageInc("Kernel",7,
604 "BlackBox::bbDisconnectInput(\""<<name
606 <<bbGetFullName()<<"]"
609 InputConnectorMapType::iterator i = bbGetInputConnectorMap().find(name);
610 if (i==bbGetInputConnectorMap().end())
612 bbtkError("no input called '"<<name<<"'");
614 i->second->UnsetConnection(c);
616 bbtkDebugDecTab("Kernel",7);
618 //=========================================================================
621 //=========================================================================
622 /// Disconnects the output <name> from the connection c
623 void BlackBox::bbDisconnectOutput( const std::string& name, Connection* c)
625 bbtkDebugMessageInc("Kernel",7,
626 "BlackBox::bbDisconnectOutput(\""<<name
628 <<bbGetFullName()<<"]"
631 OutputConnectorMapType::iterator i = bbGetOutputConnectorMap().find(name);
632 if (i==bbGetOutputConnectorMap().end())
634 bbtkError("no output called '"<<name<<"'");
636 i->second->UnsetConnection(c);
638 bbtkDebugDecTab("Kernel",7);
640 //=========================================================================
643 //=========================================================================
645 void BlackBox::bbWriteDotInputOutputName(FILE *ff,bool inputoutput,int detail, int level)
647 fprintf(ff,"%s%p",bbGetTypeName().c_str(),this);
649 //=========================================================================
652 //=========================================================================
653 std::string BlackBox::bbGetOutputAsString( const std::string &output )
656 // Looks for the adaptor
657 if (bbGetOutputType(output).name() != typeid(std::string).name() )
660 Package* p = bbGetDescriptor()->GetPackage();
661 if ((p != 0) && ( ! p->GetFactorySet().empty() ) )
663 Factory* f = *p->GetFactorySet().begin();
668 bbGetOutputType(output),
671 } catch (bbtk::Exception e)
676 a->bbSetInput("In",bbGetOutput(output));
678 v = a->bbGetOutput("Out").unsafe_get<std::string>() ;
680 v="? (no adaptor found)";
685 v="? (no factory found)";
691 v = bbGetOutput(output).unsafe_get<std::string>() ;
695 //=========================================================================
697 //=========================================================================
698 std::string BlackBox::bbGetInputAsString( const std::string &input )
701 // Looks for the adaptor
702 if (bbGetInputType(input) != typeid(std::string))
705 Package* p = bbGetDescriptor()->GetPackage();
706 if ((p != 0) && ( ! p->GetFactorySet().empty() ) )
708 Factory* f = *p->GetFactorySet().begin();
713 bbGetInputType(input),
716 }catch (bbtk::Exception e)
722 a->bbSetInput("In",bbGetInput(input));
724 v = a->bbGetOutput("Out").unsafe_get<std::string>() ;
728 v="? (no adaptor found)";
733 v="? (no factory found)";
738 v = bbGetInput(input).unsafe_get<std::string>() ;
742 //=======================================================================
744 //=======================================================================
745 // Replaces substrings "<" by "["
746 void SubsBrackets ( std::string& s )
748 // std::cout << "BEFORE=["<<s<<"]"<<std::endl;
750 std::string::size_type pos = 0;
753 while ( pos != std::string::npos )
755 // std::cout << "*** find one "<<std::endl;
756 s.replace(pos,1,cr,1);
757 pos = s.find(ss, pos);
763 while ( pos != std::string::npos )
765 // std::cout << "*** find one "<<std::endl;
766 s.replace(pos,1,cr,1);
767 pos = s.find(ss, pos);
773 while ( pos != std::string::npos )
775 // std::cout << "*** find one "<<std::endl;
776 s.replace(pos,1,cr,1);
777 pos = s.find(ss, pos);
778 } // std::cout << "AFTER=["<<s<<"]"<<std::endl;
780 //=======================================================================
782 //=========================================================================
783 /// Write Graphviz-dot description in file
784 void BlackBox::bbWriteDotFileBlackBox(FILE *ff,
785 BlackBox *parentblackbox,
786 int detail, int level,
791 InputConnectorMapType::iterator i;
793 std::string labelStr;
794 std::string valueStr("");
797 labelStr = bbGetName() ;
799 labelStr = labelStr + "\\n[" +this->bbGetDescriptor()->GetPackage()->GetName()+"::"+ bbGetTypeName() + "]";
801 labelStr = bbGetName();
802 labelStr = labelStr + " [" +this->bbGetDescriptor()->GetPackage()->GetName()+"::"+ bbGetTypeName() + "] ";
805 SubsBrackets(labelStr);
808 labelStr = labelStr + " | {{ ";
809 std::string tempStrTypeName;
812 for ( i = mInputConnectorMap.begin(); i != mInputConnectorMap.end(); ++i )
816 labelStr=labelStr+" | ";
819 if (instanceOrtype==true)
821 valueStr = this->bbGetInputAsString(i->first) + " = ";
823 const BlackBoxInputDescriptor* id = bbGetDescriptor()->GetInputDescriptor(i->first);
824 tempStrTypeName=id->GetTypeName();
825 SubsBrackets(tempStrTypeName);
826 std::string Name(i->first);
828 labelStr=labelStr + "<"+i->first.c_str()+"> " + valueStr + Name.c_str() + " [" + tempStrTypeName.c_str() + "]";
830 labelStr=labelStr+ " } | {";
832 OutputConnectorMapType::iterator ii;
833 for ( ii = mOutputConnectorMap.begin(); ii != mOutputConnectorMap.end(); ++ii )
837 labelStr=labelStr+" | ";
840 if (instanceOrtype==true)
842 valueStr = this->bbGetOutputAsString(ii->first) + " = ";
844 const BlackBoxOutputDescriptor* id = bbGetDescriptor()->GetOutputDescriptor(ii->first);
845 tempStrTypeName=id->GetTypeName();
846 SubsBrackets(tempStrTypeName);
847 std::string Name(ii->first);
849 labelStr=labelStr+"<"+ii->first.c_str()+"> " + valueStr + Name.c_str() + " ["+tempStrTypeName+"]";
851 labelStr = labelStr+ " } }" ;
855 bbWriteDotInputOutputName(ff,true,detail,level);
856 std::string tmp ( bbGetTypeName() );
860 url = this->bbGetDescriptor()->GetPackage()->GetDocRelativeURL() + "#" + tmp;
862 url = this->bbGetDescriptor()->GetPackage()->GetDocURL() + "#" + tmp;
864 fprintf( ff , " [shape=record, URL=\"%s\",label=\"%s\"]%s\n",url.c_str(),labelStr.c_str(),";" );
865 // std::cout << labelStr << std::endl;
868 if (this!=parentblackbox){
869 for ( i = mInputConnectorMap.begin(); i != mInputConnectorMap.end(); ++i )
873 Connection* con = i->second->GetConnection();
875 BlackBox *a=con->GetBlackBoxFrom();
876 BlackBox *b=con->GetBlackBoxTo();
878 a->bbWriteDotInputOutputName(ff,false,detail,level);
881 fprintf(ff,":%s",con->GetBlackBoxFromOutput().c_str());
884 b->bbWriteDotInputOutputName(ff,true,detail,level);
887 fprintf(ff,":%s",con->GetBlackBoxToInput().c_str());
889 fprintf(ff,"%s\n",";");
893 } // if parentblackbox
895 //=========================================================================
900 //=========================================================================
901 void BlackBox::bbShowRelations(BlackBox *parentblackbox,
902 int detail, int level
903 /*,Factory *factory*/ )
906 if (this->bbGetDescriptor()->GetPackage())
908 bbtkMessage("Help",1,"Black Box '"<<bbGetName()<<"' <"<<
909 this->bbGetDescriptor()->GetPackage()->GetName()
910 <<"::"<<this->bbGetDescriptor()->GetTypeName()<<">"<<std::endl);
914 bbtkMessage("Help",1,"Black Box <::"<<this->bbGetDescriptor()->GetTypeName()<<">"<<std::endl);
916 // bbtkMessage("Help",1," "<<GetDescription()<<std::endl);
917 // bbtkMessage("Help",1," By : "<<GetAuthor()<<std::endl);
919 std::vector<std::string> iname;
920 std::vector<std::string> ivalue;
921 std::vector<std::string> iconn;
923 InputConnectorMapType::iterator i;
924 unsigned int namelmax = 0;
925 unsigned int valuelmax = 0;
926 unsigned int connlmax = 0;
927 for ( i = mInputConnectorMap.begin(); i != mInputConnectorMap.end(); ++i )
929 iname.push_back(i->first);
930 if (iname.back().size()>namelmax) namelmax = iname.back().size();
931 ivalue.push_back(bbGetInputAsString(i->first));
932 if (ivalue.back().size()>valuelmax) valuelmax = ivalue.back().size();
934 Connection* con = i->second->GetConnection();
936 s = con->GetBlackBoxFrom()->bbGetName();
938 s += con->GetBlackBoxFromOutput();
942 OutputConnectorMapType::iterator o;
943 std::vector<std::string> oname;
944 std::vector<std::string> ovalue;
945 std::vector<std::vector<std::string> > oconn;
946 for ( o = mOutputConnectorMap.begin(); o != mOutputConnectorMap.end(); ++o )
948 oname.push_back(o->first);
949 if (oname.back().size()>namelmax) namelmax = oname.back().size();
950 ovalue.push_back(bbGetOutputAsString(o->first));
951 if (ovalue.back().size()>valuelmax) valuelmax = ovalue.back().size();
952 std::vector<std::string> ss;
953 const std::vector<Connection*>& con = o->second->GetConnectionVector();
954 std::vector<Connection*>::const_iterator c;
955 for (c=con.begin();c!=con.end();++c)
958 s = (*c)->GetBlackBoxTo()->bbGetName();
960 s += (*c)->GetBlackBoxToInput();
967 bbtkMessage("Help",1," * Inputs : "<<std::endl);
969 bbtkMessage("Help",1," * No inputs"<<std::endl);
971 std::vector<std::string>::iterator i1,i2,i3;
972 for (i1=iname.begin(),i2=ivalue.begin(),i3=iconn.begin();
973 i1!=iname.end(),i2!=ivalue.end(),i3!=iconn.end();
976 std::string name(*i1);
978 name.append(1+namelmax-name.size(),' ');
979 std::string value(*i2);
981 value.append(1+valuelmax-value.size(),' ');
983 bbtkMessage("Help",1," '"<<name<<" = '"<<value<<" <-- '"<<*i3<<"'"<<std::endl);
985 bbtkMessage("Help",1," '"<<name<<" = '"<<value<<std::endl);
989 bbtkMessage("Help",1," * Outputs : "<<std::endl);
991 bbtkMessage("Help",1," * No outputs"<<std::endl);
993 std::vector<std::vector<std::string> >::iterator i4;
995 for (i1=oname.begin(),i2=ovalue.begin(),i4=oconn.begin();
996 i1!=oname.end(),i2!=ovalue.end(),i4!=oconn.end();
999 std::string name(*i1);
1001 name.append(1+namelmax-name.size(),' ');
1002 std::string value(*i2);
1004 value.append(1+valuelmax-value.size(),' ');
1006 bbtkMessage("Help",1," '"<<name<<" = '"<<value<<std::endl);
1009 std::string pref = " '"+name+" = '"+value;
1010 for (i3=i4->begin();i3!=i4->end();++i3)
1012 bbtkMessage("Help",1,pref<<" --> '"<<*i3<<"'"<<std::endl);
1013 pref.replace(0,pref.size(),pref.size(),' ');
1019 //=========================================================================
1022 //=========================================================================
1023 void BlackBox::bbGlobalProcessExecutionList()
1025 bbtkDebugMessageInc("Process",1,
1026 "=> BlackBox::bbGlobalProcessExecutionList()"
1029 std::set<BlackBox*>::iterator i;
1030 for (i=bbmgExecutionList.begin();
1031 i!=bbmgExecutionList.end();
1034 bbtkDebugMessage("Process",2,
1035 " -> Executing "<<(*i)->bbGetFullName()<<std::endl);
1036 (*i)->bbExecute(true);
1039 bbmgExecutionList.clear();
1040 bbtkDebugMessageDec("Process",1,
1041 "<= BlackBox::bbGlobalProcessExecutionList()"
1046 //=========================================================================
1048 bool BlackBox::bbGlobalGetSomeBoxExecuting()
1050 return bbmgSomeBoxExecuting;
1053 void BlackBox::bbGlobalSetSomeBoxExecuting(bool b)
1055 bbmgSomeBoxExecuting = b;
1058 void BlackBox::bbGlobalSetFreezeExecution(bool b)
1060 bbmgFreezeExecution = b;
1063 bool BlackBox::bbGlobalGetFreezeExecution()
1065 return bbmgFreezeExecution;
1068 void BlackBox::bbGlobalAddToExecutionList( BlackBox* b )
1070 bbmgExecutionList.insert(b);
1074 //=========================================================================
1075 // Static members initialization
1077 bool BlackBox::bbmgSomeBoxExecuting = false;
1078 bool BlackBox::bbmgFreezeExecution = false;
1079 std::set<BlackBox*> BlackBox::bbmgExecutionList;
1081 //=========================================================================
1084 } // EO namespace bbtk