1 /*=========================================================================
4 Module: $RCSfile: bbtkBlackBox.cxx,v $
6 Date: $Date: 2008/04/21 12:43:05 $
7 Version: $Revision: 1.11 $
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::Pointer> bbmgExecutionList;
44 //=========================================================================
45 BlackBox::Deleter::Deleter()
48 //=========================================================================
50 //=========================================================================
51 void BlackBox::Deleter::Delete(Object* p)
53 BlackBox* b = dynamic_cast<BlackBox*>(p);
56 bbtkInternalError("BlackBox::Deleter::Delete("<<p->GetObjectName()
58 <<"dynamic cast to BlackBox* failed !");
60 std::string name = p->GetObjectName();//b->bbGetNameWithParent();
61 bbtkDebugMessage("object",2,"##> BlackBox::Deleter(\""<<name<<"\")"<<std::endl);
64 BlackBoxDescriptor::WeakPointer desc = b->bbGetDescriptor();
65 bbtkDebugMessage("object",2,"##> BlackBox::Deleter(\""<<name<<"\") : deleting black box"<<std::endl);
69 bbtkDebugMessage("object",2,"##> BlackBox::Deleter(\""<<name<<"\") : releasing descriptor ["<<desc.lock()<<"]"<<std::endl);
73 Package::WeakPointer pack = desc.lock()->GetPackage();
76 Package::ReleaseBlackBoxDescriptor(pack,desc);
80 bbtkDebugMessage("object",2,"##> BlackBox::Deleter(\""<<name<<"\") : descriptor package expired (was not held by a package and the box was the last instance)"<<std::endl);
85 bbtkDebugMessage("object",2,"##> BlackBox::Deleter(\""<<name<<"\") : descriptor expired : nothing to do (was not held by a package or the box is a complex black box prototype)"<<std::endl);
87 bbtkDebugMessage("object",2,"<## BlackBox::Deleter(\""<<name<<"\")"<<std::endl);
89 //=========================================================================
91 //=========================================================================
92 BlackBox::BlackBox(const std::string &name)
95 bbmBoxProcessMode("Pipeline"),
99 bbtkDebugMessage("object",4,"==> BlackBox::BlackBox(\""
100 <<name<<"\")"<<std::endl);
101 bbtkDebugMessage("object",4,"<== BlackBox::BlackBox(\""
102 <<name<<"\")"<<std::endl);
104 //=========================================================================
107 //=========================================================================
108 BlackBox::BlackBox(BlackBox& from, const std::string &name)
110 bbmStatus(from.bbmStatus),
111 bbmBoxProcessMode(from.bbmBoxProcessMode),
115 bbtkDebugMessage("object",4,"==> BlackBox::BlackBox("
116 <<from.bbGetFullName()<<",\""
117 <<name<<"\")"<<std::endl);
118 bbtkDebugMessage("object",4,"<== BlackBox::BlackBox("
119 <<from.bbGetFullName()<<",\""
120 <<name<<"\")"<<std::endl);
122 //=========================================================================
125 //=========================================================================
126 BlackBox::~BlackBox()
128 bbtkDebugMessage("object",4,"==> BlackBox::~BlackBox() ["<<bbmName
130 this->bbDesallocateConnectors();
131 bbtkDebugMessage("object",4,"<== BlackBox::~BlackBox() ["<<bbmName
134 //=========================================================================
137 //=========================================================================
138 /// Main processing method of the box.
139 void BlackBox::bbExecute(bool force)
141 bbtkDebugMessageInc("Process",1,
142 "=> BlackBox::bbExecute() ["
143 <<bbGetFullName()<<"]"<<std::endl);
145 Wx::BeginBusyCursor();
147 // If execution frozen : return
148 if (bbGlobalGetFreezeExecution())
150 bbtkDebugMessage("Process",1,
151 " -> FreezeExecution global flag is 'true' : abort execution"<<std::endl);
154 // If force is true then update is triggered even if the box is UPTODATE
155 if (force) bbSetModifiedStatus();
157 // Calls the main recursive update method
158 bbBackwardUpdate(Connection::Pointer());
162 bbtkDebugMessageDec("Process",1,
163 "<= BlackBox::bbExecute() ["
164 <<bbGetFullName()<<"]"<<std::endl);
166 //=========================================================================
168 //=========================================================================
169 std::string BlackBox::bbGetFullName() const
171 return this->bbGetNameWithParent()+"<"+this->bbGetDescriptor()->GetTypeName()+">";
173 //=========================================================================
177 //=========================================================================
178 /// Returns the name with the name of the parent prepended if any
179 std::string BlackBox::bbGetNameWithParent() const
181 if (bbmParent.lock())
183 return bbmParent.lock()->bbGetNameWithParent() + ":" + bbmName;
190 //=========================================================================
192 //=========================================================================
193 /// Prints the Help on the BlackBox type
194 void BlackBox::bbGetHelp(bool full) const
196 bbGetDescriptor()->GetHelp(full);
198 //=========================================================================
201 //=========================================================================
202 /// Returns true if the UserBlackBox has an input of name name
203 bool BlackBox::bbHasInput(const std::string& name) const
205 bbtkDebugMessageInc("Kernel",8,
206 "BlackBox::bbHasInput(\""
207 <<name<<"\") ["<<bbGetFullName()<<"]"
209 bool r = ( bbGetDescriptor()->GetInputDescriptorMap().find(name)
210 != bbGetDescriptor()->GetInputDescriptorMap().end());
211 bbtkDebugDecTab("Kernel",8);
214 //=========================================================================
217 //=========================================================================
218 /// Returns true if the UserBlackBox has an output of name name
219 bool BlackBox::bbHasOutput(const std::string& name) const
221 bbtkDebugMessageInc("Kernel",8,"BlackBox::bbHasOutput(\""
222 <<name<<"\") ["<<bbGetFullName()<<"]"<<std::endl);
223 bool r = ( bbGetDescriptor()->GetOutputDescriptorMap().find(name)
224 != bbGetDescriptor()->GetOutputDescriptorMap().end());
225 bbtkDebugDecTab("Kernel",8);
228 //=========================================================================
231 //=========================================================================
232 /// Gets the output type of a given name
233 TypeInfo BlackBox::bbGetOutputType( const std::string &name ) const
235 bbtkDebugMessageInc("Kernel",8,
236 "BlackBox::bbGetOutputType(\""
237 <<name<<"\") ["<<bbGetFullName()<<"]"<<std::endl);
238 TypeInfo r = bbGetDescriptor()->GetOutputDescriptor(name)->GetTypeInfo();
239 bbtkDebugDecTab("Kernel",8);
242 //=========================================================================
244 //=========================================================================
245 /// Gets the input type of a given name
246 TypeInfo BlackBox::bbGetInputType( const std::string &name ) const
248 bbtkDebugMessageInc("Kernel",8,
249 "BlackBox::bbGetInputType(\""
250 <<name<<"\") ["<<bbGetFullName()<<"]"<<std::endl);
251 TypeInfo r = bbGetDescriptor()->GetInputDescriptor(name)->GetTypeInfo();
252 bbtkDebugDecTab("Kernel",8);
255 //=========================================================================
258 //=========================================================================
259 /// Allocates the i/o connectors of the black box
260 void BlackBox::bbAllocateConnectors()
262 bbtkDebugMessageInc("Kernel",8,
263 "BlackBox::bbAllocateConnectors() ["
264 <<bbGetFullName()<<"]"
266 const BlackBoxDescriptor::InputDescriptorMapType& imap
267 = bbGetDescriptor()->GetInputDescriptorMap();
268 BlackBoxDescriptor::InputDescriptorMapType::const_iterator i;
269 for ( i = imap.begin(); i != imap.end(); ++i )
271 bbtkDebugMessage("Kernel",8,"* Allocate \""<<i->first<<"\""<<std::endl);
272 bbGetInputConnectorMap()[i->second->GetName()]
273 = new BlackBoxInputConnector(GetThisPointer<BlackBox>());
275 const BlackBoxDescriptor::OutputDescriptorMapType& omap
276 = bbGetDescriptor()->GetOutputDescriptorMap();
277 BlackBoxDescriptor::OutputDescriptorMapType::const_iterator o;
278 for ( o = omap.begin(); o != omap.end(); ++o )
280 bbtkDebugMessage("Kernel",8,"* Allocate \""<<o->first<<"\""<<std::endl);
281 bbGetOutputConnectorMap()[o->second->GetName()]
282 = new BlackBoxOutputConnector();
284 bbtkDebugDecTab("Kernel",8);
286 //=========================================================================
289 //=========================================================================
290 /// Desallocates the i/o connectors of the black box
291 void BlackBox::bbDesallocateConnectors()
293 bbtkDebugMessageInc("Kernel",8,
294 "BlackBox::bbDesallocateConnectors()"
297 InputConnectorMapType::const_iterator i;
298 for ( i = bbGetInputConnectorMap().begin();
299 i != bbGetInputConnectorMap().end(); ++i )
301 bbtkDebugMessage("Kernel",8,"* Delete \""<<i->first<<"\""<<std::endl);
304 OutputConnectorMapType::const_iterator o;
305 for ( o = bbGetOutputConnectorMap().begin();
306 o != bbGetOutputConnectorMap().end(); ++o )
308 bbtkDebugMessage("Kernel",8,"* Delete \""<<o->first<<"\""<<std::endl);
312 bbtkDebugDecTab("Kernel",8);
315 //=========================================================================
318 //=========================================================================
319 /// Copies the input / output values from another box
320 void BlackBox::bbCopyIOValues(BlackBox& from)
322 bbtkDebugMessageInc("Kernel",9,
323 "BlackBox::bbCopyIOValues("
324 <<from.bbGetFullName()<<") ["
325 <<bbGetFullName()<<"]"<<std::endl);
326 // copies the input values
327 const BlackBoxDescriptor::InputDescriptorMapType& imap
328 = bbGetDescriptor()->GetInputDescriptorMap();
329 BlackBoxDescriptor::InputDescriptorMapType::const_iterator i;
330 for ( i = imap.begin(); i != imap.end(); ++i )
332 if (! i->second->GetCopyConstruct() ) continue;
333 std::string input = i->second->GetName();
334 this->bbSetInput(input, from.bbGetInput(input) );
336 // copies the output values
337 const BlackBoxDescriptor::OutputDescriptorMapType& omap
338 = bbGetDescriptor()->GetOutputDescriptorMap();
339 BlackBoxDescriptor::OutputDescriptorMapType::const_iterator o;
340 for ( o = omap.begin(); o != omap.end(); ++o )
342 if (! o->second->GetCopyConstruct() ) continue;
343 std::string output = o->second->GetName();
344 this->bbSetOutput(output, from.bbGetOutput(output) );
347 bbtkDebugDecTab("Kernel",9);
350 //=========================================================================
354 //=========================================================================
355 bool BlackBox::bbCanReact() const
357 return ( bbGlobalGetSomeBoxExecuting()
358 #ifdef _USE_WXWIDGETS_
359 || Wx::IsSomeWindowAlive()
363 //=========================================================================
367 //=========================================================================
368 /// User overloadable destruction method of a black box
369 void BlackBox::bbUserDelete()
371 bbtkDebugMessage("Process",5,
372 "=> BlackBox::bbUserDelete() ["
373 <<bbGetFullName()<<"]"
374 <<" : not overloaded; using standard deletion"
378 //=========================================================================
381 //=========================================================================
382 BlackBox::BoxProcessModeValue BlackBox::bbGetBoxProcessModeValue() const
384 const std::string& p = bbmBoxProcessMode;
386 (p == "P") || (p == "p") ||
387 (p == "Pipeline") || (p == "pipeline") ) return Pipeline;
389 (p == "A") || (p == "a") ||
390 (p == "Always") || (p == "always") ) return Always;
392 (p == "R") || (p == "r") ||
393 (p == "Reactive") || (p == "reactive") ) return Reactive;
394 bbtkError(bbGetFullName()<<" : BoxProcessMode value '"<<p
395 <<"' unknown. Possible values : "
396 <<"'0'/'P'/'p'/'Pipeline'/'pipeline' | "
397 <<"'1'/'A'/'a'/'Always'/'always' | "
398 <<"'2'/'R'/'r'/'Reactive'/'reactive'"<<std::endl);
400 //=========================================================================
402 //=========================================================================
403 bool BlackBox::bbBoxProcessModeIsReactive() const
405 return (bbGetBoxProcessModeValue() == Reactive);
407 //=========================================================================
409 //=========================================================================
410 bool BlackBox::bbBoxProcessModeIsAlways() const
412 return (bbGetBoxProcessModeValue() == Always);
414 //=========================================================================
416 //=========================================================================
417 /// Signals that the BlackBox has been modified
418 void BlackBox::bbSetModifiedStatus(BlackBoxInputConnector* c)
420 bbtkDebugMessageInc("Process",5,
421 "=> BlackBox::bbSetModifiedStatus("<<c<<") ["
422 <<bbGetFullName()<<"]"<<std::endl);
424 if ( (c==bbGetInputConnectorMap().find("WinHide")->second) )
425 // && (bbCanReact()))
427 bbtkDebugMessage("Process",9,
428 "-> Hide triggered by WinHide input change"
430 this->bbHideWindow();
431 this->bbSetStatus(MODIFIED);
435 if ( ( bbBoxProcessModeIsReactive() ||
436 (c==bbGetInputConnectorMap().find("BoxExecute")->second))
439 bbtkDebugMessage("Process",9,
440 "-> Execution triggered by Reactive mode or BoxExecute input change"<<std::endl);
441 this->bbSetStatus(MODIFIED);
442 bbGlobalAddToExecutionList( GetThisPointer<BlackBox>() );
444 else if ( bbGetStatus() == MODIFIED ) //! this->bbIsUptodate())
446 bbtkDebugMessage("Process",5,"-> Already modified"<<std::endl);
447 bbtkDebugDecTab("Process",5);
452 bbtkDebugMessage("Process",5,"-> Status set to modified"<<std::endl);
453 bbtkDebugDecTab("Process",5);
454 this->bbSetStatus(MODIFIED);
457 this->bbSignalOutputModification(false);
459 bbtkDebugMessageDec("Process",5,
460 "<= BlackBox::bbSetModifiedStatus("<<c<<") ["
461 <<bbGetFullName()<<"]"<<std::endl);
463 //=========================================================================
465 //=========================================================================
466 void BlackBox::bbSignalOutputModification(bool reaction)
468 bbtkDebugMessageInc("Process",5,
469 "=> BlackBox::bbSignalOutputModification() ["
470 <<bbGetFullName()<<"]"<<std::endl);
472 OutputConnectorMapType::iterator change = bbGetOutputConnectorMap().end();
473 OutputConnectorMapType::iterator i;
474 for ( i = bbGetOutputConnectorMap().begin();
475 i != bbGetOutputConnectorMap().end(); ++i) {
476 /* if ( i->first == "BoxChange" )
482 i->second->SetModifiedStatus();
484 // if (change != bbGetOutputConnectorMap().end())
485 // change->second->SetModifiedStatus();
487 if (reaction) bbGlobalProcessExecutionList();
489 bbtkDebugMessageDec("Process",5,
490 "<= BlackBox::bbSignalOutputModification() ["
491 <<bbGetFullName()<<"]"<<std::endl);
494 //=========================================================================
495 //=========================================================================
496 void BlackBox::bbSignalOutputModification(const std::string& output,
499 bbtkDebugMessageInc("Process",5,
500 "=> BlackBox::bbSignalOutputModification("
502 <<bbGetFullName()<<"]"<<std::endl);
504 OutputConnectorMapType::iterator i = bbGetOutputConnectorMap().find(output);
505 if ( i == bbGetOutputConnectorMap().end() )
507 bbtkError("BlackBox["<<bbGetFullName()<<"]::bbSignalOutputModification("<<output<<") : unknown output");
509 i->second->SetModifiedStatus();
510 // Has to notify the output "BoxChange" also
511 if (output != "BoxChange")
513 i = bbGetOutputConnectorMap().find("BoxChange");
514 if ( i != bbGetOutputConnectorMap().end() )
516 i->second->SetModifiedStatus();
519 if (reaction) bbGlobalProcessExecutionList();
521 bbtkDebugMessageDec("Process",5,
522 "<= BlackBox::bbSignalOutputModification("
524 <<bbGetFullName()<<"]"<<std::endl);
527 //=========================================================================
528 //=========================================================================
529 void BlackBox::bbSignalOutputModification(const std::vector<std::string>& output,
532 bbtkDebugMessageInc("Process",5,
533 "=> BlackBox::bbSignalOutputModification(vector of outputs) ["
534 <<bbGetFullName()<<"]"<<std::endl);
535 OutputConnectorMapType::iterator i;
536 std::vector<std::string>::const_iterator o;
537 for (o=output.begin();o!=output.end();++o)
539 // the output "BoxChange" must be signaled **AFTER** all others
540 if (*o == "BoxChange") continue;
541 // Look for the connector
542 i = bbGetOutputConnectorMap().find(*o);
543 if ( i == bbGetOutputConnectorMap().end() )
545 bbtkError("BlackBox["<<bbGetFullName()<<"]::bbSignalOutputModification("<<*o<<") : unknown output");
547 i->second->SetModifiedStatus();
549 // Has to notify the output "BoxChange" also
550 i = bbGetOutputConnectorMap().find("BoxChange");
551 if ( i != bbGetOutputConnectorMap().end() )
553 i->second->SetModifiedStatus();
555 if (reaction) bbGlobalProcessExecutionList();
557 bbtkDebugMessageDec("Process",5,
558 "<= BlackBox::bbSignalOutputModification(vector of outputs) ["
559 <<bbGetFullName()<<"]"<<std::endl);
562 //=========================================================================
564 //=========================================================================
565 /// Updates the BlackBox inputs
566 /// \returns UPTODATE if all inputs are in UPTODATE status after update
568 IOStatus BlackBox::bbUpdateInputs(bool excludeParent)
570 bbtkDebugMessageInc("Process",4,
571 "=> BlackBox::bbUpdateInputs() ["
572 <<bbGetFullName()<<"]"
575 IOStatus s = UPTODATE;
577 InputConnectorMapType::iterator i;
578 for ( i = bbGetInputConnectorMap().begin();
579 i!= bbGetInputConnectorMap().end(); ++i)
581 if (excludeParent && (i->first=="WinParent")) continue;
582 if (i->first=="WinHide") continue;
583 // If input type is Void : no recurse
584 //if ( bbGetDescriptor()->GetInputDescriptor(i->first)->GetTypeInfo()
588 IOStatus t = i->second->BackwardUpdate();
589 if (t==MODIFIED) s = MODIFIED;
592 bbtkDebugMessageDec("Process",4,
593 "<= BlackBox::bbUpdateInputs() ["
594 <<bbGetFullName()<<"]"
600 //=========================================================================
603 //=========================================================================
604 /// Connects the input <name> to the connection c
605 void BlackBox::bbConnectInput( const std::string& name, Connection::Pointer c)
607 bbtkDebugMessageInc("Kernel",7,
608 "BlackBox::bbConnectInput(\""<<name<<"\","<<c<<") ["
609 <<bbGetFullName()<<"]"
611 InputConnectorMapType::iterator i = bbGetInputConnectorMap().find(name);
612 if (i==bbGetInputConnectorMap().end())
614 bbtkError("no input called '"<<name<<"'");
616 i->second->SetConnection(c);
618 // bbSetModifiedStatus();
620 bbtkDebugDecTab("Kernel",7);
622 //=========================================================================
625 //=========================================================================
626 /// Connects the output <name> to the connection c
627 void BlackBox::bbConnectOutput( const std::string& name, Connection::Pointer c)
629 bbtkDebugMessageInc("Kernel",7,
630 "BlackBox::bbConnectOutput(\""<<name<<"\","<<c<<") ["
631 <<bbGetFullName()<<"]"<<std::endl);
633 OutputConnectorMapType::iterator i = bbGetOutputConnectorMap().find(name);
634 if (i==bbGetOutputConnectorMap().end())
636 bbtkError("no output called '"<<name<<"'");
638 i->second->SetConnection(c);
640 bbtkDebugDecTab("Kernel",7);
642 //=========================================================================
645 //=========================================================================
646 /// Disconnects the input <name> from the connection c
647 void BlackBox::bbDisconnectInput( const std::string& name, Connection::Pointer c)
650 bbtkDebugMessageInc("Kernel",7,
651 "BlackBox::bbDisconnectInput(\""<<name
653 <<bbGetFullName()<<"]"
656 InputConnectorMapType::iterator i = bbGetInputConnectorMap().find(name);
657 if (i==bbGetInputConnectorMap().end())
659 bbtkError("no input called '"<<name<<"'");
661 i->second->UnsetConnection(c);
663 bbtkDebugDecTab("Kernel",7);
665 //=========================================================================
668 //=========================================================================
669 /// Disconnects the output <name> from the connection c
670 void BlackBox::bbDisconnectOutput( const std::string& name, Connection::Pointer c)
673 bbtkDebugMessageInc("Kernel",7,
674 "BlackBox::bbDisconnectOutput(\""<<name
676 <<bbGetFullName()<<"]"
679 OutputConnectorMapType::iterator i = bbGetOutputConnectorMap().find(name);
680 if (i==bbGetOutputConnectorMap().end())
682 bbtkError("no output called '"<<name<<"'");
684 i->second->UnsetConnection(c);
686 bbtkDebugDecTab("Kernel",7);
688 //=========================================================================
691 //=========================================================================
693 void BlackBox::bbWriteDotInputOutputName(FILE *ff,bool inputoutput,int detail, int level)
695 fprintf(ff,"%s%p",bbGetTypeName().c_str(),this);
697 //=========================================================================
700 //=========================================================================
701 std::string BlackBox::bbGetOutputAsString( const std::string &output )
704 // Looks for the adaptor
705 if (bbGetOutputType(output).name() != typeid(std::string).name() )
708 Package::Pointer p = bbGetDescriptor()->GetPackage();
709 if ((p != 0) && ( ! p->GetFactorySet().empty() ) )
711 Factory::Pointer f = p->GetFactorySet().begin()->lock();
716 bbGetOutputType(output),
719 } catch (bbtk::Exception e)
724 a->bbSetInput("In",bbGetOutput(output));
726 v = a->bbGetOutput("Out").unsafe_get<std::string>() ;
728 v="? (no adaptor found)";
733 v="? (no factory found)";
739 v = bbGetOutput(output).unsafe_get<std::string>() ;
743 //=========================================================================
745 //=========================================================================
746 std::string BlackBox::bbGetInputAsString( const std::string &input )
749 // Looks for the adaptor
750 if (bbGetInputType(input) != typeid(std::string))
753 Package::Pointer p = bbGetDescriptor()->GetPackage();
754 if ((p != 0) && ( ! p->GetFactorySet().empty() ) )
756 Factory::Pointer f = p->GetFactorySet().begin()->lock();
761 bbGetInputType(input),
764 }catch (bbtk::Exception e)
770 a->bbSetInput("In",bbGetInput(input));
772 v = a->bbGetOutput("Out").unsafe_get<std::string>() ;
776 v="? (no adaptor found)";
781 v="? (no factory found)";
786 v = bbGetInput(input).unsafe_get<std::string>() ;
790 //=======================================================================
792 //=======================================================================
793 // Replaces substrings "<" by "["
794 void SubsBrackets ( std::string& s )
796 // std::cout << "BEFORE=["<<s<<"]"<<std::endl;
798 std::string::size_type pos = 0;
801 while ( pos != std::string::npos )
803 // std::cout << "*** find one "<<std::endl;
804 s.replace(pos,1,cr,1);
805 pos = s.find(ss, pos);
811 while ( pos != std::string::npos )
813 // std::cout << "*** find one "<<std::endl;
814 s.replace(pos,1,cr,1);
815 pos = s.find(ss, pos);
821 while ( pos != std::string::npos )
823 // std::cout << "*** find one "<<std::endl;
824 s.replace(pos,1,cr,1);
825 pos = s.find(ss, pos);
826 } // std::cout << "AFTER=["<<s<<"]"<<std::endl;
828 //=======================================================================
830 //=========================================================================
831 /// Write Graphviz-dot description in file
832 void BlackBox::bbWriteDotFileBlackBox(FILE *ff,
833 BlackBox::Pointer parentblackbox,
834 int detail, int level,
839 InputConnectorMapType::iterator i;
841 std::string labelStr;
842 std::string valueStr("");
845 labelStr = bbGetName() ;
847 labelStr = labelStr + "\\n[" +this->bbGetDescriptor()->GetPackage()->GetName()+"::"+ bbGetTypeName() + "]";
849 labelStr = bbGetName();
850 labelStr = labelStr + " [" +this->bbGetDescriptor()->GetPackage()->GetName()+"::"+ bbGetTypeName() + "] ";
853 SubsBrackets(labelStr);
856 labelStr = labelStr + " | {{ ";
857 std::string tempStrTypeName;
860 for ( i = mInputConnectorMap.begin(); i != mInputConnectorMap.end(); ++i )
864 labelStr=labelStr+" | ";
867 if (instanceOrtype==true)
869 valueStr = this->bbGetInputAsString(i->first) + " = ";
871 const BlackBoxInputDescriptor* id = bbGetDescriptor()->GetInputDescriptor(i->first);
872 tempStrTypeName=id->GetTypeName();
873 SubsBrackets(tempStrTypeName);
874 std::string Name(i->first);
876 labelStr=labelStr + "<"+i->first.c_str()+"> " + valueStr + Name.c_str() + " [" + tempStrTypeName.c_str() + "]";
878 labelStr=labelStr+ " } | {";
880 OutputConnectorMapType::iterator ii;
881 for ( ii = mOutputConnectorMap.begin(); ii != mOutputConnectorMap.end(); ++ii )
885 labelStr=labelStr+" | ";
888 if (instanceOrtype==true)
890 valueStr = this->bbGetOutputAsString(ii->first) + " = ";
892 const BlackBoxOutputDescriptor* id = bbGetDescriptor()->GetOutputDescriptor(ii->first);
893 tempStrTypeName=id->GetTypeName();
894 SubsBrackets(tempStrTypeName);
895 std::string Name(ii->first);
897 labelStr=labelStr+"<"+ii->first.c_str()+"> " + valueStr + Name.c_str() + " ["+tempStrTypeName+"]";
899 labelStr = labelStr+ " } }" ;
903 bbWriteDotInputOutputName(ff,true,detail,level);
904 std::string tmp ( bbGetTypeName() );
908 url = this->bbGetDescriptor()->GetPackage()->GetDocRelativeURL() + "#" + tmp;
910 url = this->bbGetDescriptor()->GetPackage()->GetDocURL() + "#" + tmp;
912 fprintf( ff , " [shape=record, URL=\"%s\",label=\"%s\"]%s\n",url.c_str(),labelStr.c_str(),";" );
913 // std::cout << labelStr << std::endl;
916 if (GetThisPointer<BlackBox>()!=parentblackbox){
917 for ( i = mInputConnectorMap.begin(); i != mInputConnectorMap.end(); ++i )
921 Connection::Pointer con = i->second->GetConnection();
923 BlackBox::Pointer a=con->GetBlackBoxFrom();
924 BlackBox::Pointer b=con->GetBlackBoxTo();
926 a->bbWriteDotInputOutputName(ff,false,detail,level);
929 fprintf(ff,":%s",con->GetBlackBoxFromOutput().c_str());
932 b->bbWriteDotInputOutputName(ff,true,detail,level);
935 fprintf(ff,":%s",con->GetBlackBoxToInput().c_str());
937 fprintf(ff,"%s\n",";");
941 } // if parentblackbox
943 //=========================================================================
948 //=========================================================================
949 void BlackBox::bbShowRelations(BlackBox::Pointer parentblackbox,
950 int detail, int level
951 /*,Factory *factory*/ )
954 if (this->bbGetDescriptor()->GetPackage())
956 bbtkMessage("Help",1,"Black Box '"<<bbGetName()<<"' <"<<
957 this->bbGetDescriptor()->GetPackage()->GetName()
958 <<"::"<<this->bbGetDescriptor()->GetTypeName()<<">"<<std::endl);
962 bbtkMessage("Help",1,"Black Box <::"<<this->bbGetDescriptor()->GetTypeName()<<">"<<std::endl);
964 // bbtkMessage("Help",1," "<<GetDescription()<<std::endl);
965 // bbtkMessage("Help",1," By : "<<GetAuthor()<<std::endl);
967 std::vector<std::string> iname;
968 std::vector<std::string> ivalue;
969 std::vector<std::string> iconn;
971 InputConnectorMapType::iterator i;
972 unsigned int namelmax = 0;
973 unsigned int valuelmax = 0;
974 unsigned int connlmax = 0;
975 for ( i = mInputConnectorMap.begin(); i != mInputConnectorMap.end(); ++i )
977 iname.push_back(i->first);
978 if (iname.back().size()>namelmax) namelmax = iname.back().size();
979 ivalue.push_back(bbGetInputAsString(i->first));
980 if (ivalue.back().size()>valuelmax) valuelmax = ivalue.back().size();
982 Connection::Pointer con = i->second->GetConnection();
984 s = con->GetBlackBoxFrom()->bbGetName();
986 s += con->GetBlackBoxFromOutput();
990 OutputConnectorMapType::iterator o;
991 std::vector<std::string> oname;
992 std::vector<std::string> ovalue;
993 std::vector<std::vector<std::string> > oconn;
994 for ( o = mOutputConnectorMap.begin(); o != mOutputConnectorMap.end(); ++o )
996 oname.push_back(o->first);
997 if (oname.back().size()>namelmax) namelmax = oname.back().size();
998 ovalue.push_back(bbGetOutputAsString(o->first));
999 if (ovalue.back().size()>valuelmax) valuelmax = ovalue.back().size();
1000 std::vector<std::string> ss;
1001 const std::vector<Connection::WeakPointer>& con
1002 = o->second->GetConnectionVector();
1003 std::vector<Connection::WeakPointer>::const_iterator c;
1004 for (c=con.begin();c!=con.end();++c)
1007 s = (*c).lock()->GetBlackBoxTo()->bbGetName();
1009 s += (*c).lock()->GetBlackBoxToInput();
1012 oconn.push_back(ss);
1016 bbtkMessage("Help",1," * Inputs : "<<std::endl);
1018 bbtkMessage("Help",1," * No inputs"<<std::endl);
1020 std::vector<std::string>::iterator i1,i2,i3;
1021 for (i1=iname.begin(),i2=ivalue.begin(),i3=iconn.begin();
1022 i1!=iname.end(),i2!=ivalue.end(),i3!=iconn.end();
1025 std::string name(*i1);
1027 name.append(1+namelmax-name.size(),' ');
1028 std::string value(*i2);
1030 value.append(1+valuelmax-value.size(),' ');
1032 bbtkMessage("Help",1," '"<<name<<" = '"<<value<<" <-- '"<<*i3<<"'"<<std::endl);
1034 bbtkMessage("Help",1," '"<<name<<" = '"<<value<<std::endl);
1038 bbtkMessage("Help",1," * Outputs : "<<std::endl);
1040 bbtkMessage("Help",1," * No outputs"<<std::endl);
1042 std::vector<std::vector<std::string> >::iterator i4;
1044 for (i1=oname.begin(),i2=ovalue.begin(),i4=oconn.begin();
1045 i1!=oname.end(),i2!=ovalue.end(),i4!=oconn.end();
1048 std::string name(*i1);
1050 name.append(1+namelmax-name.size(),' ');
1051 std::string value(*i2);
1053 value.append(1+valuelmax-value.size(),' ');
1055 bbtkMessage("Help",1," '"<<name<<" = '"<<value<<std::endl);
1058 std::string pref = " '"+name+" = '"+value;
1059 for (i3=i4->begin();i3!=i4->end();++i3)
1061 bbtkMessage("Help",1,pref<<" --> '"<<*i3<<"'"<<std::endl);
1062 pref.replace(0,pref.size(),pref.size(),' ');
1068 //=========================================================================
1071 //=========================================================================
1072 void BlackBox::bbGlobalProcessExecutionList()
1074 bbtkDebugMessageInc("Process",1,
1075 "=> BlackBox::bbGlobalProcessExecutionList()"
1078 std::set<BlackBox::Pointer>::iterator i;
1079 for (i=bbmgExecutionList.begin();
1080 i!=bbmgExecutionList.end();
1083 bbtkDebugMessage("Process",2,
1084 " -> Executing "<<(*i)->bbGetFullName()<<std::endl);
1085 (*i)->bbExecute(true);
1088 bbmgExecutionList.clear();
1089 bbtkDebugMessageDec("Process",1,
1090 "<= BlackBox::bbGlobalProcessExecutionList()"
1095 //=========================================================================
1097 bool BlackBox::bbGlobalGetSomeBoxExecuting()
1099 return bbmgSomeBoxExecuting;
1102 void BlackBox::bbGlobalSetSomeBoxExecuting(bool b)
1104 bbmgSomeBoxExecuting = b;
1107 void BlackBox::bbGlobalSetFreezeExecution(bool b)
1109 bbmgFreezeExecution = b;
1112 bool BlackBox::bbGlobalGetFreezeExecution()
1114 return bbmgFreezeExecution;
1117 void BlackBox::bbGlobalAddToExecutionList( BlackBox::Pointer b )
1119 bbmgExecutionList.insert(b);
1123 //=========================================================================
1124 // Static members initialization
1126 bool BlackBox::bbmgSomeBoxExecuting = false;
1127 bool BlackBox::bbmgFreezeExecution = false;
1128 std::set<BlackBox*> BlackBox::bbmgExecutionList;
1130 //=========================================================================
1132 //=========================================================================
1133 void BlackBox::Check(bool recursive)
1135 bbtkMessage("Debug",1,"*** Checking Black Box "<<(void*)this<<" ["<<bbGetFullName()
1136 <<"] ... OK"<<std::endl);
1138 //=========================================================================
1142 } // EO namespace bbtk