1 /*=========================================================================
4 Module: $RCSfile: bbtkComplexBlackBox.cxx,v $
6 Date: $Date: 2008/01/22 15:02:00 $
7 Version: $Revision: 1.1 $
9 Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10 l'Image). All rights reserved. See Doc/License.txt or
11 http://www.creatis.insa-lyon.fr/Public/bbtk/License.html for details.
13 This software is distributed WITHOUT ANY WARRANTY; without even
14 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 PURPOSE. See the above copyright notices for more information.
17 =========================================================================*/
22 * \brief class bbtk::ComplexBlackBox : user defined complex black boxes
24 #include "bbtkComplexBlackBox.h"
25 #include "bbtkBlackBoxDescriptor.h"
26 #include "bbtkFactory.h"
27 #include "bbtkConfigurationFile.h"
33 //=======================================================================
34 /// Usefull constructor
35 ComplexBlackBox::ComplexBlackBox(const std::string &name,
36 ComplexBlackBoxDescriptor* desc)
40 bbtkDebugMessageInc("Core",9,
41 "ComplexBlackBox::ComplexBlackBox(\""
42 <<name<<"\")"<<std::endl);
43 bbAllocateConnectors();
44 bbtkDebugDecTab("Core",9);
46 //=======================================================================
48 //=======================================================================
49 /// Constructor from an existing box (copy) with a new name
50 ComplexBlackBox::ComplexBlackBox(ComplexBlackBox& from,
51 const std::string &name)
52 : BlackBox(from,name),
53 mDescriptor(from.mDescriptor),
54 mExecutionList(from.mExecutionList)
56 bbtkDebugMessageInc("Core",9,
57 "ComplexBlackBox::ComplexBlackBox(\""
58 <<from.bbGetName()<<"\",\""
59 <<name<<"\")"<<std::endl);
61 bbtkDebugMessageInc("Core",9,"* Cloning Black Boxes"<<std::endl);
62 BlackBoxMapType::const_iterator i;
63 for ( i = from.mBlackBoxMap.begin(); i != from.mBlackBoxMap.end(); ++i )
65 bbtkDebugMessageInc("Core",9,"* Cloning \""<<i->first<<"\""<<std::endl);
66 BlackBox* B = i->second->bbClone(i->second->bbGetName());
67 bbUnsafeAddBlackBox(B);
69 bbtkDebugDecTab("Core",9);
71 bbtkDebugDecTab("Core",9);
73 bbtkDebugMessageInc("Core",9,"* Cloning Connections"<<std::endl);
74 ConnectionListType::const_iterator j;
75 for ( j = from.mConnectionList.begin(); j != from.mConnectionList.end(); ++j )
77 bbtkDebugMessageInc("Core",9,"* Cloning \""<<
78 (*j)->GetFullName()<<"\""<<std::endl);
80 BlackBox* bbfrom = bbGetBlackBox( (*j)->GetBlackBoxFrom()->bbGetName() );
81 BlackBox* bbto = bbGetBlackBox( (*j)->GetBlackBoxTo()->bbGetName() );
82 Connection* c = /*mDescriptor->GetFactory()->Create*/
83 NewConnection( bbfrom,
84 (*j)->GetBlackBoxFromOutput(),
86 (*j)->GetBlackBoxToInput() );
90 bbtkDebugDecTab("Core",9);
92 bbtkDebugDecTab("Core",9);
94 bbAllocateConnectors();
95 bbtkDebugDecTab("Core",9);
97 //=======================================================================
99 //=======================================================================
101 ComplexBlackBox::~ComplexBlackBox()
103 bbtkDebugMessageInc("Core",9,
104 "ComplexBlackBox::~ComplexBlackBox() ["
105 <<bbGetFullName()<<"]"<<std::endl);
107 bbtkDebugMessageInc("Core",9,"* Delete Connections"<<std::endl);
108 ConnectionListType::iterator j;
109 for ( j = mConnectionList.begin(); j != mConnectionList.end(); ++j )
111 bbtkDebugMessageInc("Core",9,"* Delete \""<<
112 (*j)->GetFullName()<<"\""<<std::endl);
114 bbtkDebugDecTab("Core",9);
116 bbtkDebugDecTab("Core",9);
119 bbtkDebugMessageInc("Core",9,"* Delete Black Boxes"<<std::endl);
120 BlackBoxMapType::iterator i;
121 for ( i = mBlackBoxMap.begin(); i != mBlackBoxMap.end(); ++i )
123 bbtkDebugMessageInc("Core",9,"* Delete \""<<i->first<<"\""<<std::endl);
124 i->second->bbDelete();
125 bbtkDebugDecTab("Core",9);
127 bbtkDebugDecTab("Core",9);
128 // bbtkDebugMessage("Core",9,"EO ComplexBlackBox::~ComplexBlackBox ["
129 // <<bbGetFullName()<<"]"<<std::endl);
132 this->bbDesallocateConnectors();
133 bbtkDebugDecTab("Core",9);
135 //=======================================================================
137 //=========================================================================
138 /// Allocates the i/o connectors of the black box
139 void ComplexBlackBox::bbAllocateConnectors()
141 bbtkDebugMessageInc("Core",8,
142 "ComplexBlackBox::bbAllocateConnectors() ["
143 <<bbGetFullName()<<"]"
147 const BlackBoxDescriptor::InputDescriptorMapType& imap
148 = bbGetDescriptor()->GetInputDescriptorMap();
149 BlackBoxDescriptor::InputDescriptorMapType::const_iterator i;
150 for ( i = imap.begin(); i != imap.end(); ++i )
152 bbtkDebugMessage("Core",8,"* Allocate \""<<i->first<<"\""<<std::endl);
153 // Redirect the connector to the internal box connector
154 // Cast the BBInputDescriptor into a ComplexBBInputDescriptor
155 ComplexBlackBoxInputDescriptor* d =
156 (ComplexBlackBoxInputDescriptor*)i->second;
157 // Get the internal box connector
158 BlackBoxInputConnector* c =
159 bbUnsafeGetBlackBox ( d->GetTarget() )
160 ->bbGetInputConnectorMap()[ d->GetInput() ];
162 bbGetInputConnectorMap()[i->second->GetName()] = c;
163 //new BlackBoxInputConnector();
167 const BlackBoxDescriptor::OutputDescriptorMapType& omap
168 = bbGetDescriptor()->GetOutputDescriptorMap();
169 BlackBoxDescriptor::OutputDescriptorMapType::const_iterator o;
170 for ( o = omap.begin(); o != omap.end(); ++o )
172 bbtkDebugMessage("Core",8,"* Allocate \""<<o->first<<"\""<<std::endl);
173 // Redirect the connector to the internal box connector
174 // Cast the BBOutputDescriptor into a ComplexBBOutputDescriptor
175 ComplexBlackBoxOutputDescriptor* d =
176 (ComplexBlackBoxOutputDescriptor*)o->second;
177 // Get the internal box connector
178 BlackBoxOutputConnector* c =
179 bbUnsafeGetBlackBox ( d->GetTarget() )
180 ->bbGetOutputConnectorMap()[ d->GetOutput() ];
182 bbGetOutputConnectorMap()[o->second->GetName()] = c;
183 //new BlackBoxOutputConnector();
185 bbtkDebugDecTab("Core",8);
187 //=========================================================================
190 //=========================================================================
191 /// Desallocates the i/o connectors of the black box
192 void ComplexBlackBox::bbDesallocateConnectors()
194 bbtkDebugMessageInc("Core",8,
195 "ComplexBlackBox::DesallocateConnectors()"
198 // The connectors have not been allocated by the complex box
199 // but by the internal boxes. Hence **DO NOT** desallocate !
200 // just clear the maps to avoid that
201 // BlackBox::bbDesallocateConnectors delete the connectors
202 bbGetInputConnectorMap().clear();
203 bbGetOutputConnectorMap().clear();
205 bbtkDebugDecTab("Core",8);
208 //=========================================================================
210 //=======================================================================
211 BlackBox* ComplexBlackBox::bbClone(const std::string& name)
213 bbtkDebugMessageInc("Core",9,
214 "ComplexBlackBox::bbClone(\""<<name<<"\") ["
215 <<bbGetFullName()<<"]"<<std::endl);
217 ComplexBlackBox* CBB = new ComplexBlackBox(*this,name);
219 bbtkDebugDecTab("Core",9);
223 //=======================================================================
225 //=======================================================================
226 /// Main processing method of the box.
227 /// Executes the box so that its outputs are up-to-date on exit
228 void ComplexBlackBox::bbExecute(bool force)
230 bbtkDebugMessageInc("Process",1,
231 "ComplexBlackBox::bbExecute() ["
232 <<bbGetFullName()<<"]"<<std::endl);
234 wx::BeginBusyCursor();
236 if (mExecutionList.size() != 0)
239 std::vector<std::string>::const_iterator i;
240 for (i=mExecutionList.begin();
241 i!=mExecutionList.end();
244 bbtkDebugMessage("Process",2," -> Executing '"<<*i<<"'"<<std::endl);
245 mBlackBoxMap[*i]->bbExecute(force);
250 std::map<std::string, BlackBox*>::iterator i;
251 for (i=mBlackBoxMap.begin(); i!=mBlackBoxMap.end(); ++i)
253 i->second->bbExecute(force);
259 bbtkDebugDecTab("Process",1);
262 //==================================================================
264 //==================================================================
265 void ComplexBlackBox::bbSetModifiedStatus(BlackBoxInputConnector* c)
267 bbtkDebugMessage("Process",3,
268 "ComplexBlackBox::bbSetModifiedStatus("
269 <<c<<") ["<<bbGetFullName()<<"]"<<std::endl);
271 c->GetBlackBox()->bbSetModifiedStatus(c);
273 bbtkDebugMessage("Process",3,
274 "EO ComplexBlackBox::bbSetModifiedStatus("
275 <<c<<") ["<<bbGetFullName()<<"]"<<std::endl);
277 //==================================================================
279 //==================================================================
280 void ComplexBlackBox::bbAddToExecutionList( const std::string& name )
282 bbtkDebugMessageInc("Core",9,
283 "ComplexBlackBox::bbAddToExecutionList(\""
285 <<bbGetFullName()<<"]"<<std::endl);
287 mExecutionList.push_back( name );
289 bbtkDebugDecTab("Core",9);
292 //==================================================================
294 //==================================================================
295 IOStatus ComplexBlackBox::bbBackwardUpdate(Connection* caller)
297 bbtkDebugMessageInc("Process",1,
298 "ComplexBlackBox::bbBackwardUpdate("<<caller->GetFullName()<<") ["
299 <<bbGetFullName()<<"]"<<std::endl);
301 IOStatus s = UPTODATE;
302 const BlackBoxDescriptor::OutputDescriptorMapType& omap
303 = bbGetDescriptor()->GetOutputDescriptorMap();
304 BlackBoxDescriptor::OutputDescriptorMapType::const_iterator i
305 = omap.find(caller->GetBlackBoxFromOutput());
308 // Cast the BBOutputDescriptor into a ComplexBBOutputDescriptor
309 ComplexBlackBoxOutputDescriptor* d =
310 (ComplexBlackBoxOutputDescriptor*)i->second;
311 // Get the internal box
312 BlackBox* b = bbUnsafeGetBlackBox ( d->GetTarget() );
313 // Calls BackwardUpdate on it
314 bbtkDebugMessageInc("Process",2,"Internal box connected to output : "<<d->GetTarget()<<std::endl);
315 IOStatus s1 = b->bbBackwardUpdate(caller);
316 // ??? STATUS OF CBBs ???
317 // ??? Here it is only the final status of the boxes connected to the output
318 if (s1==MODIFIED) s=MODIFIED;
319 bbtkDebugDecTab("Process",2);
323 bbtkError("Connection '"<<caller->GetFullName()<<"' does not point to a valid output of the complex box !");
325 bbtkDebugDecTab("Process",1);
328 //==================================================================
331 //==================================================================
332 void ComplexBlackBox::bbForwardUpdate(Connection* caller)
334 bbtkDebugMessageInc("Process",1,
335 "ComplexBlackBox::bbForwardUpdate("<<caller->GetFullName()<<") ["
336 <<bbGetFullName()<<"]"<<std::endl);
338 const BlackBoxDescriptor::InputDescriptorMapType& imap
339 = bbGetDescriptor()->GetInputDescriptorMap();
340 BlackBoxDescriptor::InputDescriptorMapType::const_iterator i
341 = imap.find(caller->GetBlackBoxToInput());
344 // Cast the BBOutputDescriptor into a ComplexBBOutputDescriptor
345 ComplexBlackBoxInputDescriptor* d =
346 (ComplexBlackBoxInputDescriptor*)i->second;
347 // Get the internal box
348 BlackBox* b = bbUnsafeGetBlackBox ( d->GetTarget() );
349 // Calls ForwardUpdate on it
350 bbtkDebugMessage("Process",2,"-> Internal box connected to input : "<<d->GetTarget()<<std::endl);
351 b->bbForwardUpdate(caller);
355 bbtkError("Connection '"<<caller->GetFullName()<<"' does not point to a valid input of the complex box !");
357 bbtkDebugDecTab("Process",1);
359 //==================================================================
363 //==================================================================
364 Data ComplexBlackBox::bbGetOutput( const std::string &name )
366 bbtkDebugMessageInc("Data",7,
367 "ComplexBlackBox::bbGetOutput(\""<<name<<"\") ["
368 <<bbGetFullName()<<"]"<<std::endl);
370 ComplexBlackBoxOutputDescriptor* d =
371 (ComplexBlackBoxOutputDescriptor*)
372 bbGetDescriptor()->GetOutputDescriptor(name);
374 Data p = bbGetBlackBox(d->GetTarget())->bbGetOutput(d->GetOutput());
377 bbtkDebugDecTab("Data",7);
380 //==================================================================
382 //==================================================================
383 /// Gets the input Data of a given name
384 Data ComplexBlackBox::bbGetInput( const std::string &name )
386 bbtkDebugMessageInc("Data",7,
387 "ComplexBlackBox::bbGetInput(\""<<name<<"\") ["
388 <<bbGetFullName()<<"]"<<std::endl);
390 ComplexBlackBoxInputDescriptor* d =
391 (ComplexBlackBoxInputDescriptor*)
392 bbGetDescriptor()->GetInputDescriptor(name);
394 Data p = bbGetBlackBox(d->GetTarget())->bbGetInput(d->GetInput());
396 bbtkDebugDecTab("Data",7);
399 //==================================================================
401 //==================================================================
402 /// Sets the data of the output called <name>
403 void ComplexBlackBox::bbSetOutput( const std::string &name, Data data)
405 bbtkDebugMessageInc("Data",7,
406 "ComplexBlackBox::bbSetOutput(\""<<name<<"\",data) ["
407 <<bbGetFullName()<<"]"<<std::endl);
409 ComplexBlackBoxOutputDescriptor* d =
410 (ComplexBlackBoxOutputDescriptor*)
411 bbGetDescriptor()->GetOutputDescriptor(name);
413 bbGetBlackBox(d->GetTarget())->bbSetOutput(d->GetOutput(),data);
415 bbtkDebugDecTab("Data",7);
417 //==================================================================
419 //==================================================================
420 /// Sets the data of the input called <name>
421 void ComplexBlackBox::bbSetInput( const std::string &name, Data data,
424 bbtkDebugMessageInc("Data",7,
425 "ComplexBlackBox::bbSetInput(\""<<name<<"\",data) ["
426 <<bbGetFullName()<<"]"<<std::endl);
428 ComplexBlackBoxInputDescriptor* d = (ComplexBlackBoxInputDescriptor*)
429 bbGetDescriptor()->GetInputDescriptor(name);
431 bbGetBlackBox(d->GetTarget())->bbSetInput(d->GetInput(),data,setModified);
433 bbtkDebugDecTab("Data",7);
435 //==================================================================
438 //==================================================================
439 /// Sets the data of the input called <name>
440 void ComplexBlackBox::bbBruteForceSetInputPointer( const std::string &name,
444 bbtkDebugMessageInc("Data",7,
445 "ComplexBlackBox::bbBruteForceSetInputPointer('"
446 <<name<<"',"<<data<<") ["
447 <<bbGetFullName()<<"]"<<std::endl);
449 ComplexBlackBoxInputDescriptor* d = (ComplexBlackBoxInputDescriptor*)
450 bbGetDescriptor()->GetInputDescriptor(name);
452 bbGetBlackBox(d->GetTarget())->bbBruteForceSetInputPointer(d->GetInput(),
456 bbtkDebugDecTab("Data",7);
458 //==================================================================
460 //==================================================================
461 /// Adds the black box to the complex box
462 void ComplexBlackBox::bbAddBlackBox( BlackBox* b)
464 bbtkDebugMessageInc("Core",7,
465 "ComplexBlackBox::AddBlackBox(\""<<b->bbGetName()
467 <<bbGetFullName()<<"]"<<std::endl);
469 if ( bbUnsafeGetBlackBox(b->bbGetName()) )
471 bbtkError("a black box called \""<<b->bbGetName()
472 <<"\" already exists");
474 b->bbSetParent(this);
475 mBlackBoxMap[b->bbGetName()] = b;
477 bbtkDebugDecTab("Core",7);
479 //==================================================================
481 //==================================================================
482 /// Adds the black box to the complex box (unsafe)
483 void ComplexBlackBox::bbUnsafeAddBlackBox( BlackBox* b)
485 bbtkDebugMessageInc("Core",7,
486 "ComplexBlackBox::UnsafeAddBlackBox(\""<<b->bbGetName()
488 <<bbGetFullName()<<"]"<<std::endl);
490 b->bbSetParent(this);
491 mBlackBoxMap[b->bbGetName()] = b;
493 bbtkDebugDecTab("Core",7);
495 //==================================================================
497 //==================================================================
498 /// Removes the black box from the complex box
499 void ComplexBlackBox::bbRemoveBlackBox( const std::string& name )
501 bbtkDebugMessageInc("Core",7,
502 "ComplexBlackBox::RemoveBlackBox(\""<<name<<"\") ["
503 <<bbGetFullName()<<"]"<<std::endl);
505 bbtkError("ComplexBlackBox::RemoveBlackBox not implemented");
507 bbtkDebugDecTab("Core",7);
509 //==================================================================
511 //==================================================================
512 /// Adds the connection to the complex box
513 void ComplexBlackBox::bbAddConnection( Connection* c)
515 bbtkDebugMessageInc("Core",7,
516 "ComplexBlackBox::AddConnection(\""<<"..."<<"\") ["
517 <<bbGetFullName()<<"]"<<std::endl);
519 mConnectionList.push_back(c);
521 bbtkDebugDecTab("Core",7);
523 //==================================================================
524 // void RemoveConnection( );
526 //==================================================================
527 /// Returns the black box with name <name>
528 BlackBox* ComplexBlackBox::bbGetBlackBox( const std::string& name )
530 bbtkDebugMessageInc("Core",9,
531 "ComplexBlackBox::GetBlackBox(\""<<name<<"\") ["
532 <<bbGetFullName()<<"]"<<std::endl);
534 BlackBoxMapType::iterator i = mBlackBoxMap.find(name);
535 if ( i == mBlackBoxMap.end() )
537 bbtkError("the black box \""<<name<<"\" does not exist");
540 bbtkDebugDecTab("Core",9);
543 //==================================================================
545 //==================================================================
546 /// Returns the black box with name <name> : does not throw an exception
547 /// if it does not exist but return a null pointer
548 BlackBox* ComplexBlackBox::bbUnsafeGetBlackBox( const std::string& name )
550 bbtkDebugMessageInc("Core",9,
551 "ComplexBlackBox::UnsafeGetBlackBox(\""<<name<<"\") ["
552 <<bbGetFullName()<<"]"
555 BlackBoxMapType::iterator i = mBlackBoxMap.find(name);
556 if ( i == mBlackBoxMap.end() )
558 bbtkDebugDecTab("Core",9);
562 bbtkDebugDecTab("Core",9);
566 //==================================================================
568 //==================================================================
569 void ComplexBlackBox::bbPrintBlackBoxes()
571 bbtkDebugMessageInc("Core",9,
572 "ComplexBlackBox::PrintBlackBoxes() ["
573 <<bbGetFullName()<<"]"
576 BlackBoxMapType::iterator i;
577 for ( i = mBlackBoxMap.begin(); i != mBlackBoxMap.end(); ++i )
579 bbtkMessage("Help",1,i->second->bbGetFullName()<<std::endl);
582 bbtkDebugDecTab("Core",9);
584 //==================================================================
588 //=========================================================================
590 void ComplexBlackBox::bbWriteDotInputOutputName(FILE *ff,bool inputoutput,int detail, int level)
594 fprintf(ff,"%s_IN_%p",bbGetTypeName().c_str(),this);
596 fprintf(ff,"%s_OUT_%p",bbGetTypeName().c_str(),this);
599 //=========================================================================
602 //=========================================================================
603 BlackBox *ComplexBlackBox::bbFindBlackBox(const std::string &blackboxname)
605 BlackBox *blackbox=NULL;
606 std::string subname="";
607 std::string restname="";
608 std::string delimiters(">");
609 // Skip delimiters at beginning.
610 std::string::size_type lastPos = blackboxname.find_first_not_of(delimiters, 0);
611 // Find first "non-delimiter".
612 std::string::size_type pos = blackboxname.find_first_of(delimiters, lastPos);
614 // Found a token, add it to the vector.
615 subname = blackboxname.substr(lastPos, pos - lastPos);
616 restname = blackboxname.substr(lastPos+pos - lastPos+1, 999);
618 if (restname==subname)
623 BlackBoxMapType::iterator i = mBlackBoxMap.find(subname);
624 if ( i == mBlackBoxMap.end() )
628 blackbox = i->second;
631 blackbox = blackbox->bbFindBlackBox(restname);
636 //=========================================================================
638 //=========================================================================
639 void ComplexBlackBox::bbInsertHTMLGraph( std::ofstream& s,
643 const std::string& output_dir,
647 std::string directory(output_dir);
649 if (output_dir.length() == 0)
651 // Don't pollute the file store with "doc_tmp" directories ...
652 std::string default_doc_dir = ConfigurationFile::GetInstance().Get_default_doc_tmp();
653 directory = default_doc_dir + "/" + "doc_tmp";
656 std::string simplefilename (this->bbGetTypeName()+"_"+this->bbGetName());
657 std::string simplefilename_png (simplefilename+".png");
658 std::string filename (directory+"/"+simplefilename);
659 std::string filename_png (filename+".png");
660 std::string filename_cmap (filename+".cmap");
661 std::string filename_dot (filename+".dot");
663 std::string filename_png2 ("\"" + filename_png + "\"");
664 std::string filename_cmap2 ("\"" + filename_cmap + "\"");
665 std::string filename_dot2 ("\"" + filename_dot + "\"");
668 std::string command1 ("dot -T png -o "
669 + filename_png2 + " " + filename_dot2);
670 std::string command1a("dot -T cmap -o "
671 + filename_cmap2 + " " + filename_dot2);
673 // 1. Generating .dot file
675 ff = fopen(filename_dot.c_str(),"w");
676 fprintf(ff,"digraph bbtk_graph{\n");
677 fprintf(ff,"rankdir=LR%s\n",";");
678 fprintf(ff,"node [shape=record]%s\n",";");
680 this->bbWriteDotFileBlackBox(ff,this,detail,level,
687 // 2. Executing .dot file -> png
688 system( command1.c_str() );
689 // 3. Executing .dot file -> cmap
690 system( command1a.c_str() );
692 // 4. HTML code insertion
694 (s) << "<center><img src=\"" << simplefilename_png
695 << "\" border=\"0\" usemap=\"#map_"<< simplefilename
696 <<"\" alt=\"\"></center>\n";
699 (s) << "<map name=\"map_"<< simplefilename <<"\">\n";
702 ff2=fopen(filename_cmap.c_str(),"r");
715 //=========================================================================
718 //=========================================================================
719 /// Write Graphviz-dot description in file
720 void ComplexBlackBox::bbWriteDotFileBlackBox(FILE *ff,
721 BlackBox *parentblackbox,
722 int detail, int level,
727 std::string valueStr("");
728 Package *package = this->bbGetDescriptor()->GetPackage();
733 tmp1 = this->bbGetDescriptor()->GetPackage()->GetDocRelativeURL();
735 tmp1 = this->bbGetDescriptor()->GetPackage()->GetDocURL();
742 std::string tmp2=bbGetTypeName();
743 std::string url(tmp1 + "#" + tmp2 );
744 fprintf( ff , "subgraph cluster_%s_%p {\n",bbGetName().c_str(),this);
746 if (!( (bbGetTypeName()=="workspace") && (bbGetName()=="workspacePrototype")) )
748 fprintf( ff , " URL = \"%s\" %s",url.c_str(),";");
751 std::string boxname="["+bbGetTypeName()+"]";
752 if (this!=parentblackbox)
758 boxname = bbGetName();
759 boxname = boxname + " [" +this->bbGetDescriptor()->GetPackage()->GetName()+"::"+ bbGetTypeName() + "]";
763 fprintf( ff , " label = \"%s\"%s\n", boxname.c_str() ,";");
767 // fprintf( ff , " style=filled%s\n",";");
768 // fprintf( ff , " color=grey%s\n",";");
769 fprintf( ff , " node [style=filled]%s\n",";");
770 fprintf( ff , " fillcolor=grey%s\n",";");
771 fprintf( ff , " edge [color=blue]%s\n",";");
775 std::string labelStr1;
776 std::string labelStr2;
777 labelStr1 = boxname + "\\n(output)" ;
778 labelStr2 = " | {{ ";
781 OutputConnectorMapType::iterator i;
783 const BlackBoxDescriptor::OutputDescriptorMapType& omap = this->bbGetDescriptor()->GetOutputDescriptorMap();
784 BlackBoxDescriptor::OutputDescriptorMapType::const_iterator o;
785 for ( o = omap.begin(); o != omap.end(); ++o )
789 labelStr2=labelStr2+" | ";
792 if (instanceOrtype==true)
794 valueStr = this->bbGetOutputAsString(o->second->GetName()/*
797 labelStr2=labelStr2+"<"+o->second->GetName().c_str()+"> " + valueStr + o->second->GetName().c_str();
800 labelStr2 = labelStr2+ " } }";
806 labelStr1 = labelStr1 + labelStr2;
811 bbWriteDotInputOutputName(ff,false,detail,level);
812 fprintf( ff , " [shape=record, style=filled,fillcolor=grey,color=red,label=\"%s\"]%s\n",labelStr1.c_str(),";" );
817 labelStr1 = boxname + "\\n(input)" ;
818 labelStr2 = " | {{ ";
820 InputConnectorMapType::iterator ii;
822 const BlackBoxDescriptor::InputDescriptorMapType& imap = this->bbGetDescriptor()->GetInputDescriptorMap();
823 BlackBoxDescriptor::InputDescriptorMapType::const_iterator iii;
824 for ( iii = imap.begin(); iii != imap.end(); ++iii )
828 labelStr2=labelStr2+" | ";
831 if (instanceOrtype==true)
833 valueStr = this->bbGetInputAsString(iii->second->GetName()/*,factory*/) + " = ";
835 labelStr2=labelStr2+"<"+iii->second->GetName().c_str()+"> " + valueStr + iii->second->GetName().c_str();
839 labelStr2 = labelStr2+ " } }";
842 labelStr1 = labelStr1 + labelStr2;
846 bbWriteDotInputOutputName(ff,true,detail,level);
847 fprintf( ff , " [shape=record, style=filled,fillcolor=grey,color=red,label=\"%s\"]%s\n",labelStr1.c_str(),";" );
852 BlackBoxMapType::iterator j;
853 for ( j = mBlackBoxMap.begin(); j != mBlackBoxMap.end(); ++j )
857 j->second->bbWriteDotFileBlackBox(ff,parentblackbox,detail,
864 fprintf( ff , "}\n\n");
866 fprintf( ff , " edge[color=blue]%s\n",";");
870 // Relation Input with the inside BlackBox of the this ComplexBlackbox
871 ComplexBlackBoxDescriptor::InputDescriptorMapType::iterator xx;
872 ComplexBlackBoxDescriptor::InputDescriptorMapType idmt=bbGetDescriptor()->GetInputDescriptorMap();
873 for ( xx = idmt.begin(); xx != idmt.end(); ++xx )
875 ComplexBlackBoxInputDescriptor *cbbid = (ComplexBlackBoxInputDescriptor*)xx->second;
878 bbWriteDotInputOutputName(ff,true,detail,level);
881 fprintf(ff,":%s",cbbid->GetName().c_str() );
884 BlackBox *bb = bbGetBlackBox( cbbid->GetTarget() );
885 bb->bbWriteDotInputOutputName(ff,true,detail,level);
888 fprintf(ff,":%s \n", cbbid->GetInput().c_str() );
898 // Relation Output ComplexBlackBox
899 ComplexBlackBoxDescriptor::OutputDescriptorMapType::iterator yy;
900 ComplexBlackBoxDescriptor::OutputDescriptorMapType odmt=bbGetDescriptor()->GetOutputDescriptorMap();
901 for ( yy = odmt.begin(); yy != odmt.end(); ++yy )
903 ComplexBlackBoxOutputDescriptor *cbbod = (ComplexBlackBoxOutputDescriptor*)yy->second;
905 BlackBox *bb = bbGetBlackBox( cbbod->GetTarget() );
906 bb->bbWriteDotInputOutputName(ff,false,detail,level);
909 fprintf(ff,":%s", cbbod->GetOutput().c_str() );
912 bbWriteDotInputOutputName(ff,false,detail,level);
915 fprintf(ff,":%s",cbbod->GetName().c_str() );
924 // Relation from the out side of this ComplexBlackBox with its Inputs
925 if (this!=parentblackbox) {
926 for ( ii = bbGetInputConnectorMap().begin();
927 ii != bbGetInputConnectorMap().end(); ++ii )
931 Connection* con = ii->second->GetConnection();
933 BlackBox *a=con->GetBlackBoxFrom();
934 BlackBox *b=con->GetBlackBoxTo();
936 a->bbWriteDotInputOutputName(ff,false,detail,level);
939 fprintf(ff,":%s",con->GetBlackBoxFromOutput().c_str());
942 b->bbWriteDotInputOutputName(ff,true,detail,level);
945 fprintf(ff,":%s",con->GetBlackBoxToInput().c_str());
947 fprintf(ff,"%s\n",";");
951 } // if parentblackbox
954 //=========================================================================
959 //=======================================================================
960 /// Generates the list of the packages of which its depends
961 /// (cause an internal box belongs to it)
962 void ComplexBlackBox::GetPackagesDependencies(std::vector<Package*>& deps)
965 BlackBoxMapType::iterator i;
966 for ( i = mBlackBoxMap.begin(); i != mBlackBoxMap.end(); ++i )
968 deps.push_back(i->second->bbGetDescriptor()->GetPackage());
972 //=======================================================================