1 /*=========================================================================
4 Module: $RCSfile: bbtkComplexBlackBoxDescriptor.cxx,v $
6 Date: $Date: 2008/02/19 18:40:10 $
7 Version: $Revision: 1.11 $
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("Kernel",9,"ComplexBlackBoxDescriptor::ComplexBlackBoxDescriptor(\""<<name<<"\")"<<std::endl);
40 AddToCategory("complex box");
41 mPrototype = new ComplexBlackBox(name+std::string("Prototype"),this);
42 bbtkDebugDecTab("Kernel",9);
44 //=======================================================================
48 //=======================================================================
50 ComplexBlackBoxDescriptor::~ComplexBlackBoxDescriptor()
52 bbtkDebugMessageInc("Kernel",9,"ComplexBlackBoxDescriptor::~ComplexBlackBoxDescriptor(\""<<GetTypeName()<<"\")"<<std::endl);
56 bbtkDebugDecTab("Kernel",9);
58 //=======================================================================
61 //=======================================================================
62 /// Creates an instance of name <name> of the ComplexBlackBox of which this is the descriptor
63 BlackBox* ComplexBlackBoxDescriptor::CreateInstance(const std::string& name)
65 //bbtkError("ComplexBlackBoxDescriptor::CreateInstance not implemented");
66 bbtkDebugMessageInc("Kernel",5,
67 "ComplexBlackBoxDescriptor::CreateInstance(\""
69 <<GetTypeName()<<"]"<<std::endl);
71 return mPrototype->bbClone(name);
73 bbtkDebugDecTab("Kernel",5);
75 //=======================================================================
79 //=======================================================================
80 /// Adds a black box to the complex box
81 void ComplexBlackBoxDescriptor::Add ( const std::string& type,
82 const std::string& name
85 bbtkDebugMessageInc("Kernel",5,
86 "ComplexBlackBoxDescriptor::Add(\""
87 <<type<<"\",\""<<name<<"\") ["
88 <<GetTypeName()<<"]"<<std::endl);
91 // Verify that a box with the same name does not exist already
92 if ( mPrototype->bbUnsafeGetBlackBox( name ) )
94 bbtkError("a black box \""<<name<<"\" already exists");
96 // ok : create new one
97 mPrototype->bbAddBlackBox ( /*mFactory->Create*/ NewBlackBox(type,name) );
99 bbtkDebugDecTab("Kernel",5);
101 //=======================================================================
103 //=======================================================================
104 /// Adds a black box to the execution list
105 void ComplexBlackBoxDescriptor::AddToExecutionList ( const std::string& box)
107 bbtkDebugMessageInc("Kernel",5,
108 "ComplexBlackBoxDescriptor::AddToExecutionList(\""
110 <<GetTypeName()<<"]"<<std::endl);
111 // Verify that the box exists
112 BlackBox* b = mPrototype->bbUnsafeGetBlackBox( box );
115 bbtkError("the black box \""<<box<<"\" does not exist");
118 mPrototype->bbAddToExecutionList ( box );
120 bbtkDebugDecTab("Kernel",5);
124 //=======================================================================
125 /// Connects two black boxes of the complex box
126 void ComplexBlackBoxDescriptor::Connect ( const std::string& from,
127 const std::string& output,
128 const std::string& to,
129 const std::string& input
132 bbtkDebugMessageInc("Kernel",5,
133 "ComplexBlackBoxDescriptor::Connect(\""
134 <<from<<"\",\""<<output<<"\",\""
137 <<GetTypeName()<<"]"<<std::endl);
138 // Verify that a box with the same name does not exist already
139 BlackBox* bbfrom = mPrototype->bbGetBlackBox( from );
142 bbtkError("the black box \""<<from<<"\" does not exist");
144 BlackBox* bbto = mPrototype->bbGetBlackBox( to );
147 bbtkError("the black box \""<<to<<"\" does not exist");
150 Connection* c = /*mFactory->*/ NewConnection( bbfrom, output, bbto, input );
152 mPrototype->bbAddConnection(c);
154 bbtkDebugDecTab("Kernel",5);
156 //=======================================================================
159 //=======================================================================
160 /// Defines an input of the complex box
161 void ComplexBlackBoxDescriptor::DefineInput ( const std::string& name,
162 const std::string& box,
163 const std::string& input,
164 const std::string& help)
166 bbtkDebugMessageInc("Kernel",5,
167 "ComplexBlackBoxDescriptor::DefineInput(\""
168 <<name<<"\",\""<<box<<"\",\""
169 <<input<<"\",\""<<help
171 <<GetTypeName()<<"]"<<std::endl);
173 BlackBox* bb = mPrototype->bbGetBlackBox( box );
176 bbtkError("the black box \""<<box<<"\" does not exist");
179 if (!bb->bbHasInput(input) )
181 bbtkError("the black box \""<<box<<"\" does not have input \""
185 AddInputDescriptor ( new ComplexBlackBoxInputDescriptor
186 ( typeid(ComplexBlackBoxDescriptor),
191 bb->bbGetInputType(input)));
194 bbtkDebugDecTab("Kernel",5);
196 //=======================================================================
198 //=======================================================================
199 /// Defines an output of the complex box
200 void ComplexBlackBoxDescriptor::DefineOutput ( const std::string& name,
201 const std::string& box,
202 const std::string& output,
203 const std::string& help)
205 bbtkDebugMessageInc("Kernel",5,
206 "ComplexBlackBoxDescriptor::DefineOutput(\""
207 <<name<<"\",\""<<box<<"\",\""
208 <<output<<"\",\""<<help
210 <<GetTypeName()<<"]"<<std::endl);
212 BlackBox* bb = mPrototype->bbGetBlackBox( box );
215 bbtkError("the black box \""<<box<<"\" does not exist");
218 if (!bb->bbHasOutput(output) )
220 bbtkError("the black box \""<<box<<"\" does not have output \""
224 AddOutputDescriptor ( new ComplexBlackBoxOutputDescriptor
225 ( typeid(ComplexBlackBoxDescriptor),
230 bb->bbGetOutputType(output)));
233 bbtkDebugDecTab("Kernel",5);
235 //=======================================================================
237 //=======================================================================
238 void ComplexBlackBoxDescriptor::PrintBlackBoxes()
240 mPrototype->bbPrintBlackBoxes();
242 //=======================================================================
245 //=======================================================================
246 void ComplexBlackBoxDescriptor::InsertHTMLGraph( std::ofstream& s ,
247 int detail, int level,
248 const std::string& output_dir, bool relative_link )
250 this->mPrototype->bbInsertHTMLGraph( s,
256 //=======================================================================
258 //=========================================================================
259 void ComplexBlackBoxDescriptor::InsertHtmlHelp ( std::ofstream& s,
260 int detail, int level,
261 const std::string& output_dir, bool relative_link)
263 bbtkDebugMessageInc("Kernel",9,
264 "ComplexBlackBoxDescriptor::InsertHtmlHelp() ["
265 <<GetTypeName()<<"]"<<std::endl);
269 std::string name = GetTypeName();
270 Utilities::html_format(name);
272 // std::ofstream* s = &s1;
275 (s) << "<a name=\""<<name<<"\"></a>\n";
277 "<a rel=\"top\" accesskey=\"t\" href=\"#Top\">Top</a>\n";
278 // (s) << "Previous: <a rel="previous" accesskey="p" href="#dir">(dir)</a>,
279 // (s) << "Up: <a rel="up" accesskey="u" href="#dir">(dir)</a>
280 (s) << "<h2 class=\"section\">"<<name<<"</h2>\n";
283 std::string descr = GetDescription();
284 Utilities::html_format(descr);
286 std::string author = GetAuthor();
287 Utilities::html_format(author);
289 std::vector<std::string> categories;
290 // Split the category string
291 std::string delimiters = ";,";
292 Utilities::SplitString(GetCategory(),
293 delimiters,categories);
296 (s) << "<p><TABLE cellspacing=0 cellpadding=3>\n";
297 (s) << "<TR><TD style='vertical-align: top;'><b> Description </b></TD><TD style='vertical-align: top;'> : </TD><TD style='vertical-align: top;'> "
298 << descr << "</TD></TR>\n";
300 (s) << "<TR><TD style='vertical-align: top;'><b> Author(s) </b></TD><TD style='vertical-align: top;'> : </TD><TD style='vertical-align: top;'> "
301 << author << "</TD></TR>\n";
303 (s) << "<TR><TD style='vertical-align: top;'><b> Category(s) </b></TD><TD style='vertical-align: top;'> : </TD><TD style='vertical-align: top;'> ";
304 std::vector<std::string>::iterator ci;
305 for (ci=categories.begin(); ci!=categories.end(); ++ci)
307 s << "<a href=\"../index-category.html#"<< *ci <<"\">" << *ci
311 std::string inc = GetScriptFileName();
314 s << "<TR><TD style='vertical-align: top;'><b> To use it </b></TD><TD style='vertical-align: top;'> : </TD><TD style='vertical-align: top;'> include ";
315 s << inc << " <a href=\"../../../bbs/"<<inc<<"\">[source]</a>";
320 const ComplexBlackBox::BlackBoxMapType& B = mPrototype->bbGetBlackBoxMap();
324 (s) << "<TR><TD style='vertical-align: top;'><b> Uses </b></TD><TD style='vertical-align: top;'> : </TD><TD style='vertical-align: top;'> ";
326 std::set<BlackBoxDescriptor*> pdeps;
327 ComplexBlackBox::BlackBoxMapType::const_iterator b;
328 for ( b = B.begin(); b != B.end(); ++b )
330 BlackBoxDescriptor* d = b->second->bbGetDescriptor();
331 if (pdeps.find(d) != pdeps.end())
335 Package* p = d->GetPackage();
337 std::string name = b->second->bbGetTypeName();
341 url = p->GetDocRelativeURL();
343 url = p->GetDocURL();
345 s << "<a href=\"" <<url<<"#"<<name<<"\">"
346 << p->GetName()<<"::"<<name<<"</a>\n";
349 (s) << "</TD></TR>\n";
358 InsertHTMLGraph( s , detail,level, output_dir, relative_link);
362 std::string col("#CCCCFF");
364 // (s) << "<h3 class=\"subsection\">Inputs</h3>\n";
365 (s) << "<p><TABLE border=1 cellspacing=0 cellpadding=3>\n";
366 (s) << "<TR><TD colspan=3 align=center bgcolor=\""<<col
367 <<"\">Inputs</TD></TR>\n";
368 const BlackBoxDescriptor::InputDescriptorMapType& imap =
369 GetInputDescriptorMap();
371 InputDescriptorMapType::const_iterator in;
373 for ( in = imap.begin(); in != imap.end(); ++in )
375 std::string name(in->second->GetName());
376 Utilities::html_format(name);
378 std::string type("<");
379 type += in->second->GetTypeName();
381 Utilities::html_format(type);
383 std::string descr(in->second->GetDescription());
384 Utilities::html_format(descr);
386 (s) << "<TR><TD style='vertical-align: top;'><B><PRE> "<<name<<" </PRE></B></TD>"
387 << "<TD style='vertical-align: top;'><I><PRE> "<<type<<" </PRE></I></TD>"
388 << "<TD style='vertical-align: top;'>"<<descr<<"</TD></TR>\n";
391 // (s) << "</TABLE>\n";
396 // (s) << "<h3 class=\"subsection\">Outputs</h3>\n";
397 // (s) << "<TABLE border=1 cellspacing=0>\n";
398 (s) << "<TR><TD colspan=3 align=center bgcolor=\""<<col
399 <<"\">Outputs</TD></TR>\n";
401 const BlackBoxDescriptor::OutputDescriptorMapType& omap =
402 GetOutputDescriptorMap();
404 BlackBoxDescriptor::OutputDescriptorMapType::const_iterator o;
406 for ( o = omap.begin(); o != omap.end(); ++o )
408 std::string name(o->second->GetName());
409 Utilities::html_format(name);
411 std::string type("<");
412 type += o->second->GetTypeName();
414 Utilities::html_format(type);
416 std::string descr(o->second->GetDescription());
417 Utilities::html_format(descr);
419 (s) << "<TR><TD style='vertical-align: top;'><B><PRE> "<<name<<" </PRE></B></TD>"
420 << "<TD style='vertical-align: top;'><I><PRE> "<<type<<" </PRE></I></TD>"
421 << "<TD style='vertical-align: top;'>"<<descr<<"</TD></TR>\n";
429 bbtkDebugDecTab("Kernel",9);
431 //=========================================================================
434 //=======================================================================
435 void ComplexBlackBoxDescriptor::GetHelp(bool full) const
437 if (full) bbtkMessage("Help",1,"Complex Black Box <"<<
438 GetPackage()->GetName()<<"::"
439 <<GetTypeName()<<">"<<std::endl);
440 bbtkMessage("Help",1," " << GetDescription() <<std::endl);
441 bbtkMessage("Help",1," By : " << GetAuthor() <<std::endl);
442 bbtkMessage("Help",1," Category(s) : " << GetCategory() <<std::endl);
444 bbtkMessage("Help",1," * Inputs : "<<std::endl);
446 bbtkMessage("Help",1," * No inputs"<<std::endl);
447 InputDescriptorMapType::const_iterator i;
448 unsigned int namelmax = 0;
449 unsigned int typelmax = 0;
450 for ( i = mInput.begin(); i != mInput.end(); ++i )
452 if (i->second->GetName().size()>namelmax)
453 namelmax = i->second->GetName().size();
454 if (i->second->GetTypeName().size()>typelmax)
455 typelmax = i->second->GetTypeName().size();
457 OutputDescriptorMapType::const_iterator o;
460 for ( o = mOutput.begin(); o != mOutput.end(); ++o )
462 if (o->second->GetName().size()>namelmax)
463 namelmax = o->second->GetName().size();
464 if (o->second->GetTypeName().size()>typelmax)
465 typelmax = o->second->GetTypeName().size();
470 for ( i = mInput.begin(); i != mInput.end(); ++i )
472 std::string name(i->second->GetName());
474 name.append(1+namelmax-name.size(),' ');
475 std::string type(i->second->GetTypeName());
477 type.append(1+typelmax-type.size(),' ');
478 bbtkMessage("Help",1,
481 <<" : "<<i->second->GetDescription()<<std::endl);
486 bbtkMessage("Help",1," * Outputs : "<<std::endl);
488 bbtkMessage("Help",1," * No outputs"<<std::endl);
489 for ( o = mOutput.begin(); o != mOutput.end(); ++o )
491 std::string name(o->second->GetName());
493 name.append(1+namelmax-name.size(),' ');
494 std::string type(o->second->GetTypeName());
496 type.append(1+typelmax-type.size(),' ');
497 bbtkMessage("Help",1,
500 <<" : "<<o->second->GetDescription()<<std::endl);
505 const ComplexBlackBox::BlackBoxMapType& B = mPrototype->bbGetBlackBoxMap();
508 bbtkMessage("Help",1," * Boxes : "<<std::endl);
510 bbtkMessage("Help",1," * No boxes"<<std::endl);
512 ComplexBlackBox::BlackBoxMapType::const_iterator b;
513 for ( b = B.begin(); b != B.end(); ++b )
515 bbtkMessage("Help",1," '"<<b->second->bbGetName()<<
517 << b->second->bbGetDescriptor()->GetPackage()->GetName()
519 <<b->second->bbGetTypeName()<<">"<<std::endl);
524 //=======================================================================