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<<"','"<<
57 desc->GetTypeName()<<"')" <<bbtkendl);
58 ComplexBlackBox::Pointer p =
59 MakeBlackBoxPointer(new ComplexBlackBox(name,desc));
60 bbtkDebugMessage("object",2,"<## ComplexBlackBox::New('"<<name<<"','"<<
61 desc->GetTypeName()<<"')" <<bbtkendl);
64 //==========================================================================
66 //=======================================================================
67 /// Usefull constructor
68 ComplexBlackBox::ComplexBlackBox(const std::string &name,
69 ComplexBlackBoxDescriptor::Pointer desc)
72 mLockedDescriptor(desc),
75 bbtkBlackBoxDebugMessage("object",3,
76 "##> ComplexBlackBox(\""
77 <<name<<"\")"<<std::endl);
78 bbAllocateConnectors();
79 bbtkBlackBoxDebugMessage("object",3,
80 "<## ComplexBlackBox(\""
81 <<name<<"\")"<<std::endl);
83 //=======================================================================
85 //=======================================================================
86 /// Constructor from an existing box (copy) with a new name
87 ComplexBlackBox::ComplexBlackBox(ComplexBlackBox& from,
88 const std::string &name)
89 : BlackBox(from,name),
90 // The locked descriptor is copied from the unlocked one
91 // to make the box a non-prototype !!
92 mLockedDescriptor(from.mDescriptor),
93 mDescriptor(from.mDescriptor),
94 mExecutionList(from.mExecutionList)
96 bbtkBlackBoxDebugMessage("object",3,
97 "##> ComplexBlackBox(\""
98 <<from.bbGetName()<<"\",\""
99 <<name<<"\")"<<std::endl);
100 bbtkBlackBoxDebugMessage("object",4," * Cloning Black Boxes"<<std::endl);
102 // We have to make the shared_ptr on this because it is used
103 // in bbUnsafeAddBlackBox !
104 MakeBlackBoxPointer(this,true);
106 BlackBoxMapType::const_iterator i;
107 for ( i = from.mBlackBoxMap.begin(); i != from.mBlackBoxMap.end(); ++i )
109 bbtkBlackBoxDebugMessage("object",5," * Cloning \""<<i->first<<"\""<<std::endl);
110 BlackBox::Pointer B = i->second->bbClone(i->second->bbGetName());
111 bbUnsafeAddBlackBox(B);
114 bbtkBlackBoxDebugMessage("object",4," * Cloning Connections"<<std::endl);
115 ConnectionListType::const_iterator j;
116 for ( j = from.mConnectionList.begin(); j != from.mConnectionList.end(); ++j )
118 bbtkBlackBoxDebugMessage("object",5," * Cloning \""<<
119 (*j)->GetFullName()<<"\""<<std::endl);
121 BlackBox::Pointer bbfrom = bbGetBlackBox( (*j)->GetOriginalBlackBoxFrom()->bbGetName() );
122 BlackBox::Pointer bbto = bbGetBlackBox( (*j)->GetOriginalBlackBoxTo()->bbGetName() );
124 Connection::Pointer c = mDescriptor.lock()->GetFactory()->
125 NewConnection( bbfrom,
126 (*j)->GetOriginalBlackBoxFromOutput(),
128 (*j)->GetOriginalBlackBoxToInput() );
135 bbAllocateConnectors();
136 bbtkBlackBoxDebugMessage("object",3,
137 "<## ComplexBlackBox(\""
138 <<from.bbGetName()<<"\",\""
139 <<name<<"\")"<<std::endl);
141 //=======================================================================
143 //=======================================================================
145 ComplexBlackBox::~ComplexBlackBox()
147 bbtkBlackBoxDebugMessage("object",3,
148 "==> ~ComplexBlackBox()"
152 this->bbDesallocateConnectors();
154 bbtkBlackBoxDebugMessage("object",3,
155 "<== ~ComplexBlackBox()"
158 //=======================================================================
161 //=======================================================================
163 void ComplexBlackBox::Clear()
165 bbtkBlackBoxDebugMessage("object",3,
166 "==> ComplexBlackBox::Clear()"
169 bbtkBlackBoxDebugMessage("object",4,
170 " -> Releasing connections"<<std::endl);
171 mConnectionList.clear();
172 bbtkBlackBoxDebugMessage("object",4,
173 " -> Releasing boxes"<<std::endl);
174 mBlackBoxMap.clear();
176 bbtkBlackBoxDebugMessage("object",3,
177 "<== ComplexBlackBox::Clear()"
180 //=======================================================================
182 //=========================================================================
183 /// Allocates the i/o connectors of the black box
184 void ComplexBlackBox::bbAllocateConnectors()
186 bbtkBlackBoxDebugMessage("kernel",8,
187 "==> ComplexBlackBox::bbAllocateConnectors()"
191 const BlackBoxDescriptor::InputDescriptorMapType& imap
192 = bbGetDescriptor()->GetInputDescriptorMap();
193 BlackBoxDescriptor::InputDescriptorMapType::const_iterator i;
194 for ( i = imap.begin(); i != imap.end(); ++i )
196 bbtkBlackBoxDebugMessage("kernel",8,"* Allocate \""<<i->first<<"\""<<std::endl);
197 // Redirect the connector to the internal box connector
198 // Cast the BBInputDescriptor into a ComplexBBInputDescriptor
199 ComplexBlackBoxInputDescriptor* d =
200 (ComplexBlackBoxInputDescriptor*)i->second;
201 // Get the internal box connector
202 BlackBoxInputConnector* c =
203 bbUnsafeGetBlackBox ( d->GetTarget() )
204 ->bbGetInputConnectorMap()[ d->GetInput() ];
206 bbGetInputConnectorMap()[i->second->GetName()] = c;
210 const BlackBoxDescriptor::OutputDescriptorMapType& omap
211 = bbGetDescriptor()->GetOutputDescriptorMap();
212 BlackBoxDescriptor::OutputDescriptorMapType::const_iterator o;
213 for ( o = omap.begin(); o != omap.end(); ++o )
215 bbtkBlackBoxDebugMessage("kernel",8,"* Allocate \""<<o->first<<"\""<<std::endl);
216 // Redirect the connector to the internal box connector
217 // Cast the BBOutputDescriptor into a ComplexBBOutputDescriptor
218 ComplexBlackBoxOutputDescriptor* d =
219 (ComplexBlackBoxOutputDescriptor*)o->second;
220 // Get the internal box connector
221 BlackBoxOutputConnector* c =
222 bbUnsafeGetBlackBox ( d->GetTarget() )
223 ->bbGetOutputConnectorMap()[ d->GetOutput() ];
225 bbGetOutputConnectorMap()[o->second->GetName()] = c;
227 bbtkBlackBoxDebugMessage("kernel",8,
228 "<== ComplexBlackBox::bbAllocateConnectors()"
231 //=========================================================================
234 //=========================================================================
235 /// Desallocates the i/o connectors of the black box
236 void ComplexBlackBox::bbDesallocateConnectors()
238 bbtkBlackBoxDebugMessage("kernel",8,
239 "==> ComplexBlackBox::DesallocateConnectors()"
242 // The connectors have not been allocated by the complex box
243 // but by the internal boxes. Hence **DO NOT** desallocate !
244 // just clear the maps to avoid that
245 // BlackBox::bbDesallocateConnectors delete the connectors
246 bbGetInputConnectorMap().clear();
247 bbGetOutputConnectorMap().clear();
249 bbtkBlackBoxDebugMessage("kernel",8,
250 "<== ComplexBlackBox::DesallocateConnectors()"
255 //=========================================================================
257 //=======================================================================
258 BlackBox::Pointer ComplexBlackBox::bbClone(const std::string& name)
260 bbtkBlackBoxDebugMessage("kernel",9,
261 "==> ComplexBlackBox::bbClone(\""<<name<<"\")"
264 ComplexBlackBox* CBB = new ComplexBlackBox(*this,name);
265 bbtkBlackBoxDebugMessage("kernel",9,
266 "<== ComplexBlackBox::bbClone(\""<<name<<"\")"
268 return MakeBlackBoxPointer(CBB);
270 //=======================================================================
272 //=======================================================================
273 /// Main processing method of the box.
274 /// Executes the box so that its outputs are up-to-date on exit
275 void ComplexBlackBox::bbExecute(bool force)
277 bbtkBlackBoxDebugMessage("process",2,
278 "**> ComplexBlackBox::bbExecute()"
284 if (mExecutionList.size() != 0)
287 std::vector<std::string>::const_iterator i;
288 for (i=mExecutionList.begin();
289 i!=mExecutionList.end();
292 bbtkBlackBoxDebugMessage("process",3," -> Executing '"<<*i<<"'"<<std::endl);
293 mBlackBoxMap[*i]->bbExecute(force);
298 std::map<std::string, BlackBox::Pointer>::iterator i;
299 for (i=mBlackBoxMap.begin(); i!=mBlackBoxMap.end(); ++i)
301 i->second->bbExecute(force);
304 bbtkBlackBoxDebugMessage("process",2,
305 "<** ComplexBlackBox::bbExecute()"
309 //==================================================================
311 //==================================================================
312 void ComplexBlackBox::bbAddToExecutionList( const std::string& name )
314 bbtkBlackBoxDebugMessage("kernel",9,
315 "ComplexBlackBox::bbAddToExecutionList(\""
319 mExecutionList.push_back( name );
323 //==================================================================
326 //==================================================================
327 Data ComplexBlackBox::bbGetOutput( const std::string &name )
329 bbtkBlackBoxDebugMessage("data",7,
330 "ComplexBlackBox::bbGetOutput(\""<<name<<"\")"
333 ComplexBlackBoxOutputDescriptor* d =
334 (ComplexBlackBoxOutputDescriptor*)
335 bbGetDescriptor()->GetOutputDescriptor(name);
337 Data p = bbGetBlackBox(d->GetTarget())->bbGetOutput(d->GetOutput());
341 //==================================================================
343 //==================================================================
344 /// Gets the input Data of a given name
345 Data ComplexBlackBox::bbGetInput( const std::string &name )
347 bbtkBlackBoxDebugMessage("data",7,
348 "ComplexBlackBox::bbGetInput(\""<<name<<"\")"
351 ComplexBlackBoxInputDescriptor* d =
352 (ComplexBlackBoxInputDescriptor*)
353 bbGetDescriptor()->GetInputDescriptor(name);
355 Data p = bbGetBlackBox(d->GetTarget())->bbGetInput(d->GetInput());
359 //==================================================================
361 //==================================================================
362 /// Sets the data of the output called <name>
363 void ComplexBlackBox::bbSetOutput( const std::string &name, Data data)
365 bbtkBlackBoxDebugMessage("data",7,
366 "ComplexBlackBox::bbSetOutput(\""<<name<<"\",data)"
369 ComplexBlackBoxOutputDescriptor* d =
370 (ComplexBlackBoxOutputDescriptor*)
371 bbGetDescriptor()->GetOutputDescriptor(name);
373 bbGetBlackBox(d->GetTarget())->bbSetOutput(d->GetOutput(),data);
376 //==================================================================
378 //==================================================================
379 /// Sets the data of the input called <name>
380 void ComplexBlackBox::bbSetInput( const std::string &name, Data data,
383 bbtkBlackBoxDebugMessage("data",7,
384 "ComplexBlackBox::bbSetInput(\""<<name<<"\",data)"
387 ComplexBlackBoxInputDescriptor* d = (ComplexBlackBoxInputDescriptor*)
388 bbGetDescriptor()->GetInputDescriptor(name);
390 bbGetBlackBox(d->GetTarget())->bbSetInput(d->GetInput(),data,setModified);
393 //==================================================================
396 //==================================================================
397 /// Sets the data of the input called <name>
398 void ComplexBlackBox::bbBruteForceSetInputPointer( const std::string &name,
402 bbtkBlackBoxDebugMessage("data",7,
403 "ComplexBlackBox::bbBruteForceSetInputPointer('"
404 <<name<<"',"<<data<<")"
407 ComplexBlackBoxInputDescriptor* d = (ComplexBlackBoxInputDescriptor*)
408 bbGetDescriptor()->GetInputDescriptor(name);
410 bbGetBlackBox(d->GetTarget())->bbBruteForceSetInputPointer(d->GetInput(),
415 //==================================================================
417 //=========================================================================
418 /// Connects the input <name> to the connection c
419 void ComplexBlackBox::bbConnectInput( const std::string& name, Connection* c)
421 bbtkBlackBoxDebugMessage("connection",2,
422 "==> ComplexBlackBox::bbConnectInput(\""
423 <<name<<"\","<<c->GetFullName()<<")"
426 ComplexBlackBoxInputDescriptor* d = (ComplexBlackBoxInputDescriptor*)
427 bbGetDescriptor()->GetInputDescriptor(name);
430 BlackBox::Pointer t = bbGetBlackBox(d->GetTarget());
432 bbtkBlackBoxDebugMessage("connection",2," - Target = "<<d->GetTarget()<<" = "<<t->bbGetFullName()<<std::endl);
435 c->SetBlackBoxToInput(d->GetInput());
437 bbtkBlackBoxDebugMessage("connection",2," - New conn = "<<c->GetFullName()<<std::endl);
438 t->bbConnectInput(d->GetInput(),c);
440 bbtkBlackBoxDebugMessage("connection",2,
441 "<== ComplexBlackBox::bbConnectInput(\""
442 <<name<<"\","<<c->GetFullName()<<")"
445 //=========================================================================
448 //=========================================================================
449 /// Connects the output <name> to the connection c
450 void ComplexBlackBox::bbConnectOutput( const std::string& name, Connection* c)
452 bbtkBlackBoxDebugMessage("connection",2,
453 "==> ComplexBlackBox::bbConnectOutput(\""
454 <<name<<"\","<<c->GetFullName()<<")"
457 ComplexBlackBoxOutputDescriptor* d = (ComplexBlackBoxOutputDescriptor*)
458 bbGetDescriptor()->GetOutputDescriptor(name);
460 BlackBox::Pointer t = bbGetBlackBox(d->GetTarget());
462 bbtkBlackBoxDebugMessage("connection",2," - Target = "<<d->GetTarget()<<" = "<<t->bbGetFullName()<<std::endl);
464 c->SetBlackBoxFrom(t);
465 c->SetBlackBoxFromOutput(d->GetOutput());
467 bbtkBlackBoxDebugMessage("connection",2," - New conn = "<<c->GetFullName()<<std::endl);
469 t->bbConnectOutput(d->GetOutput(),c);
471 bbtkBlackBoxDebugMessage("connection",2,
472 "<== ComplexBlackBox::bbConnectOutput(\""
473 <<name<<"\","<<c->GetFullName()<<")"
476 //=========================================================================
479 //==================================================================
480 /// Adds the black box to the complex box
481 void ComplexBlackBox::bbAddBlackBox( BlackBox::Pointer b)
483 bbtkBlackBoxDebugMessage("kernel",7,
484 "ComplexBlackBox::AddBlackBox(\""<<b->bbGetName()
488 if ( bbUnsafeGetBlackBox(b->bbGetName()) )
490 bbtkError("a black box called \""<<b->bbGetName()
491 <<"\" already exists");
493 b->bbSetParent(GetThisPointer<ComplexBlackBox>());
494 mBlackBoxMap[b->bbGetName()] = b;
497 //==================================================================
499 //==================================================================
500 /// Adds the black box to the complex box (unsafe)
501 void ComplexBlackBox::bbUnsafeAddBlackBox( BlackBox::Pointer b)
503 bbtkBlackBoxDebugMessage("kernel",7,
504 "ComplexBlackBox::UnsafeAddBlackBox(\""<<b->bbGetName()
508 b->bbSetParent(GetThisPointer<ComplexBlackBox>());
509 mBlackBoxMap[b->bbGetName()] = b;
512 //==================================================================
514 //==================================================================
515 /// Removes the black box from the complex box
516 void ComplexBlackBox::bbRemoveBlackBox( const std::string& name,
517 bool remove_connections )
519 bbtkBlackBoxDebugMessage("kernel",7,
520 "ComplexBlackBox::RemoveBlackBox(\""<<name<<"\")"
523 BlackBoxMapType::iterator i = mBlackBoxMap.find(name);
524 if ( i == mBlackBoxMap.end() )
526 bbtkError("the black box \""<<name<<"\" does not exist");
528 BlackBox::WeakPointer p = i->second;
530 if (remove_connections)
532 ConnectionListType::const_iterator j;
533 for ( j = mConnectionList.begin();
534 j != mConnectionList.end(); ++j )
539 if (p.use_count()!=1)
541 bbtkError("the black box \""<<name<<"\" is still connected");
544 mBlackBoxMap.erase(i);
547 // Unload orphan dl packages
548 Package::UnLoadReleasedDynamicallyLoadedPackages();
551 //==================================================================
553 //==================================================================
554 /// Adds the connection to the complex box
555 void ComplexBlackBox::bbAddConnection( Connection::Pointer c)
557 bbtkBlackBoxDebugMessage("kernel",7,
558 "ComplexBlackBox::AddConnection(\""<<"..."<<"\")"
561 mConnectionList.push_back(c);
564 //==================================================================
565 // void RemoveConnection( );
567 //==================================================================
568 /// Returns the black box with name <name>
569 BlackBox::Pointer ComplexBlackBox::bbGetBlackBox( const std::string& name )
571 bbtkBlackBoxDebugMessage("kernel",9,
572 "ComplexBlackBox::GetBlackBox(\""<<name<<"\")"
574 BlackBoxMapType::iterator i = mBlackBoxMap.find(name);
575 if ( i == mBlackBoxMap.end() )
577 bbtkError("the black box \""<<name<<"\" does not exist");
581 //==================================================================
583 //==================================================================
584 /// Returns the black box with name <name> : does not throw an exception
585 /// if it does not exist but return a null pointer
586 BlackBox::Pointer ComplexBlackBox::bbUnsafeGetBlackBox( const std::string& name )
588 bbtkBlackBoxDebugMessage("kernel",9,
589 "ComplexBlackBox::UnsafeGetBlackBox(\""<<name<<"\")"
592 BlackBoxMapType::iterator i = mBlackBoxMap.find(name);
593 if ( i == mBlackBoxMap.end() )
595 return BlackBox::Pointer();
601 //==================================================================
603 //==================================================================
604 void ComplexBlackBox::bbPrintBlackBoxes()
606 bbtkBlackBoxDebugMessage("kernel",9,
607 "ComplexBlackBox::PrintBlackBoxes()"
610 BlackBoxMapType::iterator i;
611 for ( i = mBlackBoxMap.begin(); i != mBlackBoxMap.end(); ++i )
613 bbtkMessage("help",1,i->second->bbGetFullName()<<std::endl);
617 //==================================================================
621 //=========================================================================
623 void ComplexBlackBox::bbWriteDotInputOutputName(FILE *ff,bool inputoutput,int detail, int level)
627 fprintf(ff,"%s_IN_%p",bbGetTypeName().c_str(),this);
629 fprintf(ff,"%s_OUT_%p",bbGetTypeName().c_str(),this);
632 //=========================================================================
635 //=========================================================================
636 BlackBox::Pointer ComplexBlackBox::bbFindBlackBox(const std::string &blackboxname)
638 BlackBox::Pointer blackbox;
639 std::string subname="";
640 std::string restname="";
641 std::string delimiters(">");
642 // Skip delimiters at beginning.
643 std::string::size_type lastPos = blackboxname.find_first_not_of(delimiters, 0);
644 // Find first "non-delimiter".
645 std::string::size_type pos = blackboxname.find_first_of(delimiters, lastPos);
647 // Found a token, add it to the vector.
648 subname = blackboxname.substr(lastPos, pos - lastPos);
649 restname = blackboxname.substr(lastPos+pos - lastPos+1, 999);
651 if (restname==subname)
656 BlackBoxMapType::iterator i = mBlackBoxMap.find(subname);
657 if ( i != mBlackBoxMap.end() )
659 blackbox = i->second;
662 blackbox = blackbox->bbFindBlackBox(restname);
667 //=========================================================================
669 //=========================================================================
670 void ComplexBlackBox::bbInsertHTMLGraph( std::ofstream& s,
674 const std::string& output_dir,
677 std::string directory(output_dir);
679 if (output_dir.length() == 0)
681 // Don't pollute the file store with "temp_dir" directories ...
682 std::string default_temp_dir = ConfigurationFile::GetInstance().Get_default_temp_dir();
683 directory = default_temp_dir + "/" + "temp_dir";
686 std::string simplefilename (this->bbGetTypeName()+"_"+this->bbGetName());
687 std::string simplefilename_png (simplefilename+".png");
688 std::string filename (directory+"/"+simplefilename);
689 std::string filename_png (filename+".png");
690 std::string filename_cmap (filename+".cmap");
691 std::string filename_dot (filename+".dot");
693 std::string filename_png2 ("\"" + filename_png + "\"");
694 std::string filename_cmap2 ("\"" + filename_cmap + "\"");
695 std::string filename_dot2 ("\"" + filename_dot + "\"");
699 std::string currentexecpath("\"\"" + crea::System::GetDllAppPath("bbtk") +"\\dot_embedded\\dot\"");
700 std::string command1 (currentexecpath + " -Tpng -o " + filename_png2 + " " + filename_dot2 + "\"");
701 std::string command1a(currentexecpath + " -T cmap -o " + filename_cmap2 + " " + filename_dot2 + "\"");
704 std::string command1 ("dot -Tpng:quartz -o " + filename_png2 + " " + filename_dot2 );
705 std::string command1a("dot -T cmap -o " + filename_cmap2 + " " + filename_dot2 );
707 std::string command1 ("dot -Tpng:cairo -o " + filename_png2 + " " + filename_dot2 );
708 std::string command1a("dot -T cmap -o " + filename_cmap2 + " " + filename_dot2 );
715 // 1. Generating .dot file
717 ff = fopen(filename_dot.c_str(),"w");
718 fprintf(ff,"digraph bbtk_graph{\n");
719 fprintf(ff,"rankdir=LR%s\n",";");
720 fprintf(ff,"node [shape=record]%s\n",";");
722 this->bbWriteDotFileBlackBox(ff,
723 GetThisPointer<ComplexBlackBox>(),
731 std::cout<<"JCP bbtkComplexBlackBox.cxx execute1="<<command1<<std::endl;
732 // 2. Executing .dot file -> png
733 system( command1.c_str() );
734 // 3. Executing .dot file -> cmap
735 std::cout<<"JCP bbtkComplexBlackBox.cxx execute2="<<command1a<<std::endl;
736 system( command1a.c_str() );
738 // 4. HTML code insertion
740 (s) << "<center><img src=\"" << simplefilename_png
741 << "\" border=\"0\" usemap=\"#map_"<< simplefilename
742 <<"\" alt=\"\"></center>\n";
745 (s) << "<map name=\"map_"<< simplefilename <<"\">\n";
748 ff2=fopen(filename_cmap.c_str(),"r");
763 //=========================================================================
766 //=========================================================================
767 /// Write Graphviz-dot description in file
768 void ComplexBlackBox::bbWriteDotFileBlackBox(FILE *ff,
769 BlackBox::Pointer parentblackbox,
770 int detail, int level,
775 std::string valueStr("");
776 Package::Pointer package = this->bbGetDescriptor()->GetPackage();
781 tmp1 = this->bbGetDescriptor()->GetPackage()->GetDocRelativeURL();
783 tmp1 = this->bbGetDescriptor()->GetPackage()->GetDocURL();
790 std::string tmp2=bbGetTypeName();
791 std::string url(tmp1 + "#" + tmp2 );
792 fprintf( ff , "subgraph cluster_%s_%p {\n",bbGetName().c_str(),this);
794 if (!( (bbGetTypeName()=="workspace") && (bbGetName()=="workspacePrototype")) )
796 fprintf( ff , " URL = \"%s\" %s",url.c_str(),";");
799 std::string boxname="["+bbGetTypeName()+"]";
800 if (GetThisPointer<ComplexBlackBox>()!=parentblackbox)
808 boxname = bbGetName();
809 boxname = boxname + " [" +this->bbGetDescriptor()->GetPackage()->GetName()+"::"+ bbGetTypeName() + "]";
813 fprintf( ff , " label = \"%s\"%s\n", boxname.c_str() ,";");
817 // fprintf( ff , " style=filled%s\n",";");
818 // fprintf( ff , " color=grey%s\n",";");
819 fprintf( ff , " node [style=filled]%s\n",";");
820 fprintf( ff , " fillcolor=grey%s\n",";");
821 fprintf( ff , " edge [color=blue]%s\n",";");
825 std::string labelStr1;
826 std::string labelStr2;
827 labelStr1 = boxname + "\\n(output)" ;
828 labelStr2 = " | {{ ";
831 OutputConnectorMapType::iterator i;
833 const BlackBoxDescriptor::OutputDescriptorMapType& omap = this->bbGetDescriptor()->GetOutputDescriptorMap();
834 BlackBoxDescriptor::OutputDescriptorMapType::const_iterator o;
835 for ( o = omap.begin(); o != omap.end(); ++o )
839 labelStr2=labelStr2+" | ";
842 if (instanceOrtype==true)
844 valueStr = this->bbGetOutputAsString(o->second->GetName()/*
847 labelStr2=labelStr2+"<"+o->second->GetName().c_str()+"> " + valueStr + o->second->GetName().c_str();
850 labelStr2 = labelStr2+ " } }";
856 labelStr1 = labelStr1 + labelStr2;
861 bbWriteDotInputOutputName(ff,false,detail,level);
862 fprintf( ff , " [shape=record, style=filled,fillcolor=grey,color=red,label=\"%s\"]%s\n",labelStr1.c_str(),";" );
867 labelStr1 = boxname + "\\n(input)" ;
868 labelStr2 = " | {{ ";
870 InputConnectorMapType::iterator ii;
872 const BlackBoxDescriptor::InputDescriptorMapType& imap = this->bbGetDescriptor()->GetInputDescriptorMap();
873 BlackBoxDescriptor::InputDescriptorMapType::const_iterator iii;
874 for ( iii = imap.begin(); iii != imap.end(); ++iii )
878 labelStr2=labelStr2+" | ";
881 if (instanceOrtype==true)
883 valueStr = this->bbGetInputAsString(iii->second->GetName()/*,factory*/) + " = ";
885 labelStr2=labelStr2+"<"+iii->second->GetName().c_str()+"> " + valueStr + iii->second->GetName().c_str();
889 labelStr2 = labelStr2+ " } }";
892 labelStr1 = labelStr1 + labelStr2;
896 bbWriteDotInputOutputName(ff,true,detail,level);
897 fprintf( ff , " [shape=record, style=filled,fillcolor=grey,color=red,label=\"%s\"]%s\n",labelStr1.c_str(),";" );
902 BlackBoxMapType::iterator j;
903 for ( j = mBlackBoxMap.begin(); j != mBlackBoxMap.end(); ++j )
907 j->second->bbWriteDotFileBlackBox(ff,
916 fprintf( ff , "}\n\n");
918 fprintf( ff , " edge[color=blue]%s\n",";");
922 // Relation Input with the inside BlackBox of the this ComplexBlackbox
923 ComplexBlackBoxDescriptor::InputDescriptorMapType::iterator xx;
924 ComplexBlackBoxDescriptor::InputDescriptorMapType idmt=bbGetDescriptor()->GetInputDescriptorMap();
925 for ( xx = idmt.begin(); xx != idmt.end(); ++xx )
927 ComplexBlackBoxInputDescriptor *cbbid = (ComplexBlackBoxInputDescriptor*)xx->second;
930 bbWriteDotInputOutputName(ff,true,detail,level);
933 fprintf(ff,":%s",cbbid->GetName().c_str() );
936 BlackBox::Pointer bb = bbGetBlackBox( cbbid->GetTarget() );
937 bb->bbWriteDotInputOutputName(ff,true,detail,level);
940 fprintf(ff,":%s \n", cbbid->GetInput().c_str() );
950 // Relation Output ComplexBlackBox
951 ComplexBlackBoxDescriptor::OutputDescriptorMapType::iterator yy;
952 ComplexBlackBoxDescriptor::OutputDescriptorMapType odmt=bbGetDescriptor()->GetOutputDescriptorMap();
953 for ( yy = odmt.begin(); yy != odmt.end(); ++yy )
955 ComplexBlackBoxOutputDescriptor *cbbod = (ComplexBlackBoxOutputDescriptor*)yy->second;
957 BlackBox::Pointer bb = bbGetBlackBox( cbbod->GetTarget() );
958 bb->bbWriteDotInputOutputName(ff,false,detail,level);
961 fprintf(ff,":%s", cbbod->GetOutput().c_str() );
964 bbWriteDotInputOutputName(ff,false,detail,level);
967 fprintf(ff,":%s",cbbod->GetName().c_str() );
976 // Relation from the out side of this ComplexBlackBox with its Inputs
977 if (GetThisPointer<ComplexBlackBox>()!=parentblackbox) {
978 for ( ii = bbGetInputConnectorMap().begin();
979 ii != bbGetInputConnectorMap().end(); ++ii )
983 Connection* con = ii->second->GetConnection();
985 BlackBox::Pointer a=con->GetOriginalBlackBoxFrom();
986 BlackBox::Pointer b=con->GetOriginalBlackBoxTo();
988 a->bbWriteDotInputOutputName(ff,false,detail,level);
991 fprintf(ff,":%s",con->GetOriginalBlackBoxFromOutput().c_str());
994 b->bbWriteDotInputOutputName(ff,true,detail,level);
997 fprintf(ff,":%s",con->GetOriginalBlackBoxToInput().c_str());
999 fprintf(ff,"%s\n",";");
1003 } // if parentblackbox
1005 //=========================================================================
1012 //=======================================================================
1013 /// Generates the list of the packages of which its depends
1014 /// (cause an internal box belongs to it)
1015 void ComplexBlackBox::GetPackagesDependencies(std::vector<Package*>& deps)
1018 BlackBoxMapType::iterator i;
1019 for ( i = mBlackBoxMap.begin(); i != mBlackBoxMap.end(); ++i )
1021 deps.push_back(i->second->bbGetDescriptor()->GetPackage());
1025 //=======================================================================
1028 //=======================================================================
1029 void ComplexBlackBox::Check(bool recursive)
1031 bbtkMessage("debug",1,"**** Checking Complex Black Box "<<(void*)this
1032 <<" ["<<bbGetFullName()<<"]"<<std::endl);
1034 BlackBoxMapType::const_iterator i;
1035 for ( i = mBlackBoxMap.begin(); i != mBlackBoxMap.end(); ++i )
1037 i->second->Check(recursive);
1039 ConnectionListType::const_iterator j;
1040 for ( j = mConnectionList.begin();
1041 j != mConnectionList.end(); ++j )
1045 bbtkMessage("debug",1,"**** Checking Complex Black Box "<<(void*)this
1046 <<" ["<<bbGetFullName()<<"] ... OK"<<std::endl);
1049 //=======================================================================
1051 //=========================================================================
1052 /// Returns the name with the name of the parent prepended if any
1053 std::string ComplexBlackBox::bbGetNameWithParent() const
1055 if (!IsAPrototype()) return BlackBox::bbGetNameWithParent();
1056 if (bbGetDescriptor())
1058 return bbGetDescriptor()->GetFullTypeName() + ":" + bbGetName();
1062 return std::string(":") + bbGetName();
1065 //=========================================================================
1067 //==========================================================================
1068 std::string ComplexBlackBox::GetObjectName() const
1070 return std::string("ComplexBlackBox '")+bbGetNameWithParent()
1073 //==========================================================================
1075 //==========================================================================
1076 std::string ComplexBlackBox::GetObjectInfo() const
1078 std::stringstream i;
1079 i << " - "<<mBlackBoxMap.size() << " boxes / "
1080 <<mConnectionList.size() << " connections" << std::endl;
1083 //==========================================================================
1085 //==========================================================================
1086 size_t ComplexBlackBox::GetObjectSize() const
1088 size_t s = Superclass::GetObjectSize();
1089 s += ComplexBlackBox::GetObjectInternalSize();
1092 //==========================================================================
1093 //==========================================================================
1094 size_t ComplexBlackBox::GetObjectInternalSize() const
1096 size_t s = sizeof(ComplexBlackBox);
1099 //==========================================================================
1100 //==========================================================================
1101 size_t ComplexBlackBox::GetObjectRecursiveSize() const
1103 size_t s = Superclass::GetObjectRecursiveSize();
1104 s += ComplexBlackBox::GetObjectInternalSize();
1105 BlackBoxMapType::const_iterator i;
1106 for ( i = mBlackBoxMap.begin(); i != mBlackBoxMap.end(); ++i )
1108 s += i->second->GetObjectRecursiveSize();
1110 ConnectionListType::const_iterator j;
1111 for ( j = mConnectionList.begin();
1112 j != mConnectionList.end(); ++j )
1114 s += (*j)->GetObjectRecursiveSize();
1118 //==========================================================================