1 /*=========================================================================
4 Module: $RCSfile: bbtkBlackBox.cxx,v $
6 Date: $Date: 2008/10/15 15:09:45 $
7 Version: $Revision: 1.24 $
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)
96 bbmBoxProcessMode("Pipeline"),
100 bbtkDebugMessage("object",4,"==> BlackBox::BlackBox(\""
101 <<name<<"\")"<<std::endl);
102 bbtkDebugMessage("object",4,"<== BlackBox::BlackBox(\""
103 <<name<<"\")"<<std::endl);
105 //=========================================================================
107 //=========================================================================
108 BlackBox::BlackBox(const BlackBox&)
111 //=========================================================================
112 BlackBox::BlackBox(BlackBox& from, const std::string &name)
114 bbmStatus(from.bbmStatus),
116 bbmBoxProcessMode(from.bbmBoxProcessMode),
120 bbtkDebugMessage("object",4,"==> BlackBox::BlackBox("
121 <<from.bbGetFullName()<<",\""
122 <<name<<"\")"<<std::endl);
123 bbtkDebugMessage("object",4,"<== BlackBox::BlackBox("
124 <<from.bbGetFullName()<<",\""
125 <<name<<"\")"<<std::endl);
127 //=========================================================================
130 //=========================================================================
131 BlackBox::~BlackBox()
133 bbtkDebugMessage("object",4,"==> BlackBox::~BlackBox() ["<<bbmName
135 this->bbDesallocateConnectors();
136 bbtkDebugMessage("object",4,"<== BlackBox::~BlackBox() ["<<bbmName
139 //=========================================================================
142 //=========================================================================
143 /// Main processing method of the box.
144 void BlackBox::bbExecute(bool force)
146 bbtkDebugMessageInc("process",2,
147 "=> BlackBox::bbExecute() ["
148 <<bbGetFullName()<<"]"<<std::endl);
150 // Wx::BusyCursor wait;
153 // If execution frozen : return
154 if (bbGlobalGetFreezeExecution())
156 bbtkDebugMessage("process",2,
157 " -> FreezeExecution global flag is 'true' : abort execution"<<std::endl);
160 // If force is true then update is triggered even if the box is UPTODATE
161 if (force) bbSetModifiedStatus();
163 // Calls the main recursive update method
164 bbBackwardUpdate(Connection::Pointer());
166 bbtkDebugMessageDec("process",2,
167 "<= BlackBox::bbExecute() ["
168 <<bbGetFullName()<<"]"<<std::endl);
170 //=========================================================================
172 //=========================================================================
173 std::string BlackBox::bbGetFullName() const
175 return this->bbGetNameWithParent()+"<"+this->bbGetDescriptor()->GetTypeName()+">";
177 //=========================================================================
181 //=========================================================================
182 /// Returns the name with the name of the parent prepended if any
183 std::string BlackBox::bbGetNameWithParent() const
185 if (bbmParent.lock())
187 return bbmParent.lock()->bbGetNameWithParent() + ":" + bbmName;
194 //=========================================================================
196 //=========================================================================
197 /// Prints the Help on the BlackBox type
198 void BlackBox::bbGetHelp(bool full) const
200 bbGetDescriptor()->GetHelp(full);
202 //=========================================================================
205 //=========================================================================
206 /// Returns true if the UserBlackBox has an input of name name
207 bool BlackBox::bbHasInput(const std::string& name) const
209 bbtkDebugMessageInc("Kernel",8,
210 "BlackBox::bbHasInput(\""
211 <<name<<"\") ["<<bbGetFullName()<<"]"
213 bool r = ( bbGetDescriptor()->GetInputDescriptorMap().find(name)
214 != bbGetDescriptor()->GetInputDescriptorMap().end());
215 bbtkDebugDecTab("Kernel",8);
218 //=========================================================================
221 //=========================================================================
222 /// Returns true if the UserBlackBox has an output of name name
223 bool BlackBox::bbHasOutput(const std::string& name) const
225 bbtkDebugMessageInc("Kernel",8,"BlackBox::bbHasOutput(\""
226 <<name<<"\") ["<<bbGetFullName()<<"]"<<std::endl);
227 bool r = ( bbGetDescriptor()->GetOutputDescriptorMap().find(name)
228 != bbGetDescriptor()->GetOutputDescriptorMap().end());
229 bbtkDebugDecTab("Kernel",8);
232 //=========================================================================
235 //=========================================================================
236 /// Gets the output type of a given name
237 TypeInfo BlackBox::bbGetOutputType( const std::string &name ) const
239 bbtkDebugMessageInc("Kernel",8,
240 "BlackBox::bbGetOutputType(\""
241 <<name<<"\") ["<<bbGetFullName()<<"]"<<std::endl);
242 TypeInfo r = bbGetDescriptor()->GetOutputDescriptor(name)->GetTypeInfo();
243 bbtkDebugDecTab("Kernel",8);
246 //=========================================================================
248 //=========================================================================
249 /// Gets the input type of a given name
250 TypeInfo BlackBox::bbGetInputType( const std::string &name ) const
252 bbtkDebugMessageInc("Kernel",8,
253 "BlackBox::bbGetInputType(\""
254 <<name<<"\") ["<<bbGetFullName()<<"]"<<std::endl);
255 TypeInfo r = bbGetDescriptor()->GetInputDescriptor(name)->GetTypeInfo();
256 bbtkDebugDecTab("Kernel",8);
259 //=========================================================================
262 //=========================================================================
263 /// Allocates the i/o connectors of the black box
264 void BlackBox::bbAllocateConnectors()
266 bbtkDebugMessageInc("Kernel",8,
267 "BlackBox::bbAllocateConnectors() ["
268 <<bbGetFullName()<<"]"
270 const BlackBoxDescriptor::InputDescriptorMapType& imap
271 = bbGetDescriptor()->GetInputDescriptorMap();
272 BlackBoxDescriptor::InputDescriptorMapType::const_iterator i;
273 for ( i = imap.begin(); i != imap.end(); ++i )
275 bbtkDebugMessage("Kernel",8,"* Allocate \""<<i->first<<"\""<<std::endl);
276 bbGetInputConnectorMap()[i->second->GetName()]
277 = new BlackBoxInputConnector(GetThisPointer<BlackBox>());
279 const BlackBoxDescriptor::OutputDescriptorMapType& omap
280 = bbGetDescriptor()->GetOutputDescriptorMap();
281 BlackBoxDescriptor::OutputDescriptorMapType::const_iterator o;
282 for ( o = omap.begin(); o != omap.end(); ++o )
284 bbtkDebugMessage("Kernel",8,"* Allocate \""<<o->first<<"\""<<std::endl);
285 bbGetOutputConnectorMap()[o->second->GetName()]
286 = new BlackBoxOutputConnector();
288 bbtkDebugDecTab("Kernel",8);
290 //=========================================================================
293 //=========================================================================
294 /// Desallocates the i/o connectors of the black box
295 void BlackBox::bbDesallocateConnectors()
297 bbtkDebugMessageInc("Kernel",8,
298 "BlackBox::bbDesallocateConnectors()"
301 InputConnectorMapType::const_iterator i;
302 for ( i = bbGetInputConnectorMap().begin();
303 i != bbGetInputConnectorMap().end(); ++i )
305 bbtkDebugMessage("Kernel",8,"* Delete \""<<i->first<<"\""<<std::endl);
308 OutputConnectorMapType::const_iterator o;
309 for ( o = bbGetOutputConnectorMap().begin();
310 o != bbGetOutputConnectorMap().end(); ++o )
312 bbtkDebugMessage("Kernel",8,"* Delete \""<<o->first<<"\""<<std::endl);
316 bbtkDebugDecTab("Kernel",8);
319 //=========================================================================
322 //=========================================================================
323 /// Copies the input / output values from another box
324 void BlackBox::bbCopyIOValues(BlackBox& from)
326 bbtkDebugMessageInc("Kernel",9,
327 "BlackBox::bbCopyIOValues("
328 <<from.bbGetFullName()<<") ["
329 <<bbGetFullName()<<"]"<<std::endl);
330 // copies the input values
331 const BlackBoxDescriptor::InputDescriptorMapType& imap
332 = bbGetDescriptor()->GetInputDescriptorMap();
333 BlackBoxDescriptor::InputDescriptorMapType::const_iterator i;
334 for ( i = imap.begin(); i != imap.end(); ++i )
336 if (! i->second->GetCopyConstruct() ) continue;
337 std::string input = i->second->GetName();
338 this->bbSetInput(input, from.bbGetInput(input) );
340 // copies the output values
341 const BlackBoxDescriptor::OutputDescriptorMapType& omap
342 = bbGetDescriptor()->GetOutputDescriptorMap();
343 BlackBoxDescriptor::OutputDescriptorMapType::const_iterator o;
344 for ( o = omap.begin(); o != omap.end(); ++o )
346 if (! o->second->GetCopyConstruct() ) continue;
347 std::string output = o->second->GetName();
348 this->bbSetOutput(output, from.bbGetOutput(output) );
351 bbtkDebugDecTab("Kernel",9);
354 //=========================================================================
358 //=========================================================================
359 bool BlackBox::bbCanReact() const
361 return ( bbGlobalGetSomeBoxExecuting()
362 #ifdef _USE_WXWIDGETS_
363 || Wx::IsSomeWindowAlive()
367 //=========================================================================
371 //=========================================================================
372 /// User overloadable destruction method of a black box
373 void BlackBox::bbUserDelete()
375 bbtkDebugMessage("process",5,
376 "=> BlackBox::bbUserDelete() ["
377 <<bbGetFullName()<<"]"
378 <<" : not overloaded; using standard deletion"
382 //=========================================================================
385 //=========================================================================
386 BlackBox::BoxProcessModeValue BlackBox::bbGetBoxProcessModeValue() const
388 const std::string& p = bbmBoxProcessMode;
390 (p == "P") || (p == "p") ||
391 (p == "Pipeline") || (p == "pipeline") ) return Pipeline;
393 (p == "A") || (p == "a") ||
394 (p == "Always") || (p == "always") ) return Always;
396 (p == "R") || (p == "r") ||
397 (p == "Reactive") || (p == "reactive") ) return Reactive;
398 bbtkError(bbGetFullName()<<" : BoxProcessMode value '"<<p
399 <<"' unknown. Possible values : "
400 <<"'0'/'P'/'p'/'Pipeline'/'pipeline' | "
401 <<"'1'/'A'/'a'/'Always'/'always' | "
402 <<"'2'/'R'/'r'/'Reactive'/'reactive'"<<std::endl);
404 //=========================================================================
406 //=========================================================================
407 bool BlackBox::bbBoxProcessModeIsReactive() const
409 return (bbGetBoxProcessModeValue() == Reactive);
411 //=========================================================================
413 //=========================================================================
414 bool BlackBox::bbBoxProcessModeIsAlways() const
416 return (bbGetBoxProcessModeValue() == Always);
418 //=========================================================================
420 //=========================================================================
421 /// Signals that the BlackBox has been modified
422 void BlackBox::bbSetModifiedStatus(BlackBoxInputConnector* c)
424 bbtkDebugMessage("modified",1,
425 "==> BlackBox::bbSetModifiedStatus("<<c<<") ["
426 <<bbGetFullName()<<"]"<<std::endl);
428 if ( (c==bbGetInputConnectorMap().find("WinHide")->second) )
429 // && (bbCanReact()))
431 bbtkDebugMessage("modified",2,
432 "-> Hide triggered by WinHide input change"
434 this->bbHideWindow();
435 this->bbSetStatus(MODIFIED);
438 if ( (c==bbGetInputConnectorMap().find("WinClose")->second) )
439 // && (bbCanReact()))
441 bbtkDebugMessage("modified",2,
442 "-> Close triggered by WinClose input change"
444 this->bbHideWindow();
445 this->bbSetStatus(MODIFIED);
449 if ( ( bbBoxProcessModeIsReactive() ||
450 (c==bbGetInputConnectorMap().find("BoxExecute")->second))
453 bbtkDebugMessage("modified",2,
454 "-> Execution triggered by Reactive mode or BoxExecute input change"<<std::endl);
455 this->bbSetStatus(MODIFIED);
456 bbGlobalAddToExecutionList( GetThisPointer<BlackBox>() );
459 else if ( bbGetStatus() == MODIFIED ) //! this->bbIsUptodate())
461 bbtkDebugMessage("modified",2,"-> Already modified"<<std::endl);
467 bbtkDebugMessage("modified",2,"-> Status set to modified"<<std::endl);
468 this->bbSetStatus(MODIFIED);
471 this->bbSignalOutputModification(false);
474 bbtkDebugMessageDec("process",5,
475 "<= BlackBox::bbSetModifiedStatus("<<c<<") ["
476 <<bbGetFullName()<<"]"<<std::endl);
479 //=========================================================================
481 //=========================================================================
482 void BlackBox::bbSignalOutputModification(bool reaction)
484 bbtkDebugMessageInc("process",5,
485 "=> BlackBox::bbSignalOutputModification() ["
486 <<bbGetFullName()<<"]"<<std::endl);
488 OutputConnectorMapType::iterator change = bbGetOutputConnectorMap().end();
489 OutputConnectorMapType::iterator i;
490 for ( i = bbGetOutputConnectorMap().begin();
491 i != bbGetOutputConnectorMap().end(); ++i) {
492 /* if ( i->first == "BoxChange" )
498 i->second->SetModifiedStatus();
500 // if (change != bbGetOutputConnectorMap().end())
501 // change->second->SetModifiedStatus();
503 if (reaction) bbGlobalProcessExecutionList();
505 bbtkDebugMessageDec("process",5,
506 "<= BlackBox::bbSignalOutputModification() ["
507 <<bbGetFullName()<<"]"<<std::endl);
510 //=========================================================================
511 //=========================================================================
512 void BlackBox::bbSignalOutputModification(const std::string& output,
515 bbtkDebugMessageInc("process",5,
516 "=> BlackBox::bbSignalOutputModification("
518 <<bbGetFullName()<<"]"<<std::endl);
520 OutputConnectorMapType::iterator i = bbGetOutputConnectorMap().find(output);
521 if ( i == bbGetOutputConnectorMap().end() )
523 bbtkError("BlackBox["<<bbGetFullName()<<"]::bbSignalOutputModification("<<output<<") : unknown output");
525 i->second->SetModifiedStatus();
526 // Has to notify the output "BoxChange" also
527 if (output != "BoxChange")
529 i = bbGetOutputConnectorMap().find("BoxChange");
530 if ( i != bbGetOutputConnectorMap().end() )
532 i->second->SetModifiedStatus();
535 if (reaction) bbGlobalProcessExecutionList();
537 bbtkDebugMessageDec("process",5,
538 "<= BlackBox::bbSignalOutputModification("
540 <<bbGetFullName()<<"]"<<std::endl);
543 //=========================================================================
544 //=========================================================================
545 void BlackBox::bbSignalOutputModification(const std::vector<std::string>& output,
548 bbtkDebugMessageInc("process",5,
549 "=> BlackBox::bbSignalOutputModification(vector of outputs) ["
550 <<bbGetFullName()<<"]"<<std::endl);
551 OutputConnectorMapType::iterator i;
552 std::vector<std::string>::const_iterator o;
553 for (o=output.begin();o!=output.end();++o)
555 // the output "BoxChange" must be signaled **AFTER** all others
556 if (*o == "BoxChange") continue;
557 // Look for the connector
558 i = bbGetOutputConnectorMap().find(*o);
559 if ( i == bbGetOutputConnectorMap().end() )
561 bbtkError("BlackBox["<<bbGetFullName()<<"]::bbSignalOutputModification("<<*o<<") : unknown output");
563 i->second->SetModifiedStatus();
565 // Has to notify the output "BoxChange" also
566 i = bbGetOutputConnectorMap().find("BoxChange");
567 if ( i != bbGetOutputConnectorMap().end() )
569 i->second->SetModifiedStatus();
571 if (reaction) bbGlobalProcessExecutionList();
573 bbtkDebugMessageDec("process",5,
574 "<= BlackBox::bbSignalOutputModification(vector of outputs) ["
575 <<bbGetFullName()<<"]"<<std::endl);
578 //=========================================================================
580 //=========================================================================
581 /// Updates the BlackBox inputs
582 /// \returns UPTODATE if all inputs are in UPTODATE status after update
584 IOStatus BlackBox::bbUpdateInputs(bool excludeParent)
586 bbtkDebugMessageInc("process",4,
587 "=> BlackBox::bbUpdateInputs() ["
588 <<bbGetFullName()<<"]"
591 IOStatus s = UPTODATE;
593 InputConnectorMapType::iterator i;
594 for ( i = bbGetInputConnectorMap().begin();
595 i!= bbGetInputConnectorMap().end(); ++i)
597 if (excludeParent && (i->first=="WinParent")) continue;
598 if (i->first=="WinHide") continue;
599 // If input type is Void : no recurse
600 //if ( bbGetDescriptor()->GetInputDescriptor(i->first)->GetTypeInfo()
604 IOStatus t = i->second->BackwardUpdate();
605 if (t==MODIFIED) s = MODIFIED;
608 bbtkDebugMessageDec("process",4,
609 "<= BlackBox::bbUpdateInputs() ["
610 <<bbGetFullName()<<"]"
616 //=========================================================================
619 //=========================================================================
620 /// Connects the input <name> to the connection c
621 void BlackBox::bbConnectInput( const std::string& name, Connection* c)
623 bbtkDebugMessage("connection",2,
624 "==> BlackBox::bbConnectInput(\""
625 <<name<<"\","<<c->GetFullName()<<") ["
626 <<bbGetFullName()<<"]"
630 InputConnectorMapType::iterator i = bbGetInputConnectorMap().find(name);
631 if (i==bbGetInputConnectorMap().end())
633 bbtkError("no input called '"<<name<<"'");
635 i->second->SetConnection(c);
637 bbtkDebugMessage("connection",2,
638 "<== BlackBox::bbConnectInput(\""
639 <<name<<"\","<<c->GetFullName()<<") ["
640 <<bbGetFullName()<<"]"
642 // bbSetModifiedStatus();
645 //=========================================================================
648 //=========================================================================
649 /// Connects the output <name> to the connection c
650 void BlackBox::bbConnectOutput( const std::string& name, Connection* c)
652 bbtkDebugMessage("connection",2,
653 "==> BlackBox::bbConnectOutput(\""<<name<<"\","
654 <<c->GetFullName()<<") ["
655 <<bbGetFullName()<<"]"<<std::endl);
657 OutputConnectorMapType::iterator i = bbGetOutputConnectorMap().find(name);
658 if (i==bbGetOutputConnectorMap().end())
660 bbtkError("no output called '"<<name<<"'");
662 i->second->SetConnection(c);
664 bbtkDebugMessage("connection",2,
665 "<== BlackBox::bbConnectOutput(\""<<name<<"\","
666 <<c->GetFullName()<<") ["
667 <<bbGetFullName()<<"]"<<std::endl);
670 //=========================================================================
673 //=========================================================================
674 /// Disconnects the input <name> from the connection c
675 void BlackBox::bbDisconnectInput( const std::string& name, Connection* c)
678 bbtkDebugMessage("connection",2,
679 "==> BlackBox::bbDisconnectInput(\""<<name
680 <<"\","<<c->GetFullName()<<") ["
681 <<bbGetFullName()<<"]"
687 bbtkDebugMessage("connection",2,"c==0"<<std::endl);
691 InputConnectorMapType::iterator i = bbGetInputConnectorMap().find(name);
692 if (i==bbGetInputConnectorMap().end())
694 bbtkError("no input called '"<<name<<"'");
696 i->second->UnsetConnection(c);
698 bbtkDebugMessage("connection",2,
699 "<== BlackBox::bbDisconnectInput(\""<<name
700 <<"\","<<c->GetFullName()<<") ["
701 <<bbGetFullName()<<"]"
705 //=========================================================================
708 //=========================================================================
709 /// Disconnects the output <name> from the connection c
710 void BlackBox::bbDisconnectOutput( const std::string& name, Connection* c)
712 bbtkDebugMessage("connection",2,
713 "==> BlackBox::bbDisconnectOutput(\""<<name
714 <<"\","<<c->GetFullName()<<") ["
715 <<bbGetFullName()<<"]"
720 bbtkDebugMessage("connection",2,"c==0"<<std::endl);
724 OutputConnectorMapType::iterator i = bbGetOutputConnectorMap().find(name);
725 if (i==bbGetOutputConnectorMap().end())
727 bbtkError("no output called '"<<name<<"'");
729 i->second->UnsetConnection(c);
731 bbtkDebugMessage("connection",2,
732 "<== BlackBox::bbDisconnectOutput(\""<<name
733 <<"\","<<c->GetFullName()<<") ["
734 <<bbGetFullName()<<"]"
737 //=========================================================================
740 //=========================================================================
742 void BlackBox::bbWriteDotInputOutputName(FILE *ff,bool inputoutput,int detail, int level)
744 fprintf(ff,"%s%p",bbGetTypeName().c_str(),this);
746 //=========================================================================
749 //=========================================================================
750 std::string BlackBox::bbGetOutputAsString( const std::string &output )
753 // Looks for the adaptor
754 if (bbGetOutputType(output).name() != typeid(std::string).name() )
757 Package::Pointer p = bbGetDescriptor()->GetPackage();
758 if ((p != 0) && ( ! p->GetFactorySet().empty() ) )
760 Factory::Pointer f = p->GetFactorySet().begin()->lock();
765 bbGetOutputType(output),
768 } catch (bbtk::Exception e)
773 a->bbSetInput("In",bbGetOutput(output));
775 v = a->bbGetOutput("Out").unsafe_get<std::string>() ;
777 v="? (no adaptor found)";
782 v="? (no factory found)";
788 v = bbGetOutput(output).unsafe_get<std::string>() ;
792 //=========================================================================
794 //=========================================================================
795 std::string BlackBox::bbGetInputAsString( const std::string &input )
798 // Looks for the adaptor
799 if (bbGetInputType(input) != typeid(std::string))
802 Package::Pointer p = bbGetDescriptor()->GetPackage();
803 if ((p != 0) && ( ! p->GetFactorySet().empty() ) )
805 Factory::Pointer f = p->GetFactorySet().begin()->lock();
810 bbGetInputType(input),
813 }catch (bbtk::Exception e)
819 a->bbSetInput("In",bbGetInput(input));
821 v = a->bbGetOutput("Out").unsafe_get<std::string>() ;
825 v="? (no adaptor found)";
830 v="? (no factory found)";
835 v = bbGetInput(input).unsafe_get<std::string>() ;
839 //=======================================================================
841 //=======================================================================
842 // Replaces substrings "<" by "["
843 void SubsBrackets ( std::string& s )
845 // std::cout << "BEFORE=["<<s<<"]"<<std::endl;
847 std::string::size_type pos = 0;
850 while ( pos != std::string::npos )
852 // std::cout << "*** find one "<<std::endl;
853 s.replace(pos,1,cr,1);
854 pos = s.find(ss, pos);
860 while ( pos != std::string::npos )
862 // std::cout << "*** find one "<<std::endl;
863 s.replace(pos,1,cr,1);
864 pos = s.find(ss, pos);
870 while ( pos != std::string::npos )
872 // std::cout << "*** find one "<<std::endl;
873 s.replace(pos,1,cr,1);
874 pos = s.find(ss, pos);
875 } // std::cout << "AFTER=["<<s<<"]"<<std::endl;
877 //=======================================================================
879 //=========================================================================
880 /// Write Graphviz-dot description in file
881 void BlackBox::bbWriteDotFileBlackBox(FILE *ff,
882 BlackBox::Pointer parentblackbox,
883 int detail, int level,
888 InputConnectorMapType::iterator i;
890 std::string labelStr;
891 std::string valueStr("");
894 labelStr = bbGetName() ;
896 labelStr = labelStr + "\\n[" +this->bbGetDescriptor()->GetPackage()->GetName()+"::"+ bbGetTypeName() + "]";
898 labelStr = bbGetName();
899 labelStr = labelStr + " [" +this->bbGetDescriptor()->GetPackage()->GetName()+"::"+ bbGetTypeName() + "] ";
902 SubsBrackets(labelStr);
905 labelStr = labelStr + " | {{ ";
906 std::string tempStrTypeName;
909 for ( i = mInputConnectorMap.begin(); i != mInputConnectorMap.end(); ++i )
913 labelStr=labelStr+" | ";
916 if (instanceOrtype==true)
918 valueStr = this->bbGetInputAsString(i->first) + " = ";
920 const BlackBoxInputDescriptor* id = bbGetDescriptor()->GetInputDescriptor(i->first);
921 tempStrTypeName=id->GetTypeName();
922 SubsBrackets(tempStrTypeName);
923 std::string Name(i->first);
925 labelStr=labelStr + "<"+i->first.c_str()+"> " + valueStr + Name.c_str() + " [" + tempStrTypeName.c_str() + "]";
927 labelStr=labelStr+ " } | {";
929 OutputConnectorMapType::iterator ii;
930 for ( ii = mOutputConnectorMap.begin(); ii != mOutputConnectorMap.end(); ++ii )
934 labelStr=labelStr+" | ";
937 if (instanceOrtype==true)
939 valueStr = this->bbGetOutputAsString(ii->first) + " = ";
941 const BlackBoxOutputDescriptor* id = bbGetDescriptor()->GetOutputDescriptor(ii->first);
942 tempStrTypeName=id->GetTypeName();
943 SubsBrackets(tempStrTypeName);
944 std::string Name(ii->first);
946 labelStr=labelStr+"<"+ii->first.c_str()+"> " + valueStr + Name.c_str() + " ["+tempStrTypeName+"]";
948 labelStr = labelStr+ " } }" ;
952 bbWriteDotInputOutputName(ff,true,detail,level);
953 std::string tmp ( bbGetTypeName() );
957 url = this->bbGetDescriptor()->GetPackage()->GetDocRelativeURL() + "#" + tmp;
959 url = this->bbGetDescriptor()->GetPackage()->GetDocURL() + "#" + tmp;
961 fprintf( ff , " [shape=record, URL=\"%s\",label=\"%s\"]%s\n",url.c_str(),labelStr.c_str(),";" );
962 // std::cout << labelStr << std::endl;
965 if (GetThisPointer<BlackBox>()!=parentblackbox){
966 for ( i = mInputConnectorMap.begin(); i != mInputConnectorMap.end(); ++i )
970 Connection* con = i->second->GetConnection();
972 BlackBox::Pointer a=con->GetOriginalBlackBoxFrom();
973 BlackBox::Pointer b=con->GetOriginalBlackBoxTo();
975 a->bbWriteDotInputOutputName(ff,false,detail,level);
978 fprintf(ff,":%s",con->GetOriginalBlackBoxFromOutput().c_str());
981 b->bbWriteDotInputOutputName(ff,true,detail,level);
984 fprintf(ff,":%s",con->GetOriginalBlackBoxToInput().c_str());
986 fprintf(ff,"%s\n",";");
990 } // if parentblackbox
992 //=========================================================================
997 //=========================================================================
998 void BlackBox::bbShowRelations(BlackBox::Pointer parentblackbox,
999 int detail, int level
1000 /*,Factory *factory*/ )
1003 if (this->bbGetDescriptor()->GetPackage())
1005 bbtkMessage("Help",1,"Black Box '"<<bbGetName()<<"' <"<<
1006 this->bbGetDescriptor()->GetPackage()->GetName()
1007 <<"::"<<this->bbGetDescriptor()->GetTypeName()<<">"<<std::endl);
1011 bbtkMessage("Help",1,"Black Box <::"<<this->bbGetDescriptor()->GetTypeName()<<">"<<std::endl);
1013 // bbtkMessage("Help",1," "<<GetDescription()<<std::endl);
1014 // bbtkMessage("Help",1," By : "<<GetAuthor()<<std::endl);
1016 std::vector<std::string> iname;
1017 std::vector<std::string> ivalue;
1018 std::vector<std::string> iconn;
1020 InputConnectorMapType::iterator i;
1021 unsigned int namelmax = 0;
1022 unsigned int valuelmax = 0;
1023 // unsigned int connlmax = 0;
1024 for ( i = mInputConnectorMap.begin(); i != mInputConnectorMap.end(); ++i )
1026 iname.push_back(i->first);
1027 if (iname.back().size()>namelmax) namelmax = iname.back().size();
1028 ivalue.push_back(bbGetInputAsString(i->first));
1029 if (ivalue.back().size()>valuelmax) valuelmax = ivalue.back().size();
1031 Connection* con = i->second->GetConnection();
1033 s = con->GetOriginalBlackBoxFrom()->bbGetName();
1035 s += con->GetOriginalBlackBoxFromOutput();
1039 OutputConnectorMapType::iterator o;
1040 std::vector<std::string> oname;
1041 std::vector<std::string> ovalue;
1042 std::vector<std::vector<std::string> > oconn;
1043 for ( o = mOutputConnectorMap.begin(); o != mOutputConnectorMap.end(); ++o )
1045 oname.push_back(o->first);
1046 if (oname.back().size()>namelmax) namelmax = oname.back().size();
1047 ovalue.push_back(bbGetOutputAsString(o->first));
1048 if (ovalue.back().size()>valuelmax) valuelmax = ovalue.back().size();
1049 std::vector<std::string> ss;
1050 const std::vector<Connection*>& con
1051 = o->second->GetConnectionVector();
1052 std::vector<Connection*>::const_iterator c;
1053 for (c=con.begin();c!=con.end();++c)
1056 s = (*c)->GetOriginalBlackBoxTo()->bbGetName();
1058 s += (*c)->GetOriginalBlackBoxToInput();
1061 oconn.push_back(ss);
1065 bbtkMessage("Help",1," * Inputs : "<<std::endl);
1067 bbtkMessage("Help",1," * No inputs"<<std::endl);
1069 std::vector<std::string>::iterator i1,i2,i3;
1070 for (i1=iname.begin(),i2=ivalue.begin(),i3=iconn.begin();
1071 i1!=iname.end(),i2!=ivalue.end(),i3!=iconn.end();
1074 std::string name(*i1);
1076 name.append(1+namelmax-name.size(),' ');
1077 std::string value(*i2);
1079 value.append(1+valuelmax-value.size(),' ');
1081 bbtkMessage("Help",1," '"<<name<<" = '"<<value<<" <-- '"<<*i3<<"'"<<std::endl);
1083 bbtkMessage("Help",1," '"<<name<<" = '"<<value<<std::endl);
1087 bbtkMessage("Help",1," * Outputs : "<<std::endl);
1089 bbtkMessage("Help",1," * No outputs"<<std::endl);
1091 std::vector<std::vector<std::string> >::iterator i4;
1093 for (i1=oname.begin(),i2=ovalue.begin(),i4=oconn.begin();
1094 i1!=oname.end(),i2!=ovalue.end(),i4!=oconn.end();
1097 std::string name(*i1);
1099 name.append(1+namelmax-name.size(),' ');
1100 std::string value(*i2);
1102 value.append(1+valuelmax-value.size(),' ');
1104 bbtkMessage("Help",1," '"<<name<<" = '"<<value<<std::endl);
1107 std::string pref = " '"+name+" = '"+value;
1108 for (i3=i4->begin();i3!=i4->end();++i3)
1110 bbtkMessage("Help",1,pref<<" --> '"<<*i3<<"'"<<std::endl);
1111 pref.replace(0,pref.size(),pref.size(),' ');
1117 //=========================================================================
1120 //=========================================================================
1121 void BlackBox::bbGlobalProcessExecutionList()
1123 bbtkDebugMessageInc("process",3,
1124 "=> BlackBox::bbGlobalProcessExecutionList()"
1127 std::set<BlackBox::Pointer>::iterator i;
1128 for (i=bbmgExecutionList.begin();
1129 i!=bbmgExecutionList.end();
1132 bbtkDebugMessage("process",4,
1133 " -> Executing "<<(*i)->bbGetFullName()<<std::endl);
1134 (*i)->bbExecute(true);
1137 bbmgExecutionList.clear();
1138 bbtkDebugMessageDec("process",3,
1139 "<= BlackBox::bbGlobalProcessExecutionList()"
1144 //=========================================================================
1146 bool BlackBox::bbGlobalGetSomeBoxExecuting()
1148 return bbmgSomeBoxExecuting;
1151 void BlackBox::bbGlobalSetSomeBoxExecuting(bool b)
1153 bbmgSomeBoxExecuting = b;
1156 void BlackBox::bbGlobalSetFreezeExecution(bool b)
1158 bbmgFreezeExecution = b;
1161 bool BlackBox::bbGlobalGetFreezeExecution()
1163 return bbmgFreezeExecution;
1166 void BlackBox::bbGlobalAddToExecutionList( BlackBox::Pointer b )
1168 bbmgExecutionList.insert(b);
1172 //=========================================================================
1174 //=========================================================================
1175 void BlackBox::Check(bool recursive)
1177 bbtkMessage("debug",1,"*** Checking Black Box "<<(void*)this<<" ["<<bbGetFullName()
1178 <<"] ... OK"<<std::endl);
1180 //=========================================================================
1182 void BlackBox::bbUserOnShowWidget(std::string nameInput)
1184 bbtk::BlackBoxInputConnector *cc;
1185 cc = this->bbGetInputConnectorMap().find( nameInput.c_str() )->second;
1186 if (cc->GetConnection()!=NULL)
1188 cc->GetConnection()->GetBlackBoxFrom()->bbUserOnShow();
1194 } // EO namespace bbtk