1 /*=========================================================================
4 Module: $RCSfile: bbtkBlackBox.cxx,v $
6 Date: $Date: 2008/04/08 06:59:29 $
7 Version: $Revision: 1.8 $
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)
49 bbmBoxProcessMode("Pipeline"),
53 bbtkDebugMessage("Kernel",7,"BlackBox::BlackBox(\""
54 <<name<<"\")"<<std::endl);
56 //=========================================================================
59 //=========================================================================
60 BlackBox::BlackBox(BlackBox& from, const std::string &name)
62 bbmStatus(from.bbmStatus),
63 bbmBoxProcessMode(from.bbmBoxProcessMode),
67 bbtkDebugMessage("Kernel",7,"BlackBox::BlackBox("
68 <<from.bbGetFullName()<<",\""
69 <<name<<"\")"<<std::endl);
71 //=========================================================================
74 //=========================================================================
77 // std::cout << "EED BlackBox::~BlackBox 01 [" << bbGetName()<<"]\n";
78 bbtkDebugMessageInc("Kernel",7,"BlackBox::~BlackBox()"<<std::endl);
79 this->bbDesallocateConnectors();
80 //printf("EED BlackBox::~BlackBox 02 \n");
81 bbtkDebugDecTab("Kernel",7);
83 //=========================================================================
85 //=========================================================================
86 /// Destruction method of a black box
87 void BlackBox::bbDelete()
89 bbtkDebugMessage("Kernel",5,"BlackBox::bbDelete() ["
90 <<bbGetFullName()<<"]"<<std::endl);
93 //=========================================================================
96 //=========================================================================
97 /// Main processing method of the box.
98 void BlackBox::bbExecute(bool force)
100 bbtkDebugMessageInc("Process",1,
101 "=> BlackBox::bbExecute() ["
102 <<bbGetFullName()<<"]"<<std::endl);
104 Wx::BeginBusyCursor();
106 // If execution frozen : return
107 if (bbGlobalGetFreezeExecution())
109 bbtkDebugMessage("Process",1,
110 " -> FreezeExecution global flag is 'true' : abort execution"<<std::endl);
113 // If force is true then update is triggered even if the box is UPTODATE
114 if (force) bbSetModifiedStatus();
116 // Calls the main recursive update method
121 bbtkDebugMessageDec("Process",1,
122 "<= BlackBox::bbExecute() ["
123 <<bbGetFullName()<<"]"<<std::endl);
125 //=========================================================================
127 //=========================================================================
128 std::string BlackBox::bbGetFullName() const
130 return bbGetNameWithParent()+"<"+this->bbGetDescriptor()->GetTypeName()+">";
132 //=========================================================================
136 //=========================================================================
137 /// Returns the name with the name of the parent prepended if any
138 std::string BlackBox::bbGetNameWithParent() const
142 return bbmParent->bbGetNameWithParent() + ":" + bbmName;
149 //=========================================================================
151 //=========================================================================
152 /// Prints the Help on the BlackBox type
153 void BlackBox::bbGetHelp(bool full) const
155 bbGetDescriptor()->GetHelp(full);
157 //=========================================================================
160 //=========================================================================
161 /// Returns true if the UserBlackBox has an input of name name
162 bool BlackBox::bbHasInput(const std::string& name) const
164 bbtkDebugMessageInc("Kernel",8,
165 "BlackBox::bbHasInput(\""
166 <<name<<"\") ["<<bbGetFullName()<<"]"
168 bool r = ( bbGetDescriptor()->GetInputDescriptorMap().find(name)
169 != bbGetDescriptor()->GetInputDescriptorMap().end());
170 bbtkDebugDecTab("Kernel",8);
173 //=========================================================================
176 //=========================================================================
177 /// Returns true if the UserBlackBox has an output of name name
178 bool BlackBox::bbHasOutput(const std::string& name) const
180 bbtkDebugMessageInc("Kernel",8,"BlackBox::bbHasOutput(\""
181 <<name<<"\") ["<<bbGetFullName()<<"]"<<std::endl);
182 bool r = ( bbGetDescriptor()->GetOutputDescriptorMap().find(name)
183 != bbGetDescriptor()->GetOutputDescriptorMap().end());
184 bbtkDebugDecTab("Kernel",8);
187 //=========================================================================
190 //=========================================================================
191 /// Gets the output type of a given name
192 TypeInfo BlackBox::bbGetOutputType( const std::string &name ) const
194 bbtkDebugMessageInc("Kernel",8,
195 "BlackBox::bbGetOutputType(\""
196 <<name<<"\") ["<<bbGetFullName()<<"]"<<std::endl);
197 TypeInfo r = bbGetDescriptor()->GetOutputDescriptor(name)->GetTypeInfo();
198 bbtkDebugDecTab("Kernel",8);
201 //=========================================================================
203 //=========================================================================
204 /// Gets the input type of a given name
205 TypeInfo BlackBox::bbGetInputType( const std::string &name ) const
207 bbtkDebugMessageInc("Kernel",8,
208 "BlackBox::bbGetInputType(\""
209 <<name<<"\") ["<<bbGetFullName()<<"]"<<std::endl);
210 TypeInfo r = bbGetDescriptor()->GetInputDescriptor(name)->GetTypeInfo();
211 bbtkDebugDecTab("Kernel",8);
214 //=========================================================================
217 //=========================================================================
218 /// Allocates the i/o connectors of the black box
219 void BlackBox::bbAllocateConnectors()
221 bbtkDebugMessageInc("Kernel",8,
222 "BlackBox::bbAllocateConnectors() ["
223 <<bbGetFullName()<<"]"
225 const BlackBoxDescriptor::InputDescriptorMapType& imap
226 = bbGetDescriptor()->GetInputDescriptorMap();
227 BlackBoxDescriptor::InputDescriptorMapType::const_iterator i;
228 for ( i = imap.begin(); i != imap.end(); ++i )
230 bbtkDebugMessage("Kernel",8,"* Allocate \""<<i->first<<"\""<<std::endl);
231 bbGetInputConnectorMap()[i->second->GetName()]
232 = new BlackBoxInputConnector(this);
234 const BlackBoxDescriptor::OutputDescriptorMapType& omap
235 = bbGetDescriptor()->GetOutputDescriptorMap();
236 BlackBoxDescriptor::OutputDescriptorMapType::const_iterator o;
237 for ( o = omap.begin(); o != omap.end(); ++o )
239 bbtkDebugMessage("Kernel",8,"* Allocate \""<<o->first<<"\""<<std::endl);
240 bbGetOutputConnectorMap()[o->second->GetName()]
241 = new BlackBoxOutputConnector();
243 bbtkDebugDecTab("Kernel",8);
245 //=========================================================================
248 //=========================================================================
249 /// Desallocates the i/o connectors of the black box
250 void BlackBox::bbDesallocateConnectors()
252 bbtkDebugMessageInc("Kernel",8,
253 "BlackBox::bbDesallocateConnectors()"
256 InputConnectorMapType::const_iterator i;
257 for ( i = bbGetInputConnectorMap().begin();
258 i != bbGetInputConnectorMap().end(); ++i )
260 bbtkDebugMessage("Kernel",8,"* Delete \""<<i->first<<"\""<<std::endl);
263 OutputConnectorMapType::const_iterator o;
264 for ( o = bbGetOutputConnectorMap().begin();
265 o != bbGetOutputConnectorMap().end(); ++o )
267 bbtkDebugMessage("Kernel",8,"* Delete \""<<o->first<<"\""<<std::endl);
271 bbtkDebugDecTab("Kernel",8);
274 //=========================================================================
277 //=========================================================================
278 /// Copies the input / output values from another box
279 void BlackBox::bbCopyIOValues(BlackBox& from)
281 bbtkDebugMessageInc("Kernel",9,
282 "BlackBox::bbCopyIOValues("
283 <<from.bbGetFullName()<<") ["
284 <<bbGetFullName()<<"]"<<std::endl);
285 // copies the input values
286 const BlackBoxDescriptor::InputDescriptorMapType& imap
287 = bbGetDescriptor()->GetInputDescriptorMap();
288 BlackBoxDescriptor::InputDescriptorMapType::const_iterator i;
289 for ( i = imap.begin(); i != imap.end(); ++i )
291 if (! i->second->GetCopyConstruct() ) continue;
292 std::string input = i->second->GetName();
293 this->bbSetInput(input, from.bbGetInput(input) );
295 // copies the output values
296 const BlackBoxDescriptor::OutputDescriptorMapType& omap
297 = bbGetDescriptor()->GetOutputDescriptorMap();
298 BlackBoxDescriptor::OutputDescriptorMapType::const_iterator o;
299 for ( o = omap.begin(); o != omap.end(); ++o )
301 if (! o->second->GetCopyConstruct() ) continue;
302 std::string output = o->second->GetName();
303 this->bbSetOutput(output, from.bbGetOutput(output) );
306 bbtkDebugDecTab("Kernel",9);
309 //=========================================================================
313 //=========================================================================
314 bool BlackBox::bbCanReact() const
316 return ( bbGlobalGetSomeBoxExecuting()
317 #ifdef _USE_WXWIDGETS_
318 || Wx::IsSomeWindowAlive()
322 //=========================================================================
326 //=========================================================================
327 /// User overloadable destruction method of a black box
328 void BlackBox::bbUserDelete()
330 bbtkDebugMessage("Process",5,
331 "=> BlackBox::bbUserDelete() ["
332 <<bbGetFullName()<<"]"
333 <<" : not overloaded; using standard deletion"
337 //=========================================================================
340 //=========================================================================
341 BlackBox::BoxProcessModeValue BlackBox::bbGetBoxProcessModeValue() const
343 const std::string& p = bbmBoxProcessMode;
345 (p == "P") || (p == "p") ||
346 (p == "Pipeline") || (p == "pipeline") ) return Pipeline;
348 (p == "A") || (p == "a") ||
349 (p == "Always") || (p == "always") ) return Always;
351 (p == "R") || (p == "r") ||
352 (p == "Reactive") || (p == "reactive") ) return Reactive;
353 bbtkError(bbGetFullName()<<" : BoxProcessMode value '"<<p
354 <<"' unknown. Possible values : "
355 <<"'0'/'P'/'p'/'Pipeline'/'pipeline' | "
356 <<"'1'/'A'/'a'/'Always'/'always' | "
357 <<"'2'/'R'/'r'/'Reactive'/'reactive'"<<std::endl);
359 //=========================================================================
361 //=========================================================================
362 bool BlackBox::bbBoxProcessModeIsReactive() const
364 return (bbGetBoxProcessModeValue() == Reactive);
366 //=========================================================================
368 //=========================================================================
369 bool BlackBox::bbBoxProcessModeIsAlways() const
371 return (bbGetBoxProcessModeValue() == Always);
373 //=========================================================================
375 //=========================================================================
376 /// Signals that the BlackBox has been modified
377 void BlackBox::bbSetModifiedStatus(BlackBoxInputConnector* c)
379 bbtkDebugMessageInc("Process",5,
380 "=> BlackBox::bbSetModifiedStatus("<<c<<") ["
381 <<bbGetFullName()<<"]"<<std::endl);
383 if ( (c==bbGetInputConnectorMap().find("WinHide")->second) )
384 // && (bbCanReact()))
386 bbtkDebugMessage("Process",9,
387 "-> Hide triggered by WinHide input change"
389 this->bbHideWindow();
390 this->bbSetStatus(MODIFIED);
394 if ( ( bbBoxProcessModeIsReactive() ||
395 (c==bbGetInputConnectorMap().find("BoxExecute")->second))
398 bbtkDebugMessage("Process",9,
399 "-> Execution triggered by Reactive mode or BoxExecute input change"<<std::endl);
400 this->bbSetStatus(MODIFIED);
401 bbGlobalAddToExecutionList( this );
403 else if ( bbGetStatus() == MODIFIED ) //! this->bbIsUptodate())
405 bbtkDebugMessage("Process",5,"-> Already modified"<<std::endl);
406 bbtkDebugDecTab("Process",5);
411 bbtkDebugMessage("Process",5,"-> Status set to modified"<<std::endl);
412 bbtkDebugDecTab("Process",5);
413 this->bbSetStatus(MODIFIED);
416 this->bbSignalOutputModification(false);
418 bbtkDebugMessageDec("Process",5,
419 "<= BlackBox::bbSetModifiedStatus("<<c<<") ["
420 <<bbGetFullName()<<"]"<<std::endl);
422 //=========================================================================
424 //=========================================================================
425 void BlackBox::bbSignalOutputModification(bool reaction)
427 bbtkDebugMessageInc("Process",5,
428 "=> BlackBox::bbSignalOutputModification() ["
429 <<bbGetFullName()<<"]"<<std::endl);
431 OutputConnectorMapType::iterator change = bbGetOutputConnectorMap().end();
432 OutputConnectorMapType::iterator i;
433 for ( i = bbGetOutputConnectorMap().begin();
434 i != bbGetOutputConnectorMap().end(); ++i) {
435 /* if ( i->first == "BoxChange" )
441 i->second->SetModifiedStatus();
443 // if (change != bbGetOutputConnectorMap().end())
444 // change->second->SetModifiedStatus();
446 if (reaction) bbGlobalProcessExecutionList();
448 bbtkDebugMessageDec("Process",5,
449 "<= BlackBox::bbSignalOutputModification() ["
450 <<bbGetFullName()<<"]"<<std::endl);
453 //=========================================================================
454 //=========================================================================
455 void BlackBox::bbSignalOutputModification(const std::string& output,
458 bbtkDebugMessageInc("Process",5,
459 "=> BlackBox::bbSignalOutputModification("
461 <<bbGetFullName()<<"]"<<std::endl);
463 OutputConnectorMapType::iterator i = bbGetOutputConnectorMap().find(output);
464 if ( i == bbGetOutputConnectorMap().end() )
466 bbtkError("BlackBox["<<bbGetFullName()<<"]::bbSignalOutputModification("<<output<<") : unknown output");
468 i->second->SetModifiedStatus();
469 // Has to notify the output "BoxChange" also
470 if (output != "BoxChange")
472 i = bbGetOutputConnectorMap().find("BoxChange");
473 if ( i != bbGetOutputConnectorMap().end() )
475 i->second->SetModifiedStatus();
478 if (reaction) bbGlobalProcessExecutionList();
480 bbtkDebugMessageDec("Process",5,
481 "<= BlackBox::bbSignalOutputModification("
483 <<bbGetFullName()<<"]"<<std::endl);
486 //=========================================================================
487 //=========================================================================
488 void BlackBox::bbSignalOutputModification(const std::vector<std::string>& output,
491 bbtkDebugMessageInc("Process",5,
492 "=> BlackBox::bbSignalOutputModification(vector of outputs) ["
493 <<bbGetFullName()<<"]"<<std::endl);
494 OutputConnectorMapType::iterator i;
495 std::vector<std::string>::const_iterator o;
496 for (o=output.begin();o!=output.end();++o)
498 // the output "BoxChange" must be signaled **AFTER** all others
499 if (*o == "BoxChange") continue;
500 // Look for the connector
501 i = bbGetOutputConnectorMap().find(*o);
502 if ( i == bbGetOutputConnectorMap().end() )
504 bbtkError("BlackBox["<<bbGetFullName()<<"]::bbSignalOutputModification("<<*o<<") : unknown output");
506 i->second->SetModifiedStatus();
508 // Has to notify the output "BoxChange" also
509 i = bbGetOutputConnectorMap().find("BoxChange");
510 if ( i != bbGetOutputConnectorMap().end() )
512 i->second->SetModifiedStatus();
514 if (reaction) bbGlobalProcessExecutionList();
516 bbtkDebugMessageDec("Process",5,
517 "<= BlackBox::bbSignalOutputModification(vector of outputs) ["
518 <<bbGetFullName()<<"]"<<std::endl);
521 //=========================================================================
523 //=========================================================================
524 /// Updates the BlackBox inputs
525 /// \returns UPTODATE if all inputs are in UPTODATE status after update
527 IOStatus BlackBox::bbUpdateInputs(bool excludeParent)
529 bbtkDebugMessageInc("Process",4,
530 "=> BlackBox::bbUpdateInputs() ["
531 <<bbGetFullName()<<"]"
534 IOStatus s = UPTODATE;
536 InputConnectorMapType::iterator i;
537 for ( i = bbGetInputConnectorMap().begin();
538 i!= bbGetInputConnectorMap().end(); ++i)
540 if (excludeParent && (i->first=="WinParent")) continue;
541 if (i->first=="WinHide") continue;
542 // If input type is Void : no recurse
543 //if ( bbGetDescriptor()->GetInputDescriptor(i->first)->GetTypeInfo()
547 IOStatus t = i->second->BackwardUpdate();
548 if (t==MODIFIED) s = MODIFIED;
551 bbtkDebugMessageDec("Process",4,
552 "<= BlackBox::bbUpdateInputs() ["
553 <<bbGetFullName()<<"]"
559 //=========================================================================
562 //=========================================================================
563 /// Connects the input <name> to the connection c
564 void BlackBox::bbConnectInput( const std::string& name, Connection* c)
566 bbtkDebugMessageInc("Kernel",7,
567 "BlackBox::bbConnectInput(\""<<name<<"\","<<c<<") ["
568 <<bbGetFullName()<<"]"
570 InputConnectorMapType::iterator i = bbGetInputConnectorMap().find(name);
571 if (i==bbGetInputConnectorMap().end())
573 bbtkError("no input called '"<<name<<"'");
575 i->second->SetConnection(c);
577 // bbSetModifiedStatus();
579 bbtkDebugDecTab("Kernel",7);
581 //=========================================================================
584 //=========================================================================
585 /// Connects the output <name> to the connection c
586 void BlackBox::bbConnectOutput( const std::string& name, Connection* c)
588 bbtkDebugMessageInc("Kernel",7,
589 "BlackBox::bbConnectOutput(\""<<name<<"\","<<c<<") ["
590 <<bbGetFullName()<<"]"<<std::endl);
592 OutputConnectorMapType::iterator i = bbGetOutputConnectorMap().find(name);
593 if (i==bbGetOutputConnectorMap().end())
595 bbtkError("no output called '"<<name<<"'");
597 i->second->SetConnection(c);
599 bbtkDebugDecTab("Kernel",7);
601 //=========================================================================
604 //=========================================================================
605 /// Disconnects the input <name> from the connection c
606 void BlackBox::bbDisconnectInput( const std::string& name, Connection* c)
608 bbtkDebugMessageInc("Kernel",7,
609 "BlackBox::bbDisconnectInput(\""<<name
611 <<bbGetFullName()<<"]"
614 InputConnectorMapType::iterator i = bbGetInputConnectorMap().find(name);
615 if (i==bbGetInputConnectorMap().end())
617 bbtkError("no input called '"<<name<<"'");
619 i->second->UnsetConnection(c);
621 bbtkDebugDecTab("Kernel",7);
623 //=========================================================================
626 //=========================================================================
627 /// Disconnects the output <name> from the connection c
628 void BlackBox::bbDisconnectOutput( const std::string& name, Connection* c)
630 bbtkDebugMessageInc("Kernel",7,
631 "BlackBox::bbDisconnectOutput(\""<<name
633 <<bbGetFullName()<<"]"
636 OutputConnectorMapType::iterator i = bbGetOutputConnectorMap().find(name);
637 if (i==bbGetOutputConnectorMap().end())
639 bbtkError("no output called '"<<name<<"'");
641 i->second->UnsetConnection(c);
643 bbtkDebugDecTab("Kernel",7);
645 //=========================================================================
648 //=========================================================================
650 void BlackBox::bbWriteDotInputOutputName(FILE *ff,bool inputoutput,int detail, int level)
652 fprintf(ff,"%s%p",bbGetTypeName().c_str(),this);
654 //=========================================================================
657 //=========================================================================
658 std::string BlackBox::bbGetOutputAsString( const std::string &output )
661 // Looks for the adaptor
662 if (bbGetOutputType(output).name() != typeid(std::string).name() )
665 Package* p = bbGetDescriptor()->GetPackage();
666 if ((p != 0) && ( ! p->GetFactorySet().empty() ) )
668 Factory* f = *p->GetFactorySet().begin();
673 bbGetOutputType(output),
676 } catch (bbtk::Exception e)
681 a->bbSetInput("In",bbGetOutput(output));
683 v = a->bbGetOutput("Out").unsafe_get<std::string>() ;
685 v="? (no adaptor found)";
690 v="? (no factory found)";
696 v = bbGetOutput(output).unsafe_get<std::string>() ;
700 //=========================================================================
702 //=========================================================================
703 std::string BlackBox::bbGetInputAsString( const std::string &input )
706 // Looks for the adaptor
707 if (bbGetInputType(input) != typeid(std::string))
710 Package* p = bbGetDescriptor()->GetPackage();
711 if ((p != 0) && ( ! p->GetFactorySet().empty() ) )
713 Factory* f = *p->GetFactorySet().begin();
718 bbGetInputType(input),
721 }catch (bbtk::Exception e)
727 a->bbSetInput("In",bbGetInput(input));
729 v = a->bbGetOutput("Out").unsafe_get<std::string>() ;
733 v="? (no adaptor found)";
738 v="? (no factory found)";
743 v = bbGetInput(input).unsafe_get<std::string>() ;
747 //=======================================================================
749 //=======================================================================
750 // Replaces substrings "<" by "["
751 void SubsBrackets ( std::string& s )
753 // std::cout << "BEFORE=["<<s<<"]"<<std::endl;
755 std::string::size_type pos = 0;
758 while ( pos != std::string::npos )
760 // std::cout << "*** find one "<<std::endl;
761 s.replace(pos,1,cr,1);
762 pos = s.find(ss, pos);
768 while ( pos != std::string::npos )
770 // std::cout << "*** find one "<<std::endl;
771 s.replace(pos,1,cr,1);
772 pos = s.find(ss, pos);
778 while ( pos != std::string::npos )
780 // std::cout << "*** find one "<<std::endl;
781 s.replace(pos,1,cr,1);
782 pos = s.find(ss, pos);
783 } // std::cout << "AFTER=["<<s<<"]"<<std::endl;
785 //=======================================================================
787 //=========================================================================
788 /// Write Graphviz-dot description in file
789 void BlackBox::bbWriteDotFileBlackBox(FILE *ff,
790 BlackBox *parentblackbox,
791 int detail, int level,
796 InputConnectorMapType::iterator i;
798 std::string labelStr;
799 std::string valueStr("");
802 labelStr = bbGetName() ;
804 labelStr = labelStr + "\\n[" +this->bbGetDescriptor()->GetPackage()->GetName()+"::"+ bbGetTypeName() + "]";
806 labelStr = bbGetName();
807 labelStr = labelStr + " [" +this->bbGetDescriptor()->GetPackage()->GetName()+"::"+ bbGetTypeName() + "] ";
810 SubsBrackets(labelStr);
813 labelStr = labelStr + " | {{ ";
814 std::string tempStrTypeName;
817 for ( i = mInputConnectorMap.begin(); i != mInputConnectorMap.end(); ++i )
821 labelStr=labelStr+" | ";
824 if (instanceOrtype==true)
826 valueStr = this->bbGetInputAsString(i->first) + " = ";
828 const BlackBoxInputDescriptor* id = bbGetDescriptor()->GetInputDescriptor(i->first);
829 tempStrTypeName=id->GetTypeName();
830 SubsBrackets(tempStrTypeName);
831 std::string Name(i->first);
833 labelStr=labelStr + "<"+i->first.c_str()+"> " + valueStr + Name.c_str() + " [" + tempStrTypeName.c_str() + "]";
835 labelStr=labelStr+ " } | {";
837 OutputConnectorMapType::iterator ii;
838 for ( ii = mOutputConnectorMap.begin(); ii != mOutputConnectorMap.end(); ++ii )
842 labelStr=labelStr+" | ";
845 if (instanceOrtype==true)
847 valueStr = this->bbGetOutputAsString(ii->first) + " = ";
849 const BlackBoxOutputDescriptor* id = bbGetDescriptor()->GetOutputDescriptor(ii->first);
850 tempStrTypeName=id->GetTypeName();
851 SubsBrackets(tempStrTypeName);
852 std::string Name(ii->first);
854 labelStr=labelStr+"<"+ii->first.c_str()+"> " + valueStr + Name.c_str() + " ["+tempStrTypeName+"]";
856 labelStr = labelStr+ " } }" ;
860 bbWriteDotInputOutputName(ff,true,detail,level);
861 std::string tmp ( bbGetTypeName() );
865 url = this->bbGetDescriptor()->GetPackage()->GetDocRelativeURL() + "#" + tmp;
867 url = this->bbGetDescriptor()->GetPackage()->GetDocURL() + "#" + tmp;
869 fprintf( ff , " [shape=record, URL=\"%s\",label=\"%s\"]%s\n",url.c_str(),labelStr.c_str(),";" );
870 // std::cout << labelStr << std::endl;
873 if (this!=parentblackbox){
874 for ( i = mInputConnectorMap.begin(); i != mInputConnectorMap.end(); ++i )
878 Connection* con = i->second->GetConnection();
880 BlackBox *a=con->GetBlackBoxFrom();
881 BlackBox *b=con->GetBlackBoxTo();
883 a->bbWriteDotInputOutputName(ff,false,detail,level);
886 fprintf(ff,":%s",con->GetBlackBoxFromOutput().c_str());
889 b->bbWriteDotInputOutputName(ff,true,detail,level);
892 fprintf(ff,":%s",con->GetBlackBoxToInput().c_str());
894 fprintf(ff,"%s\n",";");
898 } // if parentblackbox
900 //=========================================================================
905 //=========================================================================
906 void BlackBox::bbShowRelations(BlackBox *parentblackbox,
907 int detail, int level
908 /*,Factory *factory*/ )
911 if (this->bbGetDescriptor()->GetPackage())
913 bbtkMessage("Help",1,"Black Box '"<<bbGetName()<<"' <"<<
914 this->bbGetDescriptor()->GetPackage()->GetName()
915 <<"::"<<this->bbGetDescriptor()->GetTypeName()<<">"<<std::endl);
919 bbtkMessage("Help",1,"Black Box <::"<<this->bbGetDescriptor()->GetTypeName()<<">"<<std::endl);
921 // bbtkMessage("Help",1," "<<GetDescription()<<std::endl);
922 // bbtkMessage("Help",1," By : "<<GetAuthor()<<std::endl);
924 std::vector<std::string> iname;
925 std::vector<std::string> ivalue;
926 std::vector<std::string> iconn;
928 InputConnectorMapType::iterator i;
929 unsigned int namelmax = 0;
930 unsigned int valuelmax = 0;
931 unsigned int connlmax = 0;
932 for ( i = mInputConnectorMap.begin(); i != mInputConnectorMap.end(); ++i )
934 iname.push_back(i->first);
935 if (iname.back().size()>namelmax) namelmax = iname.back().size();
936 ivalue.push_back(bbGetInputAsString(i->first));
937 if (ivalue.back().size()>valuelmax) valuelmax = ivalue.back().size();
939 Connection* con = i->second->GetConnection();
941 s = con->GetBlackBoxFrom()->bbGetName();
943 s += con->GetBlackBoxFromOutput();
947 OutputConnectorMapType::iterator o;
948 std::vector<std::string> oname;
949 std::vector<std::string> ovalue;
950 std::vector<std::vector<std::string> > oconn;
951 for ( o = mOutputConnectorMap.begin(); o != mOutputConnectorMap.end(); ++o )
953 oname.push_back(o->first);
954 if (oname.back().size()>namelmax) namelmax = oname.back().size();
955 ovalue.push_back(bbGetOutputAsString(o->first));
956 if (ovalue.back().size()>valuelmax) valuelmax = ovalue.back().size();
957 std::vector<std::string> ss;
958 const std::vector<Connection*>& con = o->second->GetConnectionVector();
959 std::vector<Connection*>::const_iterator c;
960 for (c=con.begin();c!=con.end();++c)
963 s = (*c)->GetBlackBoxTo()->bbGetName();
965 s += (*c)->GetBlackBoxToInput();
972 bbtkMessage("Help",1," * Inputs : "<<std::endl);
974 bbtkMessage("Help",1," * No inputs"<<std::endl);
976 std::vector<std::string>::iterator i1,i2,i3;
977 for (i1=iname.begin(),i2=ivalue.begin(),i3=iconn.begin();
978 i1!=iname.end(),i2!=ivalue.end(),i3!=iconn.end();
981 std::string name(*i1);
983 name.append(1+namelmax-name.size(),' ');
984 std::string value(*i2);
986 value.append(1+valuelmax-value.size(),' ');
988 bbtkMessage("Help",1," '"<<name<<" = '"<<value<<" <-- '"<<*i3<<"'"<<std::endl);
990 bbtkMessage("Help",1," '"<<name<<" = '"<<value<<std::endl);
994 bbtkMessage("Help",1," * Outputs : "<<std::endl);
996 bbtkMessage("Help",1," * No outputs"<<std::endl);
998 std::vector<std::vector<std::string> >::iterator i4;
1000 for (i1=oname.begin(),i2=ovalue.begin(),i4=oconn.begin();
1001 i1!=oname.end(),i2!=ovalue.end(),i4!=oconn.end();
1004 std::string name(*i1);
1006 name.append(1+namelmax-name.size(),' ');
1007 std::string value(*i2);
1009 value.append(1+valuelmax-value.size(),' ');
1011 bbtkMessage("Help",1," '"<<name<<" = '"<<value<<std::endl);
1014 std::string pref = " '"+name+" = '"+value;
1015 for (i3=i4->begin();i3!=i4->end();++i3)
1017 bbtkMessage("Help",1,pref<<" --> '"<<*i3<<"'"<<std::endl);
1018 pref.replace(0,pref.size(),pref.size(),' ');
1024 //=========================================================================
1027 //=========================================================================
1028 void BlackBox::bbGlobalProcessExecutionList()
1030 bbtkDebugMessageInc("Process",1,
1031 "=> BlackBox::bbGlobalProcessExecutionList()"
1034 std::set<BlackBox*>::iterator i;
1035 for (i=bbmgExecutionList.begin();
1036 i!=bbmgExecutionList.end();
1039 bbtkDebugMessage("Process",2,
1040 " -> Executing "<<(*i)->bbGetFullName()<<std::endl);
1041 (*i)->bbExecute(true);
1044 bbmgExecutionList.clear();
1045 bbtkDebugMessageDec("Process",1,
1046 "<= BlackBox::bbGlobalProcessExecutionList()"
1051 //=========================================================================
1053 bool BlackBox::bbGlobalGetSomeBoxExecuting()
1055 return bbmgSomeBoxExecuting;
1058 void BlackBox::bbGlobalSetSomeBoxExecuting(bool b)
1060 bbmgSomeBoxExecuting = b;
1063 void BlackBox::bbGlobalSetFreezeExecution(bool b)
1065 bbmgFreezeExecution = b;
1068 bool BlackBox::bbGlobalGetFreezeExecution()
1070 return bbmgFreezeExecution;
1073 void BlackBox::bbGlobalAddToExecutionList( BlackBox* b )
1075 bbmgExecutionList.insert(b);
1079 //=========================================================================
1080 // Static members initialization
1082 bool BlackBox::bbmgSomeBoxExecuting = false;
1083 bool BlackBox::bbmgFreezeExecution = false;
1084 std::set<BlackBox*> BlackBox::bbmgExecutionList;
1086 //=========================================================================
1089 } // EO namespace bbtk