2 # ---------------------------------------------------------------------
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
10 # This software is governed by the CeCILL-B license under French law and
11 # abiding by the rules of distribution of free software. You can use,
12 # modify and/ or redistribute the software under the terms of the CeCILL-B
13 # license as circulated by CEA, CNRS and INRIA at the following URL
14 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
15 # or in the file LICENSE.txt.
17 # As a counterpart to the access to the source code and rights to copy,
18 # modify and redistribute granted by the license, users are provided only
19 # with a limited warranty and the software's author, the holder of the
20 # economic rights, and the successive licensors have only limited
23 # The fact that you are presently reading this means that you have had
24 # knowledge of the CeCILL-B license and that you accept its terms.
25 # ------------------------------------------------------------------------ */
28 /*=========================================================================
30 Module: $RCSfile: bbtkComplexBlackBox.cxx,v $
32 Date: $Date: 2012/11/16 08:49:01 $
33 Version: $Revision: 1.33 $
34 =========================================================================*/
40 * \brief class bbtk::ComplexBlackBox : user defined complex black boxes
42 #include "bbtkComplexBlackBox.h"
44 //#include "bbtkBlackBoxDescriptor.h"
45 //#include "bbtkFactory.h"
46 #include "bbtkConfigurationFile.h"
51 //==========================================================================
52 /// Creates a new complex black box
53 ComplexBlackBox::Pointer ComplexBlackBox::New(const std::string& name,
54 ComplexBlackBoxDescriptor::Pointer desc)
56 bbtkDebugMessage("object",1,"##> ComplexBlackBox::New('"<<name<<"','"<< desc->GetTypeName()<<"')" <<bbtkendl);
57 ComplexBlackBox::Pointer p = MakeBlackBoxPointer(new ComplexBlackBox(name,desc));
58 bbtkDebugMessage("object",2,"<## ComplexBlackBox::New('"<<name<<"','"<< desc->GetTypeName()<<"')" <<bbtkendl);
61 //==========================================================================
63 //=======================================================================
64 /// Usefull constructor
65 ComplexBlackBox::ComplexBlackBox(const std::string &name,
66 ComplexBlackBoxDescriptor::Pointer desc)
69 mLockedDescriptor(desc),
72 bbtkBlackBoxDebugMessage("object",3,
73 "##> ComplexBlackBox(\""
74 <<name<<"\")"<<std::endl);
75 bbAllocateConnectors();
76 bbtkBlackBoxDebugMessage("object",3,
77 "<## ComplexBlackBox(\""
78 <<name<<"\")"<<std::endl);
80 //=======================================================================
82 //=======================================================================
83 /// Constructor from an existing box (copy) with a new name
84 ComplexBlackBox::ComplexBlackBox(ComplexBlackBox& from,
85 const std::string &name)
86 : BlackBox(from,name),
87 // The locked descriptor is copied from the unlocked one
88 // to make the box a non-prototype !!
89 mLockedDescriptor(from.mDescriptor),
90 mDescriptor(from.mDescriptor),
91 mExecutionList(from.mExecutionList)
93 bbtkBlackBoxDebugMessage("object",3,
94 "##> ComplexBlackBox(\""
95 <<from.bbGetName()<<"\",\""
96 <<name<<"\")"<<std::endl);
97 bbtkBlackBoxDebugMessage("object",4," * Cloning Black Boxes"<<std::endl);
99 // We have to make the shared_ptr on this because it is used
100 // in bbUnsafeAddBlackBox !
101 MakeBlackBoxPointer(this,true);
103 BlackBoxMapType::const_iterator i;
104 for ( i = from.mBlackBoxMap.begin(); i != from.mBlackBoxMap.end(); ++i )
106 bbtkBlackBoxDebugMessage("object",5," * Cloning \""<<i->first<<"\""<<std::endl);
107 BlackBox::Pointer B = i->second->bbClone(i->second->bbGetName());
108 bbUnsafeAddBlackBox(B);
111 bbtkBlackBoxDebugMessage("object",4," * Cloning Connections"<<std::endl);
112 ConnectionListType::const_iterator j;
113 for ( j = from.mConnectionList.begin(); j != from.mConnectionList.end(); ++j )
115 bbtkBlackBoxDebugMessage("object",5," * Cloning \""<<
116 (*j)->GetFullName()<<"\""<<std::endl);
118 BlackBox::Pointer bbfrom = bbGetBlackBox( (*j)->GetOriginalBlackBoxFrom()->bbGetName() );
119 BlackBox::Pointer bbto = bbGetBlackBox( (*j)->GetOriginalBlackBoxTo()->bbGetName() );
121 Connection::Pointer c = mDescriptor.lock()->GetFactory()->
122 NewConnection( bbfrom,
123 (*j)->GetOriginalBlackBoxFromOutput(),
125 (*j)->GetOriginalBlackBoxToInput() );
132 bbAllocateConnectors();
133 bbtkBlackBoxDebugMessage("object",3,
134 "<## ComplexBlackBox(\""
135 <<from.bbGetName()<<"\",\""
136 <<name<<"\")"<<std::endl);
138 //=======================================================================
140 //=======================================================================
142 ComplexBlackBox::~ComplexBlackBox()
144 bbtkBlackBoxDebugMessage("object",3,
145 "==> ~ComplexBlackBox()"
149 this->bbDesallocateConnectors();
151 bbtkBlackBoxDebugMessage("object",3,
152 "<== ~ComplexBlackBox()"
155 //=======================================================================
158 //=======================================================================
160 void ComplexBlackBox::Clear()
162 bbtkBlackBoxDebugMessage("object",3,
163 "==> ComplexBlackBox::Clear()"
166 bbtkBlackBoxDebugMessage("object",4,
167 " -> Releasing connections"<<std::endl);
168 mConnectionList.clear();
169 bbtkBlackBoxDebugMessage("object",4,
170 " -> Releasing boxes"<<std::endl);
171 mBlackBoxMap.clear();
173 bbtkBlackBoxDebugMessage("object",3,
174 "<== ComplexBlackBox::Clear()"
177 //=======================================================================
179 //=========================================================================
180 /// Allocates the i/o connectors of the black box
181 void ComplexBlackBox::bbAllocateConnectors()
183 bbtkBlackBoxDebugMessage("kernel",8,
184 "==> ComplexBlackBox::bbAllocateConnectors()"
188 const BlackBoxDescriptor::InputDescriptorMapType& imap
189 = bbGetDescriptor()->GetInputDescriptorMap();
190 BlackBoxDescriptor::InputDescriptorMapType::const_iterator i;
191 for ( i = imap.begin(); i != imap.end(); ++i )
193 bbtkBlackBoxDebugMessage("kernel",8,"* Allocate \""<<i->first<<"\""<<std::endl);
194 // Redirect the connector to the internal box connector
195 // Cast the BBInputDescriptor into a ComplexBBInputDescriptor
196 ComplexBlackBoxInputDescriptor* d =
197 (ComplexBlackBoxInputDescriptor*)i->second;
198 // Get the internal box connector
199 BlackBoxInputConnector* c =
200 bbUnsafeGetBlackBox ( d->GetTarget() )
201 ->bbGetInputConnectorMap()[ d->GetInput() ];
203 bbGetInputConnectorMap()[i->second->GetName()] = c;
207 const BlackBoxDescriptor::OutputDescriptorMapType& omap
208 = bbGetDescriptor()->GetOutputDescriptorMap();
209 BlackBoxDescriptor::OutputDescriptorMapType::const_iterator o;
210 for ( o = omap.begin(); o != omap.end(); ++o )
212 bbtkBlackBoxDebugMessage("kernel",8,"* Allocate \""<<o->first<<"\""<<std::endl);
213 // Redirect the connector to the internal box connector
214 // Cast the BBOutputDescriptor into a ComplexBBOutputDescriptor
215 ComplexBlackBoxOutputDescriptor* d =
216 (ComplexBlackBoxOutputDescriptor*)o->second;
217 // Get the internal box connector
218 BlackBoxOutputConnector* c =
219 bbUnsafeGetBlackBox ( d->GetTarget() )
220 ->bbGetOutputConnectorMap()[ d->GetOutput() ];
222 bbGetOutputConnectorMap()[o->second->GetName()] = c;
224 bbtkBlackBoxDebugMessage("kernel",8,
225 "<== ComplexBlackBox::bbAllocateConnectors()"
228 //=========================================================================
231 //=========================================================================
232 /// Desallocates the i/o connectors of the black box
233 void ComplexBlackBox::bbDesallocateConnectors()
235 bbtkBlackBoxDebugMessage("kernel",8,
236 "==> ComplexBlackBox::DesallocateConnectors()"
239 // The connectors have not been allocated by the complex box
240 // but by the internal boxes. Hence **DO NOT** desallocate !
241 // just clear the maps to avoid that
242 // BlackBox::bbDesallocateConnectors delete the connectors
243 bbGetInputConnectorMap().clear();
244 bbGetOutputConnectorMap().clear();
246 bbtkBlackBoxDebugMessage("kernel",8,
247 "<== ComplexBlackBox::DesallocateConnectors()"
252 //=========================================================================
254 //=======================================================================
255 BlackBox::Pointer ComplexBlackBox::bbClone(const std::string& name)
257 bbtkBlackBoxDebugMessage("kernel",9,
258 "==> ComplexBlackBox::bbClone(\""<<name<<"\")"
261 ComplexBlackBox* CBB = new ComplexBlackBox(*this,name);
262 bbtkBlackBoxDebugMessage("kernel",9,
263 "<== ComplexBlackBox::bbClone(\""<<name<<"\")"
265 return MakeBlackBoxPointer(CBB);
267 //=======================================================================
269 //=======================================================================
270 /// Main processing method of the box.
271 /// Executes the box so that its outputs are up-to-date on exit
272 void ComplexBlackBox::bbExecute(bool force)
274 bbtkBlackBoxDebugMessage("process",2,
275 "**> ComplexBlackBox::bbExecute()"
281 if (mExecutionList.size() != 0)
284 std::vector<std::string>::const_iterator i;
285 for (i=mExecutionList.begin();
286 i!=mExecutionList.end();
289 bbtkBlackBoxDebugMessage("process",3," -> Executing '"<<*i<<"'"<<std::endl);
290 mBlackBoxMap[*i]->bbExecute(force);
295 std::map<std::string, BlackBox::Pointer>::iterator i;
296 for (i=mBlackBoxMap.begin(); i!=mBlackBoxMap.end(); ++i)
298 i->second->bbExecute(force);
301 bbtkBlackBoxDebugMessage("process",2,
302 "<** ComplexBlackBox::bbExecute()"
306 //==================================================================
308 //==================================================================
309 void ComplexBlackBox::bbAddToExecutionList( const std::string& name )
311 bbtkBlackBoxDebugMessage("kernel",9,
312 "ComplexBlackBox::bbAddToExecutionList(\""
316 mExecutionList.push_back( name );
320 //==================================================================
323 //==================================================================
324 Data ComplexBlackBox::bbGetOutput( const std::string &name )
326 bbtkBlackBoxDebugMessage("data",7,
327 "ComplexBlackBox::bbGetOutput(\""<<name<<"\")"
330 ComplexBlackBoxOutputDescriptor* d =
331 (ComplexBlackBoxOutputDescriptor*)
332 bbGetDescriptor()->GetOutputDescriptor(name);
334 Data p = bbGetBlackBox(d->GetTarget())->bbGetOutput(d->GetOutput());
338 //==================================================================
340 //==================================================================
341 /// Gets the input Data of a given name
342 Data ComplexBlackBox::bbGetInput( const std::string &name )
344 bbtkBlackBoxDebugMessage("data",7,
345 "ComplexBlackBox::bbGetInput(\""<<name<<"\")"
348 ComplexBlackBoxInputDescriptor* d =
349 (ComplexBlackBoxInputDescriptor*)
350 bbGetDescriptor()->GetInputDescriptor(name);
352 Data p = bbGetBlackBox(d->GetTarget())->bbGetInput(d->GetInput());
356 //==================================================================
358 //==================================================================
359 /// Sets the data of the output called <name>
360 void ComplexBlackBox::bbSetOutput( const std::string &name, Data data)
362 bbtkBlackBoxDebugMessage("data",7,
363 "ComplexBlackBox::bbSetOutput(\""<<name<<"\",data)"
366 ComplexBlackBoxOutputDescriptor* d =
367 (ComplexBlackBoxOutputDescriptor*)
368 bbGetDescriptor()->GetOutputDescriptor(name);
370 bbGetBlackBox(d->GetTarget())->bbSetOutput(d->GetOutput(),data);
373 //==================================================================
375 //==================================================================
376 /// Sets the data of the input called <name>
377 void ComplexBlackBox::bbSetInput( const std::string &name, Data data,
380 bbtkBlackBoxDebugMessage("data",7,
381 "ComplexBlackBox::bbSetInput(\""<<name<<"\",data)"
384 ComplexBlackBoxInputDescriptor* d = (ComplexBlackBoxInputDescriptor*)
385 bbGetDescriptor()->GetInputDescriptor(name);
387 bbGetBlackBox(d->GetTarget())->bbSetInput(d->GetInput(),data,setModified);
390 //==================================================================
393 //==================================================================
394 /// Sets the data of the input called <name>
395 void ComplexBlackBox::bbBruteForceSetInputPointer( const std::string &name,
399 bbtkBlackBoxDebugMessage("data",7,
400 "ComplexBlackBox::bbBruteForceSetInputPointer('"
401 <<name<<"',"<<data<<")"
404 ComplexBlackBoxInputDescriptor* d = (ComplexBlackBoxInputDescriptor*)
405 bbGetDescriptor()->GetInputDescriptor(name);
407 bbGetBlackBox(d->GetTarget())->bbBruteForceSetInputPointer(d->GetInput(),
412 //==================================================================
414 //=========================================================================
415 /// Connects the input <name> to the connection c
416 void ComplexBlackBox::bbConnectInput( const std::string& name, Connection* c)
418 bbtkBlackBoxDebugMessage("connection",2,
419 "==> ComplexBlackBox::bbConnectInput(\""
420 <<name<<"\","<<c->GetFullName()<<")"
423 ComplexBlackBoxInputDescriptor* d = (ComplexBlackBoxInputDescriptor*)
424 bbGetDescriptor()->GetInputDescriptor(name);
427 BlackBox::Pointer t = bbGetBlackBox(d->GetTarget());
429 bbtkBlackBoxDebugMessage("connection",2," - Target = "<<d->GetTarget()<<" = "<<t->bbGetFullName()<<std::endl);
432 c->SetBlackBoxToInput(d->GetInput());
434 bbtkBlackBoxDebugMessage("connection",2," - New conn = "<<c->GetFullName()<<std::endl);
435 t->bbConnectInput(d->GetInput(),c);
437 bbtkBlackBoxDebugMessage("connection",2,
438 "<== ComplexBlackBox::bbConnectInput(\""
439 <<name<<"\","<<c->GetFullName()<<")"
442 //=========================================================================
445 //=========================================================================
446 /// Connects the output <name> to the connection c
447 void ComplexBlackBox::bbConnectOutput( const std::string& name, Connection* c)
449 bbtkBlackBoxDebugMessage("connection",2,
450 "==> ComplexBlackBox::bbConnectOutput(\""
451 <<name<<"\","<<c->GetFullName()<<")"
454 ComplexBlackBoxOutputDescriptor* d = (ComplexBlackBoxOutputDescriptor*)
455 bbGetDescriptor()->GetOutputDescriptor(name);
457 BlackBox::Pointer t = bbGetBlackBox(d->GetTarget());
459 bbtkBlackBoxDebugMessage("connection",2," - Target = "<<d->GetTarget()<<" = "<<t->bbGetFullName()<<std::endl);
461 c->SetBlackBoxFrom(t);
462 c->SetBlackBoxFromOutput(d->GetOutput());
464 bbtkBlackBoxDebugMessage("connection",2," - New conn = "<<c->GetFullName()<<std::endl);
466 t->bbConnectOutput(d->GetOutput(),c);
468 bbtkBlackBoxDebugMessage("connection",2,
469 "<== ComplexBlackBox::bbConnectOutput(\""
470 <<name<<"\","<<c->GetFullName()<<")"
473 //=========================================================================
476 //==================================================================
477 /// Adds the black box to the complex box
478 void ComplexBlackBox::bbAddBlackBox( BlackBox::Pointer b)
480 bbtkBlackBoxDebugMessage("kernel",7,
481 "ComplexBlackBox::AddBlackBox(\""<<b->bbGetName()
485 if ( bbUnsafeGetBlackBox(b->bbGetName()) )
487 bbtkError("a black box called \""<<b->bbGetName()
488 <<"\" already exists");
490 b->bbSetParent(GetThisPointer<ComplexBlackBox>());
491 mBlackBoxMap[b->bbGetName()] = b;
494 //==================================================================
496 //==================================================================
497 /// Adds the black box to the complex box (unsafe)
498 void ComplexBlackBox::bbUnsafeAddBlackBox( BlackBox::Pointer b)
500 bbtkBlackBoxDebugMessage("kernel",7,
501 "ComplexBlackBox::UnsafeAddBlackBox(\""<<b->bbGetName()
505 b->bbSetParent(GetThisPointer<ComplexBlackBox>());
506 mBlackBoxMap[b->bbGetName()] = b;
509 //==================================================================
511 //==================================================================
512 /// Removes the black box from the complex box
513 void ComplexBlackBox::bbRemoveBlackBox( const std::string& name,
514 bool remove_connections )
516 bbtkBlackBoxDebugMessage("kernel",7,
517 "ComplexBlackBox::RemoveBlackBox(\""<<name<<"\")"
520 BlackBoxMapType::iterator i = mBlackBoxMap.find(name);
521 if ( i == mBlackBoxMap.end() )
523 bbtkError("the black box \""<<name<<"\" does not exist");
525 BlackBox::WeakPointer p = i->second;
527 if (remove_connections)
529 ConnectionListType::const_iterator j;
530 for ( j = mConnectionList.begin();
531 j != mConnectionList.end(); ++j )
536 if (p.use_count()!=1)
538 bbtkError("the black box \""<<name<<"\" is still connected");
541 mBlackBoxMap.erase(i);
544 // Unload orphan dl packages
545 Package::UnLoadReleasedDynamicallyLoadedPackages();
548 //==================================================================
550 //==================================================================
551 /// Adds the connection to the complex box
552 void ComplexBlackBox::bbAddConnection( Connection::Pointer c)
554 bbtkBlackBoxDebugMessage("kernel",7,
555 "ComplexBlackBox::AddConnection(\""<<"..."<<"\")"
558 mConnectionList.push_back(c);
561 //==================================================================
562 // void RemoveConnection( );
564 //==================================================================
565 /// Returns the black box with name <name>
566 BlackBox::Pointer ComplexBlackBox::bbGetBlackBox( const std::string& name )
568 bbtkBlackBoxDebugMessage("kernel",9,
569 "ComplexBlackBox::GetBlackBox(\""<<name<<"\")"
571 BlackBoxMapType::iterator i = mBlackBoxMap.find(name);
572 if ( i == mBlackBoxMap.end() )
574 bbtkError("the black box \""<<name<<"\" does not exist");
578 //==================================================================
580 //==================================================================
581 /// Returns the black box with name <name> : does not throw an exception
582 /// if it does not exist but return a null pointer
583 BlackBox::Pointer ComplexBlackBox::bbUnsafeGetBlackBox( const std::string& name )
585 bbtkBlackBoxDebugMessage("kernel",9,
586 "ComplexBlackBox::UnsafeGetBlackBox(\""<<name<<"\")"
589 BlackBoxMapType::iterator i = mBlackBoxMap.find(name);
590 if ( i == mBlackBoxMap.end() )
592 return BlackBox::Pointer();
598 //==================================================================
600 //==================================================================
601 void ComplexBlackBox::bbPrintBlackBoxes()
603 bbtkBlackBoxDebugMessage("kernel",9,
604 "ComplexBlackBox::PrintBlackBoxes()"
607 BlackBoxMapType::iterator i;
608 for ( i = mBlackBoxMap.begin(); i != mBlackBoxMap.end(); ++i )
610 bbtkMessage("help",1,i->second->bbGetFullName()<<std::endl);
614 //==================================================================
618 //=========================================================================
620 void ComplexBlackBox::bbWriteDotInputOutputName(FILE *ff,bool inputoutput,int detail, int level)
624 fprintf(ff,"%s_IN_%p",bbGetTypeName().c_str(),this);
626 fprintf(ff,"%s_OUT_%p",bbGetTypeName().c_str(),this);
629 //=========================================================================
632 //=========================================================================
633 BlackBox::Pointer ComplexBlackBox::bbFindBlackBox(const std::string &blackboxname)
635 BlackBox::Pointer blackbox;
636 std::string subname="";
637 std::string restname="";
638 std::string delimiters(">");
639 // Skip delimiters at beginning.
640 std::string::size_type lastPos = blackboxname.find_first_not_of(delimiters, 0);
641 // Find first "non-delimiter".
642 std::string::size_type pos = blackboxname.find_first_of(delimiters, lastPos);
644 // Found a token, add it to the vector.
645 subname = blackboxname.substr(lastPos, pos - lastPos);
646 restname = blackboxname.substr(lastPos+pos - lastPos+1, 999);
648 if (restname==subname)
653 BlackBoxMapType::iterator i = mBlackBoxMap.find(subname);
654 if ( i != mBlackBoxMap.end() )
656 blackbox = i->second;
659 blackbox = blackbox->bbFindBlackBox(restname);
664 //=========================================================================
666 //=========================================================================
667 void ComplexBlackBox::bbInsertHTMLGraph( std::ofstream& s,
671 const std::string& output_dir,
674 std::string directory(output_dir);
676 if (output_dir.length() == 0)
678 // Don't pollute the file store with "temp_dir" directories ...
679 std::string default_temp_dir = ConfigurationFile::GetInstance().Get_default_temp_dir();
680 directory = default_temp_dir + "/" + "temp_dir";
683 std::string simplefilename (this->bbGetTypeName()+"_"+this->bbGetName());
684 std::string simplefilename_png (simplefilename+".png");
685 std::string filename (directory+"/"+simplefilename);
686 std::string filename_png (filename+".png");
687 std::string filename_cmap (filename+".cmap");
688 std::string filename_dot (filename+".dot");
690 std::string filename_png2 ("\"" + filename_png + "\"");
691 std::string filename_cmap2 ("\"" + filename_cmap + "\"");
692 std::string filename_dot2 ("\"" + filename_dot + "\"");
696 std::string currentexecpath("\"\"" + crea::System::GetDllAppPath("bbtk") +"\\dot_embedded\\dot\"");
697 std::string command1 (currentexecpath + " -Tpng -o " + filename_png2 + " " + filename_dot2 + "\"");
698 std::string command1a(currentexecpath + " -T cmap -o " + filename_cmap2 + " " + filename_dot2 + "\"");
701 std::string command1 ("dot -Tpng:quartz -o " + filename_png2 + " " + filename_dot2 );
702 std::string command1a("dot -T cmap -o " + filename_cmap2 + " " + filename_dot2 );
704 std::string command1 ("dot -Tpng:cairo -o " + filename_png2 + " " + filename_dot2 );
705 std::string command1a("dot -T cmap -o " + filename_cmap2 + " " + filename_dot2 );
712 // 1. Generating .dot file
714 ff = fopen(filename_dot.c_str(),"w");
715 fprintf(ff,"digraph bbtk_graph{\n");
716 fprintf(ff,"rankdir=LR%s\n",";");
717 fprintf(ff,"node [shape=record]%s\n",";");
719 this->bbWriteDotFileBlackBox(ff,
720 GetThisPointer<ComplexBlackBox>(),
728 std::cout<<"JCP bbtkComplexBlackBox.cxx execute1="<<command1<<std::endl;
729 // 2. Executing .dot file -> png
730 system( command1.c_str() );
731 // 3. Executing .dot file -> cmap
732 std::cout<<"JCP bbtkComplexBlackBox.cxx execute2="<<command1a<<std::endl;
733 system( command1a.c_str() );
735 // 4. HTML code insertion
737 (s) << "<center><img src=\"" << simplefilename_png
738 << "\" border=\"0\" usemap=\"#map_"<< simplefilename
739 <<"\" alt=\"\"></center>\n";
742 (s) << "<map name=\"map_"<< simplefilename <<"\">\n";
745 ff2=fopen(filename_cmap.c_str(),"r");
760 //=========================================================================
763 //=========================================================================
764 /// Write Graphviz-dot description in file
765 void ComplexBlackBox::bbWriteDotFileBlackBox(FILE *ff,
766 BlackBox::Pointer parentblackbox,
767 int detail, int level,
772 std::string valueStr("");
773 Package::Pointer package = this->bbGetDescriptor()->GetPackage();
778 tmp1 = this->bbGetDescriptor()->GetPackage()->GetDocRelativeURL();
780 tmp1 = this->bbGetDescriptor()->GetPackage()->GetDocURL();
787 std::string tmp2=bbGetTypeName();
788 std::string url(tmp1 + "#" + tmp2 );
789 fprintf( ff , "subgraph cluster_%s_%p {\n",bbGetName().c_str(),this);
791 if (!( (bbGetTypeName()=="workspace") && (bbGetName()=="workspacePrototype")) )
793 fprintf( ff , " URL = \"%s\" %s",url.c_str(),";");
796 std::string boxname="["+bbGetTypeName()+"]";
797 if (GetThisPointer<ComplexBlackBox>()!=parentblackbox)
805 boxname = bbGetName();
806 boxname = boxname + " [" +this->bbGetDescriptor()->GetPackage()->GetName()+"::"+ bbGetTypeName() + "]";
810 fprintf( ff , " label = \"%s\"%s\n", boxname.c_str() ,";");
814 // fprintf( ff , " style=filled%s\n",";");
815 // fprintf( ff , " color=grey%s\n",";");
816 fprintf( ff , " node [style=filled]%s\n",";");
817 fprintf( ff , " fillcolor=grey%s\n",";");
818 fprintf( ff , " edge [color=blue]%s\n",";");
822 std::string labelStr1;
823 std::string labelStr2;
824 labelStr1 = boxname + "\\n(output)" ;
825 labelStr2 = " | {{ ";
828 OutputConnectorMapType::iterator i;
830 const BlackBoxDescriptor::OutputDescriptorMapType& omap = this->bbGetDescriptor()->GetOutputDescriptorMap();
831 BlackBoxDescriptor::OutputDescriptorMapType::const_iterator o;
832 for ( o = omap.begin(); o != omap.end(); ++o )
836 labelStr2=labelStr2+" | ";
839 if (instanceOrtype==true)
841 valueStr = this->bbGetOutputAsString(o->second->GetName()/*
844 labelStr2=labelStr2+"<"+o->second->GetName().c_str()+"> " + valueStr + o->second->GetName().c_str();
847 labelStr2 = labelStr2+ " } }";
853 labelStr1 = labelStr1 + labelStr2;
858 bbWriteDotInputOutputName(ff,false,detail,level);
859 fprintf( ff , " [shape=record, style=filled,fillcolor=grey,color=red,label=\"%s\"]%s\n",labelStr1.c_str(),";" );
864 labelStr1 = boxname + "\\n(input)" ;
865 labelStr2 = " | {{ ";
867 InputConnectorMapType::iterator ii;
869 const BlackBoxDescriptor::InputDescriptorMapType& imap = this->bbGetDescriptor()->GetInputDescriptorMap();
870 BlackBoxDescriptor::InputDescriptorMapType::const_iterator iii;
871 for ( iii = imap.begin(); iii != imap.end(); ++iii )
875 labelStr2=labelStr2+" | ";
878 if (instanceOrtype==true)
880 valueStr = this->bbGetInputAsString(iii->second->GetName()/*,factory*/) + " = ";
882 labelStr2=labelStr2+"<"+iii->second->GetName().c_str()+"> " + valueStr + iii->second->GetName().c_str();
886 labelStr2 = labelStr2+ " } }";
889 labelStr1 = labelStr1 + labelStr2;
893 bbWriteDotInputOutputName(ff,true,detail,level);
894 fprintf( ff , " [shape=record, style=filled,fillcolor=grey,color=red,label=\"%s\"]%s\n",labelStr1.c_str(),";" );
899 BlackBoxMapType::iterator j;
900 for ( j = mBlackBoxMap.begin(); j != mBlackBoxMap.end(); ++j )
904 j->second->bbWriteDotFileBlackBox(ff,
913 fprintf( ff , "}\n\n");
915 fprintf( ff , " edge[color=blue]%s\n",";");
919 // Relation Input with the inside BlackBox of the this ComplexBlackbox
920 ComplexBlackBoxDescriptor::InputDescriptorMapType::iterator xx;
921 ComplexBlackBoxDescriptor::InputDescriptorMapType idmt=bbGetDescriptor()->GetInputDescriptorMap();
922 for ( xx = idmt.begin(); xx != idmt.end(); ++xx )
924 ComplexBlackBoxInputDescriptor *cbbid = (ComplexBlackBoxInputDescriptor*)xx->second;
927 bbWriteDotInputOutputName(ff,true,detail,level);
930 fprintf(ff,":%s",cbbid->GetName().c_str() );
933 BlackBox::Pointer bb = bbGetBlackBox( cbbid->GetTarget() );
934 bb->bbWriteDotInputOutputName(ff,true,detail,level);
937 fprintf(ff,":%s \n", cbbid->GetInput().c_str() );
947 // Relation Output ComplexBlackBox
948 ComplexBlackBoxDescriptor::OutputDescriptorMapType::iterator yy;
949 ComplexBlackBoxDescriptor::OutputDescriptorMapType odmt=bbGetDescriptor()->GetOutputDescriptorMap();
950 for ( yy = odmt.begin(); yy != odmt.end(); ++yy )
952 ComplexBlackBoxOutputDescriptor *cbbod = (ComplexBlackBoxOutputDescriptor*)yy->second;
954 BlackBox::Pointer bb = bbGetBlackBox( cbbod->GetTarget() );
955 bb->bbWriteDotInputOutputName(ff,false,detail,level);
958 fprintf(ff,":%s", cbbod->GetOutput().c_str() );
961 bbWriteDotInputOutputName(ff,false,detail,level);
964 fprintf(ff,":%s",cbbod->GetName().c_str() );
973 // Relation from the out side of this ComplexBlackBox with its Inputs
974 if (GetThisPointer<ComplexBlackBox>()!=parentblackbox) {
975 for ( ii = bbGetInputConnectorMap().begin();
976 ii != bbGetInputConnectorMap().end(); ++ii )
980 Connection* con = ii->second->GetConnection();
982 BlackBox::Pointer a=con->GetOriginalBlackBoxFrom();
983 BlackBox::Pointer b=con->GetOriginalBlackBoxTo();
985 a->bbWriteDotInputOutputName(ff,false,detail,level);
988 fprintf(ff,":%s",con->GetOriginalBlackBoxFromOutput().c_str());
991 b->bbWriteDotInputOutputName(ff,true,detail,level);
994 fprintf(ff,":%s",con->GetOriginalBlackBoxToInput().c_str());
996 fprintf(ff,"%s\n",";");
1000 } // if parentblackbox
1002 //=========================================================================
1009 //=======================================================================
1010 /// Generates the list of the packages of which its depends
1011 /// (cause an internal box belongs to it)
1012 void ComplexBlackBox::GetPackagesDependencies(std::vector<Package*>& deps)
1015 BlackBoxMapType::iterator i;
1016 for ( i = mBlackBoxMap.begin(); i != mBlackBoxMap.end(); ++i )
1018 deps.push_back(i->second->bbGetDescriptor()->GetPackage());
1022 //=======================================================================
1025 //=======================================================================
1026 void ComplexBlackBox::Check(bool recursive)
1028 bbtkMessage("debug",1,"**** Checking Complex Black Box "<<(void*)this
1029 <<" ["<<bbGetFullName()<<"]"<<std::endl);
1031 BlackBoxMapType::const_iterator i;
1032 for ( i = mBlackBoxMap.begin(); i != mBlackBoxMap.end(); ++i )
1034 i->second->Check(recursive);
1036 ConnectionListType::const_iterator j;
1037 for ( j = mConnectionList.begin();
1038 j != mConnectionList.end(); ++j )
1042 bbtkMessage("debug",1,"**** Checking Complex Black Box "<<(void*)this
1043 <<" ["<<bbGetFullName()<<"] ... OK"<<std::endl);
1046 //=======================================================================
1048 //=========================================================================
1049 /// Returns the name with the name of the parent prepended if any
1050 std::string ComplexBlackBox::bbGetNameWithParent() const
1052 if (!IsAPrototype()) return BlackBox::bbGetNameWithParent();
1053 if (bbGetDescriptor())
1055 return bbGetDescriptor()->GetFullTypeName() + ":" + bbGetName();
1059 return std::string(":") + bbGetName();
1062 //=========================================================================
1064 //==========================================================================
1065 std::string ComplexBlackBox::GetObjectName() const
1067 return std::string("ComplexBlackBox '")+bbGetNameWithParent()
1070 //==========================================================================
1072 //==========================================================================
1073 std::string ComplexBlackBox::GetObjectInfo() const
1075 std::stringstream i;
1076 i << " - "<<mBlackBoxMap.size() << " boxes / "
1077 <<mConnectionList.size() << " connections" << std::endl;
1080 //==========================================================================
1082 //==========================================================================
1083 size_t ComplexBlackBox::GetObjectSize() const
1085 size_t s = Superclass::GetObjectSize();
1086 s += ComplexBlackBox::GetObjectInternalSize();
1089 //==========================================================================
1090 //==========================================================================
1091 size_t ComplexBlackBox::GetObjectInternalSize() const
1093 size_t s = sizeof(ComplexBlackBox);
1096 //==========================================================================
1097 //==========================================================================
1098 size_t ComplexBlackBox::GetObjectRecursiveSize() const
1100 size_t s = Superclass::GetObjectRecursiveSize();
1101 s += ComplexBlackBox::GetObjectInternalSize();
1102 BlackBoxMapType::const_iterator i;
1103 for ( i = mBlackBoxMap.begin(); i != mBlackBoxMap.end(); ++i )
1105 s += i->second->GetObjectRecursiveSize();
1107 ConnectionListType::const_iterator j;
1108 for ( j = mConnectionList.begin();
1109 j != mConnectionList.end(); ++j )
1111 s += (*j)->GetObjectRecursiveSize();
1115 //==========================================================================