1 /*=========================================================================
4 Module: $RCSfile: bbtkBlackBox.cxx,v $
6 Date: $Date: 2008/05/06 13:45:12 $
7 Version: $Revision: 1.17 $
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);
148 Wx::BeginBusyCursor();
150 // If execution frozen : return
151 if (bbGlobalGetFreezeExecution())
153 bbtkDebugMessage("process",2,
154 " -> FreezeExecution global flag is 'true' : abort execution"<<std::endl);
157 // If force is true then update is triggered even if the box is UPTODATE
158 if (force) bbSetModifiedStatus();
160 // Calls the main recursive update method
161 bbBackwardUpdate(Connection::Pointer());
165 bbtkDebugMessageDec("process",2,
166 "<= BlackBox::bbExecute() ["
167 <<bbGetFullName()<<"]"<<std::endl);
169 //=========================================================================
171 //=========================================================================
172 std::string BlackBox::bbGetFullName() const
174 return this->bbGetNameWithParent()+"<"+this->bbGetDescriptor()->GetTypeName()+">";
176 //=========================================================================
180 //=========================================================================
181 /// Returns the name with the name of the parent prepended if any
182 std::string BlackBox::bbGetNameWithParent() const
184 if (bbmParent.lock())
186 return bbmParent.lock()->bbGetNameWithParent() + ":" + bbmName;
193 //=========================================================================
195 //=========================================================================
196 /// Prints the Help on the BlackBox type
197 void BlackBox::bbGetHelp(bool full) const
199 bbGetDescriptor()->GetHelp(full);
201 //=========================================================================
204 //=========================================================================
205 /// Returns true if the UserBlackBox has an input of name name
206 bool BlackBox::bbHasInput(const std::string& name) const
208 bbtkDebugMessageInc("Kernel",8,
209 "BlackBox::bbHasInput(\""
210 <<name<<"\") ["<<bbGetFullName()<<"]"
212 bool r = ( bbGetDescriptor()->GetInputDescriptorMap().find(name)
213 != bbGetDescriptor()->GetInputDescriptorMap().end());
214 bbtkDebugDecTab("Kernel",8);
217 //=========================================================================
220 //=========================================================================
221 /// Returns true if the UserBlackBox has an output of name name
222 bool BlackBox::bbHasOutput(const std::string& name) const
224 bbtkDebugMessageInc("Kernel",8,"BlackBox::bbHasOutput(\""
225 <<name<<"\") ["<<bbGetFullName()<<"]"<<std::endl);
226 bool r = ( bbGetDescriptor()->GetOutputDescriptorMap().find(name)
227 != bbGetDescriptor()->GetOutputDescriptorMap().end());
228 bbtkDebugDecTab("Kernel",8);
231 //=========================================================================
234 //=========================================================================
235 /// Gets the output type of a given name
236 TypeInfo BlackBox::bbGetOutputType( const std::string &name ) const
238 bbtkDebugMessageInc("Kernel",8,
239 "BlackBox::bbGetOutputType(\""
240 <<name<<"\") ["<<bbGetFullName()<<"]"<<std::endl);
241 TypeInfo r = bbGetDescriptor()->GetOutputDescriptor(name)->GetTypeInfo();
242 bbtkDebugDecTab("Kernel",8);
245 //=========================================================================
247 //=========================================================================
248 /// Gets the input type of a given name
249 TypeInfo BlackBox::bbGetInputType( const std::string &name ) const
251 bbtkDebugMessageInc("Kernel",8,
252 "BlackBox::bbGetInputType(\""
253 <<name<<"\") ["<<bbGetFullName()<<"]"<<std::endl);
254 TypeInfo r = bbGetDescriptor()->GetInputDescriptor(name)->GetTypeInfo();
255 bbtkDebugDecTab("Kernel",8);
258 //=========================================================================
261 //=========================================================================
262 /// Allocates the i/o connectors of the black box
263 void BlackBox::bbAllocateConnectors()
265 bbtkDebugMessageInc("Kernel",8,
266 "BlackBox::bbAllocateConnectors() ["
267 <<bbGetFullName()<<"]"
269 const BlackBoxDescriptor::InputDescriptorMapType& imap
270 = bbGetDescriptor()->GetInputDescriptorMap();
271 BlackBoxDescriptor::InputDescriptorMapType::const_iterator i;
272 for ( i = imap.begin(); i != imap.end(); ++i )
274 bbtkDebugMessage("Kernel",8,"* Allocate \""<<i->first<<"\""<<std::endl);
275 bbGetInputConnectorMap()[i->second->GetName()]
276 = new BlackBoxInputConnector(GetThisPointer<BlackBox>());
278 const BlackBoxDescriptor::OutputDescriptorMapType& omap
279 = bbGetDescriptor()->GetOutputDescriptorMap();
280 BlackBoxDescriptor::OutputDescriptorMapType::const_iterator o;
281 for ( o = omap.begin(); o != omap.end(); ++o )
283 bbtkDebugMessage("Kernel",8,"* Allocate \""<<o->first<<"\""<<std::endl);
284 bbGetOutputConnectorMap()[o->second->GetName()]
285 = new BlackBoxOutputConnector();
287 bbtkDebugDecTab("Kernel",8);
289 //=========================================================================
292 //=========================================================================
293 /// Desallocates the i/o connectors of the black box
294 void BlackBox::bbDesallocateConnectors()
296 bbtkDebugMessageInc("Kernel",8,
297 "BlackBox::bbDesallocateConnectors()"
300 InputConnectorMapType::const_iterator i;
301 for ( i = bbGetInputConnectorMap().begin();
302 i != bbGetInputConnectorMap().end(); ++i )
304 bbtkDebugMessage("Kernel",8,"* Delete \""<<i->first<<"\""<<std::endl);
307 OutputConnectorMapType::const_iterator o;
308 for ( o = bbGetOutputConnectorMap().begin();
309 o != bbGetOutputConnectorMap().end(); ++o )
311 bbtkDebugMessage("Kernel",8,"* Delete \""<<o->first<<"\""<<std::endl);
315 bbtkDebugDecTab("Kernel",8);
318 //=========================================================================
321 //=========================================================================
322 /// Copies the input / output values from another box
323 void BlackBox::bbCopyIOValues(BlackBox& from)
325 bbtkDebugMessageInc("Kernel",9,
326 "BlackBox::bbCopyIOValues("
327 <<from.bbGetFullName()<<") ["
328 <<bbGetFullName()<<"]"<<std::endl);
329 // copies the input values
330 const BlackBoxDescriptor::InputDescriptorMapType& imap
331 = bbGetDescriptor()->GetInputDescriptorMap();
332 BlackBoxDescriptor::InputDescriptorMapType::const_iterator i;
333 for ( i = imap.begin(); i != imap.end(); ++i )
335 if (! i->second->GetCopyConstruct() ) continue;
336 std::string input = i->second->GetName();
337 this->bbSetInput(input, from.bbGetInput(input) );
339 // copies the output values
340 const BlackBoxDescriptor::OutputDescriptorMapType& omap
341 = bbGetDescriptor()->GetOutputDescriptorMap();
342 BlackBoxDescriptor::OutputDescriptorMapType::const_iterator o;
343 for ( o = omap.begin(); o != omap.end(); ++o )
345 if (! o->second->GetCopyConstruct() ) continue;
346 std::string output = o->second->GetName();
347 this->bbSetOutput(output, from.bbGetOutput(output) );
350 bbtkDebugDecTab("Kernel",9);
353 //=========================================================================
357 //=========================================================================
358 bool BlackBox::bbCanReact() const
360 return ( bbGlobalGetSomeBoxExecuting()
361 #ifdef _USE_WXWIDGETS_
362 || Wx::IsSomeWindowAlive()
366 //=========================================================================
370 //=========================================================================
371 /// User overloadable destruction method of a black box
372 void BlackBox::bbUserDelete()
374 bbtkDebugMessage("process",5,
375 "=> BlackBox::bbUserDelete() ["
376 <<bbGetFullName()<<"]"
377 <<" : not overloaded; using standard deletion"
381 //=========================================================================
384 //=========================================================================
385 BlackBox::BoxProcessModeValue BlackBox::bbGetBoxProcessModeValue() const
387 const std::string& p = bbmBoxProcessMode;
389 (p == "P") || (p == "p") ||
390 (p == "Pipeline") || (p == "pipeline") ) return Pipeline;
392 (p == "A") || (p == "a") ||
393 (p == "Always") || (p == "always") ) return Always;
395 (p == "R") || (p == "r") ||
396 (p == "Reactive") || (p == "reactive") ) return Reactive;
397 bbtkError(bbGetFullName()<<" : BoxProcessMode value '"<<p
398 <<"' unknown. Possible values : "
399 <<"'0'/'P'/'p'/'Pipeline'/'pipeline' | "
400 <<"'1'/'A'/'a'/'Always'/'always' | "
401 <<"'2'/'R'/'r'/'Reactive'/'reactive'"<<std::endl);
403 //=========================================================================
405 //=========================================================================
406 bool BlackBox::bbBoxProcessModeIsReactive() const
408 return (bbGetBoxProcessModeValue() == Reactive);
410 //=========================================================================
412 //=========================================================================
413 bool BlackBox::bbBoxProcessModeIsAlways() const
415 return (bbGetBoxProcessModeValue() == Always);
417 //=========================================================================
419 //=========================================================================
420 /// Signals that the BlackBox has been modified
421 void BlackBox::bbSetModifiedStatus(BlackBoxInputConnector* c)
423 bbtkDebugMessage("modified",1,
424 "==> BlackBox::bbSetModifiedStatus("<<c<<") ["
425 <<bbGetFullName()<<"]"<<std::endl);
427 if ( (c==bbGetInputConnectorMap().find("WinHide")->second) )
428 // && (bbCanReact()))
430 bbtkDebugMessage("modified",2,
431 "-> Hide triggered by WinHide input change"
433 this->bbHideWindow();
434 this->bbSetStatus(MODIFIED);
438 if ( ( bbBoxProcessModeIsReactive() ||
439 (c==bbGetInputConnectorMap().find("BoxExecute")->second))
442 bbtkDebugMessage("modified",2,
443 "-> Execution triggered by Reactive mode or BoxExecute input change"<<std::endl);
444 this->bbSetStatus(MODIFIED);
445 bbGlobalAddToExecutionList( GetThisPointer<BlackBox>() );
447 else if ( bbGetStatus() == MODIFIED ) //! this->bbIsUptodate())
449 bbtkDebugMessage("modified",2,"-> Already modified"<<std::endl);
454 bbtkDebugMessage("modified",2,"-> Status set to modified"<<std::endl);
455 this->bbSetStatus(MODIFIED);
458 this->bbSignalOutputModification(false);
461 bbtkDebugMessageDec("process",5,
462 "<= BlackBox::bbSetModifiedStatus("<<c<<") ["
463 <<bbGetFullName()<<"]"<<std::endl);
466 //=========================================================================
468 //=========================================================================
469 void BlackBox::bbSignalOutputModification(bool reaction)
471 bbtkDebugMessageInc("process",5,
472 "=> BlackBox::bbSignalOutputModification() ["
473 <<bbGetFullName()<<"]"<<std::endl);
475 OutputConnectorMapType::iterator change = bbGetOutputConnectorMap().end();
476 OutputConnectorMapType::iterator i;
477 for ( i = bbGetOutputConnectorMap().begin();
478 i != bbGetOutputConnectorMap().end(); ++i) {
479 /* if ( i->first == "BoxChange" )
485 i->second->SetModifiedStatus();
487 // if (change != bbGetOutputConnectorMap().end())
488 // change->second->SetModifiedStatus();
490 if (reaction) bbGlobalProcessExecutionList();
492 bbtkDebugMessageDec("process",5,
493 "<= BlackBox::bbSignalOutputModification() ["
494 <<bbGetFullName()<<"]"<<std::endl);
497 //=========================================================================
498 //=========================================================================
499 void BlackBox::bbSignalOutputModification(const std::string& output,
502 bbtkDebugMessageInc("process",5,
503 "=> BlackBox::bbSignalOutputModification("
505 <<bbGetFullName()<<"]"<<std::endl);
507 OutputConnectorMapType::iterator i = bbGetOutputConnectorMap().find(output);
508 if ( i == bbGetOutputConnectorMap().end() )
510 bbtkError("BlackBox["<<bbGetFullName()<<"]::bbSignalOutputModification("<<output<<") : unknown output");
512 i->second->SetModifiedStatus();
513 // Has to notify the output "BoxChange" also
514 if (output != "BoxChange")
516 i = bbGetOutputConnectorMap().find("BoxChange");
517 if ( i != bbGetOutputConnectorMap().end() )
519 i->second->SetModifiedStatus();
522 if (reaction) bbGlobalProcessExecutionList();
524 bbtkDebugMessageDec("process",5,
525 "<= BlackBox::bbSignalOutputModification("
527 <<bbGetFullName()<<"]"<<std::endl);
530 //=========================================================================
531 //=========================================================================
532 void BlackBox::bbSignalOutputModification(const std::vector<std::string>& output,
535 bbtkDebugMessageInc("process",5,
536 "=> BlackBox::bbSignalOutputModification(vector of outputs) ["
537 <<bbGetFullName()<<"]"<<std::endl);
538 OutputConnectorMapType::iterator i;
539 std::vector<std::string>::const_iterator o;
540 for (o=output.begin();o!=output.end();++o)
542 // the output "BoxChange" must be signaled **AFTER** all others
543 if (*o == "BoxChange") continue;
544 // Look for the connector
545 i = bbGetOutputConnectorMap().find(*o);
546 if ( i == bbGetOutputConnectorMap().end() )
548 bbtkError("BlackBox["<<bbGetFullName()<<"]::bbSignalOutputModification("<<*o<<") : unknown output");
550 i->second->SetModifiedStatus();
552 // Has to notify the output "BoxChange" also
553 i = bbGetOutputConnectorMap().find("BoxChange");
554 if ( i != bbGetOutputConnectorMap().end() )
556 i->second->SetModifiedStatus();
558 if (reaction) bbGlobalProcessExecutionList();
560 bbtkDebugMessageDec("process",5,
561 "<= BlackBox::bbSignalOutputModification(vector of outputs) ["
562 <<bbGetFullName()<<"]"<<std::endl);
565 //=========================================================================
567 //=========================================================================
568 /// Updates the BlackBox inputs
569 /// \returns UPTODATE if all inputs are in UPTODATE status after update
571 IOStatus BlackBox::bbUpdateInputs(bool excludeParent)
573 bbtkDebugMessageInc("process",4,
574 "=> BlackBox::bbUpdateInputs() ["
575 <<bbGetFullName()<<"]"
578 IOStatus s = UPTODATE;
580 InputConnectorMapType::iterator i;
581 for ( i = bbGetInputConnectorMap().begin();
582 i!= bbGetInputConnectorMap().end(); ++i)
584 if (excludeParent && (i->first=="WinParent")) continue;
585 if (i->first=="WinHide") continue;
586 // If input type is Void : no recurse
587 //if ( bbGetDescriptor()->GetInputDescriptor(i->first)->GetTypeInfo()
591 IOStatus t = i->second->BackwardUpdate();
592 if (t==MODIFIED) s = MODIFIED;
595 bbtkDebugMessageDec("process",4,
596 "<= BlackBox::bbUpdateInputs() ["
597 <<bbGetFullName()<<"]"
603 //=========================================================================
606 //=========================================================================
607 /// Connects the input <name> to the connection c
608 void BlackBox::bbConnectInput( const std::string& name, Connection* c)
610 bbtkDebugMessage("connection",2,
611 "==> BlackBox::bbConnectInput(\""
612 <<name<<"\","<<c->GetFullName()<<") ["
613 <<bbGetFullName()<<"]"
617 InputConnectorMapType::iterator i = bbGetInputConnectorMap().find(name);
618 if (i==bbGetInputConnectorMap().end())
620 bbtkError("no input called '"<<name<<"'");
622 i->second->SetConnection(c);
624 bbtkDebugMessage("connection",2,
625 "<== BlackBox::bbConnectInput(\""
626 <<name<<"\","<<c->GetFullName()<<") ["
627 <<bbGetFullName()<<"]"
629 // bbSetModifiedStatus();
632 //=========================================================================
635 //=========================================================================
636 /// Connects the output <name> to the connection c
637 void BlackBox::bbConnectOutput( const std::string& name, Connection* c)
639 bbtkDebugMessage("connection",2,
640 "==> BlackBox::bbConnectOutput(\""<<name<<"\","
641 <<c->GetFullName()<<") ["
642 <<bbGetFullName()<<"]"<<std::endl);
644 OutputConnectorMapType::iterator i = bbGetOutputConnectorMap().find(name);
645 if (i==bbGetOutputConnectorMap().end())
647 bbtkError("no output called '"<<name<<"'");
649 i->second->SetConnection(c);
651 bbtkDebugMessage("connection",2,
652 "<== BlackBox::bbConnectOutput(\""<<name<<"\","
653 <<c->GetFullName()<<") ["
654 <<bbGetFullName()<<"]"<<std::endl);
657 //=========================================================================
660 //=========================================================================
661 /// Disconnects the input <name> from the connection c
662 void BlackBox::bbDisconnectInput( const std::string& name, Connection* c)
665 bbtkDebugMessage("connection",2,
666 "==> BlackBox::bbDisconnectInput(\""<<name
667 <<"\","<<c->GetFullName()<<") ["
668 <<bbGetFullName()<<"]"
674 bbtkDebugMessage("connection",2,"c==0"<<std::endl);
678 InputConnectorMapType::iterator i = bbGetInputConnectorMap().find(name);
679 if (i==bbGetInputConnectorMap().end())
681 bbtkError("no input called '"<<name<<"'");
683 i->second->UnsetConnection(c);
685 bbtkDebugMessage("connection",2,
686 "<== BlackBox::bbDisconnectInput(\""<<name
687 <<"\","<<c->GetFullName()<<") ["
688 <<bbGetFullName()<<"]"
692 //=========================================================================
695 //=========================================================================
696 /// Disconnects the output <name> from the connection c
697 void BlackBox::bbDisconnectOutput( const std::string& name, Connection* c)
699 bbtkDebugMessage("connection",2,
700 "==> BlackBox::bbDisconnectOutput(\""<<name
701 <<"\","<<c->GetFullName()<<") ["
702 <<bbGetFullName()<<"]"
707 bbtkDebugMessage("connection",2,"c==0"<<std::endl);
711 OutputConnectorMapType::iterator i = bbGetOutputConnectorMap().find(name);
712 if (i==bbGetOutputConnectorMap().end())
714 bbtkError("no output called '"<<name<<"'");
716 i->second->UnsetConnection(c);
718 bbtkDebugMessage("connection",2,
719 "<== BlackBox::bbDisconnectOutput(\""<<name
720 <<"\","<<c->GetFullName()<<") ["
721 <<bbGetFullName()<<"]"
724 //=========================================================================
727 //=========================================================================
729 void BlackBox::bbWriteDotInputOutputName(FILE *ff,bool inputoutput,int detail, int level)
731 fprintf(ff,"%s%p",bbGetTypeName().c_str(),this);
733 //=========================================================================
736 //=========================================================================
737 std::string BlackBox::bbGetOutputAsString( const std::string &output )
740 // Looks for the adaptor
741 if (bbGetOutputType(output).name() != typeid(std::string).name() )
744 Package::Pointer p = bbGetDescriptor()->GetPackage();
745 if ((p != 0) && ( ! p->GetFactorySet().empty() ) )
747 Factory::Pointer f = p->GetFactorySet().begin()->lock();
752 bbGetOutputType(output),
755 } catch (bbtk::Exception e)
760 a->bbSetInput("In",bbGetOutput(output));
762 v = a->bbGetOutput("Out").unsafe_get<std::string>() ;
764 v="? (no adaptor found)";
769 v="? (no factory found)";
775 v = bbGetOutput(output).unsafe_get<std::string>() ;
779 //=========================================================================
781 //=========================================================================
782 std::string BlackBox::bbGetInputAsString( const std::string &input )
785 // Looks for the adaptor
786 if (bbGetInputType(input) != typeid(std::string))
789 Package::Pointer p = bbGetDescriptor()->GetPackage();
790 if ((p != 0) && ( ! p->GetFactorySet().empty() ) )
792 Factory::Pointer f = p->GetFactorySet().begin()->lock();
797 bbGetInputType(input),
800 }catch (bbtk::Exception e)
806 a->bbSetInput("In",bbGetInput(input));
808 v = a->bbGetOutput("Out").unsafe_get<std::string>() ;
812 v="? (no adaptor found)";
817 v="? (no factory found)";
822 v = bbGetInput(input).unsafe_get<std::string>() ;
826 //=======================================================================
828 //=======================================================================
829 // Replaces substrings "<" by "["
830 void SubsBrackets ( std::string& s )
832 // std::cout << "BEFORE=["<<s<<"]"<<std::endl;
834 std::string::size_type pos = 0;
837 while ( pos != std::string::npos )
839 // std::cout << "*** find one "<<std::endl;
840 s.replace(pos,1,cr,1);
841 pos = s.find(ss, pos);
847 while ( pos != std::string::npos )
849 // std::cout << "*** find one "<<std::endl;
850 s.replace(pos,1,cr,1);
851 pos = s.find(ss, pos);
857 while ( pos != std::string::npos )
859 // std::cout << "*** find one "<<std::endl;
860 s.replace(pos,1,cr,1);
861 pos = s.find(ss, pos);
862 } // std::cout << "AFTER=["<<s<<"]"<<std::endl;
864 //=======================================================================
866 //=========================================================================
867 /// Write Graphviz-dot description in file
868 void BlackBox::bbWriteDotFileBlackBox(FILE *ff,
869 BlackBox::Pointer parentblackbox,
870 int detail, int level,
875 InputConnectorMapType::iterator i;
877 std::string labelStr;
878 std::string valueStr("");
881 labelStr = bbGetName() ;
883 labelStr = labelStr + "\\n[" +this->bbGetDescriptor()->GetPackage()->GetName()+"::"+ bbGetTypeName() + "]";
885 labelStr = bbGetName();
886 labelStr = labelStr + " [" +this->bbGetDescriptor()->GetPackage()->GetName()+"::"+ bbGetTypeName() + "] ";
889 SubsBrackets(labelStr);
892 labelStr = labelStr + " | {{ ";
893 std::string tempStrTypeName;
896 for ( i = mInputConnectorMap.begin(); i != mInputConnectorMap.end(); ++i )
900 labelStr=labelStr+" | ";
903 if (instanceOrtype==true)
905 valueStr = this->bbGetInputAsString(i->first) + " = ";
907 const BlackBoxInputDescriptor* id = bbGetDescriptor()->GetInputDescriptor(i->first);
908 tempStrTypeName=id->GetTypeName();
909 SubsBrackets(tempStrTypeName);
910 std::string Name(i->first);
912 labelStr=labelStr + "<"+i->first.c_str()+"> " + valueStr + Name.c_str() + " [" + tempStrTypeName.c_str() + "]";
914 labelStr=labelStr+ " } | {";
916 OutputConnectorMapType::iterator ii;
917 for ( ii = mOutputConnectorMap.begin(); ii != mOutputConnectorMap.end(); ++ii )
921 labelStr=labelStr+" | ";
924 if (instanceOrtype==true)
926 valueStr = this->bbGetOutputAsString(ii->first) + " = ";
928 const BlackBoxOutputDescriptor* id = bbGetDescriptor()->GetOutputDescriptor(ii->first);
929 tempStrTypeName=id->GetTypeName();
930 SubsBrackets(tempStrTypeName);
931 std::string Name(ii->first);
933 labelStr=labelStr+"<"+ii->first.c_str()+"> " + valueStr + Name.c_str() + " ["+tempStrTypeName+"]";
935 labelStr = labelStr+ " } }" ;
939 bbWriteDotInputOutputName(ff,true,detail,level);
940 std::string tmp ( bbGetTypeName() );
944 url = this->bbGetDescriptor()->GetPackage()->GetDocRelativeURL() + "#" + tmp;
946 url = this->bbGetDescriptor()->GetPackage()->GetDocURL() + "#" + tmp;
948 fprintf( ff , " [shape=record, URL=\"%s\",label=\"%s\"]%s\n",url.c_str(),labelStr.c_str(),";" );
949 // std::cout << labelStr << std::endl;
952 if (GetThisPointer<BlackBox>()!=parentblackbox){
953 for ( i = mInputConnectorMap.begin(); i != mInputConnectorMap.end(); ++i )
957 Connection* con = i->second->GetConnection();
959 BlackBox::Pointer a=con->GetOriginalBlackBoxFrom();
960 BlackBox::Pointer b=con->GetOriginalBlackBoxTo();
962 a->bbWriteDotInputOutputName(ff,false,detail,level);
965 fprintf(ff,":%s",con->GetOriginalBlackBoxFromOutput().c_str());
968 b->bbWriteDotInputOutputName(ff,true,detail,level);
971 fprintf(ff,":%s",con->GetOriginalBlackBoxToInput().c_str());
973 fprintf(ff,"%s\n",";");
977 } // if parentblackbox
979 //=========================================================================
984 //=========================================================================
985 void BlackBox::bbShowRelations(BlackBox::Pointer parentblackbox,
986 int detail, int level
987 /*,Factory *factory*/ )
990 if (this->bbGetDescriptor()->GetPackage())
992 bbtkMessage("Help",1,"Black Box '"<<bbGetName()<<"' <"<<
993 this->bbGetDescriptor()->GetPackage()->GetName()
994 <<"::"<<this->bbGetDescriptor()->GetTypeName()<<">"<<std::endl);
998 bbtkMessage("Help",1,"Black Box <::"<<this->bbGetDescriptor()->GetTypeName()<<">"<<std::endl);
1000 // bbtkMessage("Help",1," "<<GetDescription()<<std::endl);
1001 // bbtkMessage("Help",1," By : "<<GetAuthor()<<std::endl);
1003 std::vector<std::string> iname;
1004 std::vector<std::string> ivalue;
1005 std::vector<std::string> iconn;
1007 InputConnectorMapType::iterator i;
1008 unsigned int namelmax = 0;
1009 unsigned int valuelmax = 0;
1010 unsigned int connlmax = 0;
1011 for ( i = mInputConnectorMap.begin(); i != mInputConnectorMap.end(); ++i )
1013 iname.push_back(i->first);
1014 if (iname.back().size()>namelmax) namelmax = iname.back().size();
1015 ivalue.push_back(bbGetInputAsString(i->first));
1016 if (ivalue.back().size()>valuelmax) valuelmax = ivalue.back().size();
1018 Connection* con = i->second->GetConnection();
1020 s = con->GetOriginalBlackBoxFrom()->bbGetName();
1022 s += con->GetOriginalBlackBoxFromOutput();
1026 OutputConnectorMapType::iterator o;
1027 std::vector<std::string> oname;
1028 std::vector<std::string> ovalue;
1029 std::vector<std::vector<std::string> > oconn;
1030 for ( o = mOutputConnectorMap.begin(); o != mOutputConnectorMap.end(); ++o )
1032 oname.push_back(o->first);
1033 if (oname.back().size()>namelmax) namelmax = oname.back().size();
1034 ovalue.push_back(bbGetOutputAsString(o->first));
1035 if (ovalue.back().size()>valuelmax) valuelmax = ovalue.back().size();
1036 std::vector<std::string> ss;
1037 const std::vector<Connection*>& con
1038 = o->second->GetConnectionVector();
1039 std::vector<Connection*>::const_iterator c;
1040 for (c=con.begin();c!=con.end();++c)
1043 s = (*c)->GetOriginalBlackBoxTo()->bbGetName();
1045 s += (*c)->GetOriginalBlackBoxToInput();
1048 oconn.push_back(ss);
1052 bbtkMessage("Help",1," * Inputs : "<<std::endl);
1054 bbtkMessage("Help",1," * No inputs"<<std::endl);
1056 std::vector<std::string>::iterator i1,i2,i3;
1057 for (i1=iname.begin(),i2=ivalue.begin(),i3=iconn.begin();
1058 i1!=iname.end(),i2!=ivalue.end(),i3!=iconn.end();
1061 std::string name(*i1);
1063 name.append(1+namelmax-name.size(),' ');
1064 std::string value(*i2);
1066 value.append(1+valuelmax-value.size(),' ');
1068 bbtkMessage("Help",1," '"<<name<<" = '"<<value<<" <-- '"<<*i3<<"'"<<std::endl);
1070 bbtkMessage("Help",1," '"<<name<<" = '"<<value<<std::endl);
1074 bbtkMessage("Help",1," * Outputs : "<<std::endl);
1076 bbtkMessage("Help",1," * No outputs"<<std::endl);
1078 std::vector<std::vector<std::string> >::iterator i4;
1080 for (i1=oname.begin(),i2=ovalue.begin(),i4=oconn.begin();
1081 i1!=oname.end(),i2!=ovalue.end(),i4!=oconn.end();
1084 std::string name(*i1);
1086 name.append(1+namelmax-name.size(),' ');
1087 std::string value(*i2);
1089 value.append(1+valuelmax-value.size(),' ');
1091 bbtkMessage("Help",1," '"<<name<<" = '"<<value<<std::endl);
1094 std::string pref = " '"+name+" = '"+value;
1095 for (i3=i4->begin();i3!=i4->end();++i3)
1097 bbtkMessage("Help",1,pref<<" --> '"<<*i3<<"'"<<std::endl);
1098 pref.replace(0,pref.size(),pref.size(),' ');
1104 //=========================================================================
1107 //=========================================================================
1108 void BlackBox::bbGlobalProcessExecutionList()
1110 bbtkDebugMessageInc("process",3,
1111 "=> BlackBox::bbGlobalProcessExecutionList()"
1114 std::set<BlackBox::Pointer>::iterator i;
1115 for (i=bbmgExecutionList.begin();
1116 i!=bbmgExecutionList.end();
1119 bbtkDebugMessage("process",4,
1120 " -> Executing "<<(*i)->bbGetFullName()<<std::endl);
1121 (*i)->bbExecute(true);
1124 bbmgExecutionList.clear();
1125 bbtkDebugMessageDec("process",3,
1126 "<= BlackBox::bbGlobalProcessExecutionList()"
1131 //=========================================================================
1133 bool BlackBox::bbGlobalGetSomeBoxExecuting()
1135 return bbmgSomeBoxExecuting;
1138 void BlackBox::bbGlobalSetSomeBoxExecuting(bool b)
1140 bbmgSomeBoxExecuting = b;
1143 void BlackBox::bbGlobalSetFreezeExecution(bool b)
1145 bbmgFreezeExecution = b;
1148 bool BlackBox::bbGlobalGetFreezeExecution()
1150 return bbmgFreezeExecution;
1153 void BlackBox::bbGlobalAddToExecutionList( BlackBox::Pointer b )
1155 bbmgExecutionList.insert(b);
1159 //=========================================================================
1160 // Static members initialization
1162 bool BlackBox::bbmgSomeBoxExecuting = false;
1163 bool BlackBox::bbmgFreezeExecution = false;
1164 std::set<BlackBox*> BlackBox::bbmgExecutionList;
1166 //=========================================================================
1168 //=========================================================================
1169 void BlackBox::Check(bool recursive)
1171 bbtkMessage("debug",1,"*** Checking Black Box "<<(void*)this<<" ["<<bbGetFullName()
1172 <<"] ... OK"<<std::endl);
1174 //=========================================================================
1178 } // EO namespace bbtk