1 /*=========================================================================
4 Module: $RCSfile: bbtkComplexBlackBox.cxx,v $
6 Date: $Date: 2008/04/09 11:16:57 $
7 Version: $Revision: 1.9 $
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("Kernel",9,
41 "ComplexBlackBox::ComplexBlackBox(\""
42 <<name<<"\")"<<std::endl);
43 bbAllocateConnectors();
44 bbtkDebugDecTab("Kernel",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("Kernel",9,
57 "ComplexBlackBox::ComplexBlackBox(\""
58 <<from.bbGetName()<<"\",\""
59 <<name<<"\")"<<std::endl);
61 bbtkDebugMessageInc("Kernel",9,"* Cloning Black Boxes"<<std::endl);
62 BlackBoxMapType::const_iterator i;
63 for ( i = from.mBlackBoxMap.begin(); i != from.mBlackBoxMap.end(); ++i )
65 bbtkDebugMessageInc("Kernel",9,"* Cloning \""<<i->first<<"\""<<std::endl);
66 BlackBox* B = i->second->bbClone(i->second->bbGetName());
67 bbUnsafeAddBlackBox(B);
69 bbtkDebugDecTab("Kernel",9);
71 bbtkDebugDecTab("Kernel",9);
73 bbtkDebugMessageInc("Kernel",9,"* Cloning Connections"<<std::endl);
74 ConnectionListType::const_iterator j;
75 for ( j = from.mConnectionList.begin(); j != from.mConnectionList.end(); ++j )
77 bbtkDebugMessageInc("Kernel",9,"* Cloning \""<<
78 (*j)->GetFullName()<<"\""<<std::endl);
80 BlackBox* bbfrom = bbGetBlackBox( (*j)->GetOriginalBlackBoxFrom()->bbGetName() );
81 BlackBox* bbto = bbGetBlackBox( (*j)->GetOriginalBlackBoxTo()->bbGetName() );
82 Connection* c = mDescriptor->GetFactory()->
83 NewConnection( bbfrom,
84 (*j)->GetOriginalBlackBoxFromOutput(),
86 (*j)->GetOriginalBlackBoxToInput() );
91 bbtkDebugDecTab("Kernel",9);
93 bbtkDebugDecTab("Kernel",9);
95 bbAllocateConnectors();
96 bbtkDebugDecTab("Kernel",9);
98 //=======================================================================
100 //=======================================================================
102 ComplexBlackBox::~ComplexBlackBox()
104 bbtkDebugMessageInc("Kernel",1,
105 "ComplexBlackBox::~ComplexBlackBox() ["
106 <<bbGetFullName()<<"]"<<std::endl);
108 bbtkDebugMessageInc("Kernel",1,"* Delete Connections"<<std::endl);
109 ConnectionListType::iterator j;
110 for ( j = mConnectionList.begin(); j != mConnectionList.end(); ++j )
112 bbtkDebugMessageInc("Kernel",1,"* Delete \""<<
113 (*j)->GetFullName()<<"\""<<std::endl);
115 bbtkDebugDecTab("Kernel",9);
117 bbtkDebugDecTab("Kernel",9);
120 bbtkDebugMessageInc("Kernel",1,"* Delete Black Boxes"<<std::endl);
121 BlackBoxMapType::iterator i;
122 for ( i = mBlackBoxMap.begin(); i != mBlackBoxMap.end(); ++i )
124 bbtkDebugMessageInc("Kernel",1,"* Delete \""<<i->first<<"\""<<std::endl);
125 i->second->bbDelete();
126 bbtkDebugDecTab("Kernel",1);
128 bbtkDebugDecTab("Kernel",1);
130 bbtkDebugMessage("Kernel",1,"EO ComplexBlackBox::~ComplexBlackBox ["
131 <<bbGetFullName()<<"]"<<std::endl);
133 this->bbDesallocateConnectors();
134 bbtkDebugDecTab("Kernel",1);
136 //=======================================================================
138 //=========================================================================
139 /// Allocates the i/o connectors of the black box
140 void ComplexBlackBox::bbAllocateConnectors()
142 bbtkDebugMessageInc("Kernel",8,
143 "ComplexBlackBox::bbAllocateConnectors() ["
144 <<bbGetFullName()<<"]"
148 const BlackBoxDescriptor::InputDescriptorMapType& imap
149 = bbGetDescriptor()->GetInputDescriptorMap();
150 BlackBoxDescriptor::InputDescriptorMapType::const_iterator i;
151 for ( i = imap.begin(); i != imap.end(); ++i )
153 bbtkDebugMessage("Kernel",8,"* Allocate \""<<i->first<<"\""<<std::endl);
154 // Redirect the connector to the internal box connector
155 // Cast the BBInputDescriptor into a ComplexBBInputDescriptor
156 ComplexBlackBoxInputDescriptor* d =
157 (ComplexBlackBoxInputDescriptor*)i->second;
158 // Get the internal box connector
159 BlackBoxInputConnector* c =
160 bbUnsafeGetBlackBox ( d->GetTarget() )
161 ->bbGetInputConnectorMap()[ d->GetInput() ];
163 bbGetInputConnectorMap()[i->second->GetName()] = c;
164 //new BlackBoxInputConnector();
168 const BlackBoxDescriptor::OutputDescriptorMapType& omap
169 = bbGetDescriptor()->GetOutputDescriptorMap();
170 BlackBoxDescriptor::OutputDescriptorMapType::const_iterator o;
171 for ( o = omap.begin(); o != omap.end(); ++o )
173 bbtkDebugMessage("Kernel",8,"* Allocate \""<<o->first<<"\""<<std::endl);
174 // Redirect the connector to the internal box connector
175 // Cast the BBOutputDescriptor into a ComplexBBOutputDescriptor
176 ComplexBlackBoxOutputDescriptor* d =
177 (ComplexBlackBoxOutputDescriptor*)o->second;
178 // Get the internal box connector
179 BlackBoxOutputConnector* c =
180 bbUnsafeGetBlackBox ( d->GetTarget() )
181 ->bbGetOutputConnectorMap()[ d->GetOutput() ];
183 bbGetOutputConnectorMap()[o->second->GetName()] = c;
184 //new BlackBoxOutputConnector();
186 bbtkDebugDecTab("Kernel",8);
188 //=========================================================================
191 //=========================================================================
192 /// Desallocates the i/o connectors of the black box
193 void ComplexBlackBox::bbDesallocateConnectors()
195 bbtkDebugMessageInc("Kernel",8,
196 "ComplexBlackBox::DesallocateConnectors()"
199 // The connectors have not been allocated by the complex box
200 // but by the internal boxes. Hence **DO NOT** desallocate !
201 // just clear the maps to avoid that
202 // BlackBox::bbDesallocateConnectors delete the connectors
203 bbGetInputConnectorMap().clear();
204 bbGetOutputConnectorMap().clear();
206 bbtkDebugDecTab("Kernel",8);
209 //=========================================================================
211 //=======================================================================
212 BlackBox* ComplexBlackBox::bbClone(const std::string& name)
214 bbtkDebugMessageInc("Kernel",9,
215 "ComplexBlackBox::bbClone(\""<<name<<"\") ["
216 <<bbGetFullName()<<"]"<<std::endl);
218 ComplexBlackBox* CBB = new ComplexBlackBox(*this,name);
219 bbGetDescriptor()->Reference();
221 bbtkDebugDecTab("Kernel",9);
225 //=======================================================================
227 //=======================================================================
228 /// Main processing method of the box.
229 /// Executes the box so that its outputs are up-to-date on exit
230 void ComplexBlackBox::bbExecute(bool force)
232 bbtkDebugMessageInc("Process",1,
233 "ComplexBlackBox::bbExecute() ["
234 <<bbGetFullName()<<"]"<<std::endl);
237 Wx::BeginBusyCursor();
239 if (mExecutionList.size() != 0)
242 std::vector<std::string>::const_iterator i;
243 for (i=mExecutionList.begin();
244 i!=mExecutionList.end();
247 bbtkDebugMessage("Process",2," -> Executing '"<<*i<<"'"<<std::endl);
248 mBlackBoxMap[*i]->bbExecute(force);
253 std::map<std::string, BlackBox*>::iterator i;
254 for (i=mBlackBoxMap.begin(); i!=mBlackBoxMap.end(); ++i)
256 i->second->bbExecute(force);
263 bbtkDebugDecTab("Process",1);
266 //==================================================================
268 //==================================================================
269 void ComplexBlackBox::bbSetModifiedStatus(BlackBoxInputConnector* c)
271 bbtkDebugMessage("Process",3,
272 "ComplexBlackBox::bbSetModifiedStatus("
273 <<c<<") ["<<bbGetFullName()<<"]"<<std::endl);
275 c->GetBlackBox()->bbSetModifiedStatus(c);
277 bbtkDebugMessage("Process",3,
278 "EO ComplexBlackBox::bbSetModifiedStatus("
279 <<c<<") ["<<bbGetFullName()<<"]"<<std::endl);
281 //==================================================================
283 //==================================================================
284 void ComplexBlackBox::bbAddToExecutionList( const std::string& name )
286 bbtkDebugMessageInc("Kernel",9,
287 "ComplexBlackBox::bbAddToExecutionList(\""
289 <<bbGetFullName()<<"]"<<std::endl);
291 mExecutionList.push_back( name );
293 bbtkDebugDecTab("Kernel",9);
296 //==================================================================
298 //==================================================================
299 IOStatus ComplexBlackBox::bbBackwardUpdate(Connection* caller)
301 bbtkDebugMessageInc("Process",1,
302 "ComplexBlackBox::bbBackwardUpdate("
303 <<(caller?caller->GetFullName():"0")<<") ["
304 <<bbGetFullName()<<"]"<<std::endl);
305 bbtkInternalError("ComplexBlackBox::bbBackwardUpdate should never be called !");
309 bbtkInternalError("ComplexBlackBox::bbBackwardUpdate called with caller=0");
312 if (bbGetExecuting())
314 bbtkWarning(bbGetFullName()<<" : Cyclic execution stopped");
317 bbSetExecuting(true);
319 IOStatus s = UPTODATE;
320 const BlackBoxDescriptor::OutputDescriptorMapType& omap
321 = bbGetDescriptor()->GetOutputDescriptorMap();
322 BlackBoxDescriptor::OutputDescriptorMapType::const_iterator i
323 = omap.find(caller->GetBlackBoxFromOutput());
326 // Cast the BBOutputDescriptor into a ComplexBBOutputDescriptor
327 ComplexBlackBoxOutputDescriptor* d =
328 (ComplexBlackBoxOutputDescriptor*)i->second;
329 // Get the internal box
330 BlackBox* b = bbUnsafeGetBlackBox ( d->GetTarget() );
331 // Calls BackwardUpdate on it
332 bbtkDebugMessageInc("Process",2,"Internal box connected to output : "<<d->GetTarget()<<std::endl);
333 // Because internal box can also be a complex box we have to
334 // temporarily change the connection BlackBoxFromOutput to the
337 // std::string oldout = caller->GetBlackBoxFromOutput();
338 // std::cout << "oldout = "<<oldout<<std::endl;
339 // std::cout << "tmpout = "<<d->GetOutput()<<std::endl;
340 // caller->SetBlackBoxFromOutput(d->GetOutput());
342 //Connection newcaller(*caller);
343 //newcaller.SetBlackBoxFromOutput(d->GetOutput());
344 //IOStatus s1 = b->bbBackwardUpdate(&newcaller);
345 IOStatus s1 = b->bbBackwardUpdate(caller);
347 // restore old output
348 // caller->SetBlackBoxFromOutput(oldout);
350 // ??? STATUS OF CBBs ???
351 // ??? Here it is only the final status of the boxes connected to the output
352 if (s1==MODIFIED) s=MODIFIED;
353 bbtkDebugDecTab("Process",2);
357 bbtkError("Connection '"<<caller->GetFullName()<<"' does not point to a valid output of the complex box !");
359 bbtkDebugDecTab("Process",1);
361 bbSetExecuting(false);
367 //==================================================================
370 //==================================================================
371 Data ComplexBlackBox::bbGetOutput( const std::string &name )
373 bbtkDebugMessageInc("Data",7,
374 "ComplexBlackBox::bbGetOutput(\""<<name<<"\") ["
375 <<bbGetFullName()<<"]"<<std::endl);
377 ComplexBlackBoxOutputDescriptor* d =
378 (ComplexBlackBoxOutputDescriptor*)
379 bbGetDescriptor()->GetOutputDescriptor(name);
381 Data p = bbGetBlackBox(d->GetTarget())->bbGetOutput(d->GetOutput());
384 bbtkDebugDecTab("Data",7);
387 //==================================================================
389 //==================================================================
390 /// Gets the input Data of a given name
391 Data ComplexBlackBox::bbGetInput( const std::string &name )
393 bbtkDebugMessageInc("Data",7,
394 "ComplexBlackBox::bbGetInput(\""<<name<<"\") ["
395 <<bbGetFullName()<<"]"<<std::endl);
397 ComplexBlackBoxInputDescriptor* d =
398 (ComplexBlackBoxInputDescriptor*)
399 bbGetDescriptor()->GetInputDescriptor(name);
401 Data p = bbGetBlackBox(d->GetTarget())->bbGetInput(d->GetInput());
403 bbtkDebugDecTab("Data",7);
406 //==================================================================
408 //==================================================================
409 /// Sets the data of the output called <name>
410 void ComplexBlackBox::bbSetOutput( const std::string &name, Data data)
412 bbtkDebugMessageInc("Data",7,
413 "ComplexBlackBox::bbSetOutput(\""<<name<<"\",data) ["
414 <<bbGetFullName()<<"]"<<std::endl);
416 ComplexBlackBoxOutputDescriptor* d =
417 (ComplexBlackBoxOutputDescriptor*)
418 bbGetDescriptor()->GetOutputDescriptor(name);
420 bbGetBlackBox(d->GetTarget())->bbSetOutput(d->GetOutput(),data);
422 bbtkDebugDecTab("Data",7);
424 //==================================================================
426 //==================================================================
427 /// Sets the data of the input called <name>
428 void ComplexBlackBox::bbSetInput( const std::string &name, Data data,
431 bbtkDebugMessageInc("Data",7,
432 "ComplexBlackBox::bbSetInput(\""<<name<<"\",data) ["
433 <<bbGetFullName()<<"]"<<std::endl);
435 ComplexBlackBoxInputDescriptor* d = (ComplexBlackBoxInputDescriptor*)
436 bbGetDescriptor()->GetInputDescriptor(name);
438 bbGetBlackBox(d->GetTarget())->bbSetInput(d->GetInput(),data,setModified);
440 bbtkDebugDecTab("Data",7);
442 //==================================================================
445 //==================================================================
446 /// Sets the data of the input called <name>
447 void ComplexBlackBox::bbBruteForceSetInputPointer( const std::string &name,
451 bbtkDebugMessageInc("Data",7,
452 "ComplexBlackBox::bbBruteForceSetInputPointer('"
453 <<name<<"',"<<data<<") ["
454 <<bbGetFullName()<<"]"<<std::endl);
456 ComplexBlackBoxInputDescriptor* d = (ComplexBlackBoxInputDescriptor*)
457 bbGetDescriptor()->GetInputDescriptor(name);
459 bbGetBlackBox(d->GetTarget())->bbBruteForceSetInputPointer(d->GetInput(),
463 bbtkDebugDecTab("Data",7);
465 //==================================================================
467 //=========================================================================
468 /// Connects the input <name> to the connection c
469 void ComplexBlackBox::bbConnectInput( const std::string& name, Connection* c)
471 bbtkDebugMessageInc("Kernel",7,
472 "ComplexBlackBox::bbConnectInput(\""
473 <<name<<"\","<<c<<") ["
474 <<bbGetFullName()<<"]"
477 ComplexBlackBoxInputDescriptor* d = (ComplexBlackBoxInputDescriptor*)
478 bbGetDescriptor()->GetInputDescriptor(name);
480 BlackBox* t = bbGetBlackBox(d->GetTarget());
482 c->SetBlackBoxToInput(d->GetInput());
483 t->bbConnectInput(d->GetInput(),c);
485 bbtkMessage("Debug",1,"ComplexBlackBox["<<bbGetFullName()<<"]::bbConnectInput : "
486 <<c->GetFullName()<<std::endl);
488 bbtkDebugDecTab("Kernel",7);
490 //=========================================================================
493 //=========================================================================
494 /// Connects the output <name> to the connection c
495 void ComplexBlackBox::bbConnectOutput( const std::string& name, Connection* c)
497 bbtkDebugMessageInc("Kernel",7,
498 "ComplexBlackBox::bbConnectOutput(\""
499 <<name<<"\","<<c<<") ["
500 <<bbGetFullName()<<"]"<<std::endl);
502 ComplexBlackBoxOutputDescriptor* d = (ComplexBlackBoxOutputDescriptor*)
503 bbGetDescriptor()->GetOutputDescriptor(name);
505 BlackBox* t = bbGetBlackBox(d->GetTarget());
506 c->SetBlackBoxFrom(t);
507 c->SetBlackBoxFromOutput(d->GetOutput());
508 t->bbConnectOutput(d->GetOutput(),c);
510 bbtkMessage("Debug",1,"ComplexBlackBox["<<bbGetFullName()<<"]::bbConnectOutput : "
511 <<c->GetFullName()<<std::endl);
513 bbtkDebugDecTab("Kernel",7);
515 //=========================================================================
518 //==================================================================
519 /// Adds the black box to the complex box
520 void ComplexBlackBox::bbAddBlackBox( BlackBox* b)
522 bbtkDebugMessageInc("Kernel",7,
523 "ComplexBlackBox::AddBlackBox(\""<<b->bbGetName()
525 <<bbGetFullName()<<"]"<<std::endl);
527 if ( bbUnsafeGetBlackBox(b->bbGetName()) )
529 bbtkError("a black box called \""<<b->bbGetName()
530 <<"\" already exists");
532 b->bbSetParent(this);
533 mBlackBoxMap[b->bbGetName()] = b;
535 bbtkDebugDecTab("Kernel",7);
537 //==================================================================
539 //==================================================================
540 /// Adds the black box to the complex box (unsafe)
541 void ComplexBlackBox::bbUnsafeAddBlackBox( BlackBox* b)
543 bbtkDebugMessageInc("Kernel",7,
544 "ComplexBlackBox::UnsafeAddBlackBox(\""<<b->bbGetName()
546 <<bbGetFullName()<<"]"<<std::endl);
548 b->bbSetParent(this);
549 mBlackBoxMap[b->bbGetName()] = b;
551 bbtkDebugDecTab("Kernel",7);
553 //==================================================================
555 //==================================================================
556 /// Removes the black box from the complex box
557 void ComplexBlackBox::bbRemoveBlackBox( const std::string& name )
559 bbtkDebugMessageInc("Kernel",7,
560 "ComplexBlackBox::RemoveBlackBox(\""<<name<<"\") ["
561 <<bbGetFullName()<<"]"<<std::endl);
563 bbtkError("ComplexBlackBox::RemoveBlackBox not implemented");
565 bbtkDebugDecTab("Kernel",7);
567 //==================================================================
569 //==================================================================
570 /// Adds the connection to the complex box
571 void ComplexBlackBox::bbAddConnection( Connection* c)
573 bbtkDebugMessageInc("Kernel",7,
574 "ComplexBlackBox::AddConnection(\""<<"..."<<"\") ["
575 <<bbGetFullName()<<"]"<<std::endl);
577 mConnectionList.push_back(c);
579 bbtkDebugDecTab("Kernel",7);
581 //==================================================================
582 // void RemoveConnection( );
584 //==================================================================
585 /// Returns the black box with name <name>
586 BlackBox* ComplexBlackBox::bbGetBlackBox( const std::string& name )
588 bbtkDebugMessageInc("Kernel",9,
589 "ComplexBlackBox::GetBlackBox(\""<<name<<"\") ["
590 <<bbGetFullName()<<"]"<<std::endl);
592 BlackBoxMapType::iterator i = mBlackBoxMap.find(name);
593 if ( i == mBlackBoxMap.end() )
595 bbtkError("the black box \""<<name<<"\" does not exist");
598 bbtkDebugDecTab("Kernel",9);
601 //==================================================================
603 //==================================================================
604 /// Returns the black box with name <name> : does not throw an exception
605 /// if it does not exist but return a null pointer
606 BlackBox* ComplexBlackBox::bbUnsafeGetBlackBox( const std::string& name )
608 bbtkDebugMessageInc("Kernel",9,
609 "ComplexBlackBox::UnsafeGetBlackBox(\""<<name<<"\") ["
610 <<bbGetFullName()<<"]"
613 BlackBoxMapType::iterator i = mBlackBoxMap.find(name);
614 if ( i == mBlackBoxMap.end() )
616 bbtkDebugDecTab("Kernel",9);
620 bbtkDebugDecTab("Kernel",9);
624 //==================================================================
626 //==================================================================
627 void ComplexBlackBox::bbPrintBlackBoxes()
629 bbtkDebugMessageInc("Kernel",9,
630 "ComplexBlackBox::PrintBlackBoxes() ["
631 <<bbGetFullName()<<"]"
634 BlackBoxMapType::iterator i;
635 for ( i = mBlackBoxMap.begin(); i != mBlackBoxMap.end(); ++i )
637 bbtkMessage("Help",1,i->second->bbGetFullName()<<std::endl);
640 bbtkDebugDecTab("Kernel",9);
642 //==================================================================
646 //=========================================================================
648 void ComplexBlackBox::bbWriteDotInputOutputName(FILE *ff,bool inputoutput,int detail, int level)
652 fprintf(ff,"%s_IN_%p",bbGetTypeName().c_str(),this);
654 fprintf(ff,"%s_OUT_%p",bbGetTypeName().c_str(),this);
657 //=========================================================================
660 //=========================================================================
661 BlackBox *ComplexBlackBox::bbFindBlackBox(const std::string &blackboxname)
663 BlackBox *blackbox=NULL;
664 std::string subname="";
665 std::string restname="";
666 std::string delimiters(">");
667 // Skip delimiters at beginning.
668 std::string::size_type lastPos = blackboxname.find_first_not_of(delimiters, 0);
669 // Find first "non-delimiter".
670 std::string::size_type pos = blackboxname.find_first_of(delimiters, lastPos);
672 // Found a token, add it to the vector.
673 subname = blackboxname.substr(lastPos, pos - lastPos);
674 restname = blackboxname.substr(lastPos+pos - lastPos+1, 999);
676 if (restname==subname)
681 BlackBoxMapType::iterator i = mBlackBoxMap.find(subname);
682 if ( i == mBlackBoxMap.end() )
688 blackbox = i->second;
691 blackbox = blackbox->bbFindBlackBox(restname);
696 //=========================================================================
698 //=========================================================================
699 void ComplexBlackBox::bbInsertHTMLGraph( std::ofstream& s,
703 const std::string& output_dir,
707 std::string directory(output_dir);
709 if (output_dir.length() == 0)
711 // Don't pollute the file store with "temp_dir" directories ...
712 std::string default_temp_dir = ConfigurationFile::GetInstance().Get_default_temp_dir();
713 directory = default_temp_dir + "/" + "temp_dir";
716 std::string simplefilename (this->bbGetTypeName()+"_"+this->bbGetName());
717 std::string simplefilename_png (simplefilename+".png");
718 std::string filename (directory+"/"+simplefilename);
719 std::string filename_png (filename+".png");
720 std::string filename_cmap (filename+".cmap");
721 std::string filename_dot (filename+".dot");
723 std::string filename_png2 ("\"" + filename_png + "\"");
724 std::string filename_cmap2 ("\"" + filename_cmap + "\"");
725 std::string filename_dot2 ("\"" + filename_dot + "\"");
728 std::string command1 ("dot -T png -o "
729 + filename_png2 + " " + filename_dot2);
730 std::string command1a("dot -T cmap -o "
731 + filename_cmap2 + " " + filename_dot2);
733 // 1. Generating .dot file
735 ff = fopen(filename_dot.c_str(),"w");
736 fprintf(ff,"digraph bbtk_graph{\n");
737 fprintf(ff,"rankdir=LR%s\n",";");
738 fprintf(ff,"node [shape=record]%s\n",";");
740 this->bbWriteDotFileBlackBox(ff,this,detail,level,
747 // 2. Executing .dot file -> png
748 system( command1.c_str() );
749 // 3. Executing .dot file -> cmap
750 system( command1a.c_str() );
752 // 4. HTML code insertion
754 (s) << "<center><img src=\"" << simplefilename_png
755 << "\" border=\"0\" usemap=\"#map_"<< simplefilename
756 <<"\" alt=\"\"></center>\n";
759 (s) << "<map name=\"map_"<< simplefilename <<"\">\n";
762 ff2=fopen(filename_cmap.c_str(),"r");
775 //=========================================================================
778 //=========================================================================
779 /// Write Graphviz-dot description in file
780 void ComplexBlackBox::bbWriteDotFileBlackBox(FILE *ff,
781 BlackBox *parentblackbox,
782 int detail, int level,
787 std::string valueStr("");
788 Package *package = this->bbGetDescriptor()->GetPackage();
793 tmp1 = this->bbGetDescriptor()->GetPackage()->GetDocRelativeURL();
795 tmp1 = this->bbGetDescriptor()->GetPackage()->GetDocURL();
802 std::string tmp2=bbGetTypeName();
803 std::string url(tmp1 + "#" + tmp2 );
804 fprintf( ff , "subgraph cluster_%s_%p {\n",bbGetName().c_str(),this);
806 if (!( (bbGetTypeName()=="workspace") && (bbGetName()=="workspacePrototype")) )
808 fprintf( ff , " URL = \"%s\" %s",url.c_str(),";");
811 std::string boxname="["+bbGetTypeName()+"]";
812 if (this!=parentblackbox)
820 boxname = bbGetName();
821 boxname = boxname + " [" +this->bbGetDescriptor()->GetPackage()->GetName()+"::"+ bbGetTypeName() + "]";
825 fprintf( ff , " label = \"%s\"%s\n", boxname.c_str() ,";");
829 // fprintf( ff , " style=filled%s\n",";");
830 // fprintf( ff , " color=grey%s\n",";");
831 fprintf( ff , " node [style=filled]%s\n",";");
832 fprintf( ff , " fillcolor=grey%s\n",";");
833 fprintf( ff , " edge [color=blue]%s\n",";");
837 std::string labelStr1;
838 std::string labelStr2;
839 labelStr1 = boxname + "\\n(output)" ;
840 labelStr2 = " | {{ ";
843 OutputConnectorMapType::iterator i;
845 const BlackBoxDescriptor::OutputDescriptorMapType& omap = this->bbGetDescriptor()->GetOutputDescriptorMap();
846 BlackBoxDescriptor::OutputDescriptorMapType::const_iterator o;
847 for ( o = omap.begin(); o != omap.end(); ++o )
851 labelStr2=labelStr2+" | ";
854 if (instanceOrtype==true)
856 valueStr = this->bbGetOutputAsString(o->second->GetName()/*
859 labelStr2=labelStr2+"<"+o->second->GetName().c_str()+"> " + valueStr + o->second->GetName().c_str();
862 labelStr2 = labelStr2+ " } }";
868 labelStr1 = labelStr1 + labelStr2;
873 bbWriteDotInputOutputName(ff,false,detail,level);
874 fprintf( ff , " [shape=record, style=filled,fillcolor=grey,color=red,label=\"%s\"]%s\n",labelStr1.c_str(),";" );
879 labelStr1 = boxname + "\\n(input)" ;
880 labelStr2 = " | {{ ";
882 InputConnectorMapType::iterator ii;
884 const BlackBoxDescriptor::InputDescriptorMapType& imap = this->bbGetDescriptor()->GetInputDescriptorMap();
885 BlackBoxDescriptor::InputDescriptorMapType::const_iterator iii;
886 for ( iii = imap.begin(); iii != imap.end(); ++iii )
890 labelStr2=labelStr2+" | ";
893 if (instanceOrtype==true)
895 valueStr = this->bbGetInputAsString(iii->second->GetName()/*,factory*/) + " = ";
897 labelStr2=labelStr2+"<"+iii->second->GetName().c_str()+"> " + valueStr + iii->second->GetName().c_str();
901 labelStr2 = labelStr2+ " } }";
904 labelStr1 = labelStr1 + labelStr2;
908 bbWriteDotInputOutputName(ff,true,detail,level);
909 fprintf( ff , " [shape=record, style=filled,fillcolor=grey,color=red,label=\"%s\"]%s\n",labelStr1.c_str(),";" );
914 BlackBoxMapType::iterator j;
915 for ( j = mBlackBoxMap.begin(); j != mBlackBoxMap.end(); ++j )
919 j->second->bbWriteDotFileBlackBox(ff,parentblackbox,detail,
926 fprintf( ff , "}\n\n");
928 fprintf( ff , " edge[color=blue]%s\n",";");
932 // Relation Input with the inside BlackBox of the this ComplexBlackbox
933 ComplexBlackBoxDescriptor::InputDescriptorMapType::iterator xx;
934 ComplexBlackBoxDescriptor::InputDescriptorMapType idmt=bbGetDescriptor()->GetInputDescriptorMap();
935 for ( xx = idmt.begin(); xx != idmt.end(); ++xx )
937 ComplexBlackBoxInputDescriptor *cbbid = (ComplexBlackBoxInputDescriptor*)xx->second;
940 bbWriteDotInputOutputName(ff,true,detail,level);
943 fprintf(ff,":%s",cbbid->GetName().c_str() );
946 BlackBox *bb = bbGetBlackBox( cbbid->GetTarget() );
947 bb->bbWriteDotInputOutputName(ff,true,detail,level);
950 fprintf(ff,":%s \n", cbbid->GetInput().c_str() );
960 // Relation Output ComplexBlackBox
961 ComplexBlackBoxDescriptor::OutputDescriptorMapType::iterator yy;
962 ComplexBlackBoxDescriptor::OutputDescriptorMapType odmt=bbGetDescriptor()->GetOutputDescriptorMap();
963 for ( yy = odmt.begin(); yy != odmt.end(); ++yy )
965 ComplexBlackBoxOutputDescriptor *cbbod = (ComplexBlackBoxOutputDescriptor*)yy->second;
967 BlackBox *bb = bbGetBlackBox( cbbod->GetTarget() );
968 bb->bbWriteDotInputOutputName(ff,false,detail,level);
971 fprintf(ff,":%s", cbbod->GetOutput().c_str() );
974 bbWriteDotInputOutputName(ff,false,detail,level);
977 fprintf(ff,":%s",cbbod->GetName().c_str() );
986 // Relation from the out side of this ComplexBlackBox with its Inputs
987 if (this!=parentblackbox) {
988 for ( ii = bbGetInputConnectorMap().begin();
989 ii != bbGetInputConnectorMap().end(); ++ii )
993 Connection* con = ii->second->GetConnection();
995 BlackBox *a=con->GetBlackBoxFrom();
996 BlackBox *b=con->GetBlackBoxTo();
998 a->bbWriteDotInputOutputName(ff,false,detail,level);
1001 fprintf(ff,":%s",con->GetBlackBoxFromOutput().c_str());
1004 b->bbWriteDotInputOutputName(ff,true,detail,level);
1007 fprintf(ff,":%s",con->GetBlackBoxToInput().c_str());
1009 fprintf(ff,"%s\n",";");
1013 } // if parentblackbox
1015 //=========================================================================
1022 //=======================================================================
1023 /// Generates the list of the packages of which its depends
1024 /// (cause an internal box belongs to it)
1025 void ComplexBlackBox::GetPackagesDependencies(std::vector<Package*>& deps)
1028 BlackBoxMapType::iterator i;
1029 for ( i = mBlackBoxMap.begin(); i != mBlackBoxMap.end(); ++i )
1031 deps.push_back(i->second->bbGetDescriptor()->GetPackage());
1035 //=======================================================================
1038 //=======================================================================
1039 void ComplexBlackBox::Check(bool recursive)
1041 bbtkMessage("Debug",1,"**** Checking Complex Black Box "<<(void*)this
1042 <<" ["<<bbGetFullName()<<"]"<<std::endl);
1044 BlackBoxMapType::const_iterator i;
1045 for ( i = mBlackBoxMap.begin(); i != mBlackBoxMap.end(); ++i )
1047 i->second->Check(recursive);
1049 ConnectionListType::const_iterator j;
1050 for ( j = mConnectionList.begin();
1051 j != mConnectionList.end(); ++j )
1055 bbtkMessage("Debug",1,"**** Checking Complex Black Box "<<(void*)this
1056 <<" ["<<bbGetFullName()<<"] ... OK"<<std::endl);
1059 //=======================================================================