1 /*=========================================================================
4 Module: $RCSfile: bbtkBlackBox.cxx,v $
6 Date: $Date: 2008/06/19 09:46:41 $
7 Version: $Revision: 1.21 $
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 //=========================================================================
106 //=========================================================================
107 BlackBox::BlackBox(const BlackBox&)
110 //=========================================================================
111 BlackBox::BlackBox(BlackBox& from, const std::string &name)
113 bbmStatus(from.bbmStatus),
114 bbmBoxProcessMode(from.bbmBoxProcessMode),
118 bbtkDebugMessage("object",4,"==> BlackBox::BlackBox("
119 <<from.bbGetFullName()<<",\""
120 <<name<<"\")"<<std::endl);
121 bbtkDebugMessage("object",4,"<== BlackBox::BlackBox("
122 <<from.bbGetFullName()<<",\""
123 <<name<<"\")"<<std::endl);
125 //=========================================================================
128 //=========================================================================
129 BlackBox::~BlackBox()
131 bbtkDebugMessage("object",4,"==> BlackBox::~BlackBox() ["<<bbmName
133 this->bbDesallocateConnectors();
134 bbtkDebugMessage("object",4,"<== BlackBox::~BlackBox() ["<<bbmName
137 //=========================================================================
140 //=========================================================================
141 /// Main processing method of the box.
142 void BlackBox::bbExecute(bool force)
144 bbtkDebugMessageInc("process",2,
145 "=> BlackBox::bbExecute() ["
146 <<bbGetFullName()<<"]"<<std::endl);
149 //EED Wx::BeginBusyCursor();
151 // If execution frozen : return
152 if (bbGlobalGetFreezeExecution())
154 bbtkDebugMessage("process",2,
155 " -> FreezeExecution global flag is 'true' : abort execution"<<std::endl);
158 // If force is true then update is triggered even if the box is UPTODATE
159 if (force) bbSetModifiedStatus();
161 // Calls the main recursive update method
162 bbBackwardUpdate(Connection::Pointer());
164 //EED Wx::EndBusyCursor();
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>() );
458 else if ( bbGetStatus() == MODIFIED ) //! this->bbIsUptodate())
460 bbtkDebugMessage("modified",2,"-> Already modified"<<std::endl);
465 bbtkDebugMessage("modified",2,"-> Status set to modified"<<std::endl);
466 this->bbSetStatus(MODIFIED);
469 this->bbSignalOutputModification(false);
472 bbtkDebugMessageDec("process",5,
473 "<= BlackBox::bbSetModifiedStatus("<<c<<") ["
474 <<bbGetFullName()<<"]"<<std::endl);
477 //=========================================================================
479 //=========================================================================
480 void BlackBox::bbSignalOutputModification(bool reaction)
482 bbtkDebugMessageInc("process",5,
483 "=> BlackBox::bbSignalOutputModification() ["
484 <<bbGetFullName()<<"]"<<std::endl);
486 OutputConnectorMapType::iterator change = bbGetOutputConnectorMap().end();
487 OutputConnectorMapType::iterator i;
488 for ( i = bbGetOutputConnectorMap().begin();
489 i != bbGetOutputConnectorMap().end(); ++i) {
490 /* if ( i->first == "BoxChange" )
496 i->second->SetModifiedStatus();
498 // if (change != bbGetOutputConnectorMap().end())
499 // change->second->SetModifiedStatus();
501 if (reaction) bbGlobalProcessExecutionList();
503 bbtkDebugMessageDec("process",5,
504 "<= BlackBox::bbSignalOutputModification() ["
505 <<bbGetFullName()<<"]"<<std::endl);
508 //=========================================================================
509 //=========================================================================
510 void BlackBox::bbSignalOutputModification(const std::string& output,
513 bbtkDebugMessageInc("process",5,
514 "=> BlackBox::bbSignalOutputModification("
516 <<bbGetFullName()<<"]"<<std::endl);
518 OutputConnectorMapType::iterator i = bbGetOutputConnectorMap().find(output);
519 if ( i == bbGetOutputConnectorMap().end() )
521 bbtkError("BlackBox["<<bbGetFullName()<<"]::bbSignalOutputModification("<<output<<") : unknown output");
523 i->second->SetModifiedStatus();
524 // Has to notify the output "BoxChange" also
525 if (output != "BoxChange")
527 i = bbGetOutputConnectorMap().find("BoxChange");
528 if ( i != bbGetOutputConnectorMap().end() )
530 i->second->SetModifiedStatus();
533 if (reaction) bbGlobalProcessExecutionList();
535 bbtkDebugMessageDec("process",5,
536 "<= BlackBox::bbSignalOutputModification("
538 <<bbGetFullName()<<"]"<<std::endl);
541 //=========================================================================
542 //=========================================================================
543 void BlackBox::bbSignalOutputModification(const std::vector<std::string>& output,
546 bbtkDebugMessageInc("process",5,
547 "=> BlackBox::bbSignalOutputModification(vector of outputs) ["
548 <<bbGetFullName()<<"]"<<std::endl);
549 OutputConnectorMapType::iterator i;
550 std::vector<std::string>::const_iterator o;
551 for (o=output.begin();o!=output.end();++o)
553 // the output "BoxChange" must be signaled **AFTER** all others
554 if (*o == "BoxChange") continue;
555 // Look for the connector
556 i = bbGetOutputConnectorMap().find(*o);
557 if ( i == bbGetOutputConnectorMap().end() )
559 bbtkError("BlackBox["<<bbGetFullName()<<"]::bbSignalOutputModification("<<*o<<") : unknown output");
561 i->second->SetModifiedStatus();
563 // Has to notify the output "BoxChange" also
564 i = bbGetOutputConnectorMap().find("BoxChange");
565 if ( i != bbGetOutputConnectorMap().end() )
567 i->second->SetModifiedStatus();
569 if (reaction) bbGlobalProcessExecutionList();
571 bbtkDebugMessageDec("process",5,
572 "<= BlackBox::bbSignalOutputModification(vector of outputs) ["
573 <<bbGetFullName()<<"]"<<std::endl);
576 //=========================================================================
578 //=========================================================================
579 /// Updates the BlackBox inputs
580 /// \returns UPTODATE if all inputs are in UPTODATE status after update
582 IOStatus BlackBox::bbUpdateInputs(bool excludeParent)
584 bbtkDebugMessageInc("process",4,
585 "=> BlackBox::bbUpdateInputs() ["
586 <<bbGetFullName()<<"]"
589 IOStatus s = UPTODATE;
591 InputConnectorMapType::iterator i;
592 for ( i = bbGetInputConnectorMap().begin();
593 i!= bbGetInputConnectorMap().end(); ++i)
595 if (excludeParent && (i->first=="WinParent")) continue;
596 if (i->first=="WinHide") continue;
597 // If input type is Void : no recurse
598 //if ( bbGetDescriptor()->GetInputDescriptor(i->first)->GetTypeInfo()
602 IOStatus t = i->second->BackwardUpdate();
603 if (t==MODIFIED) s = MODIFIED;
606 bbtkDebugMessageDec("process",4,
607 "<= BlackBox::bbUpdateInputs() ["
608 <<bbGetFullName()<<"]"
614 //=========================================================================
617 //=========================================================================
618 /// Connects the input <name> to the connection c
619 void BlackBox::bbConnectInput( const std::string& name, Connection* c)
621 bbtkDebugMessage("connection",2,
622 "==> BlackBox::bbConnectInput(\""
623 <<name<<"\","<<c->GetFullName()<<") ["
624 <<bbGetFullName()<<"]"
628 InputConnectorMapType::iterator i = bbGetInputConnectorMap().find(name);
629 if (i==bbGetInputConnectorMap().end())
631 bbtkError("no input called '"<<name<<"'");
633 i->second->SetConnection(c);
635 bbtkDebugMessage("connection",2,
636 "<== BlackBox::bbConnectInput(\""
637 <<name<<"\","<<c->GetFullName()<<") ["
638 <<bbGetFullName()<<"]"
640 // bbSetModifiedStatus();
643 //=========================================================================
646 //=========================================================================
647 /// Connects the output <name> to the connection c
648 void BlackBox::bbConnectOutput( const std::string& name, Connection* c)
650 bbtkDebugMessage("connection",2,
651 "==> BlackBox::bbConnectOutput(\""<<name<<"\","
652 <<c->GetFullName()<<") ["
653 <<bbGetFullName()<<"]"<<std::endl);
655 OutputConnectorMapType::iterator i = bbGetOutputConnectorMap().find(name);
656 if (i==bbGetOutputConnectorMap().end())
658 bbtkError("no output called '"<<name<<"'");
660 i->second->SetConnection(c);
662 bbtkDebugMessage("connection",2,
663 "<== BlackBox::bbConnectOutput(\""<<name<<"\","
664 <<c->GetFullName()<<") ["
665 <<bbGetFullName()<<"]"<<std::endl);
668 //=========================================================================
671 //=========================================================================
672 /// Disconnects the input <name> from the connection c
673 void BlackBox::bbDisconnectInput( const std::string& name, Connection* c)
676 bbtkDebugMessage("connection",2,
677 "==> BlackBox::bbDisconnectInput(\""<<name
678 <<"\","<<c->GetFullName()<<") ["
679 <<bbGetFullName()<<"]"
685 bbtkDebugMessage("connection",2,"c==0"<<std::endl);
689 InputConnectorMapType::iterator i = bbGetInputConnectorMap().find(name);
690 if (i==bbGetInputConnectorMap().end())
692 bbtkError("no input called '"<<name<<"'");
694 i->second->UnsetConnection(c);
696 bbtkDebugMessage("connection",2,
697 "<== BlackBox::bbDisconnectInput(\""<<name
698 <<"\","<<c->GetFullName()<<") ["
699 <<bbGetFullName()<<"]"
703 //=========================================================================
706 //=========================================================================
707 /// Disconnects the output <name> from the connection c
708 void BlackBox::bbDisconnectOutput( const std::string& name, Connection* c)
710 bbtkDebugMessage("connection",2,
711 "==> BlackBox::bbDisconnectOutput(\""<<name
712 <<"\","<<c->GetFullName()<<") ["
713 <<bbGetFullName()<<"]"
718 bbtkDebugMessage("connection",2,"c==0"<<std::endl);
722 OutputConnectorMapType::iterator i = bbGetOutputConnectorMap().find(name);
723 if (i==bbGetOutputConnectorMap().end())
725 bbtkError("no output called '"<<name<<"'");
727 i->second->UnsetConnection(c);
729 bbtkDebugMessage("connection",2,
730 "<== BlackBox::bbDisconnectOutput(\""<<name
731 <<"\","<<c->GetFullName()<<") ["
732 <<bbGetFullName()<<"]"
735 //=========================================================================
738 //=========================================================================
740 void BlackBox::bbWriteDotInputOutputName(FILE *ff,bool inputoutput,int detail, int level)
742 fprintf(ff,"%s%p",bbGetTypeName().c_str(),this);
744 //=========================================================================
747 //=========================================================================
748 std::string BlackBox::bbGetOutputAsString( const std::string &output )
751 // Looks for the adaptor
752 if (bbGetOutputType(output).name() != typeid(std::string).name() )
755 Package::Pointer p = bbGetDescriptor()->GetPackage();
756 if ((p != 0) && ( ! p->GetFactorySet().empty() ) )
758 Factory::Pointer f = p->GetFactorySet().begin()->lock();
763 bbGetOutputType(output),
766 } catch (bbtk::Exception e)
771 a->bbSetInput("In",bbGetOutput(output));
773 v = a->bbGetOutput("Out").unsafe_get<std::string>() ;
775 v="? (no adaptor found)";
780 v="? (no factory found)";
786 v = bbGetOutput(output).unsafe_get<std::string>() ;
790 //=========================================================================
792 //=========================================================================
793 std::string BlackBox::bbGetInputAsString( const std::string &input )
796 // Looks for the adaptor
797 if (bbGetInputType(input) != typeid(std::string))
800 Package::Pointer p = bbGetDescriptor()->GetPackage();
801 if ((p != 0) && ( ! p->GetFactorySet().empty() ) )
803 Factory::Pointer f = p->GetFactorySet().begin()->lock();
808 bbGetInputType(input),
811 }catch (bbtk::Exception e)
817 a->bbSetInput("In",bbGetInput(input));
819 v = a->bbGetOutput("Out").unsafe_get<std::string>() ;
823 v="? (no adaptor found)";
828 v="? (no factory found)";
833 v = bbGetInput(input).unsafe_get<std::string>() ;
837 //=======================================================================
839 //=======================================================================
840 // Replaces substrings "<" by "["
841 void SubsBrackets ( std::string& s )
843 // std::cout << "BEFORE=["<<s<<"]"<<std::endl;
845 std::string::size_type pos = 0;
848 while ( pos != std::string::npos )
850 // std::cout << "*** find one "<<std::endl;
851 s.replace(pos,1,cr,1);
852 pos = s.find(ss, pos);
858 while ( pos != std::string::npos )
860 // std::cout << "*** find one "<<std::endl;
861 s.replace(pos,1,cr,1);
862 pos = s.find(ss, pos);
868 while ( pos != std::string::npos )
870 // std::cout << "*** find one "<<std::endl;
871 s.replace(pos,1,cr,1);
872 pos = s.find(ss, pos);
873 } // std::cout << "AFTER=["<<s<<"]"<<std::endl;
875 //=======================================================================
877 //=========================================================================
878 /// Write Graphviz-dot description in file
879 void BlackBox::bbWriteDotFileBlackBox(FILE *ff,
880 BlackBox::Pointer parentblackbox,
881 int detail, int level,
886 InputConnectorMapType::iterator i;
888 std::string labelStr;
889 std::string valueStr("");
892 labelStr = bbGetName() ;
894 labelStr = labelStr + "\\n[" +this->bbGetDescriptor()->GetPackage()->GetName()+"::"+ bbGetTypeName() + "]";
896 labelStr = bbGetName();
897 labelStr = labelStr + " [" +this->bbGetDescriptor()->GetPackage()->GetName()+"::"+ bbGetTypeName() + "] ";
900 SubsBrackets(labelStr);
903 labelStr = labelStr + " | {{ ";
904 std::string tempStrTypeName;
907 for ( i = mInputConnectorMap.begin(); i != mInputConnectorMap.end(); ++i )
911 labelStr=labelStr+" | ";
914 if (instanceOrtype==true)
916 valueStr = this->bbGetInputAsString(i->first) + " = ";
918 const BlackBoxInputDescriptor* id = bbGetDescriptor()->GetInputDescriptor(i->first);
919 tempStrTypeName=id->GetTypeName();
920 SubsBrackets(tempStrTypeName);
921 std::string Name(i->first);
923 labelStr=labelStr + "<"+i->first.c_str()+"> " + valueStr + Name.c_str() + " [" + tempStrTypeName.c_str() + "]";
925 labelStr=labelStr+ " } | {";
927 OutputConnectorMapType::iterator ii;
928 for ( ii = mOutputConnectorMap.begin(); ii != mOutputConnectorMap.end(); ++ii )
932 labelStr=labelStr+" | ";
935 if (instanceOrtype==true)
937 valueStr = this->bbGetOutputAsString(ii->first) + " = ";
939 const BlackBoxOutputDescriptor* id = bbGetDescriptor()->GetOutputDescriptor(ii->first);
940 tempStrTypeName=id->GetTypeName();
941 SubsBrackets(tempStrTypeName);
942 std::string Name(ii->first);
944 labelStr=labelStr+"<"+ii->first.c_str()+"> " + valueStr + Name.c_str() + " ["+tempStrTypeName+"]";
946 labelStr = labelStr+ " } }" ;
950 bbWriteDotInputOutputName(ff,true,detail,level);
951 std::string tmp ( bbGetTypeName() );
955 url = this->bbGetDescriptor()->GetPackage()->GetDocRelativeURL() + "#" + tmp;
957 url = this->bbGetDescriptor()->GetPackage()->GetDocURL() + "#" + tmp;
959 fprintf( ff , " [shape=record, URL=\"%s\",label=\"%s\"]%s\n",url.c_str(),labelStr.c_str(),";" );
960 // std::cout << labelStr << std::endl;
963 if (GetThisPointer<BlackBox>()!=parentblackbox){
964 for ( i = mInputConnectorMap.begin(); i != mInputConnectorMap.end(); ++i )
968 Connection* con = i->second->GetConnection();
970 BlackBox::Pointer a=con->GetOriginalBlackBoxFrom();
971 BlackBox::Pointer b=con->GetOriginalBlackBoxTo();
973 a->bbWriteDotInputOutputName(ff,false,detail,level);
976 fprintf(ff,":%s",con->GetOriginalBlackBoxFromOutput().c_str());
979 b->bbWriteDotInputOutputName(ff,true,detail,level);
982 fprintf(ff,":%s",con->GetOriginalBlackBoxToInput().c_str());
984 fprintf(ff,"%s\n",";");
988 } // if parentblackbox
990 //=========================================================================
995 //=========================================================================
996 void BlackBox::bbShowRelations(BlackBox::Pointer parentblackbox,
997 int detail, int level
998 /*,Factory *factory*/ )
1001 if (this->bbGetDescriptor()->GetPackage())
1003 bbtkMessage("Help",1,"Black Box '"<<bbGetName()<<"' <"<<
1004 this->bbGetDescriptor()->GetPackage()->GetName()
1005 <<"::"<<this->bbGetDescriptor()->GetTypeName()<<">"<<std::endl);
1009 bbtkMessage("Help",1,"Black Box <::"<<this->bbGetDescriptor()->GetTypeName()<<">"<<std::endl);
1011 // bbtkMessage("Help",1," "<<GetDescription()<<std::endl);
1012 // bbtkMessage("Help",1," By : "<<GetAuthor()<<std::endl);
1014 std::vector<std::string> iname;
1015 std::vector<std::string> ivalue;
1016 std::vector<std::string> iconn;
1018 InputConnectorMapType::iterator i;
1019 unsigned int namelmax = 0;
1020 unsigned int valuelmax = 0;
1021 unsigned int connlmax = 0;
1022 for ( i = mInputConnectorMap.begin(); i != mInputConnectorMap.end(); ++i )
1024 iname.push_back(i->first);
1025 if (iname.back().size()>namelmax) namelmax = iname.back().size();
1026 ivalue.push_back(bbGetInputAsString(i->first));
1027 if (ivalue.back().size()>valuelmax) valuelmax = ivalue.back().size();
1029 Connection* con = i->second->GetConnection();
1031 s = con->GetOriginalBlackBoxFrom()->bbGetName();
1033 s += con->GetOriginalBlackBoxFromOutput();
1037 OutputConnectorMapType::iterator o;
1038 std::vector<std::string> oname;
1039 std::vector<std::string> ovalue;
1040 std::vector<std::vector<std::string> > oconn;
1041 for ( o = mOutputConnectorMap.begin(); o != mOutputConnectorMap.end(); ++o )
1043 oname.push_back(o->first);
1044 if (oname.back().size()>namelmax) namelmax = oname.back().size();
1045 ovalue.push_back(bbGetOutputAsString(o->first));
1046 if (ovalue.back().size()>valuelmax) valuelmax = ovalue.back().size();
1047 std::vector<std::string> ss;
1048 const std::vector<Connection*>& con
1049 = o->second->GetConnectionVector();
1050 std::vector<Connection*>::const_iterator c;
1051 for (c=con.begin();c!=con.end();++c)
1054 s = (*c)->GetOriginalBlackBoxTo()->bbGetName();
1056 s += (*c)->GetOriginalBlackBoxToInput();
1059 oconn.push_back(ss);
1063 bbtkMessage("Help",1," * Inputs : "<<std::endl);
1065 bbtkMessage("Help",1," * No inputs"<<std::endl);
1067 std::vector<std::string>::iterator i1,i2,i3;
1068 for (i1=iname.begin(),i2=ivalue.begin(),i3=iconn.begin();
1069 i1!=iname.end(),i2!=ivalue.end(),i3!=iconn.end();
1072 std::string name(*i1);
1074 name.append(1+namelmax-name.size(),' ');
1075 std::string value(*i2);
1077 value.append(1+valuelmax-value.size(),' ');
1079 bbtkMessage("Help",1," '"<<name<<" = '"<<value<<" <-- '"<<*i3<<"'"<<std::endl);
1081 bbtkMessage("Help",1," '"<<name<<" = '"<<value<<std::endl);
1085 bbtkMessage("Help",1," * Outputs : "<<std::endl);
1087 bbtkMessage("Help",1," * No outputs"<<std::endl);
1089 std::vector<std::vector<std::string> >::iterator i4;
1091 for (i1=oname.begin(),i2=ovalue.begin(),i4=oconn.begin();
1092 i1!=oname.end(),i2!=ovalue.end(),i4!=oconn.end();
1095 std::string name(*i1);
1097 name.append(1+namelmax-name.size(),' ');
1098 std::string value(*i2);
1100 value.append(1+valuelmax-value.size(),' ');
1102 bbtkMessage("Help",1," '"<<name<<" = '"<<value<<std::endl);
1105 std::string pref = " '"+name+" = '"+value;
1106 for (i3=i4->begin();i3!=i4->end();++i3)
1108 bbtkMessage("Help",1,pref<<" --> '"<<*i3<<"'"<<std::endl);
1109 pref.replace(0,pref.size(),pref.size(),' ');
1115 //=========================================================================
1118 //=========================================================================
1119 void BlackBox::bbGlobalProcessExecutionList()
1121 bbtkDebugMessageInc("process",3,
1122 "=> BlackBox::bbGlobalProcessExecutionList()"
1125 std::set<BlackBox::Pointer>::iterator i;
1126 for (i=bbmgExecutionList.begin();
1127 i!=bbmgExecutionList.end();
1130 bbtkDebugMessage("process",4,
1131 " -> Executing "<<(*i)->bbGetFullName()<<std::endl);
1132 (*i)->bbExecute(true);
1135 bbmgExecutionList.clear();
1136 bbtkDebugMessageDec("process",3,
1137 "<= BlackBox::bbGlobalProcessExecutionList()"
1142 //=========================================================================
1144 bool BlackBox::bbGlobalGetSomeBoxExecuting()
1146 return bbmgSomeBoxExecuting;
1149 void BlackBox::bbGlobalSetSomeBoxExecuting(bool b)
1151 bbmgSomeBoxExecuting = b;
1154 void BlackBox::bbGlobalSetFreezeExecution(bool b)
1156 bbmgFreezeExecution = b;
1159 bool BlackBox::bbGlobalGetFreezeExecution()
1161 return bbmgFreezeExecution;
1164 void BlackBox::bbGlobalAddToExecutionList( BlackBox::Pointer b )
1166 bbmgExecutionList.insert(b);
1170 //=========================================================================
1172 //=========================================================================
1173 void BlackBox::Check(bool recursive)
1175 bbtkMessage("debug",1,"*** Checking Black Box "<<(void*)this<<" ["<<bbGetFullName()
1176 <<"] ... OK"<<std::endl);
1178 //=========================================================================
1180 void BlackBox::bbUserOnShowWidget(std::string nameInput)
1182 bbtk::BlackBoxInputConnector *cc;
1183 cc = this->bbGetInputConnectorMap().find( nameInput.c_str() )->second;
1184 if (cc->GetConnection()!=NULL)
1186 cc->GetConnection()->GetBlackBoxFrom()->bbUserOnShow();
1192 } // EO namespace bbtk