1 /*=========================================================================
4 Module: $RCSfile: bbtkBlackBox.cxx,v $
6 Date: $Date: 2008/04/09 11:16:57 $
7 Version: $Revision: 1.9 $
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",1,"BlackBox::bbDelete() ["
90 <<bbGetFullName()<<"]"<<std::endl);
91 bbGetDescriptor()->UnReference();
94 //=========================================================================
97 //=========================================================================
98 /// Main processing method of the box.
99 void BlackBox::bbExecute(bool force)
101 bbtkDebugMessageInc("Process",1,
102 "=> BlackBox::bbExecute() ["
103 <<bbGetFullName()<<"]"<<std::endl);
105 Wx::BeginBusyCursor();
107 // If execution frozen : return
108 if (bbGlobalGetFreezeExecution())
110 bbtkDebugMessage("Process",1,
111 " -> FreezeExecution global flag is 'true' : abort execution"<<std::endl);
114 // If force is true then update is triggered even if the box is UPTODATE
115 if (force) bbSetModifiedStatus();
117 // Calls the main recursive update method
122 bbtkDebugMessageDec("Process",1,
123 "<= BlackBox::bbExecute() ["
124 <<bbGetFullName()<<"]"<<std::endl);
126 //=========================================================================
128 //=========================================================================
129 std::string BlackBox::bbGetFullName() const
131 return bbGetNameWithParent()+"<"+this->bbGetDescriptor()->GetTypeName()+">";
133 //=========================================================================
137 //=========================================================================
138 /// Returns the name with the name of the parent prepended if any
139 std::string BlackBox::bbGetNameWithParent() const
143 return bbmParent->bbGetNameWithParent() + ":" + bbmName;
150 //=========================================================================
152 //=========================================================================
153 /// Prints the Help on the BlackBox type
154 void BlackBox::bbGetHelp(bool full) const
156 bbGetDescriptor()->GetHelp(full);
158 //=========================================================================
161 //=========================================================================
162 /// Returns true if the UserBlackBox has an input of name name
163 bool BlackBox::bbHasInput(const std::string& name) const
165 bbtkDebugMessageInc("Kernel",8,
166 "BlackBox::bbHasInput(\""
167 <<name<<"\") ["<<bbGetFullName()<<"]"
169 bool r = ( bbGetDescriptor()->GetInputDescriptorMap().find(name)
170 != bbGetDescriptor()->GetInputDescriptorMap().end());
171 bbtkDebugDecTab("Kernel",8);
174 //=========================================================================
177 //=========================================================================
178 /// Returns true if the UserBlackBox has an output of name name
179 bool BlackBox::bbHasOutput(const std::string& name) const
181 bbtkDebugMessageInc("Kernel",8,"BlackBox::bbHasOutput(\""
182 <<name<<"\") ["<<bbGetFullName()<<"]"<<std::endl);
183 bool r = ( bbGetDescriptor()->GetOutputDescriptorMap().find(name)
184 != bbGetDescriptor()->GetOutputDescriptorMap().end());
185 bbtkDebugDecTab("Kernel",8);
188 //=========================================================================
191 //=========================================================================
192 /// Gets the output type of a given name
193 TypeInfo BlackBox::bbGetOutputType( const std::string &name ) const
195 bbtkDebugMessageInc("Kernel",8,
196 "BlackBox::bbGetOutputType(\""
197 <<name<<"\") ["<<bbGetFullName()<<"]"<<std::endl);
198 TypeInfo r = bbGetDescriptor()->GetOutputDescriptor(name)->GetTypeInfo();
199 bbtkDebugDecTab("Kernel",8);
202 //=========================================================================
204 //=========================================================================
205 /// Gets the input type of a given name
206 TypeInfo BlackBox::bbGetInputType( const std::string &name ) const
208 bbtkDebugMessageInc("Kernel",8,
209 "BlackBox::bbGetInputType(\""
210 <<name<<"\") ["<<bbGetFullName()<<"]"<<std::endl);
211 TypeInfo r = bbGetDescriptor()->GetInputDescriptor(name)->GetTypeInfo();
212 bbtkDebugDecTab("Kernel",8);
215 //=========================================================================
218 //=========================================================================
219 /// Allocates the i/o connectors of the black box
220 void BlackBox::bbAllocateConnectors()
222 bbtkDebugMessageInc("Kernel",8,
223 "BlackBox::bbAllocateConnectors() ["
224 <<bbGetFullName()<<"]"
226 const BlackBoxDescriptor::InputDescriptorMapType& imap
227 = bbGetDescriptor()->GetInputDescriptorMap();
228 BlackBoxDescriptor::InputDescriptorMapType::const_iterator i;
229 for ( i = imap.begin(); i != imap.end(); ++i )
231 bbtkDebugMessage("Kernel",8,"* Allocate \""<<i->first<<"\""<<std::endl);
232 bbGetInputConnectorMap()[i->second->GetName()]
233 = new BlackBoxInputConnector(this);
235 const BlackBoxDescriptor::OutputDescriptorMapType& omap
236 = bbGetDescriptor()->GetOutputDescriptorMap();
237 BlackBoxDescriptor::OutputDescriptorMapType::const_iterator o;
238 for ( o = omap.begin(); o != omap.end(); ++o )
240 bbtkDebugMessage("Kernel",8,"* Allocate \""<<o->first<<"\""<<std::endl);
241 bbGetOutputConnectorMap()[o->second->GetName()]
242 = new BlackBoxOutputConnector();
244 bbtkDebugDecTab("Kernel",8);
246 //=========================================================================
249 //=========================================================================
250 /// Desallocates the i/o connectors of the black box
251 void BlackBox::bbDesallocateConnectors()
253 bbtkDebugMessageInc("Kernel",8,
254 "BlackBox::bbDesallocateConnectors()"
257 InputConnectorMapType::const_iterator i;
258 for ( i = bbGetInputConnectorMap().begin();
259 i != bbGetInputConnectorMap().end(); ++i )
261 bbtkDebugMessage("Kernel",8,"* Delete \""<<i->first<<"\""<<std::endl);
264 OutputConnectorMapType::const_iterator o;
265 for ( o = bbGetOutputConnectorMap().begin();
266 o != bbGetOutputConnectorMap().end(); ++o )
268 bbtkDebugMessage("Kernel",8,"* Delete \""<<o->first<<"\""<<std::endl);
272 bbtkDebugDecTab("Kernel",8);
275 //=========================================================================
278 //=========================================================================
279 /// Copies the input / output values from another box
280 void BlackBox::bbCopyIOValues(BlackBox& from)
282 bbtkDebugMessageInc("Kernel",9,
283 "BlackBox::bbCopyIOValues("
284 <<from.bbGetFullName()<<") ["
285 <<bbGetFullName()<<"]"<<std::endl);
286 // copies the input values
287 const BlackBoxDescriptor::InputDescriptorMapType& imap
288 = bbGetDescriptor()->GetInputDescriptorMap();
289 BlackBoxDescriptor::InputDescriptorMapType::const_iterator i;
290 for ( i = imap.begin(); i != imap.end(); ++i )
292 if (! i->second->GetCopyConstruct() ) continue;
293 std::string input = i->second->GetName();
294 this->bbSetInput(input, from.bbGetInput(input) );
296 // copies the output values
297 const BlackBoxDescriptor::OutputDescriptorMapType& omap
298 = bbGetDescriptor()->GetOutputDescriptorMap();
299 BlackBoxDescriptor::OutputDescriptorMapType::const_iterator o;
300 for ( o = omap.begin(); o != omap.end(); ++o )
302 if (! o->second->GetCopyConstruct() ) continue;
303 std::string output = o->second->GetName();
304 this->bbSetOutput(output, from.bbGetOutput(output) );
307 bbtkDebugDecTab("Kernel",9);
310 //=========================================================================
314 //=========================================================================
315 bool BlackBox::bbCanReact() const
317 return ( bbGlobalGetSomeBoxExecuting()
318 #ifdef _USE_WXWIDGETS_
319 || Wx::IsSomeWindowAlive()
323 //=========================================================================
327 //=========================================================================
328 /// User overloadable destruction method of a black box
329 void BlackBox::bbUserDelete()
331 bbtkDebugMessage("Process",5,
332 "=> BlackBox::bbUserDelete() ["
333 <<bbGetFullName()<<"]"
334 <<" : not overloaded; using standard deletion"
338 //=========================================================================
341 //=========================================================================
342 BlackBox::BoxProcessModeValue BlackBox::bbGetBoxProcessModeValue() const
344 const std::string& p = bbmBoxProcessMode;
346 (p == "P") || (p == "p") ||
347 (p == "Pipeline") || (p == "pipeline") ) return Pipeline;
349 (p == "A") || (p == "a") ||
350 (p == "Always") || (p == "always") ) return Always;
352 (p == "R") || (p == "r") ||
353 (p == "Reactive") || (p == "reactive") ) return Reactive;
354 bbtkError(bbGetFullName()<<" : BoxProcessMode value '"<<p
355 <<"' unknown. Possible values : "
356 <<"'0'/'P'/'p'/'Pipeline'/'pipeline' | "
357 <<"'1'/'A'/'a'/'Always'/'always' | "
358 <<"'2'/'R'/'r'/'Reactive'/'reactive'"<<std::endl);
360 //=========================================================================
362 //=========================================================================
363 bool BlackBox::bbBoxProcessModeIsReactive() const
365 return (bbGetBoxProcessModeValue() == Reactive);
367 //=========================================================================
369 //=========================================================================
370 bool BlackBox::bbBoxProcessModeIsAlways() const
372 return (bbGetBoxProcessModeValue() == Always);
374 //=========================================================================
376 //=========================================================================
377 /// Signals that the BlackBox has been modified
378 void BlackBox::bbSetModifiedStatus(BlackBoxInputConnector* c)
380 bbtkDebugMessageInc("Process",5,
381 "=> BlackBox::bbSetModifiedStatus("<<c<<") ["
382 <<bbGetFullName()<<"]"<<std::endl);
384 if ( (c==bbGetInputConnectorMap().find("WinHide")->second) )
385 // && (bbCanReact()))
387 bbtkDebugMessage("Process",9,
388 "-> Hide triggered by WinHide input change"
390 this->bbHideWindow();
391 this->bbSetStatus(MODIFIED);
395 if ( ( bbBoxProcessModeIsReactive() ||
396 (c==bbGetInputConnectorMap().find("BoxExecute")->second))
399 bbtkDebugMessage("Process",9,
400 "-> Execution triggered by Reactive mode or BoxExecute input change"<<std::endl);
401 this->bbSetStatus(MODIFIED);
402 bbGlobalAddToExecutionList( this );
404 else if ( bbGetStatus() == MODIFIED ) //! this->bbIsUptodate())
406 bbtkDebugMessage("Process",5,"-> Already modified"<<std::endl);
407 bbtkDebugDecTab("Process",5);
412 bbtkDebugMessage("Process",5,"-> Status set to modified"<<std::endl);
413 bbtkDebugDecTab("Process",5);
414 this->bbSetStatus(MODIFIED);
417 this->bbSignalOutputModification(false);
419 bbtkDebugMessageDec("Process",5,
420 "<= BlackBox::bbSetModifiedStatus("<<c<<") ["
421 <<bbGetFullName()<<"]"<<std::endl);
423 //=========================================================================
425 //=========================================================================
426 void BlackBox::bbSignalOutputModification(bool reaction)
428 bbtkDebugMessageInc("Process",5,
429 "=> BlackBox::bbSignalOutputModification() ["
430 <<bbGetFullName()<<"]"<<std::endl);
432 OutputConnectorMapType::iterator change = bbGetOutputConnectorMap().end();
433 OutputConnectorMapType::iterator i;
434 for ( i = bbGetOutputConnectorMap().begin();
435 i != bbGetOutputConnectorMap().end(); ++i) {
436 /* if ( i->first == "BoxChange" )
442 i->second->SetModifiedStatus();
444 // if (change != bbGetOutputConnectorMap().end())
445 // change->second->SetModifiedStatus();
447 if (reaction) bbGlobalProcessExecutionList();
449 bbtkDebugMessageDec("Process",5,
450 "<= BlackBox::bbSignalOutputModification() ["
451 <<bbGetFullName()<<"]"<<std::endl);
454 //=========================================================================
455 //=========================================================================
456 void BlackBox::bbSignalOutputModification(const std::string& output,
459 bbtkDebugMessageInc("Process",5,
460 "=> BlackBox::bbSignalOutputModification("
462 <<bbGetFullName()<<"]"<<std::endl);
464 OutputConnectorMapType::iterator i = bbGetOutputConnectorMap().find(output);
465 if ( i == bbGetOutputConnectorMap().end() )
467 bbtkError("BlackBox["<<bbGetFullName()<<"]::bbSignalOutputModification("<<output<<") : unknown output");
469 i->second->SetModifiedStatus();
470 // Has to notify the output "BoxChange" also
471 if (output != "BoxChange")
473 i = bbGetOutputConnectorMap().find("BoxChange");
474 if ( i != bbGetOutputConnectorMap().end() )
476 i->second->SetModifiedStatus();
479 if (reaction) bbGlobalProcessExecutionList();
481 bbtkDebugMessageDec("Process",5,
482 "<= BlackBox::bbSignalOutputModification("
484 <<bbGetFullName()<<"]"<<std::endl);
487 //=========================================================================
488 //=========================================================================
489 void BlackBox::bbSignalOutputModification(const std::vector<std::string>& output,
492 bbtkDebugMessageInc("Process",5,
493 "=> BlackBox::bbSignalOutputModification(vector of outputs) ["
494 <<bbGetFullName()<<"]"<<std::endl);
495 OutputConnectorMapType::iterator i;
496 std::vector<std::string>::const_iterator o;
497 for (o=output.begin();o!=output.end();++o)
499 // the output "BoxChange" must be signaled **AFTER** all others
500 if (*o == "BoxChange") continue;
501 // Look for the connector
502 i = bbGetOutputConnectorMap().find(*o);
503 if ( i == bbGetOutputConnectorMap().end() )
505 bbtkError("BlackBox["<<bbGetFullName()<<"]::bbSignalOutputModification("<<*o<<") : unknown output");
507 i->second->SetModifiedStatus();
509 // Has to notify the output "BoxChange" also
510 i = bbGetOutputConnectorMap().find("BoxChange");
511 if ( i != bbGetOutputConnectorMap().end() )
513 i->second->SetModifiedStatus();
515 if (reaction) bbGlobalProcessExecutionList();
517 bbtkDebugMessageDec("Process",5,
518 "<= BlackBox::bbSignalOutputModification(vector of outputs) ["
519 <<bbGetFullName()<<"]"<<std::endl);
522 //=========================================================================
524 //=========================================================================
525 /// Updates the BlackBox inputs
526 /// \returns UPTODATE if all inputs are in UPTODATE status after update
528 IOStatus BlackBox::bbUpdateInputs(bool excludeParent)
530 bbtkDebugMessageInc("Process",4,
531 "=> BlackBox::bbUpdateInputs() ["
532 <<bbGetFullName()<<"]"
535 IOStatus s = UPTODATE;
537 InputConnectorMapType::iterator i;
538 for ( i = bbGetInputConnectorMap().begin();
539 i!= bbGetInputConnectorMap().end(); ++i)
541 if (excludeParent && (i->first=="WinParent")) continue;
542 if (i->first=="WinHide") continue;
543 // If input type is Void : no recurse
544 //if ( bbGetDescriptor()->GetInputDescriptor(i->first)->GetTypeInfo()
548 IOStatus t = i->second->BackwardUpdate();
549 if (t==MODIFIED) s = MODIFIED;
552 bbtkDebugMessageDec("Process",4,
553 "<= BlackBox::bbUpdateInputs() ["
554 <<bbGetFullName()<<"]"
560 //=========================================================================
563 //=========================================================================
564 /// Connects the input <name> to the connection c
565 void BlackBox::bbConnectInput( const std::string& name, Connection* c)
567 bbtkDebugMessageInc("Kernel",7,
568 "BlackBox::bbConnectInput(\""<<name<<"\","<<c<<") ["
569 <<bbGetFullName()<<"]"
571 InputConnectorMapType::iterator i = bbGetInputConnectorMap().find(name);
572 if (i==bbGetInputConnectorMap().end())
574 bbtkError("no input called '"<<name<<"'");
576 i->second->SetConnection(c);
578 // bbSetModifiedStatus();
580 bbtkDebugDecTab("Kernel",7);
582 //=========================================================================
585 //=========================================================================
586 /// Connects the output <name> to the connection c
587 void BlackBox::bbConnectOutput( const std::string& name, Connection* c)
589 bbtkDebugMessageInc("Kernel",7,
590 "BlackBox::bbConnectOutput(\""<<name<<"\","<<c<<") ["
591 <<bbGetFullName()<<"]"<<std::endl);
593 OutputConnectorMapType::iterator i = bbGetOutputConnectorMap().find(name);
594 if (i==bbGetOutputConnectorMap().end())
596 bbtkError("no output called '"<<name<<"'");
598 i->second->SetConnection(c);
600 bbtkDebugDecTab("Kernel",7);
602 //=========================================================================
605 //=========================================================================
606 /// Disconnects the input <name> from the connection c
607 void BlackBox::bbDisconnectInput( const std::string& name, Connection* c)
609 bbtkDebugMessageInc("Kernel",7,
610 "BlackBox::bbDisconnectInput(\""<<name
612 <<bbGetFullName()<<"]"
615 InputConnectorMapType::iterator i = bbGetInputConnectorMap().find(name);
616 if (i==bbGetInputConnectorMap().end())
618 bbtkError("no input called '"<<name<<"'");
620 i->second->UnsetConnection(c);
622 bbtkDebugDecTab("Kernel",7);
624 //=========================================================================
627 //=========================================================================
628 /// Disconnects the output <name> from the connection c
629 void BlackBox::bbDisconnectOutput( const std::string& name, Connection* c)
631 bbtkDebugMessageInc("Kernel",7,
632 "BlackBox::bbDisconnectOutput(\""<<name
634 <<bbGetFullName()<<"]"
637 OutputConnectorMapType::iterator i = bbGetOutputConnectorMap().find(name);
638 if (i==bbGetOutputConnectorMap().end())
640 bbtkError("no output called '"<<name<<"'");
642 i->second->UnsetConnection(c);
644 bbtkDebugDecTab("Kernel",7);
646 //=========================================================================
649 //=========================================================================
651 void BlackBox::bbWriteDotInputOutputName(FILE *ff,bool inputoutput,int detail, int level)
653 fprintf(ff,"%s%p",bbGetTypeName().c_str(),this);
655 //=========================================================================
658 //=========================================================================
659 std::string BlackBox::bbGetOutputAsString( const std::string &output )
662 // Looks for the adaptor
663 if (bbGetOutputType(output).name() != typeid(std::string).name() )
666 Package* p = bbGetDescriptor()->GetPackage();
667 if ((p != 0) && ( ! p->GetFactorySet().empty() ) )
669 Factory* f = *p->GetFactorySet().begin();
674 bbGetOutputType(output),
677 } catch (bbtk::Exception e)
682 a->bbSetInput("In",bbGetOutput(output));
684 v = a->bbGetOutput("Out").unsafe_get<std::string>() ;
686 v="? (no adaptor found)";
691 v="? (no factory found)";
697 v = bbGetOutput(output).unsafe_get<std::string>() ;
701 //=========================================================================
703 //=========================================================================
704 std::string BlackBox::bbGetInputAsString( const std::string &input )
707 // Looks for the adaptor
708 if (bbGetInputType(input) != typeid(std::string))
711 Package* p = bbGetDescriptor()->GetPackage();
712 if ((p != 0) && ( ! p->GetFactorySet().empty() ) )
714 Factory* f = *p->GetFactorySet().begin();
719 bbGetInputType(input),
722 }catch (bbtk::Exception e)
728 a->bbSetInput("In",bbGetInput(input));
730 v = a->bbGetOutput("Out").unsafe_get<std::string>() ;
734 v="? (no adaptor found)";
739 v="? (no factory found)";
744 v = bbGetInput(input).unsafe_get<std::string>() ;
748 //=======================================================================
750 //=======================================================================
751 // Replaces substrings "<" by "["
752 void SubsBrackets ( std::string& s )
754 // std::cout << "BEFORE=["<<s<<"]"<<std::endl;
756 std::string::size_type pos = 0;
759 while ( pos != std::string::npos )
761 // std::cout << "*** find one "<<std::endl;
762 s.replace(pos,1,cr,1);
763 pos = s.find(ss, pos);
769 while ( pos != std::string::npos )
771 // std::cout << "*** find one "<<std::endl;
772 s.replace(pos,1,cr,1);
773 pos = s.find(ss, pos);
779 while ( pos != std::string::npos )
781 // std::cout << "*** find one "<<std::endl;
782 s.replace(pos,1,cr,1);
783 pos = s.find(ss, pos);
784 } // std::cout << "AFTER=["<<s<<"]"<<std::endl;
786 //=======================================================================
788 //=========================================================================
789 /// Write Graphviz-dot description in file
790 void BlackBox::bbWriteDotFileBlackBox(FILE *ff,
791 BlackBox *parentblackbox,
792 int detail, int level,
797 InputConnectorMapType::iterator i;
799 std::string labelStr;
800 std::string valueStr("");
803 labelStr = bbGetName() ;
805 labelStr = labelStr + "\\n[" +this->bbGetDescriptor()->GetPackage()->GetName()+"::"+ bbGetTypeName() + "]";
807 labelStr = bbGetName();
808 labelStr = labelStr + " [" +this->bbGetDescriptor()->GetPackage()->GetName()+"::"+ bbGetTypeName() + "] ";
811 SubsBrackets(labelStr);
814 labelStr = labelStr + " | {{ ";
815 std::string tempStrTypeName;
818 for ( i = mInputConnectorMap.begin(); i != mInputConnectorMap.end(); ++i )
822 labelStr=labelStr+" | ";
825 if (instanceOrtype==true)
827 valueStr = this->bbGetInputAsString(i->first) + " = ";
829 const BlackBoxInputDescriptor* id = bbGetDescriptor()->GetInputDescriptor(i->first);
830 tempStrTypeName=id->GetTypeName();
831 SubsBrackets(tempStrTypeName);
832 std::string Name(i->first);
834 labelStr=labelStr + "<"+i->first.c_str()+"> " + valueStr + Name.c_str() + " [" + tempStrTypeName.c_str() + "]";
836 labelStr=labelStr+ " } | {";
838 OutputConnectorMapType::iterator ii;
839 for ( ii = mOutputConnectorMap.begin(); ii != mOutputConnectorMap.end(); ++ii )
843 labelStr=labelStr+" | ";
846 if (instanceOrtype==true)
848 valueStr = this->bbGetOutputAsString(ii->first) + " = ";
850 const BlackBoxOutputDescriptor* id = bbGetDescriptor()->GetOutputDescriptor(ii->first);
851 tempStrTypeName=id->GetTypeName();
852 SubsBrackets(tempStrTypeName);
853 std::string Name(ii->first);
855 labelStr=labelStr+"<"+ii->first.c_str()+"> " + valueStr + Name.c_str() + " ["+tempStrTypeName+"]";
857 labelStr = labelStr+ " } }" ;
861 bbWriteDotInputOutputName(ff,true,detail,level);
862 std::string tmp ( bbGetTypeName() );
866 url = this->bbGetDescriptor()->GetPackage()->GetDocRelativeURL() + "#" + tmp;
868 url = this->bbGetDescriptor()->GetPackage()->GetDocURL() + "#" + tmp;
870 fprintf( ff , " [shape=record, URL=\"%s\",label=\"%s\"]%s\n",url.c_str(),labelStr.c_str(),";" );
871 // std::cout << labelStr << std::endl;
874 if (this!=parentblackbox){
875 for ( i = mInputConnectorMap.begin(); i != mInputConnectorMap.end(); ++i )
879 Connection* con = i->second->GetConnection();
881 BlackBox *a=con->GetBlackBoxFrom();
882 BlackBox *b=con->GetBlackBoxTo();
884 a->bbWriteDotInputOutputName(ff,false,detail,level);
887 fprintf(ff,":%s",con->GetBlackBoxFromOutput().c_str());
890 b->bbWriteDotInputOutputName(ff,true,detail,level);
893 fprintf(ff,":%s",con->GetBlackBoxToInput().c_str());
895 fprintf(ff,"%s\n",";");
899 } // if parentblackbox
901 //=========================================================================
906 //=========================================================================
907 void BlackBox::bbShowRelations(BlackBox *parentblackbox,
908 int detail, int level
909 /*,Factory *factory*/ )
912 if (this->bbGetDescriptor()->GetPackage())
914 bbtkMessage("Help",1,"Black Box '"<<bbGetName()<<"' <"<<
915 this->bbGetDescriptor()->GetPackage()->GetName()
916 <<"::"<<this->bbGetDescriptor()->GetTypeName()<<">"<<std::endl);
920 bbtkMessage("Help",1,"Black Box <::"<<this->bbGetDescriptor()->GetTypeName()<<">"<<std::endl);
922 // bbtkMessage("Help",1," "<<GetDescription()<<std::endl);
923 // bbtkMessage("Help",1," By : "<<GetAuthor()<<std::endl);
925 std::vector<std::string> iname;
926 std::vector<std::string> ivalue;
927 std::vector<std::string> iconn;
929 InputConnectorMapType::iterator i;
930 unsigned int namelmax = 0;
931 unsigned int valuelmax = 0;
932 unsigned int connlmax = 0;
933 for ( i = mInputConnectorMap.begin(); i != mInputConnectorMap.end(); ++i )
935 iname.push_back(i->first);
936 if (iname.back().size()>namelmax) namelmax = iname.back().size();
937 ivalue.push_back(bbGetInputAsString(i->first));
938 if (ivalue.back().size()>valuelmax) valuelmax = ivalue.back().size();
940 Connection* con = i->second->GetConnection();
942 s = con->GetBlackBoxFrom()->bbGetName();
944 s += con->GetBlackBoxFromOutput();
948 OutputConnectorMapType::iterator o;
949 std::vector<std::string> oname;
950 std::vector<std::string> ovalue;
951 std::vector<std::vector<std::string> > oconn;
952 for ( o = mOutputConnectorMap.begin(); o != mOutputConnectorMap.end(); ++o )
954 oname.push_back(o->first);
955 if (oname.back().size()>namelmax) namelmax = oname.back().size();
956 ovalue.push_back(bbGetOutputAsString(o->first));
957 if (ovalue.back().size()>valuelmax) valuelmax = ovalue.back().size();
958 std::vector<std::string> ss;
959 const std::vector<Connection*>& con = o->second->GetConnectionVector();
960 std::vector<Connection*>::const_iterator c;
961 for (c=con.begin();c!=con.end();++c)
964 s = (*c)->GetBlackBoxTo()->bbGetName();
966 s += (*c)->GetBlackBoxToInput();
973 bbtkMessage("Help",1," * Inputs : "<<std::endl);
975 bbtkMessage("Help",1," * No inputs"<<std::endl);
977 std::vector<std::string>::iterator i1,i2,i3;
978 for (i1=iname.begin(),i2=ivalue.begin(),i3=iconn.begin();
979 i1!=iname.end(),i2!=ivalue.end(),i3!=iconn.end();
982 std::string name(*i1);
984 name.append(1+namelmax-name.size(),' ');
985 std::string value(*i2);
987 value.append(1+valuelmax-value.size(),' ');
989 bbtkMessage("Help",1," '"<<name<<" = '"<<value<<" <-- '"<<*i3<<"'"<<std::endl);
991 bbtkMessage("Help",1," '"<<name<<" = '"<<value<<std::endl);
995 bbtkMessage("Help",1," * Outputs : "<<std::endl);
997 bbtkMessage("Help",1," * No outputs"<<std::endl);
999 std::vector<std::vector<std::string> >::iterator i4;
1001 for (i1=oname.begin(),i2=ovalue.begin(),i4=oconn.begin();
1002 i1!=oname.end(),i2!=ovalue.end(),i4!=oconn.end();
1005 std::string name(*i1);
1007 name.append(1+namelmax-name.size(),' ');
1008 std::string value(*i2);
1010 value.append(1+valuelmax-value.size(),' ');
1012 bbtkMessage("Help",1," '"<<name<<" = '"<<value<<std::endl);
1015 std::string pref = " '"+name+" = '"+value;
1016 for (i3=i4->begin();i3!=i4->end();++i3)
1018 bbtkMessage("Help",1,pref<<" --> '"<<*i3<<"'"<<std::endl);
1019 pref.replace(0,pref.size(),pref.size(),' ');
1025 //=========================================================================
1028 //=========================================================================
1029 void BlackBox::bbGlobalProcessExecutionList()
1031 bbtkDebugMessageInc("Process",1,
1032 "=> BlackBox::bbGlobalProcessExecutionList()"
1035 std::set<BlackBox*>::iterator i;
1036 for (i=bbmgExecutionList.begin();
1037 i!=bbmgExecutionList.end();
1040 bbtkDebugMessage("Process",2,
1041 " -> Executing "<<(*i)->bbGetFullName()<<std::endl);
1042 (*i)->bbExecute(true);
1045 bbmgExecutionList.clear();
1046 bbtkDebugMessageDec("Process",1,
1047 "<= BlackBox::bbGlobalProcessExecutionList()"
1052 //=========================================================================
1054 bool BlackBox::bbGlobalGetSomeBoxExecuting()
1056 return bbmgSomeBoxExecuting;
1059 void BlackBox::bbGlobalSetSomeBoxExecuting(bool b)
1061 bbmgSomeBoxExecuting = b;
1064 void BlackBox::bbGlobalSetFreezeExecution(bool b)
1066 bbmgFreezeExecution = b;
1069 bool BlackBox::bbGlobalGetFreezeExecution()
1071 return bbmgFreezeExecution;
1074 void BlackBox::bbGlobalAddToExecutionList( BlackBox* b )
1076 bbmgExecutionList.insert(b);
1080 //=========================================================================
1081 // Static members initialization
1083 bool BlackBox::bbmgSomeBoxExecuting = false;
1084 bool BlackBox::bbmgFreezeExecution = false;
1085 std::set<BlackBox*> BlackBox::bbmgExecutionList;
1087 //=========================================================================
1089 //=========================================================================
1090 void BlackBox::Check(bool recursive)
1092 bbtkMessage("Debug",1,"*** Checking Black Box "<<(void*)this<<" ["<<bbGetFullName()
1093 <<"] ... OK"<<std::endl);
1095 //=========================================================================
1097 } // EO namespace bbtk