1 /*=========================================================================
4 Module: $RCSfile: bbtkComplexBlackBoxDescriptor.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 =========================================================================*/
21 * \brief Class bbtk::ComplexBlackBoxDescriptor : describes a ComplexBlackBox (constituents, connections) and is able to create an instance of it.
23 #include "bbtkComplexBlackBoxDescriptor.h"
24 #include "bbtkComplexBlackBox.h"
25 //#include "bbtkFactory.h"
26 #include "bbtkMessageManager.h"
27 #include "bbtkUtilities.h"
33 //=======================================================================
35 ComplexBlackBoxDescriptor::ComplexBlackBoxDescriptor(const std::string& name)
36 : BlackBoxDescriptor()
38 bbtkDebugMessageInc("Core",9,"ComplexBlackBoxDescriptor::ComplexBlackBoxDescriptor(\""<<name<<"\")"<<std::endl);
40 mPrototype = new ComplexBlackBox(name+std::string("Prototype"),this);
41 bbtkDebugDecTab("Core",9);
43 //=======================================================================
47 //=======================================================================
49 ComplexBlackBoxDescriptor::~ComplexBlackBoxDescriptor()
51 bbtkDebugMessageInc("Core",9,"ComplexBlackBoxDescriptor::~ComplexBlackBoxDescriptor(\""<<GetTypeName()<<"\")"<<std::endl);
55 bbtkDebugDecTab("Core",9);
57 //=======================================================================
60 //=======================================================================
61 /// Creates an instance of name <name> of the ComplexBlackBox of which this is the descriptor
62 BlackBox* ComplexBlackBoxDescriptor::CreateInstance(const std::string& name)
64 //bbtkError("ComplexBlackBoxDescriptor::CreateInstance not implemented");
65 bbtkDebugMessageInc("Core",5,
66 "ComplexBlackBoxDescriptor::CreateInstance(\""
68 <<GetTypeName()<<"]"<<std::endl);
70 return mPrototype->bbClone(name);
72 bbtkDebugDecTab("Core",5);
74 //=======================================================================
78 //=======================================================================
79 /// Adds a black box to the complex box
80 void ComplexBlackBoxDescriptor::Add ( const std::string& type,
81 const std::string& name
84 bbtkDebugMessageInc("Core",5,
85 "ComplexBlackBoxDescriptor::Add(\""
86 <<type<<"\",\""<<name<<"\") ["
87 <<GetTypeName()<<"]"<<std::endl);
90 // Verify that a box with the same name does not exist already
91 if ( mPrototype->bbUnsafeGetBlackBox( name ) )
93 bbtkError("a black box \""<<name<<"\" already exists");
95 // ok : create new one
96 mPrototype->bbAddBlackBox ( /*mFactory->Create*/ NewBlackBox(type,name) );
98 bbtkDebugDecTab("Core",5);
100 //=======================================================================
102 //=======================================================================
103 /// Adds a black box to the execution list
104 void ComplexBlackBoxDescriptor::AddToExecutionList ( const std::string& box)
106 bbtkDebugMessageInc("Core",5,
107 "ComplexBlackBoxDescriptor::AddToExecutionList(\""
109 <<GetTypeName()<<"]"<<std::endl);
110 // Verify that the box exists
111 BlackBox* b = mPrototype->bbUnsafeGetBlackBox( box );
114 bbtkError("the black box \""<<box<<"\" does not exist");
117 mPrototype->bbAddToExecutionList ( box );
119 bbtkDebugDecTab("Core",5);
123 //=======================================================================
124 /// Connects two black boxes of the complex box
125 void ComplexBlackBoxDescriptor::Connect ( const std::string& from,
126 const std::string& output,
127 const std::string& to,
128 const std::string& input
131 bbtkDebugMessageInc("Core",5,
132 "ComplexBlackBoxDescriptor::Connect(\""
133 <<from<<"\",\""<<output<<"\",\""
136 <<GetTypeName()<<"]"<<std::endl);
137 // Verify that a box with the same name does not exist already
138 BlackBox* bbfrom = mPrototype->bbGetBlackBox( from );
141 bbtkError("the black box \""<<from<<"\" does not exist");
143 BlackBox* bbto = mPrototype->bbGetBlackBox( to );
146 bbtkError("the black box \""<<to<<"\" does not exist");
149 Connection* c = /*mFactory->*/ NewConnection( bbfrom, output, bbto, input );
151 mPrototype->bbAddConnection(c);
153 bbtkDebugDecTab("Core",5);
155 //=======================================================================
158 //=======================================================================
159 /// Defines an input of the complex box
160 void ComplexBlackBoxDescriptor::DefineInput ( const std::string& name,
161 const std::string& box,
162 const std::string& input,
163 const std::string& help)
165 bbtkDebugMessageInc("Core",5,
166 "ComplexBlackBoxDescriptor::DefineInput(\""
167 <<name<<"\",\""<<box<<"\",\""
168 <<input<<"\",\""<<help
170 <<GetTypeName()<<"]"<<std::endl);
172 BlackBox* bb = mPrototype->bbGetBlackBox( box );
175 bbtkError("the black box \""<<box<<"\" does not exist");
178 if (!bb->bbHasInput(input) )
180 bbtkError("the black box \""<<box<<"\" does not have input \""
184 AddInputDescriptor ( new ComplexBlackBoxInputDescriptor ( name,
188 bb->bbGetInputType(input)));
191 bbtkDebugDecTab("Core",5);
193 //=======================================================================
195 //=======================================================================
196 /// Defines an output of the complex box
197 void ComplexBlackBoxDescriptor::DefineOutput ( const std::string& name,
198 const std::string& box,
199 const std::string& output,
200 const std::string& help)
202 bbtkDebugMessageInc("Core",5,
203 "ComplexBlackBoxDescriptor::DefineOutput(\""
204 <<name<<"\",\""<<box<<"\",\""
205 <<output<<"\",\""<<help
207 <<GetTypeName()<<"]"<<std::endl);
209 BlackBox* bb = mPrototype->bbGetBlackBox( box );
212 bbtkError("the black box \""<<box<<"\" does not exist");
215 if (!bb->bbHasOutput(output) )
217 bbtkError("the black box \""<<box<<"\" does not have output \""
221 AddOutputDescriptor ( new ComplexBlackBoxOutputDescriptor
226 bb->bbGetOutputType(output)));
229 bbtkDebugDecTab("Core",5);
231 //=======================================================================
233 //=======================================================================
234 void ComplexBlackBoxDescriptor::PrintBlackBoxes()
236 mPrototype->bbPrintBlackBoxes();
238 //=======================================================================
241 //=======================================================================
242 void ComplexBlackBoxDescriptor::InsertHTMLGraph( std::ofstream& s ,
243 int detail, int level,
244 const std::string& output_dir, bool relative_link )
246 this->mPrototype->bbInsertHTMLGraph( s,
252 //=======================================================================
254 //=========================================================================
255 void ComplexBlackBoxDescriptor::InsertHtmlHelp ( std::ofstream& s,
256 int detail, int level,
257 const std::string& output_dir, bool relative_link)
259 bbtkDebugMessageInc("Core",9,
260 "ComplexBlackBoxDescriptor::InsertHtmlHelp() ["
261 <<GetTypeName()<<"]"<<std::endl);
265 std::string name = GetTypeName();
266 Utilities::html_format(name);
268 // std::ofstream* s = &s1;
271 (s) << "<a name=\""<<name<<"\"></a>\n";
273 "<a rel=\"top\" accesskey=\"t\" href=\"#Top\">Top</a>\n";
274 // (s) << "Previous: <a rel="previous" accesskey="p" href="#dir">(dir)</a>,
275 // (s) << "Up: <a rel="up" accesskey="u" href="#dir">(dir)</a>
276 (s) << "<h2 class=\"section\">"<<name<<"</h2>\n";
279 std::string descr = GetDescription();
280 //Utilities::html_format(descr);
281 std::string author = GetAuthor();
282 Utilities::html_format(author);
284 (s) << "<p><TABLE cellspacing=0 cellpadding=3>\n";
285 (s) << "<TR><TD style='vertical-align: top;'><b> Description </b></TD><TD style='vertical-align: top;'> : </TD><TD style='vertical-align: top;'> "
286 << descr << "</TD></TR>\n";
287 (s) << "<TR><TD style='vertical-align: top;'><b> Author(s) </b></TD><TD style='vertical-align: top;'> : </TD><TD style='vertical-align: top;'> "
288 << author << "</TD></TR>\n";
290 std::string inc = GetScriptFileName();
293 (s) << "<TR><TD style='vertical-align: top;'><b> Include </b></TD><TD style='vertical-align: top;'> : </TD><TD style='vertical-align: top;'> "
294 << inc << "</TD></TR>\n";
298 const ComplexBlackBox::BlackBoxMapType& B = mPrototype->bbGetBlackBoxMap();
302 (s) << "<TR><TD style='vertical-align: top;'><b> Dependencies </b></TD><TD style='vertical-align: top;'> : </TD><TD style='vertical-align: top;'> ";
306 std::set<BlackBoxDescriptor*> pdeps;
307 ComplexBlackBox::BlackBoxMapType::const_iterator b;
308 for ( b = B.begin(); b != B.end(); ++b )
310 BlackBoxDescriptor* d = b->second->bbGetDescriptor();
311 if (pdeps.find(d) != pdeps.end()) continue;
314 Package* p = d->GetPackage();
316 std::string name = b->second->bbGetTypeName();
320 url = p->GetDocRelativeURL();
322 url = p->GetDocURL();
324 s << "<a href=\"" <<url<<"#"<<name<<"\">"
325 << p->GetName()<<"::"<<name<<"</a>\n";
328 (s) << "</TD></TR>\n";
337 InsertHTMLGraph( s , detail,level, output_dir, relative_link);
341 std::string col("#CCCCFF");
343 // (s) << "<h3 class=\"subsection\">Inputs</h3>\n";
344 (s) << "<p><TABLE border=1 cellspacing=0 cellpadding=3>\n";
345 (s) << "<TR><TD colspan=3 align=center bgcolor=\""<<col
346 <<"\">Inputs</TD></TR>\n";
347 const BlackBoxDescriptor::InputDescriptorMapType& imap =
348 GetInputDescriptorMap();
350 InputDescriptorMapType::const_iterator in;
352 for ( in = imap.begin(); in != imap.end(); ++in )
354 std::string name(in->second->GetName());
355 Utilities::html_format(name);
357 std::string type("<");
358 type += in->second->GetTypeName();
360 Utilities::html_format(type);
362 std::string descr(in->second->GetDescription());
363 //Utilities::html_format(descr);
365 (s) << "<TR><TD style='vertical-align: top;'><B><PRE> "<<name<<" </PRE></B></TD>"
366 << "<TD style='vertical-align: top;'><I><PRE> "<<type<<" </PRE></I></TD>"
367 << "<TD style='vertical-align: top;'>"<<descr<<"</TD></TR>\n";
370 // (s) << "</TABLE>\n";
375 // (s) << "<h3 class=\"subsection\">Outputs</h3>\n";
376 // (s) << "<TABLE border=1 cellspacing=0>\n";
377 (s) << "<TR><TD colspan=3 align=center bgcolor=\""<<col
378 <<"\">Outputs</TD></TR>\n";
380 const BlackBoxDescriptor::OutputDescriptorMapType& omap =
381 GetOutputDescriptorMap();
383 BlackBoxDescriptor::OutputDescriptorMapType::const_iterator o;
385 for ( o = omap.begin(); o != omap.end(); ++o )
387 std::string name(o->second->GetName());
388 Utilities::html_format(name);
390 std::string type("<");
391 type += o->second->GetTypeName();
393 Utilities::html_format(type);
395 std::string descr(o->second->GetDescription());
396 //Utilities::html_format(descr);
399 (s) << "<TR><TD style='vertical-align: top;'><B><PRE> "<<name<<" </PRE></B></TD>"
400 << "<TD style='vertical-align: top;'><I><PRE> "<<type<<" </PRE></I></TD>"
401 << "<TD style='vertical-align: top;'>"<<descr<<"</TD></TR>\n";
409 bbtkDebugDecTab("Core",9);
411 //=========================================================================
414 //=======================================================================
415 void ComplexBlackBoxDescriptor::GetHelp(bool full) const
417 if (full) bbtkMessage("Help",1,"Complex Black Box <"<<
418 GetPackage()->GetName()<<"::"
419 <<GetTypeName()<<">"<<std::endl);
420 bbtkMessage("Help",1," "<<GetDescription()<<std::endl);
421 bbtkMessage("Help",1," By : "<<GetAuthor()<<std::endl);
423 bbtkMessage("Help",1," * Inputs : "<<std::endl);
425 bbtkMessage("Help",1," * No inputs"<<std::endl);
426 InputDescriptorMapType::const_iterator i;
427 unsigned int namelmax = 0;
428 unsigned int typelmax = 0;
429 for ( i = mInput.begin(); i != mInput.end(); ++i )
431 if (i->second->GetName().size()>namelmax)
432 namelmax = i->second->GetName().size();
433 if (i->second->GetTypeName().size()>typelmax)
434 typelmax = i->second->GetTypeName().size();
436 OutputDescriptorMapType::const_iterator o;
439 for ( o = mOutput.begin(); o != mOutput.end(); ++o )
441 if (o->second->GetName().size()>namelmax)
442 namelmax = o->second->GetName().size();
443 if (o->second->GetTypeName().size()>typelmax)
444 typelmax = o->second->GetTypeName().size();
449 for ( i = mInput.begin(); i != mInput.end(); ++i )
451 std::string name(i->second->GetName());
453 name.append(1+namelmax-name.size(),' ');
454 std::string type(i->second->GetTypeName());
456 type.append(1+typelmax-type.size(),' ');
457 bbtkMessage("Help",1,
460 <<" : "<<i->second->GetDescription()<<std::endl);
465 bbtkMessage("Help",1," * Outputs : "<<std::endl);
467 bbtkMessage("Help",1," * No outputs"<<std::endl);
468 for ( o = mOutput.begin(); o != mOutput.end(); ++o )
470 std::string name(o->second->GetName());
472 name.append(1+namelmax-name.size(),' ');
473 std::string type(o->second->GetTypeName());
475 type.append(1+typelmax-type.size(),' ');
476 bbtkMessage("Help",1,
479 <<" : "<<o->second->GetDescription()<<std::endl);
484 const ComplexBlackBox::BlackBoxMapType& B = mPrototype->bbGetBlackBoxMap();
487 bbtkMessage("Help",1," * Boxes : "<<std::endl);
489 bbtkMessage("Help",1," * No boxes"<<std::endl);
491 ComplexBlackBox::BlackBoxMapType::const_iterator b;
492 for ( b = B.begin(); b != B.end(); ++b )
494 bbtkMessage("Help",1," '"<<b->second->bbGetName()<<
496 << b->second->bbGetDescriptor()->GetPackage()->GetName()
498 <<b->second->bbGetTypeName()<<">"<<std::endl);
503 //=======================================================================