1 /*=========================================================================
3 Module: $RCSfile: bbtkComplexBlackBox.cxx,v $
5 Date: $Date: 2010/03/19 08:18:41 $
6 Version: $Revision: 1.32 $
7 =========================================================================*/
9 /* ---------------------------------------------------------------------
11 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
12 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
14 * This software is governed by the CeCILL-B license under French law and
15 * abiding by the rules of distribution of free software. You can use,
16 * modify and/ or redistribute the software under the terms of the CeCILL-B
17 * license as circulated by CEA, CNRS and INRIA at the following URL
18 * http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
19 * or in the file LICENSE.txt.
21 * As a counterpart to the access to the source code and rights to copy,
22 * modify and redistribute granted by the license, users are provided only
23 * with a limited warranty and the software's author, the holder of the
24 * economic rights, and the successive licensors have only limited
27 * The fact that you are presently reading this means that you have had
28 * knowledge of the CeCILL-B license and that you accept its terms.
29 * ------------------------------------------------------------------------ */
34 * \brief class bbtk::ComplexBlackBox : user defined complex black boxes
36 #include "bbtkComplexBlackBox.h"
38 //#include "bbtkBlackBoxDescriptor.h"
39 //#include "bbtkFactory.h"
40 #include "bbtkConfigurationFile.h"
45 //==========================================================================
46 /// Creates a new complex black box
47 ComplexBlackBox::Pointer ComplexBlackBox::New(const std::string& name,
48 ComplexBlackBoxDescriptor::Pointer desc)
50 bbtkDebugMessage("object",1,"##> ComplexBlackBox::New('"<<name<<"','"<<
51 desc->GetTypeName()<<"')" <<bbtkendl);
52 ComplexBlackBox::Pointer p =
53 MakeBlackBoxPointer(new ComplexBlackBox(name,desc));
54 bbtkDebugMessage("object",2,"<## ComplexBlackBox::New('"<<name<<"','"<<
55 desc->GetTypeName()<<"')" <<bbtkendl);
58 //==========================================================================
60 //=======================================================================
61 /// Usefull constructor
62 ComplexBlackBox::ComplexBlackBox(const std::string &name,
63 ComplexBlackBoxDescriptor::Pointer desc)
66 mLockedDescriptor(desc),
69 bbtkBlackBoxDebugMessage("object",3,
70 "##> ComplexBlackBox(\""
71 <<name<<"\")"<<std::endl);
72 bbAllocateConnectors();
73 bbtkBlackBoxDebugMessage("object",3,
74 "<## ComplexBlackBox(\""
75 <<name<<"\")"<<std::endl);
77 //=======================================================================
79 //=======================================================================
80 /// Constructor from an existing box (copy) with a new name
81 ComplexBlackBox::ComplexBlackBox(ComplexBlackBox& from,
82 const std::string &name)
83 : BlackBox(from,name),
84 // The locked descriptor is copied from the unlocked one
85 // to make the box a non-prototype !!
86 mLockedDescriptor(from.mDescriptor),
87 mDescriptor(from.mDescriptor),
88 mExecutionList(from.mExecutionList)
90 bbtkBlackBoxDebugMessage("object",3,
91 "##> ComplexBlackBox(\""
92 <<from.bbGetName()<<"\",\""
93 <<name<<"\")"<<std::endl);
94 bbtkBlackBoxDebugMessage("object",4," * Cloning Black Boxes"<<std::endl);
96 // We have to make the shared_ptr on this because it is used
97 // in bbUnsafeAddBlackBox !
98 MakeBlackBoxPointer(this,true);
100 BlackBoxMapType::const_iterator i;
101 for ( i = from.mBlackBoxMap.begin(); i != from.mBlackBoxMap.end(); ++i )
103 bbtkBlackBoxDebugMessage("object",5," * Cloning \""<<i->first<<"\""<<std::endl);
104 BlackBox::Pointer B = i->second->bbClone(i->second->bbGetName());
105 bbUnsafeAddBlackBox(B);
108 bbtkBlackBoxDebugMessage("object",4," * Cloning Connections"<<std::endl);
109 ConnectionListType::const_iterator j;
110 for ( j = from.mConnectionList.begin(); j != from.mConnectionList.end(); ++j )
112 bbtkBlackBoxDebugMessage("object",5," * Cloning \""<<
113 (*j)->GetFullName()<<"\""<<std::endl);
115 BlackBox::Pointer bbfrom = bbGetBlackBox( (*j)->GetOriginalBlackBoxFrom()->bbGetName() );
116 BlackBox::Pointer bbto = bbGetBlackBox( (*j)->GetOriginalBlackBoxTo()->bbGetName() );
118 Connection::Pointer c = mDescriptor.lock()->GetFactory()->
119 NewConnection( bbfrom,
120 (*j)->GetOriginalBlackBoxFromOutput(),
122 (*j)->GetOriginalBlackBoxToInput() );
129 bbAllocateConnectors();
130 bbtkBlackBoxDebugMessage("object",3,
131 "<## ComplexBlackBox(\""
132 <<from.bbGetName()<<"\",\""
133 <<name<<"\")"<<std::endl);
135 //=======================================================================
137 //=======================================================================
139 ComplexBlackBox::~ComplexBlackBox()
141 bbtkBlackBoxDebugMessage("object",3,
142 "==> ~ComplexBlackBox()"
146 this->bbDesallocateConnectors();
148 bbtkBlackBoxDebugMessage("object",3,
149 "<== ~ComplexBlackBox()"
152 //=======================================================================
155 //=======================================================================
157 void ComplexBlackBox::Clear()
159 bbtkBlackBoxDebugMessage("object",3,
160 "==> ComplexBlackBox::Clear()"
163 bbtkBlackBoxDebugMessage("object",4,
164 " -> Releasing connections"<<std::endl);
165 mConnectionList.clear();
166 bbtkBlackBoxDebugMessage("object",4,
167 " -> Releasing boxes"<<std::endl);
168 mBlackBoxMap.clear();
170 bbtkBlackBoxDebugMessage("object",3,
171 "<== ComplexBlackBox::Clear()"
174 //=======================================================================
176 //=========================================================================
177 /// Allocates the i/o connectors of the black box
178 void ComplexBlackBox::bbAllocateConnectors()
180 bbtkBlackBoxDebugMessage("kernel",8,
181 "==> ComplexBlackBox::bbAllocateConnectors()"
185 const BlackBoxDescriptor::InputDescriptorMapType& imap
186 = bbGetDescriptor()->GetInputDescriptorMap();
187 BlackBoxDescriptor::InputDescriptorMapType::const_iterator i;
188 for ( i = imap.begin(); i != imap.end(); ++i )
190 bbtkBlackBoxDebugMessage("kernel",8,"* Allocate \""<<i->first<<"\""<<std::endl);
191 // Redirect the connector to the internal box connector
192 // Cast the BBInputDescriptor into a ComplexBBInputDescriptor
193 ComplexBlackBoxInputDescriptor* d =
194 (ComplexBlackBoxInputDescriptor*)i->second;
195 // Get the internal box connector
196 BlackBoxInputConnector* c =
197 bbUnsafeGetBlackBox ( d->GetTarget() )
198 ->bbGetInputConnectorMap()[ d->GetInput() ];
200 bbGetInputConnectorMap()[i->second->GetName()] = c;
204 const BlackBoxDescriptor::OutputDescriptorMapType& omap
205 = bbGetDescriptor()->GetOutputDescriptorMap();
206 BlackBoxDescriptor::OutputDescriptorMapType::const_iterator o;
207 for ( o = omap.begin(); o != omap.end(); ++o )
209 bbtkBlackBoxDebugMessage("kernel",8,"* Allocate \""<<o->first<<"\""<<std::endl);
210 // Redirect the connector to the internal box connector
211 // Cast the BBOutputDescriptor into a ComplexBBOutputDescriptor
212 ComplexBlackBoxOutputDescriptor* d =
213 (ComplexBlackBoxOutputDescriptor*)o->second;
214 // Get the internal box connector
215 BlackBoxOutputConnector* c =
216 bbUnsafeGetBlackBox ( d->GetTarget() )
217 ->bbGetOutputConnectorMap()[ d->GetOutput() ];
219 bbGetOutputConnectorMap()[o->second->GetName()] = c;
221 bbtkBlackBoxDebugMessage("kernel",8,
222 "<== ComplexBlackBox::bbAllocateConnectors()"
225 //=========================================================================
228 //=========================================================================
229 /// Desallocates the i/o connectors of the black box
230 void ComplexBlackBox::bbDesallocateConnectors()
232 bbtkBlackBoxDebugMessage("kernel",8,
233 "==> ComplexBlackBox::DesallocateConnectors()"
236 // The connectors have not been allocated by the complex box
237 // but by the internal boxes. Hence **DO NOT** desallocate !
238 // just clear the maps to avoid that
239 // BlackBox::bbDesallocateConnectors delete the connectors
240 bbGetInputConnectorMap().clear();
241 bbGetOutputConnectorMap().clear();
243 bbtkBlackBoxDebugMessage("kernel",8,
244 "<== ComplexBlackBox::DesallocateConnectors()"
249 //=========================================================================
251 //=======================================================================
252 BlackBox::Pointer ComplexBlackBox::bbClone(const std::string& name)
254 bbtkBlackBoxDebugMessage("kernel",9,
255 "==> ComplexBlackBox::bbClone(\""<<name<<"\")"
258 ComplexBlackBox* CBB = new ComplexBlackBox(*this,name);
259 bbtkBlackBoxDebugMessage("kernel",9,
260 "<== ComplexBlackBox::bbClone(\""<<name<<"\")"
262 return MakeBlackBoxPointer(CBB);
264 //=======================================================================
266 //=======================================================================
267 /// Main processing method of the box.
268 /// Executes the box so that its outputs are up-to-date on exit
269 void ComplexBlackBox::bbExecute(bool force)
271 bbtkBlackBoxDebugMessage("process",2,
272 "**> ComplexBlackBox::bbExecute()"
278 if (mExecutionList.size() != 0)
281 std::vector<std::string>::const_iterator i;
282 for (i=mExecutionList.begin();
283 i!=mExecutionList.end();
286 bbtkBlackBoxDebugMessage("process",3," -> Executing '"<<*i<<"'"<<std::endl);
287 mBlackBoxMap[*i]->bbExecute(force);
292 std::map<std::string, BlackBox::Pointer>::iterator i;
293 for (i=mBlackBoxMap.begin(); i!=mBlackBoxMap.end(); ++i)
295 i->second->bbExecute(force);
298 bbtkBlackBoxDebugMessage("process",2,
299 "<** ComplexBlackBox::bbExecute()"
303 //==================================================================
305 //==================================================================
306 void ComplexBlackBox::bbAddToExecutionList( const std::string& name )
308 bbtkBlackBoxDebugMessage("kernel",9,
309 "ComplexBlackBox::bbAddToExecutionList(\""
313 mExecutionList.push_back( name );
317 //==================================================================
320 //==================================================================
321 Data ComplexBlackBox::bbGetOutput( const std::string &name )
323 bbtkBlackBoxDebugMessage("data",7,
324 "ComplexBlackBox::bbGetOutput(\""<<name<<"\")"
327 ComplexBlackBoxOutputDescriptor* d =
328 (ComplexBlackBoxOutputDescriptor*)
329 bbGetDescriptor()->GetOutputDescriptor(name);
331 Data p = bbGetBlackBox(d->GetTarget())->bbGetOutput(d->GetOutput());
335 //==================================================================
337 //==================================================================
338 /// Gets the input Data of a given name
339 Data ComplexBlackBox::bbGetInput( const std::string &name )
341 bbtkBlackBoxDebugMessage("data",7,
342 "ComplexBlackBox::bbGetInput(\""<<name<<"\")"
345 ComplexBlackBoxInputDescriptor* d =
346 (ComplexBlackBoxInputDescriptor*)
347 bbGetDescriptor()->GetInputDescriptor(name);
349 Data p = bbGetBlackBox(d->GetTarget())->bbGetInput(d->GetInput());
353 //==================================================================
355 //==================================================================
356 /// Sets the data of the output called <name>
357 void ComplexBlackBox::bbSetOutput( const std::string &name, Data data)
359 bbtkBlackBoxDebugMessage("data",7,
360 "ComplexBlackBox::bbSetOutput(\""<<name<<"\",data)"
363 ComplexBlackBoxOutputDescriptor* d =
364 (ComplexBlackBoxOutputDescriptor*)
365 bbGetDescriptor()->GetOutputDescriptor(name);
367 bbGetBlackBox(d->GetTarget())->bbSetOutput(d->GetOutput(),data);
370 //==================================================================
372 //==================================================================
373 /// Sets the data of the input called <name>
374 void ComplexBlackBox::bbSetInput( const std::string &name, Data data,
377 bbtkBlackBoxDebugMessage("data",7,
378 "ComplexBlackBox::bbSetInput(\""<<name<<"\",data)"
381 ComplexBlackBoxInputDescriptor* d = (ComplexBlackBoxInputDescriptor*)
382 bbGetDescriptor()->GetInputDescriptor(name);
384 bbGetBlackBox(d->GetTarget())->bbSetInput(d->GetInput(),data,setModified);
387 //==================================================================
390 //==================================================================
391 /// Sets the data of the input called <name>
392 void ComplexBlackBox::bbBruteForceSetInputPointer( const std::string &name,
396 bbtkBlackBoxDebugMessage("data",7,
397 "ComplexBlackBox::bbBruteForceSetInputPointer('"
398 <<name<<"',"<<data<<")"
401 ComplexBlackBoxInputDescriptor* d = (ComplexBlackBoxInputDescriptor*)
402 bbGetDescriptor()->GetInputDescriptor(name);
404 bbGetBlackBox(d->GetTarget())->bbBruteForceSetInputPointer(d->GetInput(),
409 //==================================================================
411 //=========================================================================
412 /// Connects the input <name> to the connection c
413 void ComplexBlackBox::bbConnectInput( const std::string& name, Connection* c)
415 bbtkBlackBoxDebugMessage("connection",2,
416 "==> ComplexBlackBox::bbConnectInput(\""
417 <<name<<"\","<<c->GetFullName()<<")"
420 ComplexBlackBoxInputDescriptor* d = (ComplexBlackBoxInputDescriptor*)
421 bbGetDescriptor()->GetInputDescriptor(name);
424 BlackBox::Pointer t = bbGetBlackBox(d->GetTarget());
426 bbtkBlackBoxDebugMessage("connection",2," - Target = "<<d->GetTarget()<<" = "<<t->bbGetFullName()<<std::endl);
429 c->SetBlackBoxToInput(d->GetInput());
431 bbtkBlackBoxDebugMessage("connection",2," - New conn = "<<c->GetFullName()<<std::endl);
432 t->bbConnectInput(d->GetInput(),c);
434 bbtkBlackBoxDebugMessage("connection",2,
435 "<== ComplexBlackBox::bbConnectInput(\""
436 <<name<<"\","<<c->GetFullName()<<")"
439 //=========================================================================
442 //=========================================================================
443 /// Connects the output <name> to the connection c
444 void ComplexBlackBox::bbConnectOutput( const std::string& name, Connection* c)
446 bbtkBlackBoxDebugMessage("connection",2,
447 "==> ComplexBlackBox::bbConnectOutput(\""
448 <<name<<"\","<<c->GetFullName()<<")"
451 ComplexBlackBoxOutputDescriptor* d = (ComplexBlackBoxOutputDescriptor*)
452 bbGetDescriptor()->GetOutputDescriptor(name);
454 BlackBox::Pointer t = bbGetBlackBox(d->GetTarget());
456 bbtkBlackBoxDebugMessage("connection",2," - Target = "<<d->GetTarget()<<" = "<<t->bbGetFullName()<<std::endl);
458 c->SetBlackBoxFrom(t);
459 c->SetBlackBoxFromOutput(d->GetOutput());
461 bbtkBlackBoxDebugMessage("connection",2," - New conn = "<<c->GetFullName()<<std::endl);
463 t->bbConnectOutput(d->GetOutput(),c);
465 bbtkBlackBoxDebugMessage("connection",2,
466 "<== ComplexBlackBox::bbConnectOutput(\""
467 <<name<<"\","<<c->GetFullName()<<")"
470 //=========================================================================
473 //==================================================================
474 /// Adds the black box to the complex box
475 void ComplexBlackBox::bbAddBlackBox( BlackBox::Pointer b)
477 bbtkBlackBoxDebugMessage("kernel",7,
478 "ComplexBlackBox::AddBlackBox(\""<<b->bbGetName()
482 if ( bbUnsafeGetBlackBox(b->bbGetName()) )
484 bbtkError("a black box called \""<<b->bbGetName()
485 <<"\" already exists");
487 b->bbSetParent(GetThisPointer<ComplexBlackBox>());
488 mBlackBoxMap[b->bbGetName()] = b;
491 //==================================================================
493 //==================================================================
494 /// Adds the black box to the complex box (unsafe)
495 void ComplexBlackBox::bbUnsafeAddBlackBox( BlackBox::Pointer b)
497 bbtkBlackBoxDebugMessage("kernel",7,
498 "ComplexBlackBox::UnsafeAddBlackBox(\""<<b->bbGetName()
502 b->bbSetParent(GetThisPointer<ComplexBlackBox>());
503 mBlackBoxMap[b->bbGetName()] = b;
506 //==================================================================
508 //==================================================================
509 /// Removes the black box from the complex box
510 void ComplexBlackBox::bbRemoveBlackBox( const std::string& name,
511 bool remove_connections )
513 bbtkBlackBoxDebugMessage("kernel",7,
514 "ComplexBlackBox::RemoveBlackBox(\""<<name<<"\")"
517 BlackBoxMapType::iterator i = mBlackBoxMap.find(name);
518 if ( i == mBlackBoxMap.end() )
520 bbtkError("the black box \""<<name<<"\" does not exist");
522 BlackBox::WeakPointer p = i->second;
524 if (remove_connections)
526 ConnectionListType::const_iterator j;
527 for ( j = mConnectionList.begin();
528 j != mConnectionList.end(); ++j )
533 if (p.use_count()!=1)
535 bbtkError("the black box \""<<name<<"\" is still connected");
538 mBlackBoxMap.erase(i);
541 // Unload orphan dl packages
542 Package::UnLoadReleasedDynamicallyLoadedPackages();
545 //==================================================================
547 //==================================================================
548 /// Adds the connection to the complex box
549 void ComplexBlackBox::bbAddConnection( Connection::Pointer c)
551 bbtkBlackBoxDebugMessage("kernel",7,
552 "ComplexBlackBox::AddConnection(\""<<"..."<<"\")"
555 mConnectionList.push_back(c);
558 //==================================================================
559 // void RemoveConnection( );
561 //==================================================================
562 /// Returns the black box with name <name>
563 BlackBox::Pointer ComplexBlackBox::bbGetBlackBox( const std::string& name )
565 bbtkBlackBoxDebugMessage("kernel",9,
566 "ComplexBlackBox::GetBlackBox(\""<<name<<"\")"
569 BlackBoxMapType::iterator i = mBlackBoxMap.find(name);
570 if ( i == mBlackBoxMap.end() )
572 bbtkError("the black box \""<<name<<"\" does not exist");
577 //==================================================================
579 //==================================================================
580 /// Returns the black box with name <name> : does not throw an exception
581 /// if it does not exist but return a null pointer
582 BlackBox::Pointer ComplexBlackBox::bbUnsafeGetBlackBox( const std::string& name )
584 bbtkBlackBoxDebugMessage("kernel",9,
585 "ComplexBlackBox::UnsafeGetBlackBox(\""<<name<<"\")"
588 BlackBoxMapType::iterator i = mBlackBoxMap.find(name);
589 if ( i == mBlackBoxMap.end() )
591 return BlackBox::Pointer();
597 //==================================================================
599 //==================================================================
600 void ComplexBlackBox::bbPrintBlackBoxes()
602 bbtkBlackBoxDebugMessage("kernel",9,
603 "ComplexBlackBox::PrintBlackBoxes()"
606 BlackBoxMapType::iterator i;
607 for ( i = mBlackBoxMap.begin(); i != mBlackBoxMap.end(); ++i )
609 bbtkMessage("help",1,i->second->bbGetFullName()<<std::endl);
613 //==================================================================
617 //=========================================================================
619 void ComplexBlackBox::bbWriteDotInputOutputName(FILE *ff,bool inputoutput,int detail, int level)
623 fprintf(ff,"%s_IN_%p",bbGetTypeName().c_str(),this);
625 fprintf(ff,"%s_OUT_%p",bbGetTypeName().c_str(),this);
628 //=========================================================================
631 //=========================================================================
632 BlackBox::Pointer ComplexBlackBox::bbFindBlackBox(const std::string &blackboxname)
634 BlackBox::Pointer blackbox;
635 std::string subname="";
636 std::string restname="";
637 std::string delimiters(">");
638 // Skip delimiters at beginning.
639 std::string::size_type lastPos = blackboxname.find_first_not_of(delimiters, 0);
640 // Find first "non-delimiter".
641 std::string::size_type pos = blackboxname.find_first_of(delimiters, lastPos);
643 // Found a token, add it to the vector.
644 subname = blackboxname.substr(lastPos, pos - lastPos);
645 restname = blackboxname.substr(lastPos+pos - lastPos+1, 999);
647 if (restname==subname)
652 BlackBoxMapType::iterator i = mBlackBoxMap.find(subname);
653 if ( i != mBlackBoxMap.end() )
655 blackbox = i->second;
658 blackbox = blackbox->bbFindBlackBox(restname);
663 //=========================================================================
665 //=========================================================================
666 void ComplexBlackBox::bbInsertHTMLGraph( std::ofstream& s,
670 const std::string& output_dir,
673 std::string directory(output_dir);
675 if (output_dir.length() == 0)
677 // Don't pollute the file store with "temp_dir" directories ...
678 std::string default_temp_dir = ConfigurationFile::GetInstance().Get_default_temp_dir();
679 directory = default_temp_dir + "/" + "temp_dir";
682 std::string simplefilename (this->bbGetTypeName()+"_"+this->bbGetName());
683 std::string simplefilename_png (simplefilename+".png");
684 std::string filename (directory+"/"+simplefilename);
685 std::string filename_png (filename+".png");
686 std::string filename_cmap (filename+".cmap");
687 std::string filename_dot (filename+".dot");
689 std::string filename_png2 ("\"" + filename_png + "\"");
690 std::string filename_cmap2 ("\"" + filename_cmap + "\"");
691 std::string filename_dot2 ("\"" + filename_dot + "\"");
695 std::string currentexecpath("\"\"" + crea::System::GetDllAppPath("bbtk") +"\\dot_embedded\\dot\"");
696 std::string command1 (currentexecpath + " -Tpng -o " + filename_png2 + " " + filename_dot2 + "\"");
697 std::string command1a(currentexecpath + " -T cmap -o " + filename_cmap2 + " " + filename_dot2 + "\"");
700 std::string command1 ("dot -Tpng:quartz -o " + filename_png2 + " " + filename_dot2 );
701 std::string command1a("dot -T cmap -o " + filename_cmap2 + " " + filename_dot2 );
703 std::string command1 ("dot -Tpng:cairo -o " + filename_png2 + " " + filename_dot2 );
704 std::string command1a("dot -T cmap -o " + filename_cmap2 + " " + filename_dot2 );
711 // 1. Generating .dot file
713 ff = fopen(filename_dot.c_str(),"w");
714 fprintf(ff,"digraph bbtk_graph{\n");
715 fprintf(ff,"rankdir=LR%s\n",";");
716 fprintf(ff,"node [shape=record]%s\n",";");
718 this->bbWriteDotFileBlackBox(ff,
719 GetThisPointer<ComplexBlackBox>(),
727 std::cout<<"JCP bbtkComplexBlackBox.cxx execute1="<<command1<<std::endl;
728 // 2. Executing .dot file -> png
729 system( command1.c_str() );
730 // 3. Executing .dot file -> cmap
731 std::cout<<"JCP bbtkComplexBlackBox.cxx execute2="<<command1a<<std::endl;
732 system( command1a.c_str() );
734 // 4. HTML code insertion
736 (s) << "<center><img src=\"" << simplefilename_png
737 << "\" border=\"0\" usemap=\"#map_"<< simplefilename
738 <<"\" alt=\"\"></center>\n";
741 (s) << "<map name=\"map_"<< simplefilename <<"\">\n";
744 ff2=fopen(filename_cmap.c_str(),"r");
759 //=========================================================================
762 //=========================================================================
763 /// Write Graphviz-dot description in file
764 void ComplexBlackBox::bbWriteDotFileBlackBox(FILE *ff,
765 BlackBox::Pointer parentblackbox,
766 int detail, int level,
771 std::string valueStr("");
772 Package::Pointer package = this->bbGetDescriptor()->GetPackage();
777 tmp1 = this->bbGetDescriptor()->GetPackage()->GetDocRelativeURL();
779 tmp1 = this->bbGetDescriptor()->GetPackage()->GetDocURL();
786 std::string tmp2=bbGetTypeName();
787 std::string url(tmp1 + "#" + tmp2 );
788 fprintf( ff , "subgraph cluster_%s_%p {\n",bbGetName().c_str(),this);
790 if (!( (bbGetTypeName()=="workspace") && (bbGetName()=="workspacePrototype")) )
792 fprintf( ff , " URL = \"%s\" %s",url.c_str(),";");
795 std::string boxname="["+bbGetTypeName()+"]";
796 if (GetThisPointer<ComplexBlackBox>()!=parentblackbox)
804 boxname = bbGetName();
805 boxname = boxname + " [" +this->bbGetDescriptor()->GetPackage()->GetName()+"::"+ bbGetTypeName() + "]";
809 fprintf( ff , " label = \"%s\"%s\n", boxname.c_str() ,";");
813 // fprintf( ff , " style=filled%s\n",";");
814 // fprintf( ff , " color=grey%s\n",";");
815 fprintf( ff , " node [style=filled]%s\n",";");
816 fprintf( ff , " fillcolor=grey%s\n",";");
817 fprintf( ff , " edge [color=blue]%s\n",";");
821 std::string labelStr1;
822 std::string labelStr2;
823 labelStr1 = boxname + "\\n(output)" ;
824 labelStr2 = " | {{ ";
827 OutputConnectorMapType::iterator i;
829 const BlackBoxDescriptor::OutputDescriptorMapType& omap = this->bbGetDescriptor()->GetOutputDescriptorMap();
830 BlackBoxDescriptor::OutputDescriptorMapType::const_iterator o;
831 for ( o = omap.begin(); o != omap.end(); ++o )
835 labelStr2=labelStr2+" | ";
838 if (instanceOrtype==true)
840 valueStr = this->bbGetOutputAsString(o->second->GetName()/*
843 labelStr2=labelStr2+"<"+o->second->GetName().c_str()+"> " + valueStr + o->second->GetName().c_str();
846 labelStr2 = labelStr2+ " } }";
852 labelStr1 = labelStr1 + labelStr2;
857 bbWriteDotInputOutputName(ff,false,detail,level);
858 fprintf( ff , " [shape=record, style=filled,fillcolor=grey,color=red,label=\"%s\"]%s\n",labelStr1.c_str(),";" );
863 labelStr1 = boxname + "\\n(input)" ;
864 labelStr2 = " | {{ ";
866 InputConnectorMapType::iterator ii;
868 const BlackBoxDescriptor::InputDescriptorMapType& imap = this->bbGetDescriptor()->GetInputDescriptorMap();
869 BlackBoxDescriptor::InputDescriptorMapType::const_iterator iii;
870 for ( iii = imap.begin(); iii != imap.end(); ++iii )
874 labelStr2=labelStr2+" | ";
877 if (instanceOrtype==true)
879 valueStr = this->bbGetInputAsString(iii->second->GetName()/*,factory*/) + " = ";
881 labelStr2=labelStr2+"<"+iii->second->GetName().c_str()+"> " + valueStr + iii->second->GetName().c_str();
885 labelStr2 = labelStr2+ " } }";
888 labelStr1 = labelStr1 + labelStr2;
892 bbWriteDotInputOutputName(ff,true,detail,level);
893 fprintf( ff , " [shape=record, style=filled,fillcolor=grey,color=red,label=\"%s\"]%s\n",labelStr1.c_str(),";" );
898 BlackBoxMapType::iterator j;
899 for ( j = mBlackBoxMap.begin(); j != mBlackBoxMap.end(); ++j )
903 j->second->bbWriteDotFileBlackBox(ff,
912 fprintf( ff , "}\n\n");
914 fprintf( ff , " edge[color=blue]%s\n",";");
918 // Relation Input with the inside BlackBox of the this ComplexBlackbox
919 ComplexBlackBoxDescriptor::InputDescriptorMapType::iterator xx;
920 ComplexBlackBoxDescriptor::InputDescriptorMapType idmt=bbGetDescriptor()->GetInputDescriptorMap();
921 for ( xx = idmt.begin(); xx != idmt.end(); ++xx )
923 ComplexBlackBoxInputDescriptor *cbbid = (ComplexBlackBoxInputDescriptor*)xx->second;
926 bbWriteDotInputOutputName(ff,true,detail,level);
929 fprintf(ff,":%s",cbbid->GetName().c_str() );
932 BlackBox::Pointer bb = bbGetBlackBox( cbbid->GetTarget() );
933 bb->bbWriteDotInputOutputName(ff,true,detail,level);
936 fprintf(ff,":%s \n", cbbid->GetInput().c_str() );
946 // Relation Output ComplexBlackBox
947 ComplexBlackBoxDescriptor::OutputDescriptorMapType::iterator yy;
948 ComplexBlackBoxDescriptor::OutputDescriptorMapType odmt=bbGetDescriptor()->GetOutputDescriptorMap();
949 for ( yy = odmt.begin(); yy != odmt.end(); ++yy )
951 ComplexBlackBoxOutputDescriptor *cbbod = (ComplexBlackBoxOutputDescriptor*)yy->second;
953 BlackBox::Pointer bb = bbGetBlackBox( cbbod->GetTarget() );
954 bb->bbWriteDotInputOutputName(ff,false,detail,level);
957 fprintf(ff,":%s", cbbod->GetOutput().c_str() );
960 bbWriteDotInputOutputName(ff,false,detail,level);
963 fprintf(ff,":%s",cbbod->GetName().c_str() );
972 // Relation from the out side of this ComplexBlackBox with its Inputs
973 if (GetThisPointer<ComplexBlackBox>()!=parentblackbox) {
974 for ( ii = bbGetInputConnectorMap().begin();
975 ii != bbGetInputConnectorMap().end(); ++ii )
979 Connection* con = ii->second->GetConnection();
981 BlackBox::Pointer a=con->GetOriginalBlackBoxFrom();
982 BlackBox::Pointer b=con->GetOriginalBlackBoxTo();
984 a->bbWriteDotInputOutputName(ff,false,detail,level);
987 fprintf(ff,":%s",con->GetOriginalBlackBoxFromOutput().c_str());
990 b->bbWriteDotInputOutputName(ff,true,detail,level);
993 fprintf(ff,":%s",con->GetOriginalBlackBoxToInput().c_str());
995 fprintf(ff,"%s\n",";");
999 } // if parentblackbox
1001 //=========================================================================
1008 //=======================================================================
1009 /// Generates the list of the packages of which its depends
1010 /// (cause an internal box belongs to it)
1011 void ComplexBlackBox::GetPackagesDependencies(std::vector<Package*>& deps)
1014 BlackBoxMapType::iterator i;
1015 for ( i = mBlackBoxMap.begin(); i != mBlackBoxMap.end(); ++i )
1017 deps.push_back(i->second->bbGetDescriptor()->GetPackage());
1021 //=======================================================================
1024 //=======================================================================
1025 void ComplexBlackBox::Check(bool recursive)
1027 bbtkMessage("debug",1,"**** Checking Complex Black Box "<<(void*)this
1028 <<" ["<<bbGetFullName()<<"]"<<std::endl);
1030 BlackBoxMapType::const_iterator i;
1031 for ( i = mBlackBoxMap.begin(); i != mBlackBoxMap.end(); ++i )
1033 i->second->Check(recursive);
1035 ConnectionListType::const_iterator j;
1036 for ( j = mConnectionList.begin();
1037 j != mConnectionList.end(); ++j )
1041 bbtkMessage("debug",1,"**** Checking Complex Black Box "<<(void*)this
1042 <<" ["<<bbGetFullName()<<"] ... OK"<<std::endl);
1045 //=======================================================================
1047 //=========================================================================
1048 /// Returns the name with the name of the parent prepended if any
1049 std::string ComplexBlackBox::bbGetNameWithParent() const
1051 if (!IsAPrototype()) return BlackBox::bbGetNameWithParent();
1052 if (bbGetDescriptor())
1054 return bbGetDescriptor()->GetFullTypeName() + ":" + bbGetName();
1058 return std::string(":") + bbGetName();
1061 //=========================================================================
1063 //==========================================================================
1064 std::string ComplexBlackBox::GetObjectName() const
1066 return std::string("ComplexBlackBox '")+bbGetNameWithParent()
1069 //==========================================================================
1071 //==========================================================================
1072 std::string ComplexBlackBox::GetObjectInfo() const
1074 std::stringstream i;
1075 i << " - "<<mBlackBoxMap.size() << " boxes / "
1076 <<mConnectionList.size() << " connections" << std::endl;
1079 //==========================================================================
1081 //==========================================================================
1082 size_t ComplexBlackBox::GetObjectSize() const
1084 size_t s = Superclass::GetObjectSize();
1085 s += ComplexBlackBox::GetObjectInternalSize();
1088 //==========================================================================
1089 //==========================================================================
1090 size_t ComplexBlackBox::GetObjectInternalSize() const
1092 size_t s = sizeof(ComplexBlackBox);
1095 //==========================================================================
1096 //==========================================================================
1097 size_t ComplexBlackBox::GetObjectRecursiveSize() const
1099 size_t s = Superclass::GetObjectRecursiveSize();
1100 s += ComplexBlackBox::GetObjectInternalSize();
1101 BlackBoxMapType::const_iterator i;
1102 for ( i = mBlackBoxMap.begin(); i != mBlackBoxMap.end(); ++i )
1104 s += i->second->GetObjectRecursiveSize();
1106 ConnectionListType::const_iterator j;
1107 for ( j = mConnectionList.begin();
1108 j != mConnectionList.end(); ++j )
1110 s += (*j)->GetObjectRecursiveSize();
1114 //==========================================================================