1 /*=========================================================================
4 Module: $RCSfile: bbtkBlackBox.cxx,v $
6 Date: $Date: 2008/01/22 15:02:00 $
7 Version: $Revision: 1.1 $
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"
38 //=========================================================================
39 BlackBox::BlackBox(const std::string &name)
40 : bbmName(name), bbmStatus(MODIFIED),
41 bbmBoxProcessMode("Pipeline"),bbmParent(NULL)
43 bbtkDebugMessage("Core",7,"BlackBox::BlackBox(\""
44 <<name<<"\")"<<std::endl);
46 //=========================================================================
49 //=========================================================================
50 BlackBox::BlackBox(BlackBox& from, const std::string &name)
52 bbmStatus(from.bbmStatus),
53 bbmBoxProcessMode(from.bbmBoxProcessMode),bbmParent(NULL)
55 bbtkDebugMessage("Core",7,"BlackBox::BlackBox("
56 <<from.bbGetFullName()<<",\""
57 <<name<<"\")"<<std::endl);
59 //=========================================================================
62 //=========================================================================
65 // std::cout << "EED BlackBox::~BlackBox 01 [" << bbGetName()<<"]\n";
66 bbtkDebugMessageInc("Core",7,"BlackBox::~BlackBox()"<<std::endl);
67 this->bbDesallocateConnectors();
68 //printf("EED BlackBox::~BlackBox 02 \n");
69 bbtkDebugDecTab("Core",7);
71 //=========================================================================
73 //=========================================================================
74 /// Destruction method of a black box
75 void BlackBox::bbDelete()
77 bbtkDebugMessage("Core",5,"BlackBox::bbDelete() ["
78 <<bbGetFullName()<<"]"<<std::endl);
81 //=========================================================================
84 //=========================================================================
85 /// Main processing method of the box.
86 void BlackBox::bbExecute(bool force)
88 bbtkDebugMessageInc("Process",1,
89 "=> BlackBox::bbExecute() ["
90 <<bbGetFullName()<<"]"<<std::endl);
92 wx::BeginBusyCursor();
94 // If execution frozen : return
95 if (bbGlobalGetFreezeExecution())
97 bbtkDebugMessage("Process",1,
98 " -> FreezeExecution global flag is 'true' : abort execution"<<std::endl);
101 // If force is true then update is triggered even if the box is UPTODATE
102 if (force) bbSetModifiedStatus();
104 // Calls the main recursive update method
109 bbtkDebugMessageDec("Process",1,
110 "<= BlackBox::bbExecute() ["
111 <<bbGetFullName()<<"]"<<std::endl);
113 //=========================================================================
115 //=========================================================================
116 std::string BlackBox::bbGetFullName() const
118 return bbGetNameWithParent()+"<"+this->bbGetDescriptor()->GetTypeName()+">";
120 //=========================================================================
124 //=========================================================================
125 /// Returns the name with the name of the parent prepended if any
126 std::string BlackBox::bbGetNameWithParent() const
130 return bbmParent->bbGetNameWithParent() + ":" + bbmName;
137 //=========================================================================
139 //=========================================================================
140 /// Prints the Help on the BlackBox type
141 void BlackBox::bbGetHelp(bool full) const
143 bbGetDescriptor()->GetHelp(full);
145 //=========================================================================
148 //=========================================================================
149 /// Returns true if the UserBlackBox has an input of name name
150 bool BlackBox::bbHasInput(const std::string& name) const
152 bbtkDebugMessageInc("Core",8,
153 "BlackBox::bbHasInput(\""
154 <<name<<"\") ["<<bbGetFullName()<<"]"
156 bool r = ( bbGetDescriptor()->GetInputDescriptorMap().find(name)
157 != bbGetDescriptor()->GetInputDescriptorMap().end());
158 bbtkDebugDecTab("Core",8);
161 //=========================================================================
164 //=========================================================================
165 /// Returns true if the UserBlackBox has an output of name name
166 bool BlackBox::bbHasOutput(const std::string& name) const
168 bbtkDebugMessageInc("Core",8,"BlackBox::bbHasOutput(\""
169 <<name<<"\") ["<<bbGetFullName()<<"]"<<std::endl);
170 bool r = ( bbGetDescriptor()->GetOutputDescriptorMap().find(name)
171 != bbGetDescriptor()->GetOutputDescriptorMap().end());
172 bbtkDebugDecTab("Core",8);
175 //=========================================================================
178 //=========================================================================
179 /// Gets the output type of a given name
180 TypeInfo BlackBox::bbGetOutputType( const std::string &name ) const
182 bbtkDebugMessageInc("Core",8,
183 "BlackBox::bbGetOutputType(\""
184 <<name<<"\") ["<<bbGetFullName()<<"]"<<std::endl);
185 TypeInfo r = bbGetDescriptor()->GetOutputDescriptor(name)->GetTypeInfo();
186 bbtkDebugDecTab("Core",8);
189 //=========================================================================
191 //=========================================================================
192 /// Gets the input type of a given name
193 TypeInfo BlackBox::bbGetInputType( const std::string &name ) const
195 bbtkDebugMessageInc("Core",8,
196 "BlackBox::bbGetInputType(\""
197 <<name<<"\") ["<<bbGetFullName()<<"]"<<std::endl);
198 TypeInfo r = bbGetDescriptor()->GetInputDescriptor(name)->GetTypeInfo();
199 bbtkDebugDecTab("Core",8);
202 //=========================================================================
205 //=========================================================================
206 /// Allocates the i/o connectors of the black box
207 void BlackBox::bbAllocateConnectors()
209 bbtkDebugMessageInc("Core",8,
210 "BlackBox::bbAllocateConnectors() ["
211 <<bbGetFullName()<<"]"
213 const BlackBoxDescriptor::InputDescriptorMapType& imap
214 = bbGetDescriptor()->GetInputDescriptorMap();
215 BlackBoxDescriptor::InputDescriptorMapType::const_iterator i;
216 for ( i = imap.begin(); i != imap.end(); ++i )
218 bbtkDebugMessage("Core",8,"* Allocate \""<<i->first<<"\""<<std::endl);
219 bbGetInputConnectorMap()[i->second->GetName()]
220 = new BlackBoxInputConnector(this);
222 const BlackBoxDescriptor::OutputDescriptorMapType& omap
223 = bbGetDescriptor()->GetOutputDescriptorMap();
224 BlackBoxDescriptor::OutputDescriptorMapType::const_iterator o;
225 for ( o = omap.begin(); o != omap.end(); ++o )
227 bbtkDebugMessage("Core",8,"* Allocate \""<<o->first<<"\""<<std::endl);
228 bbGetOutputConnectorMap()[o->second->GetName()]
229 = new BlackBoxOutputConnector();
231 bbtkDebugDecTab("Core",8);
233 //=========================================================================
236 //=========================================================================
237 /// Desallocates the i/o connectors of the black box
238 void BlackBox::bbDesallocateConnectors()
240 bbtkDebugMessageInc("Core",8,
241 "BlackBox::bbDesallocateConnectors()"
244 InputConnectorMapType::const_iterator i;
245 for ( i = bbGetInputConnectorMap().begin();
246 i != bbGetInputConnectorMap().end(); ++i )
248 bbtkDebugMessage("Core",8,"* Delete \""<<i->first<<"\""<<std::endl);
251 OutputConnectorMapType::const_iterator o;
252 for ( o = bbGetOutputConnectorMap().begin();
253 o != bbGetOutputConnectorMap().end(); ++o )
255 bbtkDebugMessage("Core",8,"* Delete \""<<o->first<<"\""<<std::endl);
259 bbtkDebugDecTab("Core",8);
262 //=========================================================================
265 //=========================================================================
266 /// Copies the input / output values from another box
267 void BlackBox::bbCopyIOValues(BlackBox& from)
269 bbtkDebugMessageInc("Core",9,
270 "BlackBox::bbCopyIOValues("
271 <<from.bbGetFullName()<<") ["
272 <<bbGetFullName()<<"]"<<std::endl);
273 // copies the input values
274 const BlackBoxDescriptor::InputDescriptorMapType& imap
275 = bbGetDescriptor()->GetInputDescriptorMap();
276 BlackBoxDescriptor::InputDescriptorMapType::const_iterator i;
277 for ( i = imap.begin(); i != imap.end(); ++i )
279 if (! i->second->GetCopyConstruct() ) continue;
280 std::string input = i->second->GetName();
281 this->bbSetInput(input, from.bbGetInput(input) );
283 // copies the output values
284 const BlackBoxDescriptor::OutputDescriptorMapType& omap
285 = bbGetDescriptor()->GetOutputDescriptorMap();
286 BlackBoxDescriptor::OutputDescriptorMapType::const_iterator o;
287 for ( o = omap.begin(); o != omap.end(); ++o )
289 if (! o->second->GetCopyConstruct() ) continue;
290 std::string output = o->second->GetName();
291 this->bbSetOutput(output, from.bbGetOutput(output) );
294 bbtkDebugDecTab("Core",9);
297 //=========================================================================
301 //=========================================================================
302 bool BlackBox::bbCanReact() const
304 return ( bbGlobalGetSomeBoxExecuting()
305 #ifdef _USE_WXWIDGETS_
306 || WxBlackBox::bbGlobalIsSomeWindowAlive()
310 //=========================================================================
314 //=========================================================================
315 /// User overloadable destruction method of a black box
316 void BlackBox::bbUserDelete()
318 bbtkDebugMessage("Process",5,
319 "=> BlackBox::bbUserDelete() ["
320 <<bbGetFullName()<<"]"
321 <<" : not overloaded; using standard deletion"
325 //=========================================================================
328 //=========================================================================
329 BlackBox::BoxProcessModeValue BlackBox::bbGetBoxProcessModeValue() const
331 const std::string& p = bbmBoxProcessMode;
333 (p == "P") || (p == "p") ||
334 (p == "Pipeline") || (p == "pipeline") ) return Pipeline;
336 (p == "A") || (p == "a") ||
337 (p == "Always") || (p == "always") ) return Always;
339 (p == "R") || (p == "r") ||
340 (p == "Reactive") || (p == "reactive") ) return Reactive;
341 bbtkError(bbGetFullName()<<" : BoxProcessMode value '"<<p
342 <<"' unknown. Possible values : "
343 <<"'0'/'P'/'p'/'Pipeline'/'pipeline' | "
344 <<"'1'/'A'/'a'/'Always'/'always' | "
345 <<"'2'/'R'/'r'/'Reactive'/'reactive'"<<std::endl);
347 //=========================================================================
349 //=========================================================================
350 bool BlackBox::bbBoxProcessModeIsReactive() const
352 return (bbGetBoxProcessModeValue() == Reactive);
354 //=========================================================================
356 //=========================================================================
357 bool BlackBox::bbBoxProcessModeIsAlways() const
359 return (bbGetBoxProcessModeValue() == Always);
361 //=========================================================================
363 //=========================================================================
364 /// Signals that the BlackBox has been modified
365 void BlackBox::bbSetModifiedStatus(BlackBoxInputConnector* c)
367 bbtkDebugMessageInc("Process",5,
368 "=> BlackBox::bbSetModifiedStatus("<<c<<") ["
369 <<bbGetFullName()<<"]"<<std::endl);
371 if ( (c==bbGetInputConnectorMap().find("WinHide")->second) )
372 // && (bbCanReact()))
374 bbtkDebugMessage("Process",9,
375 "-> Hide triggered by WinHide input change"
377 this->bbHideWindow();
378 this->bbSetStatus(MODIFIED);
382 if ( ( bbBoxProcessModeIsReactive() ||
383 (c==bbGetInputConnectorMap().find("BoxExecute")->second))
386 bbtkDebugMessage("Process",9,
387 "-> Execution triggered by Reactive mode or BoxExecute input change"<<std::endl);
388 this->bbSetStatus(MODIFIED);
389 bbGlobalAddToExecutionList( this );
391 else if ( bbGetStatus() == MODIFIED ) //! this->bbIsUptodate())
393 bbtkDebugMessage("Process",5,"-> Already modified"<<std::endl);
394 bbtkDebugDecTab("Process",5);
399 bbtkDebugMessage("Process",5,"-> Status set to modified"<<std::endl);
400 bbtkDebugDecTab("Process",5);
401 this->bbSetStatus(MODIFIED);
404 this->bbSignalOutputModification(false);
406 bbtkDebugMessageDec("Process",5,
407 "<= BlackBox::bbSetModifiedStatus("<<c<<") ["
408 <<bbGetFullName()<<"]"<<std::endl);
410 //=========================================================================
412 //=========================================================================
413 void BlackBox::bbSignalOutputModification(bool reaction)
415 bbtkDebugMessageInc("Process",5,
416 "=> BlackBox::bbSignalOutputModification() ["
417 <<bbGetFullName()<<"]"<<std::endl);
419 OutputConnectorMapType::iterator change = bbGetOutputConnectorMap().end();
420 OutputConnectorMapType::iterator i;
421 for ( i = bbGetOutputConnectorMap().begin();
422 i != bbGetOutputConnectorMap().end(); ++i) {
423 /* if ( i->first == "BoxChange" )
429 i->second->SetModifiedStatus();
431 // if (change != bbGetOutputConnectorMap().end())
432 // change->second->SetModifiedStatus();
434 if (reaction) bbGlobalProcessExecutionList();
436 bbtkDebugMessageDec("Process",5,
437 "<= BlackBox::bbSignalOutputModification() ["
438 <<bbGetFullName()<<"]"<<std::endl);
441 //=========================================================================
442 //=========================================================================
443 void BlackBox::bbSignalOutputModification(const std::string& output,
446 bbtkDebugMessageInc("Process",5,
447 "=> BlackBox::bbSignalOutputModification("
449 <<bbGetFullName()<<"]"<<std::endl);
451 OutputConnectorMapType::iterator i = bbGetOutputConnectorMap().find(output);
452 if ( i == bbGetOutputConnectorMap().end() )
454 bbtkError("BlackBox["<<bbGetFullName()<<"]::bbSignalOutputModification("<<output<<") : unknown output");
456 i->second->SetModifiedStatus();
457 // Has to notify the output "BoxChange" also
458 if (output != "BoxChange")
460 i = bbGetOutputConnectorMap().find("BoxChange");
461 if ( i != bbGetOutputConnectorMap().end() )
463 i->second->SetModifiedStatus();
466 if (reaction) bbGlobalProcessExecutionList();
468 bbtkDebugMessageDec("Process",5,
469 "<= BlackBox::bbSignalOutputModification("
471 <<bbGetFullName()<<"]"<<std::endl);
474 //=========================================================================
475 //=========================================================================
476 void BlackBox::bbSignalOutputModification(const std::vector<std::string>& output,
479 bbtkDebugMessageInc("Process",5,
480 "=> BlackBox::bbSignalOutputModification(vector of outputs) ["
481 <<bbGetFullName()<<"]"<<std::endl);
482 OutputConnectorMapType::iterator i;
483 std::vector<std::string>::const_iterator o;
484 for (o=output.begin();o!=output.end();++o)
486 // the output "BoxChange" must be signaled **AFTER** all others
487 if (*o == "BoxChange") continue;
488 // Look for the connector
489 i = bbGetOutputConnectorMap().find(*o);
490 if ( i == bbGetOutputConnectorMap().end() )
492 bbtkError("BlackBox["<<bbGetFullName()<<"]::bbSignalOutputModification("<<*o<<") : unknown output");
494 i->second->SetModifiedStatus();
496 // Has to notify the output "BoxChange" also
497 i = bbGetOutputConnectorMap().find("BoxChange");
498 if ( i != bbGetOutputConnectorMap().end() )
500 i->second->SetModifiedStatus();
502 if (reaction) bbGlobalProcessExecutionList();
504 bbtkDebugMessageDec("Process",5,
505 "<= BlackBox::bbSignalOutputModification(vector of outputs) ["
506 <<bbGetFullName()<<"]"<<std::endl);
509 //=========================================================================
511 //=========================================================================
512 /// Updates the BlackBox inputs
513 /// \returns UPTODATE if all inputs are in UPTODATE status after update
515 IOStatus BlackBox::bbUpdateInputs(bool excludeParent)
517 bbtkDebugMessageInc("Process",4,
518 "=> BlackBox::bbUpdateInputs() ["
519 <<bbGetFullName()<<"]"
522 IOStatus s = UPTODATE;
524 InputConnectorMapType::iterator i;
525 for ( i = bbGetInputConnectorMap().begin();
526 i!= bbGetInputConnectorMap().end(); ++i)
528 if (excludeParent && (i->first=="WinParent")) continue;
529 if (i->first=="WinHide") continue;
530 // If input type is Void : no recurse
531 //if ( bbGetDescriptor()->GetInputDescriptor(i->first)->GetTypeInfo()
535 IOStatus t = i->second->BackwardUpdate();
536 if (t==MODIFIED) s = MODIFIED;
539 bbtkDebugMessageDec("Process",4,
540 "<= BlackBox::bbUpdateInputs() ["
541 <<bbGetFullName()<<"]"
547 //=========================================================================
550 //=========================================================================
551 /// Connects the input <name> to the connection c
552 void BlackBox::bbConnectInput( const std::string& name, Connection* c)
554 bbtkDebugMessageInc("Core",7,
555 "BlackBox::bbConnectInput(\""<<name<<"\","<<c<<") ["
556 <<bbGetFullName()<<"]"
558 InputConnectorMapType::iterator i = bbGetInputConnectorMap().find(name);
559 if (i==bbGetInputConnectorMap().end())
561 bbtkError("no input called '"<<name<<"'");
563 i->second->SetConnection(c);
565 // bbSetModifiedStatus();
567 bbtkDebugDecTab("Core",7);
569 //=========================================================================
572 //=========================================================================
573 /// Connects the output <name> to the connection c
574 void BlackBox::bbConnectOutput( const std::string& name, Connection* c)
576 bbtkDebugMessageInc("Core",7,
577 "BlackBox::bbConnectOutput(\""<<name<<"\","<<c<<") ["
578 <<bbGetFullName()<<"]"<<std::endl);
580 OutputConnectorMapType::iterator i = bbGetOutputConnectorMap().find(name);
581 if (i==bbGetOutputConnectorMap().end())
583 bbtkError("no output called '"<<name<<"'");
585 i->second->SetConnection(c);
587 bbtkDebugDecTab("Core",7);
589 //=========================================================================
592 //=========================================================================
593 /// Disconnects the input <name> from the connection c
594 void BlackBox::bbDisconnectInput( const std::string& name, Connection* c)
596 bbtkDebugMessageInc("Core",7,
597 "BlackBox::bbDisconnectInput(\""<<name
599 <<bbGetFullName()<<"]"
602 InputConnectorMapType::iterator i = bbGetInputConnectorMap().find(name);
603 if (i==bbGetInputConnectorMap().end())
605 bbtkError("no input called '"<<name<<"'");
607 i->second->UnsetConnection(c);
609 bbtkDebugDecTab("Core",7);
611 //=========================================================================
614 //=========================================================================
615 /// Disconnects the output <name> from the connection c
616 void BlackBox::bbDisconnectOutput( const std::string& name, Connection* c)
618 bbtkDebugMessageInc("Core",7,
619 "BlackBox::bbDisconnectOutput(\""<<name
621 <<bbGetFullName()<<"]"
624 OutputConnectorMapType::iterator i = bbGetOutputConnectorMap().find(name);
625 if (i==bbGetOutputConnectorMap().end())
627 bbtkError("no output called '"<<name<<"'");
629 i->second->UnsetConnection(c);
631 bbtkDebugDecTab("Core",7);
633 //=========================================================================
636 //=========================================================================
638 void BlackBox::bbWriteDotInputOutputName(FILE *ff,bool inputoutput,int detail, int level)
640 fprintf(ff,"%s%p",bbGetTypeName().c_str(),this);
642 //=========================================================================
645 //=========================================================================
646 std::string BlackBox::bbGetOutputAsString( const std::string &output )
649 // Looks for the adaptor
650 if (bbGetOutputType(output).name() != typeid(std::string).name() )
656 bbGetOutputType(output),
659 } catch (bbtk::Exception e)
664 a->bbSetInput("In",bbGetOutput(output));
666 v = a->bbGetOutput("Out").unsafe_get<std::string>() ;
668 v="? (no adaptor found)";
672 v = bbGetOutput(output).unsafe_get<std::string>() ;
676 //=========================================================================
678 //=========================================================================
679 std::string BlackBox::bbGetInputAsString( const std::string &input )
682 // Looks for the adaptor
683 if (bbGetInputType(input) != typeid(std::string))
689 bbGetInputType(input),
692 }catch (bbtk::Exception e)
698 a->bbSetInput("In",bbGetInput(input));
700 v = a->bbGetOutput("Out").unsafe_get<std::string>() ;
704 v="? (no adaptor found)";
709 v = bbGetInput(input).unsafe_get<std::string>() ;
713 //=======================================================================
715 //=======================================================================
716 // Replaces substrings "<" by "["
717 void SubsBrackets ( std::string& s )
719 // std::cout << "BEFORE=["<<s<<"]"<<std::endl;
721 std::string::size_type pos = 0;
724 while ( pos != std::string::npos )
726 // std::cout << "*** find one "<<std::endl;
727 s.replace(pos,1,cr,1);
728 pos = s.find(ss, pos);
734 while ( pos != std::string::npos )
736 // std::cout << "*** find one "<<std::endl;
737 s.replace(pos,1,cr,1);
738 pos = s.find(ss, pos);
744 while ( pos != std::string::npos )
746 // std::cout << "*** find one "<<std::endl;
747 s.replace(pos,1,cr,1);
748 pos = s.find(ss, pos);
749 } // std::cout << "AFTER=["<<s<<"]"<<std::endl;
751 //=======================================================================
753 //=========================================================================
754 /// Write Graphviz-dot description in file
755 void BlackBox::bbWriteDotFileBlackBox(FILE *ff,
756 BlackBox *parentblackbox,
757 int detail, int level,
762 InputConnectorMapType::iterator i;
764 std::string labelStr;
765 std::string valueStr("");
768 labelStr = bbGetName() ;
770 labelStr = bbGetName();
771 labelStr = labelStr + " [" +this->bbGetDescriptor()->GetPackage()->GetName()+"::"+ bbGetTypeName() + "] ";
774 SubsBrackets(labelStr);
777 labelStr = labelStr + " | {{ ";
778 std::string tempStrTypeName;
781 for ( i = mInputConnectorMap.begin(); i != mInputConnectorMap.end(); ++i )
785 labelStr=labelStr+" | ";
788 if (instanceOrtype==true)
790 valueStr = this->bbGetInputAsString(i->first) + " = ";
792 const BlackBoxInputDescriptor* id = bbGetDescriptor()->GetInputDescriptor(i->first);
793 tempStrTypeName=id->GetTypeName();
794 SubsBrackets(tempStrTypeName);
795 std::string Name(i->first);
797 labelStr=labelStr + "<"+i->first.c_str()+"> " + valueStr + Name.c_str() + " [" + tempStrTypeName.c_str() + "]";
799 labelStr=labelStr+ " } | {";
801 OutputConnectorMapType::iterator ii;
802 for ( ii = mOutputConnectorMap.begin(); ii != mOutputConnectorMap.end(); ++ii )
806 labelStr=labelStr+" | ";
809 if (instanceOrtype==true)
811 valueStr = this->bbGetOutputAsString(ii->first) + " = ";
813 const BlackBoxOutputDescriptor* id = bbGetDescriptor()->GetOutputDescriptor(ii->first);
814 tempStrTypeName=id->GetTypeName();
815 SubsBrackets(tempStrTypeName);
816 std::string Name(ii->first);
818 labelStr=labelStr+"<"+ii->first.c_str()+"> " + valueStr + Name.c_str() + " ["+tempStrTypeName+"]";
820 labelStr = labelStr+ " } }" ;
824 bbWriteDotInputOutputName(ff,true,detail,level);
825 std::string tmp ( bbGetTypeName() );
829 url = this->bbGetDescriptor()->GetPackage()->GetDocRelativeURL() + "#" + tmp;
831 url = this->bbGetDescriptor()->GetPackage()->GetDocURL() + "#" + tmp;
833 fprintf( ff , " [shape=record, URL=\"%s\",label=\"%s\"]%s\n",url.c_str(),labelStr.c_str(),";" );
834 // std::cout << labelStr << std::endl;
837 if (this!=parentblackbox){
838 for ( i = mInputConnectorMap.begin(); i != mInputConnectorMap.end(); ++i )
842 Connection* con = i->second->GetConnection();
844 BlackBox *a=con->GetBlackBoxFrom();
845 BlackBox *b=con->GetBlackBoxTo();
847 a->bbWriteDotInputOutputName(ff,false,detail,level);
850 fprintf(ff,":%s",con->GetBlackBoxFromOutput().c_str());
853 b->bbWriteDotInputOutputName(ff,true,detail,level);
856 fprintf(ff,":%s",con->GetBlackBoxToInput().c_str());
858 fprintf(ff,"%s\n",";");
862 } // if parentblackbox
864 //=========================================================================
869 //=========================================================================
870 void BlackBox::bbShowRelations(BlackBox *parentblackbox,
871 int detail, int level
872 /*,Factory *factory*/ )
875 if (this->bbGetDescriptor()->GetPackage())
877 bbtkMessage("Help",1,"Black Box '"<<bbGetName()<<"' <"<<
878 this->bbGetDescriptor()->GetPackage()->GetName()
879 <<"::"<<this->bbGetDescriptor()->GetTypeName()<<">"<<std::endl);
883 bbtkMessage("Help",1,"Black Box <::"<<this->bbGetDescriptor()->GetTypeName()<<">"<<std::endl);
885 // bbtkMessage("Help",1," "<<GetDescription()<<std::endl);
886 // bbtkMessage("Help",1," By : "<<GetAuthor()<<std::endl);
888 std::vector<std::string> iname;
889 std::vector<std::string> ivalue;
890 std::vector<std::string> iconn;
892 InputConnectorMapType::iterator i;
893 unsigned int namelmax = 0;
894 unsigned int valuelmax = 0;
895 unsigned int connlmax = 0;
896 for ( i = mInputConnectorMap.begin(); i != mInputConnectorMap.end(); ++i )
898 iname.push_back(i->first);
899 if (iname.back().size()>namelmax) namelmax = iname.back().size();
900 ivalue.push_back(bbGetInputAsString(i->first));
901 if (ivalue.back().size()>valuelmax) valuelmax = ivalue.back().size();
903 Connection* con = i->second->GetConnection();
905 s = con->GetBlackBoxFrom()->bbGetName();
907 s += con->GetBlackBoxFromOutput();
911 OutputConnectorMapType::iterator o;
912 std::vector<std::string> oname;
913 std::vector<std::string> ovalue;
914 std::vector<std::vector<std::string> > oconn;
915 for ( o = mOutputConnectorMap.begin(); o != mOutputConnectorMap.end(); ++o )
917 oname.push_back(o->first);
918 if (oname.back().size()>namelmax) namelmax = oname.back().size();
919 ovalue.push_back(bbGetOutputAsString(o->first));
920 if (ovalue.back().size()>valuelmax) valuelmax = ovalue.back().size();
921 std::vector<std::string> ss;
922 const std::vector<Connection*>& con = o->second->GetConnectionVector();
923 std::vector<Connection*>::const_iterator c;
924 for (c=con.begin();c!=con.end();++c)
927 s = (*c)->GetBlackBoxTo()->bbGetName();
929 s += (*c)->GetBlackBoxToInput();
936 bbtkMessage("Help",1," * Inputs : "<<std::endl);
938 bbtkMessage("Help",1," * No inputs"<<std::endl);
940 std::vector<std::string>::iterator i1,i2,i3;
941 for (i1=iname.begin(),i2=ivalue.begin(),i3=iconn.begin();
942 i1!=iname.end(),i2!=ivalue.end(),i3!=iconn.end();
945 std::string name(*i1);
947 name.append(1+namelmax-name.size(),' ');
948 std::string value(*i2);
950 value.append(1+valuelmax-value.size(),' ');
952 bbtkMessage("Help",1," '"<<name<<" = '"<<value<<" <-- '"<<*i3<<"'"<<std::endl);
954 bbtkMessage("Help",1," '"<<name<<" = '"<<value<<std::endl);
958 bbtkMessage("Help",1," * Outputs : "<<std::endl);
960 bbtkMessage("Help",1," * No outputs"<<std::endl);
962 std::vector<std::vector<std::string> >::iterator i4;
964 for (i1=oname.begin(),i2=ovalue.begin(),i4=oconn.begin();
965 i1!=oname.end(),i2!=ovalue.end(),i4!=oconn.end();
968 std::string name(*i1);
970 name.append(1+namelmax-name.size(),' ');
971 std::string value(*i2);
973 value.append(1+valuelmax-value.size(),' ');
975 bbtkMessage("Help",1," '"<<name<<" = '"<<value<<std::endl);
978 std::string pref = " '"+name+" = '"+value;
979 for (i3=i4->begin();i3!=i4->end();++i3)
981 bbtkMessage("Help",1,pref<<" --> '"<<*i3<<"'"<<std::endl);
982 pref.replace(0,pref.size(),pref.size(),' ');
988 //=========================================================================
991 //=========================================================================
992 void BlackBox::bbGlobalProcessExecutionList()
994 bbtkDebugMessageInc("Process",1,
995 "=> BlackBox::bbGlobalProcessExecutionList()"
998 std::set<BlackBox*>::iterator i;
999 for (i=bbmgExecutionList.begin();
1000 i!=bbmgExecutionList.end();
1003 bbtkDebugMessage("Process",2,
1004 " -> Executing "<<(*i)->bbGetFullName()<<std::endl);
1005 (*i)->bbExecute(true);
1008 bbmgExecutionList.clear();
1009 bbtkDebugMessageDec("Process",1,
1010 "<= BlackBox::bbGlobalProcessExecutionList()"
1015 //=========================================================================
1017 //=========================================================================
1018 // Static members initialization
1019 bool BlackBox::bbmgSomeBoxExecuting = false;
1020 bool BlackBox::bbmgFreezeExecution = false;
1021 std::set<BlackBox*> BlackBox::bbmgExecutionList;
1022 //=========================================================================
1025 } // EO namespace bbtk