1 /*=========================================================================
4 Module: $RCSfile: bbtkComplexBlackBoxDescriptor.cxx,v $
6 Date: $Date: 2008/02/05 12:16:55 $
7 Version: $Revision: 1.3 $
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);
282 std::string author = GetAuthor();
283 Utilities::html_format(author);
285 std::string category = GetCategory();
286 Utilities::html_format(category);
288 (s) << "<p><TABLE cellspacing=0 cellpadding=3>\n";
289 (s) << "<TR><TD style='vertical-align: top;'><b> Description </b></TD><TD style='vertical-align: top;'> : </TD><TD style='vertical-align: top;'> "
290 << descr << "</TD></TR>\n";
292 (s) << "<TR><TD style='vertical-align: top;'><b> Author(s) </b></TD><TD style='vertical-align: top;'> : </TD><TD style='vertical-align: top;'> "
293 << author << "</TD></TR>\n";
295 (s) << "<TR><TD style='vertical-align: top;'><b> Category(s) </b></TD><TD style='vertical-align: top;'> : </TD><TD style='vertical-align: top;'> "
296 << category << "</TD></TR>\n";
298 std::string inc = GetScriptFileName();
301 (s) << "<TR><TD style='vertical-align: top;'><b> Include </b></TD><TD style='vertical-align: top;'> : </TD><TD style='vertical-align: top;'> "
302 << inc << "</TD></TR>\n";
306 const ComplexBlackBox::BlackBoxMapType& B = mPrototype->bbGetBlackBoxMap();
310 (s) << "<TR><TD style='vertical-align: top;'><b> Dependencies </b></TD><TD style='vertical-align: top;'> : </TD><TD style='vertical-align: top;'> ";
312 std::set<BlackBoxDescriptor*> pdeps;
313 ComplexBlackBox::BlackBoxMapType::const_iterator b;
314 for ( b = B.begin(); b != B.end(); ++b )
316 BlackBoxDescriptor* d = b->second->bbGetDescriptor();
317 if (pdeps.find(d) != pdeps.end())
321 Package* p = d->GetPackage();
323 std::string name = b->second->bbGetTypeName();
327 url = p->GetDocRelativeURL();
329 url = p->GetDocURL();
331 s << "<a href=\"" <<url<<"#"<<name<<"\">"
332 << p->GetName()<<"::"<<name<<"</a>\n";
335 (s) << "</TD></TR>\n";
344 InsertHTMLGraph( s , detail,level, output_dir, relative_link);
348 std::string col("#CCCCFF");
350 // (s) << "<h3 class=\"subsection\">Inputs</h3>\n";
351 (s) << "<p><TABLE border=1 cellspacing=0 cellpadding=3>\n";
352 (s) << "<TR><TD colspan=3 align=center bgcolor=\""<<col
353 <<"\">Inputs</TD></TR>\n";
354 const BlackBoxDescriptor::InputDescriptorMapType& imap =
355 GetInputDescriptorMap();
357 InputDescriptorMapType::const_iterator in;
359 for ( in = imap.begin(); in != imap.end(); ++in )
361 std::string name(in->second->GetName());
362 Utilities::html_format(name);
364 std::string type("<");
365 type += in->second->GetTypeName();
367 Utilities::html_format(type);
369 std::string descr(in->second->GetDescription());
370 //Utilities::html_format(descr);
372 (s) << "<TR><TD style='vertical-align: top;'><B><PRE> "<<name<<" </PRE></B></TD>"
373 << "<TD style='vertical-align: top;'><I><PRE> "<<type<<" </PRE></I></TD>"
374 << "<TD style='vertical-align: top;'>"<<descr<<"</TD></TR>\n";
377 // (s) << "</TABLE>\n";
382 // (s) << "<h3 class=\"subsection\">Outputs</h3>\n";
383 // (s) << "<TABLE border=1 cellspacing=0>\n";
384 (s) << "<TR><TD colspan=3 align=center bgcolor=\""<<col
385 <<"\">Outputs</TD></TR>\n";
387 const BlackBoxDescriptor::OutputDescriptorMapType& omap =
388 GetOutputDescriptorMap();
390 BlackBoxDescriptor::OutputDescriptorMapType::const_iterator o;
392 for ( o = omap.begin(); o != omap.end(); ++o )
394 std::string name(o->second->GetName());
395 Utilities::html_format(name);
397 std::string type("<");
398 type += o->second->GetTypeName();
400 Utilities::html_format(type);
402 std::string descr(o->second->GetDescription());
403 //Utilities::html_format(descr);
405 (s) << "<TR><TD style='vertical-align: top;'><B><PRE> "<<name<<" </PRE></B></TD>"
406 << "<TD style='vertical-align: top;'><I><PRE> "<<type<<" </PRE></I></TD>"
407 << "<TD style='vertical-align: top;'>"<<descr<<"</TD></TR>\n";
415 bbtkDebugDecTab("Core",9);
417 //=========================================================================
420 //=======================================================================
421 void ComplexBlackBoxDescriptor::GetHelp(bool full) const
423 if (full) bbtkMessage("Help",1,"Complex Black Box <"<<
424 GetPackage()->GetName()<<"::"
425 <<GetTypeName()<<">"<<std::endl);
426 bbtkMessage("Help",1," " << GetDescription() <<std::endl);
427 bbtkMessage("Help",1," By : " << GetAuthor() <<std::endl);
428 bbtkMessage("Help",1," Category(s) : " << GetCategory() <<std::endl);
430 bbtkMessage("Help",1," * Inputs : "<<std::endl);
432 bbtkMessage("Help",1," * No inputs"<<std::endl);
433 InputDescriptorMapType::const_iterator i;
434 unsigned int namelmax = 0;
435 unsigned int typelmax = 0;
436 for ( i = mInput.begin(); i != mInput.end(); ++i )
438 if (i->second->GetName().size()>namelmax)
439 namelmax = i->second->GetName().size();
440 if (i->second->GetTypeName().size()>typelmax)
441 typelmax = i->second->GetTypeName().size();
443 OutputDescriptorMapType::const_iterator o;
446 for ( o = mOutput.begin(); o != mOutput.end(); ++o )
448 if (o->second->GetName().size()>namelmax)
449 namelmax = o->second->GetName().size();
450 if (o->second->GetTypeName().size()>typelmax)
451 typelmax = o->second->GetTypeName().size();
456 for ( i = mInput.begin(); i != mInput.end(); ++i )
458 std::string name(i->second->GetName());
460 name.append(1+namelmax-name.size(),' ');
461 std::string type(i->second->GetTypeName());
463 type.append(1+typelmax-type.size(),' ');
464 bbtkMessage("Help",1,
467 <<" : "<<i->second->GetDescription()<<std::endl);
472 bbtkMessage("Help",1," * Outputs : "<<std::endl);
474 bbtkMessage("Help",1," * No outputs"<<std::endl);
475 for ( o = mOutput.begin(); o != mOutput.end(); ++o )
477 std::string name(o->second->GetName());
479 name.append(1+namelmax-name.size(),' ');
480 std::string type(o->second->GetTypeName());
482 type.append(1+typelmax-type.size(),' ');
483 bbtkMessage("Help",1,
486 <<" : "<<o->second->GetDescription()<<std::endl);
491 const ComplexBlackBox::BlackBoxMapType& B = mPrototype->bbGetBlackBoxMap();
494 bbtkMessage("Help",1," * Boxes : "<<std::endl);
496 bbtkMessage("Help",1," * No boxes"<<std::endl);
498 ComplexBlackBox::BlackBoxMapType::const_iterator b;
499 for ( b = B.begin(); b != B.end(); ++b )
501 bbtkMessage("Help",1," '"<<b->second->bbGetName()<<
503 << b->second->bbGetDescriptor()->GetPackage()->GetName()
505 <<b->second->bbGetTypeName()<<">"<<std::endl);
510 //=======================================================================