1 /*=========================================================================
4 Module: $RCSfile: bbtkBlackBoxDescriptor.cxx,v $
6 Date: $Date: 2008/02/18 10:41:02 $
7 Version: $Revision: 1.13 $
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::BlackBoxDescriptor : (abstract) describes a BlackBox (name, description, author) and is able to create an instance of it.
23 #include "bbtkBlackBoxDescriptor.h"
24 #include "bbtkMessageManager.h"
25 #include "bbtkPackage.h"
26 #include "bbtkUtilities.h"
27 #include "bbtkAtomicBlackBoxDescriptor.h"
28 #include "bbtkWxBlackBox.h"
33 //=========================================================================
35 BlackBoxDescriptor::BlackBoxDescriptor()
36 : mTypeName("Unknown"),
43 bbtkDebugMessage("Kernel",9,
44 "BlackBoxDescriptor::BlackBoxDescriptor()"<<std::endl);
46 //=========================================================================
48 //=========================================================================
50 BlackBoxDescriptor::~BlackBoxDescriptor()
52 bbtkDebugMessageInc("Kernel",9,
53 "BlackBoxDescriptor::~BlackBoxDescriptor() ["
54 <<mTypeName<<"]"<<std::endl);
56 // deletes all I/O descriptors
57 InputDescriptorMapType::iterator i;
58 for (i=mInput.begin(); i!=mInput.end(); ++i) delete i->second;
59 OutputDescriptorMapType::iterator o;
60 for (o=mOutput.begin(); o!=mOutput.end(); ++o) delete o->second;
62 bbtkDebugDecTab("Kernel",9);
64 //=========================================================================
66 //=========================================================================
67 /// Adds the string to the BlackBox description
68 void BlackBoxDescriptor::AddToDescription( const std::string& s, bool clear)
70 bbtkDebugMessage("Kernel",9,"BlackBoxDescriptor::AddToDescription(\""<<s<<
71 "\") ["<<GetTypeName()<<"]"<<std::endl);
72 if (clear) mDescription = s;
73 else mDescription += s;
75 //=========================================================================
77 //=========================================================================
78 /// Adds the string to the BlackBox author list
79 void BlackBoxDescriptor::AddToAuthor( const std::string& s, bool clear)
81 bbtkDebugMessage("Kernel",9,"BlackBoxDescriptor::AddToAuthor(\""<<s<<"\") ["
82 <<GetTypeName()<<"]"<<std::endl);
83 if (clear) mAuthor = s;
86 //=========================================================================
88 //=========================================================================
89 /// Adds the string to the BlackBox category list
90 void BlackBoxDescriptor::AddToCategory( const std::string& s, bool clear)
92 bbtkDebugMessage("Kernel",9,"BlackBoxDescriptor::AddToCategory(\""<<s<<"\") ["
93 <<GetTypeName()<<"]"<<std::endl);
94 if (clear) mCategory = s;
98 //=========================================================================
100 //=========================================================================
101 const BlackBoxDescriptor::InputDescriptor*
102 BlackBoxDescriptor::GetInputDescriptor(const std::string & name) const
104 bbtkDebugMessageInc("Kernel",9,"BlackBoxDescriptor::GetInputDescriptor('"
105 <<name<<"') ["<<GetTypeName()<<"]"<<std::endl);
107 InputDescriptorMapType::const_iterator i;
108 i = mInput.find(name);
109 if ( i == mInput.end() )
111 bbtkError("input '"<<name<<"' does not exist");
113 bbtkDebugDecTab("Kernel",9);
116 //=========================================================================
118 //=========================================================================
119 const BlackBoxDescriptor::OutputDescriptor*
120 BlackBoxDescriptor::GetOutputDescriptor(const std::string & name) const
122 bbtkDebugMessageInc("Kernel",9,"BlackBoxDescriptor::GetOutputDescriptor('"
123 <<name<<"') ["<<GetTypeName()<<"]"<<std::endl);
125 OutputDescriptorMapType::const_iterator i;
126 i = mOutput.find(name);
127 if ( i == mOutput.end() )
129 bbtkError("output '"<<name<<"' does not exist");
131 bbtkDebugDecTab("Kernel",9);
134 //=========================================================================
136 //=========================================================================
137 void BlackBoxDescriptor::GetHelp(bool full) const
139 bbtkDebugMessageInc("Kernel",9,"BlackBoxDescriptor::GetHelp() ["<<GetTypeName()<<"]"<<std::endl);
142 bbtkMessage("Help",1,"Black Box <"<<
143 GetPackage()->GetName()<<"::"<<GetTypeName()<<">"<<std::endl);
147 bbtkMessage("Help",1,"Black Box <::"<<GetTypeName()<<">"<<std::endl);
149 bbtkMessage("Help",1," " <<GetDescription()<<std::endl);
150 bbtkMessage("Help",1," By : " <<GetAuthor() <<std::endl);
151 bbtkMessage("Help",1," Categories : " <<GetCategory() <<std::endl);
153 bbtkMessage("Help",1," * Inputs : "<<std::endl);
155 bbtkMessage("Help",1," * No inputs"<<std::endl);
156 InputDescriptorMapType::const_iterator i;
157 unsigned int namelmax = 0;
158 unsigned int typelmax = 0;
159 for ( i = mInput.begin(); i != mInput.end(); ++i )
161 if (i->second->GetName().size()>namelmax)
162 namelmax = i->second->GetName().size();
163 if (i->second->GetHumanTypeName().size()>typelmax)
164 typelmax = i->second->GetHumanTypeName().size();
166 OutputDescriptorMapType::const_iterator o;
167 for ( o = mOutput.begin(); o != mOutput.end(); ++o )
169 if (o->second->GetName().size()>namelmax)
170 namelmax = o->second->GetName().size();
171 if (o->second->GetHumanTypeName().size()>typelmax)
172 typelmax = o->second->GetHumanTypeName().size();
175 for ( i = mInput.begin(); i != mInput.end(); ++i )
177 std::string name(i->second->GetName());
179 name.append(1+namelmax-name.size(),' ');
180 std::string type(i->second->GetHumanTypeName());
182 type.append(1+typelmax-type.size(),' ');
183 bbtkMessage("Help",1,
186 <<" : "<<i->second->GetDescription()<<std::endl);
189 bbtkMessage("Help",1," * Outputs : "<<std::endl);
191 bbtkMessage("Help",1," * No outputs"<<std::endl);
192 for ( o = mOutput.begin(); o != mOutput.end(); ++o )
194 std::string name(o->second->GetName());
196 name.append(1+namelmax-name.size(),' ');
197 std::string type(o->second->GetHumanTypeName());
199 type.append(1+typelmax-type.size(),' ');
200 bbtkMessage("Help",1,
203 <<" : "<<o->second->GetDescription()<<std::endl);
206 bbtkDebugDecTab("Kernel",9);
210 //=========================================================================
212 //=========================================================================
213 void BlackBoxDescriptor::InsertHtmlHelp ( std::ofstream& s,
214 int detail, int level,
215 const std::string& output_dir,
218 printf("BlackBoxDescriptor::InsertHtmlHelp 01 lllllllllllllllllllllllllllllllllllllllllllllllll \n");
219 bbtkDebugMessageInc("Kernel",9,"BlackBoxDescriptor::InsertHtmlHelp() ["<<GetTypeName()<<"]"<<std::endl);
223 std::string name = GetTypeName();
224 Utilities::html_format(name);
227 (s) << "<a name=\""<<name<<"\"></a>\n";
229 "<a rel=\"top\" accesskey=\"t\" href=\"#Top\">Top</a>\n";
230 // (s) << "Previous: <a rel="previous" accesskey="p" href="#dir">(dir)</a>,
231 // (s) << "Up: <a rel="up" accesskey="u" href="#dir">(dir)</a>
232 (s) << "<h2 class=\"section\">"<<name<<"</h2>\n";
235 std::string descr = GetDescription();
236 Utilities::html_format(descr);
237 std::string author = GetAuthor();
238 Utilities::html_format(author);
240 std::vector<std::string> categories;
241 // Split the category string
242 std::string delimiters = ";,";
243 Utilities::SplitString(GetCategory(),
244 delimiters,categories);
247 (s) << "<p><TABLE cellspacing=0 cellpadding=3>\n";
248 (s) << "<TR><TD style='vertical-align: top;'><b> Description </b></TD><TD style='vertical-align: top;'> : </TD><TD style='vertical-align: top;'> "
249 << descr << "</TD></TR>\n";
250 (s) << "<TR><TD style='vertical-align: top;'><b> Author(s) </b></TD><TD style='vertical-align: top;'> : </TD><TD style='vertical-align: top;'> "
251 << author << "</TD></TR>\n";
252 (s) << "<TR><TD style='vertical-align: top;'><b> Category(s) </b></TD><TD style='vertical-align: top;'> : </TD><TD style='vertical-align: top;'> ";
253 std::vector<std::string>::iterator ci;
254 for (ci=categories.begin(); ci!=categories.end(); ++ci)
256 s << "<a href=\"../index-category.html#"<< *ci <<"\">" << *ci
261 (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 "
262 << GetPackage()->GetName() << "</TD></TR>\n";
267 //i->second->InsertHTMLGraph( &s , detail,level,dir);
271 std::string titlecol("#BBBBFF");
272 std::string usercol("#FFFFFF");
273 std::string ubbcol("#DDFFFF");
274 std::string wxbbcol("#EEFFFF");
277 // (s) << "<h3 class=\"subsection\">Inputs</h3>\n";
278 (s) << "<p><TABLE border=1 cellspacing=0 cellpadding=3>\n";
279 (s) << "<TR><TD colspan=3 align=center bgcolor=\""<<titlecol
280 <<"\">Inputs</TD></TR>\n";
282 std::vector<std::string> user_defined;
283 std::vector<std::string> ubb_defined;
284 std::vector<std::string> wxbb_defined;
286 const BlackBoxDescriptor::InputDescriptorMapType& imap =
287 GetInputDescriptorMap();
288 InputDescriptorMapType::const_iterator in;
289 for ( in = imap.begin(); in != imap.end(); ++in )
291 // Skips system-defined inputs
292 std::string col(usercol);
294 if (in->second->GetCreatorTypeInfo() ==
295 typeid(AtomicBlackBoxDescriptor))
300 else if (in->second->GetCreatorTypeInfo() ==
301 typeid(WxBlackBoxDescriptor))
307 std::string name(in->second->GetName());
308 Utilities::html_format(name);
310 std::string type("<");
311 type += in->second->GetTypeName();
313 Utilities::html_format(type);
315 std::string descr(in->second->GetDescription());
316 Utilities::html_format(descr);
319 "<TR><TD style='vertical-align: top;' bgcolor=\"" + col
320 +"\"><B><PRE> "+name+" </PRE></B></TD>"
321 + "<TD style='vertical-align: top;' bgcolor=\""+col
322 +"\"><I><PRE> "+type+" </PRE></I></TD>"
323 + "<TD style='vertical-align: top;' bgcolor=\""+col
324 +"\">"+descr+"</TD></TR>\n";
326 if (iotype==0) user_defined.push_back(out);
327 else if (iotype==1) ubb_defined.push_back(out);
328 else if (iotype==2) wxbb_defined.push_back(out);
332 std::vector<std::string>::iterator hi;
333 for (hi=user_defined.begin();hi!=user_defined.end();++hi) s << *hi;
334 for (hi=wxbb_defined.begin();hi!=wxbb_defined.end();++hi) s << *hi;
335 for (hi=ubb_defined.begin();hi!=ubb_defined.end();++hi) s << *hi;
337 user_defined.clear();
339 wxbb_defined.clear();
343 // (s) << "<h3 class=\"subsection\">Outputs</h3>\n";
344 // (s) << "<TABLE border=1 cellspacing=0>\n";
345 (s) << "<TR><TD colspan=3 align=center bgcolor=\""<<titlecol
346 <<"\">Outputs</TD></TR>\n";
348 const BlackBoxDescriptor::OutputDescriptorMapType& omap =
349 GetOutputDescriptorMap();
351 BlackBoxDescriptor::OutputDescriptorMapType::const_iterator o;
353 for ( o = omap.begin(); o != omap.end(); ++o )
355 std::string col(usercol);
357 if (o->second->GetCreatorTypeInfo() ==
358 typeid(AtomicBlackBoxDescriptor))
363 else if (o->second->GetCreatorTypeInfo() ==
364 typeid(WxBlackBoxDescriptor))
370 std::string name(o->second->GetName());
371 Utilities::html_format(name);
373 std::string type("<");
374 type += o->second->GetTypeName();
376 Utilities::html_format(type);
378 std::string descr(o->second->GetDescription());
379 Utilities::html_format(descr);
382 "<TR><TD style='vertical-align: top;' bgcolor=\"" + col
383 +"\"><B><PRE> "+name+" </PRE></B></TD>"
384 + "<TD style='vertical-align: top;' bgcolor=\""+col
385 +"\"><I><PRE> "+type+" </PRE></I></TD>"
386 + "<TD style='vertical-align: top;' bgcolor=\""+col
387 +"\">"+descr+"</TD></TR>\n";
389 if (iotype==0) user_defined.push_back(out);
390 else if (iotype==1) ubb_defined.push_back(out);
391 else if (iotype==2) wxbb_defined.push_back(out);
395 for (hi=user_defined.begin();hi!=user_defined.end();++hi) s << *hi;
396 for (hi=wxbb_defined.begin();hi!=wxbb_defined.end();++hi) s << *hi;
397 for (hi=ubb_defined.begin();hi!=ubb_defined.end();++hi) s << *hi;
404 bbtkDebugDecTab("Kernel",9);
405 printf("BlackBoxDescriptor::InsertHtmlHelp 02 lllllllllllllllllllllllllllllllllllllllllllllllll \n");
407 //=========================================================================