1 /*=========================================================================
4 Module: $RCSfile: bbtkBlackBox.cxx,v $
6 Date: $Date: 2008/07/23 11:46:10 $
7 Version: $Revision: 1.22 $
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);
151 //EED Wx::BeginBusyCursor();
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 //EED Wx::EndBusyCursor();
168 bbtkDebugMessageDec("process",2,
169 "<= BlackBox::bbExecute() ["
170 <<bbGetFullName()<<"]"<<std::endl);
172 //=========================================================================
174 //=========================================================================
175 std::string BlackBox::bbGetFullName() const
177 return this->bbGetNameWithParent()+"<"+this->bbGetDescriptor()->GetTypeName()+">";
179 //=========================================================================
183 //=========================================================================
184 /// Returns the name with the name of the parent prepended if any
185 std::string BlackBox::bbGetNameWithParent() const
187 if (bbmParent.lock())
189 return bbmParent.lock()->bbGetNameWithParent() + ":" + bbmName;
196 //=========================================================================
198 //=========================================================================
199 /// Prints the Help on the BlackBox type
200 void BlackBox::bbGetHelp(bool full) const
202 bbGetDescriptor()->GetHelp(full);
204 //=========================================================================
207 //=========================================================================
208 /// Returns true if the UserBlackBox has an input of name name
209 bool BlackBox::bbHasInput(const std::string& name) const
211 bbtkDebugMessageInc("Kernel",8,
212 "BlackBox::bbHasInput(\""
213 <<name<<"\") ["<<bbGetFullName()<<"]"
215 bool r = ( bbGetDescriptor()->GetInputDescriptorMap().find(name)
216 != bbGetDescriptor()->GetInputDescriptorMap().end());
217 bbtkDebugDecTab("Kernel",8);
220 //=========================================================================
223 //=========================================================================
224 /// Returns true if the UserBlackBox has an output of name name
225 bool BlackBox::bbHasOutput(const std::string& name) const
227 bbtkDebugMessageInc("Kernel",8,"BlackBox::bbHasOutput(\""
228 <<name<<"\") ["<<bbGetFullName()<<"]"<<std::endl);
229 bool r = ( bbGetDescriptor()->GetOutputDescriptorMap().find(name)
230 != bbGetDescriptor()->GetOutputDescriptorMap().end());
231 bbtkDebugDecTab("Kernel",8);
234 //=========================================================================
237 //=========================================================================
238 /// Gets the output type of a given name
239 TypeInfo BlackBox::bbGetOutputType( const std::string &name ) const
241 bbtkDebugMessageInc("Kernel",8,
242 "BlackBox::bbGetOutputType(\""
243 <<name<<"\") ["<<bbGetFullName()<<"]"<<std::endl);
244 TypeInfo r = bbGetDescriptor()->GetOutputDescriptor(name)->GetTypeInfo();
245 bbtkDebugDecTab("Kernel",8);
248 //=========================================================================
250 //=========================================================================
251 /// Gets the input type of a given name
252 TypeInfo BlackBox::bbGetInputType( const std::string &name ) const
254 bbtkDebugMessageInc("Kernel",8,
255 "BlackBox::bbGetInputType(\""
256 <<name<<"\") ["<<bbGetFullName()<<"]"<<std::endl);
257 TypeInfo r = bbGetDescriptor()->GetInputDescriptor(name)->GetTypeInfo();
258 bbtkDebugDecTab("Kernel",8);
261 //=========================================================================
264 //=========================================================================
265 /// Allocates the i/o connectors of the black box
266 void BlackBox::bbAllocateConnectors()
268 bbtkDebugMessageInc("Kernel",8,
269 "BlackBox::bbAllocateConnectors() ["
270 <<bbGetFullName()<<"]"
272 const BlackBoxDescriptor::InputDescriptorMapType& imap
273 = bbGetDescriptor()->GetInputDescriptorMap();
274 BlackBoxDescriptor::InputDescriptorMapType::const_iterator i;
275 for ( i = imap.begin(); i != imap.end(); ++i )
277 bbtkDebugMessage("Kernel",8,"* Allocate \""<<i->first<<"\""<<std::endl);
278 bbGetInputConnectorMap()[i->second->GetName()]
279 = new BlackBoxInputConnector(GetThisPointer<BlackBox>());
281 const BlackBoxDescriptor::OutputDescriptorMapType& omap
282 = bbGetDescriptor()->GetOutputDescriptorMap();
283 BlackBoxDescriptor::OutputDescriptorMapType::const_iterator o;
284 for ( o = omap.begin(); o != omap.end(); ++o )
286 bbtkDebugMessage("Kernel",8,"* Allocate \""<<o->first<<"\""<<std::endl);
287 bbGetOutputConnectorMap()[o->second->GetName()]
288 = new BlackBoxOutputConnector();
290 bbtkDebugDecTab("Kernel",8);
292 //=========================================================================
295 //=========================================================================
296 /// Desallocates the i/o connectors of the black box
297 void BlackBox::bbDesallocateConnectors()
299 bbtkDebugMessageInc("Kernel",8,
300 "BlackBox::bbDesallocateConnectors()"
303 InputConnectorMapType::const_iterator i;
304 for ( i = bbGetInputConnectorMap().begin();
305 i != bbGetInputConnectorMap().end(); ++i )
307 bbtkDebugMessage("Kernel",8,"* Delete \""<<i->first<<"\""<<std::endl);
310 OutputConnectorMapType::const_iterator o;
311 for ( o = bbGetOutputConnectorMap().begin();
312 o != bbGetOutputConnectorMap().end(); ++o )
314 bbtkDebugMessage("Kernel",8,"* Delete \""<<o->first<<"\""<<std::endl);
318 bbtkDebugDecTab("Kernel",8);
321 //=========================================================================
324 //=========================================================================
325 /// Copies the input / output values from another box
326 void BlackBox::bbCopyIOValues(BlackBox& from)
328 bbtkDebugMessageInc("Kernel",9,
329 "BlackBox::bbCopyIOValues("
330 <<from.bbGetFullName()<<") ["
331 <<bbGetFullName()<<"]"<<std::endl);
332 // copies the input values
333 const BlackBoxDescriptor::InputDescriptorMapType& imap
334 = bbGetDescriptor()->GetInputDescriptorMap();
335 BlackBoxDescriptor::InputDescriptorMapType::const_iterator i;
336 for ( i = imap.begin(); i != imap.end(); ++i )
338 if (! i->second->GetCopyConstruct() ) continue;
339 std::string input = i->second->GetName();
340 this->bbSetInput(input, from.bbGetInput(input) );
342 // copies the output values
343 const BlackBoxDescriptor::OutputDescriptorMapType& omap
344 = bbGetDescriptor()->GetOutputDescriptorMap();
345 BlackBoxDescriptor::OutputDescriptorMapType::const_iterator o;
346 for ( o = omap.begin(); o != omap.end(); ++o )
348 if (! o->second->GetCopyConstruct() ) continue;
349 std::string output = o->second->GetName();
350 this->bbSetOutput(output, from.bbGetOutput(output) );
353 bbtkDebugDecTab("Kernel",9);
356 //=========================================================================
360 //=========================================================================
361 bool BlackBox::bbCanReact() const
363 return ( bbGlobalGetSomeBoxExecuting()
364 #ifdef _USE_WXWIDGETS_
365 || Wx::IsSomeWindowAlive()
369 //=========================================================================
373 //=========================================================================
374 /// User overloadable destruction method of a black box
375 void BlackBox::bbUserDelete()
377 bbtkDebugMessage("process",5,
378 "=> BlackBox::bbUserDelete() ["
379 <<bbGetFullName()<<"]"
380 <<" : not overloaded; using standard deletion"
384 //=========================================================================
387 //=========================================================================
388 BlackBox::BoxProcessModeValue BlackBox::bbGetBoxProcessModeValue() const
390 const std::string& p = bbmBoxProcessMode;
392 (p == "P") || (p == "p") ||
393 (p == "Pipeline") || (p == "pipeline") ) return Pipeline;
395 (p == "A") || (p == "a") ||
396 (p == "Always") || (p == "always") ) return Always;
398 (p == "R") || (p == "r") ||
399 (p == "Reactive") || (p == "reactive") ) return Reactive;
400 bbtkError(bbGetFullName()<<" : BoxProcessMode value '"<<p
401 <<"' unknown. Possible values : "
402 <<"'0'/'P'/'p'/'Pipeline'/'pipeline' | "
403 <<"'1'/'A'/'a'/'Always'/'always' | "
404 <<"'2'/'R'/'r'/'Reactive'/'reactive'"<<std::endl);
406 //=========================================================================
408 //=========================================================================
409 bool BlackBox::bbBoxProcessModeIsReactive() const
411 return (bbGetBoxProcessModeValue() == Reactive);
413 //=========================================================================
415 //=========================================================================
416 bool BlackBox::bbBoxProcessModeIsAlways() const
418 return (bbGetBoxProcessModeValue() == Always);
420 //=========================================================================
422 //=========================================================================
423 /// Signals that the BlackBox has been modified
424 void BlackBox::bbSetModifiedStatus(BlackBoxInputConnector* c)
426 bbtkDebugMessage("modified",1,
427 "==> BlackBox::bbSetModifiedStatus("<<c<<") ["
428 <<bbGetFullName()<<"]"<<std::endl);
430 if ( (c==bbGetInputConnectorMap().find("WinHide")->second) )
431 // && (bbCanReact()))
433 bbtkDebugMessage("modified",2,
434 "-> Hide triggered by WinHide input change"
436 this->bbHideWindow();
437 this->bbSetStatus(MODIFIED);
440 if ( (c==bbGetInputConnectorMap().find("WinClose")->second) )
441 // && (bbCanReact()))
443 bbtkDebugMessage("modified",2,
444 "-> Close triggered by WinClose input change"
446 this->bbHideWindow();
447 this->bbSetStatus(MODIFIED);
451 if ( ( bbBoxProcessModeIsReactive() ||
452 (c==bbGetInputConnectorMap().find("BoxExecute")->second))
455 bbtkDebugMessage("modified",2,
456 "-> Execution triggered by Reactive mode or BoxExecute input change"<<std::endl);
457 this->bbSetStatus(MODIFIED);
458 bbGlobalAddToExecutionList( GetThisPointer<BlackBox>() );
461 else if ( bbGetStatus() == MODIFIED ) //! this->bbIsUptodate())
463 bbtkDebugMessage("modified",2,"-> Already modified"<<std::endl);
469 bbtkDebugMessage("modified",2,"-> Status set to modified"<<std::endl);
470 this->bbSetStatus(MODIFIED);
473 this->bbSignalOutputModification(false);
476 bbtkDebugMessageDec("process",5,
477 "<= BlackBox::bbSetModifiedStatus("<<c<<") ["
478 <<bbGetFullName()<<"]"<<std::endl);
481 //=========================================================================
483 //=========================================================================
484 void BlackBox::bbSignalOutputModification(bool reaction)
486 bbtkDebugMessageInc("process",5,
487 "=> BlackBox::bbSignalOutputModification() ["
488 <<bbGetFullName()<<"]"<<std::endl);
490 OutputConnectorMapType::iterator change = bbGetOutputConnectorMap().end();
491 OutputConnectorMapType::iterator i;
492 for ( i = bbGetOutputConnectorMap().begin();
493 i != bbGetOutputConnectorMap().end(); ++i) {
494 /* if ( i->first == "BoxChange" )
500 i->second->SetModifiedStatus();
502 // if (change != bbGetOutputConnectorMap().end())
503 // change->second->SetModifiedStatus();
505 if (reaction) bbGlobalProcessExecutionList();
507 bbtkDebugMessageDec("process",5,
508 "<= BlackBox::bbSignalOutputModification() ["
509 <<bbGetFullName()<<"]"<<std::endl);
512 //=========================================================================
513 //=========================================================================
514 void BlackBox::bbSignalOutputModification(const std::string& output,
517 bbtkDebugMessageInc("process",5,
518 "=> BlackBox::bbSignalOutputModification("
520 <<bbGetFullName()<<"]"<<std::endl);
522 OutputConnectorMapType::iterator i = bbGetOutputConnectorMap().find(output);
523 if ( i == bbGetOutputConnectorMap().end() )
525 bbtkError("BlackBox["<<bbGetFullName()<<"]::bbSignalOutputModification("<<output<<") : unknown output");
527 i->second->SetModifiedStatus();
528 // Has to notify the output "BoxChange" also
529 if (output != "BoxChange")
531 i = bbGetOutputConnectorMap().find("BoxChange");
532 if ( i != bbGetOutputConnectorMap().end() )
534 i->second->SetModifiedStatus();
537 if (reaction) bbGlobalProcessExecutionList();
539 bbtkDebugMessageDec("process",5,
540 "<= BlackBox::bbSignalOutputModification("
542 <<bbGetFullName()<<"]"<<std::endl);
545 //=========================================================================
546 //=========================================================================
547 void BlackBox::bbSignalOutputModification(const std::vector<std::string>& output,
550 bbtkDebugMessageInc("process",5,
551 "=> BlackBox::bbSignalOutputModification(vector of outputs) ["
552 <<bbGetFullName()<<"]"<<std::endl);
553 OutputConnectorMapType::iterator i;
554 std::vector<std::string>::const_iterator o;
555 for (o=output.begin();o!=output.end();++o)
557 // the output "BoxChange" must be signaled **AFTER** all others
558 if (*o == "BoxChange") continue;
559 // Look for the connector
560 i = bbGetOutputConnectorMap().find(*o);
561 if ( i == bbGetOutputConnectorMap().end() )
563 bbtkError("BlackBox["<<bbGetFullName()<<"]::bbSignalOutputModification("<<*o<<") : unknown output");
565 i->second->SetModifiedStatus();
567 // Has to notify the output "BoxChange" also
568 i = bbGetOutputConnectorMap().find("BoxChange");
569 if ( i != bbGetOutputConnectorMap().end() )
571 i->second->SetModifiedStatus();
573 if (reaction) bbGlobalProcessExecutionList();
575 bbtkDebugMessageDec("process",5,
576 "<= BlackBox::bbSignalOutputModification(vector of outputs) ["
577 <<bbGetFullName()<<"]"<<std::endl);
580 //=========================================================================
582 //=========================================================================
583 /// Updates the BlackBox inputs
584 /// \returns UPTODATE if all inputs are in UPTODATE status after update
586 IOStatus BlackBox::bbUpdateInputs(bool excludeParent)
588 bbtkDebugMessageInc("process",4,
589 "=> BlackBox::bbUpdateInputs() ["
590 <<bbGetFullName()<<"]"
593 IOStatus s = UPTODATE;
595 InputConnectorMapType::iterator i;
596 for ( i = bbGetInputConnectorMap().begin();
597 i!= bbGetInputConnectorMap().end(); ++i)
599 if (excludeParent && (i->first=="WinParent")) continue;
600 if (i->first=="WinHide") continue;
601 // If input type is Void : no recurse
602 //if ( bbGetDescriptor()->GetInputDescriptor(i->first)->GetTypeInfo()
606 IOStatus t = i->second->BackwardUpdate();
607 if (t==MODIFIED) s = MODIFIED;
610 bbtkDebugMessageDec("process",4,
611 "<= BlackBox::bbUpdateInputs() ["
612 <<bbGetFullName()<<"]"
618 //=========================================================================
621 //=========================================================================
622 /// Connects the input <name> to the connection c
623 void BlackBox::bbConnectInput( const std::string& name, Connection* c)
625 bbtkDebugMessage("connection",2,
626 "==> BlackBox::bbConnectInput(\""
627 <<name<<"\","<<c->GetFullName()<<") ["
628 <<bbGetFullName()<<"]"
632 InputConnectorMapType::iterator i = bbGetInputConnectorMap().find(name);
633 if (i==bbGetInputConnectorMap().end())
635 bbtkError("no input called '"<<name<<"'");
637 i->second->SetConnection(c);
639 bbtkDebugMessage("connection",2,
640 "<== BlackBox::bbConnectInput(\""
641 <<name<<"\","<<c->GetFullName()<<") ["
642 <<bbGetFullName()<<"]"
644 // bbSetModifiedStatus();
647 //=========================================================================
650 //=========================================================================
651 /// Connects the output <name> to the connection c
652 void BlackBox::bbConnectOutput( const std::string& name, Connection* c)
654 bbtkDebugMessage("connection",2,
655 "==> BlackBox::bbConnectOutput(\""<<name<<"\","
656 <<c->GetFullName()<<") ["
657 <<bbGetFullName()<<"]"<<std::endl);
659 OutputConnectorMapType::iterator i = bbGetOutputConnectorMap().find(name);
660 if (i==bbGetOutputConnectorMap().end())
662 bbtkError("no output called '"<<name<<"'");
664 i->second->SetConnection(c);
666 bbtkDebugMessage("connection",2,
667 "<== BlackBox::bbConnectOutput(\""<<name<<"\","
668 <<c->GetFullName()<<") ["
669 <<bbGetFullName()<<"]"<<std::endl);
672 //=========================================================================
675 //=========================================================================
676 /// Disconnects the input <name> from the connection c
677 void BlackBox::bbDisconnectInput( const std::string& name, Connection* c)
680 bbtkDebugMessage("connection",2,
681 "==> BlackBox::bbDisconnectInput(\""<<name
682 <<"\","<<c->GetFullName()<<") ["
683 <<bbGetFullName()<<"]"
689 bbtkDebugMessage("connection",2,"c==0"<<std::endl);
693 InputConnectorMapType::iterator i = bbGetInputConnectorMap().find(name);
694 if (i==bbGetInputConnectorMap().end())
696 bbtkError("no input called '"<<name<<"'");
698 i->second->UnsetConnection(c);
700 bbtkDebugMessage("connection",2,
701 "<== BlackBox::bbDisconnectInput(\""<<name
702 <<"\","<<c->GetFullName()<<") ["
703 <<bbGetFullName()<<"]"
707 //=========================================================================
710 //=========================================================================
711 /// Disconnects the output <name> from the connection c
712 void BlackBox::bbDisconnectOutput( const std::string& name, Connection* c)
714 bbtkDebugMessage("connection",2,
715 "==> BlackBox::bbDisconnectOutput(\""<<name
716 <<"\","<<c->GetFullName()<<") ["
717 <<bbGetFullName()<<"]"
722 bbtkDebugMessage("connection",2,"c==0"<<std::endl);
726 OutputConnectorMapType::iterator i = bbGetOutputConnectorMap().find(name);
727 if (i==bbGetOutputConnectorMap().end())
729 bbtkError("no output called '"<<name<<"'");
731 i->second->UnsetConnection(c);
733 bbtkDebugMessage("connection",2,
734 "<== BlackBox::bbDisconnectOutput(\""<<name
735 <<"\","<<c->GetFullName()<<") ["
736 <<bbGetFullName()<<"]"
739 //=========================================================================
742 //=========================================================================
744 void BlackBox::bbWriteDotInputOutputName(FILE *ff,bool inputoutput,int detail, int level)
746 fprintf(ff,"%s%p",bbGetTypeName().c_str(),this);
748 //=========================================================================
751 //=========================================================================
752 std::string BlackBox::bbGetOutputAsString( const std::string &output )
755 // Looks for the adaptor
756 if (bbGetOutputType(output).name() != typeid(std::string).name() )
759 Package::Pointer p = bbGetDescriptor()->GetPackage();
760 if ((p != 0) && ( ! p->GetFactorySet().empty() ) )
762 Factory::Pointer f = p->GetFactorySet().begin()->lock();
767 bbGetOutputType(output),
770 } catch (bbtk::Exception e)
775 a->bbSetInput("In",bbGetOutput(output));
777 v = a->bbGetOutput("Out").unsafe_get<std::string>() ;
779 v="? (no adaptor found)";
784 v="? (no factory found)";
790 v = bbGetOutput(output).unsafe_get<std::string>() ;
794 //=========================================================================
796 //=========================================================================
797 std::string BlackBox::bbGetInputAsString( const std::string &input )
800 // Looks for the adaptor
801 if (bbGetInputType(input) != typeid(std::string))
804 Package::Pointer p = bbGetDescriptor()->GetPackage();
805 if ((p != 0) && ( ! p->GetFactorySet().empty() ) )
807 Factory::Pointer f = p->GetFactorySet().begin()->lock();
812 bbGetInputType(input),
815 }catch (bbtk::Exception e)
821 a->bbSetInput("In",bbGetInput(input));
823 v = a->bbGetOutput("Out").unsafe_get<std::string>() ;
827 v="? (no adaptor found)";
832 v="? (no factory found)";
837 v = bbGetInput(input).unsafe_get<std::string>() ;
841 //=======================================================================
843 //=======================================================================
844 // Replaces substrings "<" by "["
845 void SubsBrackets ( std::string& s )
847 // std::cout << "BEFORE=["<<s<<"]"<<std::endl;
849 std::string::size_type pos = 0;
852 while ( pos != std::string::npos )
854 // std::cout << "*** find one "<<std::endl;
855 s.replace(pos,1,cr,1);
856 pos = s.find(ss, pos);
862 while ( pos != std::string::npos )
864 // std::cout << "*** find one "<<std::endl;
865 s.replace(pos,1,cr,1);
866 pos = s.find(ss, pos);
872 while ( pos != std::string::npos )
874 // std::cout << "*** find one "<<std::endl;
875 s.replace(pos,1,cr,1);
876 pos = s.find(ss, pos);
877 } // std::cout << "AFTER=["<<s<<"]"<<std::endl;
879 //=======================================================================
881 //=========================================================================
882 /// Write Graphviz-dot description in file
883 void BlackBox::bbWriteDotFileBlackBox(FILE *ff,
884 BlackBox::Pointer parentblackbox,
885 int detail, int level,
890 InputConnectorMapType::iterator i;
892 std::string labelStr;
893 std::string valueStr("");
896 labelStr = bbGetName() ;
898 labelStr = labelStr + "\\n[" +this->bbGetDescriptor()->GetPackage()->GetName()+"::"+ bbGetTypeName() + "]";
900 labelStr = bbGetName();
901 labelStr = labelStr + " [" +this->bbGetDescriptor()->GetPackage()->GetName()+"::"+ bbGetTypeName() + "] ";
904 SubsBrackets(labelStr);
907 labelStr = labelStr + " | {{ ";
908 std::string tempStrTypeName;
911 for ( i = mInputConnectorMap.begin(); i != mInputConnectorMap.end(); ++i )
915 labelStr=labelStr+" | ";
918 if (instanceOrtype==true)
920 valueStr = this->bbGetInputAsString(i->first) + " = ";
922 const BlackBoxInputDescriptor* id = bbGetDescriptor()->GetInputDescriptor(i->first);
923 tempStrTypeName=id->GetTypeName();
924 SubsBrackets(tempStrTypeName);
925 std::string Name(i->first);
927 labelStr=labelStr + "<"+i->first.c_str()+"> " + valueStr + Name.c_str() + " [" + tempStrTypeName.c_str() + "]";
929 labelStr=labelStr+ " } | {";
931 OutputConnectorMapType::iterator ii;
932 for ( ii = mOutputConnectorMap.begin(); ii != mOutputConnectorMap.end(); ++ii )
936 labelStr=labelStr+" | ";
939 if (instanceOrtype==true)
941 valueStr = this->bbGetOutputAsString(ii->first) + " = ";
943 const BlackBoxOutputDescriptor* id = bbGetDescriptor()->GetOutputDescriptor(ii->first);
944 tempStrTypeName=id->GetTypeName();
945 SubsBrackets(tempStrTypeName);
946 std::string Name(ii->first);
948 labelStr=labelStr+"<"+ii->first.c_str()+"> " + valueStr + Name.c_str() + " ["+tempStrTypeName+"]";
950 labelStr = labelStr+ " } }" ;
954 bbWriteDotInputOutputName(ff,true,detail,level);
955 std::string tmp ( bbGetTypeName() );
959 url = this->bbGetDescriptor()->GetPackage()->GetDocRelativeURL() + "#" + tmp;
961 url = this->bbGetDescriptor()->GetPackage()->GetDocURL() + "#" + tmp;
963 fprintf( ff , " [shape=record, URL=\"%s\",label=\"%s\"]%s\n",url.c_str(),labelStr.c_str(),";" );
964 // std::cout << labelStr << std::endl;
967 if (GetThisPointer<BlackBox>()!=parentblackbox){
968 for ( i = mInputConnectorMap.begin(); i != mInputConnectorMap.end(); ++i )
972 Connection* con = i->second->GetConnection();
974 BlackBox::Pointer a=con->GetOriginalBlackBoxFrom();
975 BlackBox::Pointer b=con->GetOriginalBlackBoxTo();
977 a->bbWriteDotInputOutputName(ff,false,detail,level);
980 fprintf(ff,":%s",con->GetOriginalBlackBoxFromOutput().c_str());
983 b->bbWriteDotInputOutputName(ff,true,detail,level);
986 fprintf(ff,":%s",con->GetOriginalBlackBoxToInput().c_str());
988 fprintf(ff,"%s\n",";");
992 } // if parentblackbox
994 //=========================================================================
999 //=========================================================================
1000 void BlackBox::bbShowRelations(BlackBox::Pointer parentblackbox,
1001 int detail, int level
1002 /*,Factory *factory*/ )
1005 if (this->bbGetDescriptor()->GetPackage())
1007 bbtkMessage("Help",1,"Black Box '"<<bbGetName()<<"' <"<<
1008 this->bbGetDescriptor()->GetPackage()->GetName()
1009 <<"::"<<this->bbGetDescriptor()->GetTypeName()<<">"<<std::endl);
1013 bbtkMessage("Help",1,"Black Box <::"<<this->bbGetDescriptor()->GetTypeName()<<">"<<std::endl);
1015 // bbtkMessage("Help",1," "<<GetDescription()<<std::endl);
1016 // bbtkMessage("Help",1," By : "<<GetAuthor()<<std::endl);
1018 std::vector<std::string> iname;
1019 std::vector<std::string> ivalue;
1020 std::vector<std::string> iconn;
1022 InputConnectorMapType::iterator i;
1023 unsigned int namelmax = 0;
1024 unsigned int valuelmax = 0;
1025 // unsigned int connlmax = 0;
1026 for ( i = mInputConnectorMap.begin(); i != mInputConnectorMap.end(); ++i )
1028 iname.push_back(i->first);
1029 if (iname.back().size()>namelmax) namelmax = iname.back().size();
1030 ivalue.push_back(bbGetInputAsString(i->first));
1031 if (ivalue.back().size()>valuelmax) valuelmax = ivalue.back().size();
1033 Connection* con = i->second->GetConnection();
1035 s = con->GetOriginalBlackBoxFrom()->bbGetName();
1037 s += con->GetOriginalBlackBoxFromOutput();
1041 OutputConnectorMapType::iterator o;
1042 std::vector<std::string> oname;
1043 std::vector<std::string> ovalue;
1044 std::vector<std::vector<std::string> > oconn;
1045 for ( o = mOutputConnectorMap.begin(); o != mOutputConnectorMap.end(); ++o )
1047 oname.push_back(o->first);
1048 if (oname.back().size()>namelmax) namelmax = oname.back().size();
1049 ovalue.push_back(bbGetOutputAsString(o->first));
1050 if (ovalue.back().size()>valuelmax) valuelmax = ovalue.back().size();
1051 std::vector<std::string> ss;
1052 const std::vector<Connection*>& con
1053 = o->second->GetConnectionVector();
1054 std::vector<Connection*>::const_iterator c;
1055 for (c=con.begin();c!=con.end();++c)
1058 s = (*c)->GetOriginalBlackBoxTo()->bbGetName();
1060 s += (*c)->GetOriginalBlackBoxToInput();
1063 oconn.push_back(ss);
1067 bbtkMessage("Help",1," * Inputs : "<<std::endl);
1069 bbtkMessage("Help",1," * No inputs"<<std::endl);
1071 std::vector<std::string>::iterator i1,i2,i3;
1072 for (i1=iname.begin(),i2=ivalue.begin(),i3=iconn.begin();
1073 i1!=iname.end(),i2!=ivalue.end(),i3!=iconn.end();
1076 std::string name(*i1);
1078 name.append(1+namelmax-name.size(),' ');
1079 std::string value(*i2);
1081 value.append(1+valuelmax-value.size(),' ');
1083 bbtkMessage("Help",1," '"<<name<<" = '"<<value<<" <-- '"<<*i3<<"'"<<std::endl);
1085 bbtkMessage("Help",1," '"<<name<<" = '"<<value<<std::endl);
1089 bbtkMessage("Help",1," * Outputs : "<<std::endl);
1091 bbtkMessage("Help",1," * No outputs"<<std::endl);
1093 std::vector<std::vector<std::string> >::iterator i4;
1095 for (i1=oname.begin(),i2=ovalue.begin(),i4=oconn.begin();
1096 i1!=oname.end(),i2!=ovalue.end(),i4!=oconn.end();
1099 std::string name(*i1);
1101 name.append(1+namelmax-name.size(),' ');
1102 std::string value(*i2);
1104 value.append(1+valuelmax-value.size(),' ');
1106 bbtkMessage("Help",1," '"<<name<<" = '"<<value<<std::endl);
1109 std::string pref = " '"+name+" = '"+value;
1110 for (i3=i4->begin();i3!=i4->end();++i3)
1112 bbtkMessage("Help",1,pref<<" --> '"<<*i3<<"'"<<std::endl);
1113 pref.replace(0,pref.size(),pref.size(),' ');
1119 //=========================================================================
1122 //=========================================================================
1123 void BlackBox::bbGlobalProcessExecutionList()
1125 bbtkDebugMessageInc("process",3,
1126 "=> BlackBox::bbGlobalProcessExecutionList()"
1129 std::set<BlackBox::Pointer>::iterator i;
1130 for (i=bbmgExecutionList.begin();
1131 i!=bbmgExecutionList.end();
1134 bbtkDebugMessage("process",4,
1135 " -> Executing "<<(*i)->bbGetFullName()<<std::endl);
1136 (*i)->bbExecute(true);
1139 bbmgExecutionList.clear();
1140 bbtkDebugMessageDec("process",3,
1141 "<= BlackBox::bbGlobalProcessExecutionList()"
1146 //=========================================================================
1148 bool BlackBox::bbGlobalGetSomeBoxExecuting()
1150 return bbmgSomeBoxExecuting;
1153 void BlackBox::bbGlobalSetSomeBoxExecuting(bool b)
1155 bbmgSomeBoxExecuting = b;
1158 void BlackBox::bbGlobalSetFreezeExecution(bool b)
1160 bbmgFreezeExecution = b;
1163 bool BlackBox::bbGlobalGetFreezeExecution()
1165 return bbmgFreezeExecution;
1168 void BlackBox::bbGlobalAddToExecutionList( BlackBox::Pointer b )
1170 bbmgExecutionList.insert(b);
1174 //=========================================================================
1176 //=========================================================================
1177 void BlackBox::Check(bool recursive)
1179 bbtkMessage("debug",1,"*** Checking Black Box "<<(void*)this<<" ["<<bbGetFullName()
1180 <<"] ... OK"<<std::endl);
1182 //=========================================================================
1184 void BlackBox::bbUserOnShowWidget(std::string nameInput)
1186 bbtk::BlackBoxInputConnector *cc;
1187 cc = this->bbGetInputConnectorMap().find( nameInput.c_str() )->second;
1188 if (cc->GetConnection()!=NULL)
1190 cc->GetConnection()->GetBlackBoxFrom()->bbUserOnShow();
1196 } // EO namespace bbtk