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<<"\")"
575 BlackBoxMapType::iterator i = mBlackBoxMap.find(name);
576 if ( i == mBlackBoxMap.end() )
578 bbtkError("the black box \""<<name<<"\" does not exist");
583 //==================================================================
585 //==================================================================
586 /// Returns the black box with name <name> : does not throw an exception
587 /// if it does not exist but return a null pointer
588 BlackBox::Pointer ComplexBlackBox::bbUnsafeGetBlackBox( const std::string& name )
590 bbtkBlackBoxDebugMessage("kernel",9,
591 "ComplexBlackBox::UnsafeGetBlackBox(\""<<name<<"\")"
594 BlackBoxMapType::iterator i = mBlackBoxMap.find(name);
595 if ( i == mBlackBoxMap.end() )
597 return BlackBox::Pointer();
603 //==================================================================
605 //==================================================================
606 void ComplexBlackBox::bbPrintBlackBoxes()
608 bbtkBlackBoxDebugMessage("kernel",9,
609 "ComplexBlackBox::PrintBlackBoxes()"
612 BlackBoxMapType::iterator i;
613 for ( i = mBlackBoxMap.begin(); i != mBlackBoxMap.end(); ++i )
615 bbtkMessage("help",1,i->second->bbGetFullName()<<std::endl);
619 //==================================================================
623 //=========================================================================
625 void ComplexBlackBox::bbWriteDotInputOutputName(FILE *ff,bool inputoutput,int detail, int level)
629 fprintf(ff,"%s_IN_%p",bbGetTypeName().c_str(),this);
631 fprintf(ff,"%s_OUT_%p",bbGetTypeName().c_str(),this);
634 //=========================================================================
637 //=========================================================================
638 BlackBox::Pointer ComplexBlackBox::bbFindBlackBox(const std::string &blackboxname)
640 BlackBox::Pointer blackbox;
641 std::string subname="";
642 std::string restname="";
643 std::string delimiters(">");
644 // Skip delimiters at beginning.
645 std::string::size_type lastPos = blackboxname.find_first_not_of(delimiters, 0);
646 // Find first "non-delimiter".
647 std::string::size_type pos = blackboxname.find_first_of(delimiters, lastPos);
649 // Found a token, add it to the vector.
650 subname = blackboxname.substr(lastPos, pos - lastPos);
651 restname = blackboxname.substr(lastPos+pos - lastPos+1, 999);
653 if (restname==subname)
658 BlackBoxMapType::iterator i = mBlackBoxMap.find(subname);
659 if ( i != mBlackBoxMap.end() )
661 blackbox = i->second;
664 blackbox = blackbox->bbFindBlackBox(restname);
669 //=========================================================================
671 //=========================================================================
672 void ComplexBlackBox::bbInsertHTMLGraph( std::ofstream& s,
676 const std::string& output_dir,
679 std::string directory(output_dir);
681 if (output_dir.length() == 0)
683 // Don't pollute the file store with "temp_dir" directories ...
684 std::string default_temp_dir = ConfigurationFile::GetInstance().Get_default_temp_dir();
685 directory = default_temp_dir + "/" + "temp_dir";
688 std::string simplefilename (this->bbGetTypeName()+"_"+this->bbGetName());
689 std::string simplefilename_png (simplefilename+".png");
690 std::string filename (directory+"/"+simplefilename);
691 std::string filename_png (filename+".png");
692 std::string filename_cmap (filename+".cmap");
693 std::string filename_dot (filename+".dot");
695 std::string filename_png2 ("\"" + filename_png + "\"");
696 std::string filename_cmap2 ("\"" + filename_cmap + "\"");
697 std::string filename_dot2 ("\"" + filename_dot + "\"");
701 std::string currentexecpath("\"\"" + crea::System::GetDllAppPath("bbtk") +"\\dot_embedded\\dot\"");
702 std::string command1 (currentexecpath + " -Tpng -o " + filename_png2 + " " + filename_dot2 + "\"");
703 std::string command1a(currentexecpath + " -T cmap -o " + filename_cmap2 + " " + filename_dot2 + "\"");
706 std::string command1 ("dot -Tpng:quartz -o " + filename_png2 + " " + filename_dot2 );
707 std::string command1a("dot -T cmap -o " + filename_cmap2 + " " + filename_dot2 );
709 std::string command1 ("dot -Tpng:cairo -o " + filename_png2 + " " + filename_dot2 );
710 std::string command1a("dot -T cmap -o " + filename_cmap2 + " " + filename_dot2 );
717 // 1. Generating .dot file
719 ff = fopen(filename_dot.c_str(),"w");
720 fprintf(ff,"digraph bbtk_graph{\n");
721 fprintf(ff,"rankdir=LR%s\n",";");
722 fprintf(ff,"node [shape=record]%s\n",";");
724 this->bbWriteDotFileBlackBox(ff,
725 GetThisPointer<ComplexBlackBox>(),
733 std::cout<<"JCP bbtkComplexBlackBox.cxx execute1="<<command1<<std::endl;
734 // 2. Executing .dot file -> png
735 system( command1.c_str() );
736 // 3. Executing .dot file -> cmap
737 std::cout<<"JCP bbtkComplexBlackBox.cxx execute2="<<command1a<<std::endl;
738 system( command1a.c_str() );
740 // 4. HTML code insertion
742 (s) << "<center><img src=\"" << simplefilename_png
743 << "\" border=\"0\" usemap=\"#map_"<< simplefilename
744 <<"\" alt=\"\"></center>\n";
747 (s) << "<map name=\"map_"<< simplefilename <<"\">\n";
750 ff2=fopen(filename_cmap.c_str(),"r");
765 //=========================================================================
768 //=========================================================================
769 /// Write Graphviz-dot description in file
770 void ComplexBlackBox::bbWriteDotFileBlackBox(FILE *ff,
771 BlackBox::Pointer parentblackbox,
772 int detail, int level,
777 std::string valueStr("");
778 Package::Pointer package = this->bbGetDescriptor()->GetPackage();
783 tmp1 = this->bbGetDescriptor()->GetPackage()->GetDocRelativeURL();
785 tmp1 = this->bbGetDescriptor()->GetPackage()->GetDocURL();
792 std::string tmp2=bbGetTypeName();
793 std::string url(tmp1 + "#" + tmp2 );
794 fprintf( ff , "subgraph cluster_%s_%p {\n",bbGetName().c_str(),this);
796 if (!( (bbGetTypeName()=="workspace") && (bbGetName()=="workspacePrototype")) )
798 fprintf( ff , " URL = \"%s\" %s",url.c_str(),";");
801 std::string boxname="["+bbGetTypeName()+"]";
802 if (GetThisPointer<ComplexBlackBox>()!=parentblackbox)
810 boxname = bbGetName();
811 boxname = boxname + " [" +this->bbGetDescriptor()->GetPackage()->GetName()+"::"+ bbGetTypeName() + "]";
815 fprintf( ff , " label = \"%s\"%s\n", boxname.c_str() ,";");
819 // fprintf( ff , " style=filled%s\n",";");
820 // fprintf( ff , " color=grey%s\n",";");
821 fprintf( ff , " node [style=filled]%s\n",";");
822 fprintf( ff , " fillcolor=grey%s\n",";");
823 fprintf( ff , " edge [color=blue]%s\n",";");
827 std::string labelStr1;
828 std::string labelStr2;
829 labelStr1 = boxname + "\\n(output)" ;
830 labelStr2 = " | {{ ";
833 OutputConnectorMapType::iterator i;
835 const BlackBoxDescriptor::OutputDescriptorMapType& omap = this->bbGetDescriptor()->GetOutputDescriptorMap();
836 BlackBoxDescriptor::OutputDescriptorMapType::const_iterator o;
837 for ( o = omap.begin(); o != omap.end(); ++o )
841 labelStr2=labelStr2+" | ";
844 if (instanceOrtype==true)
846 valueStr = this->bbGetOutputAsString(o->second->GetName()/*
849 labelStr2=labelStr2+"<"+o->second->GetName().c_str()+"> " + valueStr + o->second->GetName().c_str();
852 labelStr2 = labelStr2+ " } }";
858 labelStr1 = labelStr1 + labelStr2;
863 bbWriteDotInputOutputName(ff,false,detail,level);
864 fprintf( ff , " [shape=record, style=filled,fillcolor=grey,color=red,label=\"%s\"]%s\n",labelStr1.c_str(),";" );
869 labelStr1 = boxname + "\\n(input)" ;
870 labelStr2 = " | {{ ";
872 InputConnectorMapType::iterator ii;
874 const BlackBoxDescriptor::InputDescriptorMapType& imap = this->bbGetDescriptor()->GetInputDescriptorMap();
875 BlackBoxDescriptor::InputDescriptorMapType::const_iterator iii;
876 for ( iii = imap.begin(); iii != imap.end(); ++iii )
880 labelStr2=labelStr2+" | ";
883 if (instanceOrtype==true)
885 valueStr = this->bbGetInputAsString(iii->second->GetName()/*,factory*/) + " = ";
887 labelStr2=labelStr2+"<"+iii->second->GetName().c_str()+"> " + valueStr + iii->second->GetName().c_str();
891 labelStr2 = labelStr2+ " } }";
894 labelStr1 = labelStr1 + labelStr2;
898 bbWriteDotInputOutputName(ff,true,detail,level);
899 fprintf( ff , " [shape=record, style=filled,fillcolor=grey,color=red,label=\"%s\"]%s\n",labelStr1.c_str(),";" );
904 BlackBoxMapType::iterator j;
905 for ( j = mBlackBoxMap.begin(); j != mBlackBoxMap.end(); ++j )
909 j->second->bbWriteDotFileBlackBox(ff,
918 fprintf( ff , "}\n\n");
920 fprintf( ff , " edge[color=blue]%s\n",";");
924 // Relation Input with the inside BlackBox of the this ComplexBlackbox
925 ComplexBlackBoxDescriptor::InputDescriptorMapType::iterator xx;
926 ComplexBlackBoxDescriptor::InputDescriptorMapType idmt=bbGetDescriptor()->GetInputDescriptorMap();
927 for ( xx = idmt.begin(); xx != idmt.end(); ++xx )
929 ComplexBlackBoxInputDescriptor *cbbid = (ComplexBlackBoxInputDescriptor*)xx->second;
932 bbWriteDotInputOutputName(ff,true,detail,level);
935 fprintf(ff,":%s",cbbid->GetName().c_str() );
938 BlackBox::Pointer bb = bbGetBlackBox( cbbid->GetTarget() );
939 bb->bbWriteDotInputOutputName(ff,true,detail,level);
942 fprintf(ff,":%s \n", cbbid->GetInput().c_str() );
952 // Relation Output ComplexBlackBox
953 ComplexBlackBoxDescriptor::OutputDescriptorMapType::iterator yy;
954 ComplexBlackBoxDescriptor::OutputDescriptorMapType odmt=bbGetDescriptor()->GetOutputDescriptorMap();
955 for ( yy = odmt.begin(); yy != odmt.end(); ++yy )
957 ComplexBlackBoxOutputDescriptor *cbbod = (ComplexBlackBoxOutputDescriptor*)yy->second;
959 BlackBox::Pointer bb = bbGetBlackBox( cbbod->GetTarget() );
960 bb->bbWriteDotInputOutputName(ff,false,detail,level);
963 fprintf(ff,":%s", cbbod->GetOutput().c_str() );
966 bbWriteDotInputOutputName(ff,false,detail,level);
969 fprintf(ff,":%s",cbbod->GetName().c_str() );
978 // Relation from the out side of this ComplexBlackBox with its Inputs
979 if (GetThisPointer<ComplexBlackBox>()!=parentblackbox) {
980 for ( ii = bbGetInputConnectorMap().begin();
981 ii != bbGetInputConnectorMap().end(); ++ii )
985 Connection* con = ii->second->GetConnection();
987 BlackBox::Pointer a=con->GetOriginalBlackBoxFrom();
988 BlackBox::Pointer b=con->GetOriginalBlackBoxTo();
990 a->bbWriteDotInputOutputName(ff,false,detail,level);
993 fprintf(ff,":%s",con->GetOriginalBlackBoxFromOutput().c_str());
996 b->bbWriteDotInputOutputName(ff,true,detail,level);
999 fprintf(ff,":%s",con->GetOriginalBlackBoxToInput().c_str());
1001 fprintf(ff,"%s\n",";");
1005 } // if parentblackbox
1007 //=========================================================================
1014 //=======================================================================
1015 /// Generates the list of the packages of which its depends
1016 /// (cause an internal box belongs to it)
1017 void ComplexBlackBox::GetPackagesDependencies(std::vector<Package*>& deps)
1020 BlackBoxMapType::iterator i;
1021 for ( i = mBlackBoxMap.begin(); i != mBlackBoxMap.end(); ++i )
1023 deps.push_back(i->second->bbGetDescriptor()->GetPackage());
1027 //=======================================================================
1030 //=======================================================================
1031 void ComplexBlackBox::Check(bool recursive)
1033 bbtkMessage("debug",1,"**** Checking Complex Black Box "<<(void*)this
1034 <<" ["<<bbGetFullName()<<"]"<<std::endl);
1036 BlackBoxMapType::const_iterator i;
1037 for ( i = mBlackBoxMap.begin(); i != mBlackBoxMap.end(); ++i )
1039 i->second->Check(recursive);
1041 ConnectionListType::const_iterator j;
1042 for ( j = mConnectionList.begin();
1043 j != mConnectionList.end(); ++j )
1047 bbtkMessage("debug",1,"**** Checking Complex Black Box "<<(void*)this
1048 <<" ["<<bbGetFullName()<<"] ... OK"<<std::endl);
1051 //=======================================================================
1053 //=========================================================================
1054 /// Returns the name with the name of the parent prepended if any
1055 std::string ComplexBlackBox::bbGetNameWithParent() const
1057 if (!IsAPrototype()) return BlackBox::bbGetNameWithParent();
1058 if (bbGetDescriptor())
1060 return bbGetDescriptor()->GetFullTypeName() + ":" + bbGetName();
1064 return std::string(":") + bbGetName();
1067 //=========================================================================
1069 //==========================================================================
1070 std::string ComplexBlackBox::GetObjectName() const
1072 return std::string("ComplexBlackBox '")+bbGetNameWithParent()
1075 //==========================================================================
1077 //==========================================================================
1078 std::string ComplexBlackBox::GetObjectInfo() const
1080 std::stringstream i;
1081 i << " - "<<mBlackBoxMap.size() << " boxes / "
1082 <<mConnectionList.size() << " connections" << std::endl;
1085 //==========================================================================
1087 //==========================================================================
1088 size_t ComplexBlackBox::GetObjectSize() const
1090 size_t s = Superclass::GetObjectSize();
1091 s += ComplexBlackBox::GetObjectInternalSize();
1094 //==========================================================================
1095 //==========================================================================
1096 size_t ComplexBlackBox::GetObjectInternalSize() const
1098 size_t s = sizeof(ComplexBlackBox);
1101 //==========================================================================
1102 //==========================================================================
1103 size_t ComplexBlackBox::GetObjectRecursiveSize() const
1105 size_t s = Superclass::GetObjectRecursiveSize();
1106 s += ComplexBlackBox::GetObjectInternalSize();
1107 BlackBoxMapType::const_iterator i;
1108 for ( i = mBlackBoxMap.begin(); i != mBlackBoxMap.end(); ++i )
1110 s += i->second->GetObjectRecursiveSize();
1112 ConnectionListType::const_iterator j;
1113 for ( j = mConnectionList.begin();
1114 j != mConnectionList.end(); ++j )
1116 s += (*j)->GetObjectRecursiveSize();
1120 //==========================================================================