1 /*=========================================================================
4 Module: $RCSfile: bbtkBlackBoxDescriptor.cxx,v $
6 Date: $Date: 2008/04/09 11:16:57 $
7 Version: $Revision: 1.15 $
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"),
44 bbtkDebugMessage("Kernel",9,
45 "BlackBoxDescriptor::BlackBoxDescriptor()"<<std::endl);
47 //=========================================================================
49 //=========================================================================
51 BlackBoxDescriptor::~BlackBoxDescriptor()
53 bbtkDebugMessageInc("Kernel",9,
54 "BlackBoxDescriptor::~BlackBoxDescriptor() ["
55 <<mTypeName<<"]"<<std::endl);
57 // deletes all I/O descriptors
58 InputDescriptorMapType::iterator i;
59 for (i=mInput.begin(); i!=mInput.end(); ++i) delete i->second;
60 OutputDescriptorMapType::iterator o;
61 for (o=mOutput.begin(); o!=mOutput.end(); ++o) delete o->second;
63 bbtkDebugDecTab("Kernel",9);
65 //=========================================================================
67 //=========================================================================
69 void BlackBoxDescriptor::UnReference()
71 bbtkDebugMessageInc("Kernel",1,
72 "BlackBoxDescriptor::UnReference() ["
73 <<mTypeName<<"] #"<<mRefCount-1<<std::endl);
77 bbtkDebugMessage("Kernel",1,"--> Destructing BlackBoxDescriptor ["<<mTypeName<<"]"<<std::endl);
81 //=========================================================================
83 //=========================================================================
85 void BlackBoxDescriptor::Check(bool) const
89 //=========================================================================
91 //=========================================================================
92 /// Adds the string to the BlackBox description
93 void BlackBoxDescriptor::AddToDescription( const std::string& s, bool clear)
95 bbtkDebugMessage("Kernel",9,"BlackBoxDescriptor::AddToDescription(\""<<s<<
96 "\") ["<<GetFullTypeName()<<"]"<<std::endl);
97 if (clear) mDescription = s;
98 else mDescription += s;
100 //=========================================================================
102 //=========================================================================
103 /// Adds the string to the BlackBox author list
104 void BlackBoxDescriptor::AddToAuthor( const std::string& s, bool clear)
106 bbtkDebugMessage("Kernel",9,"BlackBoxDescriptor::AddToAuthor(\""<<s<<"\") ["
107 <<GetFullTypeName()<<"]"<<std::endl);
108 if (clear) mAuthor = s;
111 //=========================================================================
113 //=========================================================================
114 /// Adds the string to the BlackBox category list
115 void BlackBoxDescriptor::AddToCategory( const std::string& s, bool clear)
117 bbtkDebugMessage("Kernel",9,"BlackBoxDescriptor::AddToCategory(\""<<s<<"\") ["
118 <<GetFullTypeName()<<"]"<<std::endl);
119 if (clear) mCategory = s;
123 //=========================================================================
125 //=========================================================================
126 const BlackBoxDescriptor::InputDescriptor*
127 BlackBoxDescriptor::GetInputDescriptor(const std::string & name) const
129 bbtkDebugMessageInc("Kernel",9,"BlackBoxDescriptor::GetInputDescriptor('"
130 <<name<<"') ["<<GetFullTypeName()<<"]"<<std::endl);
132 InputDescriptorMapType::const_iterator i;
133 i = mInput.find(name);
134 if ( i == mInput.end() )
136 bbtkError("input '"<<name<<"' does not exist");
138 bbtkDebugDecTab("Kernel",9);
141 //=========================================================================
143 //=========================================================================
144 const BlackBoxDescriptor::OutputDescriptor*
145 BlackBoxDescriptor::GetOutputDescriptor(const std::string & name) const
147 bbtkDebugMessageInc("Kernel",9,"BlackBoxDescriptor::GetOutputDescriptor('"
148 <<name<<"') ["<<GetFullTypeName()<<"]"<<std::endl);
150 OutputDescriptorMapType::const_iterator i;
151 i = mOutput.find(name);
152 if ( i == mOutput.end() )
154 bbtkError("output '"<<name<<"' does not exist");
156 bbtkDebugDecTab("Kernel",9);
159 //=========================================================================
161 //=========================================================================
162 void BlackBoxDescriptor::GetHelp(bool full) const
164 bbtkDebugMessageInc("Kernel",9,"BlackBoxDescriptor::GetHelp() ["<<GetFullTypeName()<<"]"<<std::endl);
166 bbtkMessage("Help",1,"Black Box <"<<GetFullTypeName()<<">"<<std::endl);
167 bbtkMessage("Help",1," " <<GetDescription()<<std::endl);
168 bbtkMessage("Help",1," By : " <<GetAuthor() <<std::endl);
169 bbtkMessage("Help",1," Categories : " <<GetCategory() <<std::endl);
171 bbtkMessage("Help",1," * Inputs : "<<std::endl);
173 bbtkMessage("Help",1," * No inputs"<<std::endl);
174 InputDescriptorMapType::const_iterator i;
175 unsigned int namelmax = 0;
176 unsigned int typelmax = 0;
177 unsigned int natlmax = 0;
178 for ( i = mInput.begin(); i != mInput.end(); ++i )
180 if (i->second->GetName().size()>namelmax)
181 namelmax = i->second->GetName().size();
182 if (i->second->GetHumanTypeName().size()>typelmax)
183 typelmax = i->second->GetHumanTypeName().size();
184 if (i->second->GetNature().size()>natlmax)
185 natlmax = i->second->GetNature().size();
187 OutputDescriptorMapType::const_iterator o;
188 for ( o = mOutput.begin(); o != mOutput.end(); ++o )
190 if (o->second->GetName().size()>namelmax)
191 namelmax = o->second->GetName().size();
192 if (o->second->GetHumanTypeName().size()>typelmax)
193 typelmax = o->second->GetHumanTypeName().size();
194 if (o->second->GetNature().size()>natlmax)
195 natlmax = o->second->GetNature().size();
198 for ( i = mInput.begin(); i != mInput.end(); ++i )
200 std::string name(i->second->GetName());
202 name.append(1+namelmax-name.size(),' ');
203 std::string type(i->second->GetHumanTypeName());
205 type.append(1+typelmax-type.size(),' ');
206 std::string nature(i->second->GetNature());
208 nature.append(1+natlmax-nature.size(),' ');
209 bbtkMessage("Help",1,
213 <<" : "<<i->second->GetDescription()<<std::endl);
216 bbtkMessage("Help",1," * Outputs : "<<std::endl);
218 bbtkMessage("Help",1," * No outputs"<<std::endl);
219 for ( o = mOutput.begin(); o != mOutput.end(); ++o )
221 std::string name(o->second->GetName());
223 name.append(1+namelmax-name.size(),' ');
224 std::string type(o->second->GetHumanTypeName());
226 type.append(1+typelmax-type.size(),' ');
227 std::string nature(o->second->GetNature());
229 nature.append(1+natlmax-nature.size(),' ');
230 bbtkMessage("Help",1,
234 <<" : "<<o->second->GetDescription()<<std::endl);
237 bbtkDebugDecTab("Kernel",9);
241 //=========================================================================
243 //=========================================================================
244 /// Returns the full name of the **TYPE** of the black box (+package name)
245 std::string BlackBoxDescriptor::GetFullTypeName() const
247 if (mPackage!=0) return mPackage->GetName() + "::" + mTypeName;
248 return "::" + mTypeName;
250 //=========================================================================
252 //=========================================================================
253 void BlackBoxDescriptor::InsertHtmlHelp ( std::ofstream& s,
254 int detail, int level,
255 const std::string& output_dir,
258 bbtkDebugMessageInc("Kernel",9,"BlackBoxDescriptor::InsertHtmlHelp() ["<<GetFullTypeName()<<"]"<<std::endl);
262 std::string name = GetTypeName();
263 Utilities::html_format(name);
266 (s) << "<a name=\""<<name<<"\"></a>\n";
268 "<a rel=\"top\" accesskey=\"t\" href=\"#Top\">Top</a>\n";
269 // (s) << "Previous: <a rel="previous" accesskey="p" href="#dir">(dir)</a>,
270 // (s) << "Up: <a rel="up" accesskey="u" href="#dir">(dir)</a>
271 (s) << "<h2 class=\"section\">"<<name<<"</h2>\n";
274 std::string descr = GetDescription();
275 Utilities::html_format(descr);
276 std::string author = GetAuthor();
277 Utilities::html_format(author);
279 std::vector<std::string> categories;
280 // Split the category string
281 std::string delimiters = ";,";
282 Utilities::SplitString(GetCategory(),
283 delimiters,categories);
286 (s) << "<p><TABLE cellspacing=0 cellpadding=3>\n";
287 (s) << "<TR><TD style='vertical-align: top;'><b> Description </b></TD><TD style='vertical-align: top;'> : </TD><TD style='vertical-align: top;'> "
288 << descr << "</TD></TR>\n";
289 (s) << "<TR><TD style='vertical-align: top;'><b> Author(s) </b></TD><TD style='vertical-align: top;'> : </TD><TD style='vertical-align: top;'> "
290 << author << "</TD></TR>\n";
291 (s) << "<TR><TD style='vertical-align: top;'><b> Category(s) </b></TD><TD style='vertical-align: top;'> : </TD><TD style='vertical-align: top;'> ";
292 std::vector<std::string>::iterator ci;
293 for (ci=categories.begin(); ci!=categories.end(); ++ci)
295 s << "<a href=\"../index-category.html#"<< *ci <<"\">" << *ci
300 (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 "
301 << GetPackage()->GetName() << "</TD></TR>\n";
306 //i->second->InsertHTMLGraph( &s , detail,level,dir);
310 std::string titlecol("#BBBBFF");
311 std::string usercol("#FFFFFF");
312 std::string ubbcol("#DDFFFF");
313 std::string wxbbcol("#EEFFFF");
316 // (s) << "<h3 class=\"subsection\">Inputs</h3>\n";
317 (s) << "<p><TABLE border=1 cellspacing=0 cellpadding=3>\n";
318 (s) << "<TR><TD colspan=3 align=center bgcolor=\""<<titlecol
319 <<"\">Inputs</TD></TR>\n";
321 std::vector<std::string> user_defined;
322 std::vector<std::string> ubb_defined;
323 std::vector<std::string> wxbb_defined;
325 const BlackBoxDescriptor::InputDescriptorMapType& imap =
326 GetInputDescriptorMap();
327 InputDescriptorMapType::const_iterator in;
328 for ( in = imap.begin(); in != imap.end(); ++in )
330 // Skips system-defined inputs
331 std::string col(usercol);
333 if (in->second->GetCreatorTypeInfo() ==
334 typeid(AtomicBlackBoxDescriptor))
339 else if (in->second->GetCreatorTypeInfo() ==
340 typeid(WxBlackBoxDescriptor))
346 std::string name(in->second->GetName());
347 Utilities::html_format(name);
349 std::string type("<");
350 type += in->second->GetTypeName();
352 Utilities::html_format(type);
354 std::string descr(in->second->GetDescription());
355 Utilities::html_format(descr);
358 "<TR><TD style='vertical-align: top;' bgcolor=\"" + col
359 +"\"><B><PRE> "+name+" </PRE></B></TD>"
360 + "<TD style='vertical-align: top;' bgcolor=\""+col
361 +"\"><I><PRE> "+type+" </PRE></I></TD>"
362 + "<TD style='vertical-align: top;' bgcolor=\""+col
363 +"\">"+descr+"</TD></TR>\n";
365 if (iotype==0) user_defined.push_back(out);
366 else if (iotype==1) ubb_defined.push_back(out);
367 else if (iotype==2) wxbb_defined.push_back(out);
371 std::vector<std::string>::iterator hi;
372 for (hi=user_defined.begin();hi!=user_defined.end();++hi) s << *hi;
373 for (hi=wxbb_defined.begin();hi!=wxbb_defined.end();++hi) s << *hi;
374 for (hi=ubb_defined.begin();hi!=ubb_defined.end();++hi) s << *hi;
376 user_defined.clear();
378 wxbb_defined.clear();
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=\""<<titlecol
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 col(usercol);
396 if (o->second->GetCreatorTypeInfo() ==
397 typeid(AtomicBlackBoxDescriptor))
402 else if (o->second->GetCreatorTypeInfo() ==
403 typeid(WxBlackBoxDescriptor))
409 std::string name(o->second->GetName());
410 Utilities::html_format(name);
412 std::string type("<");
413 type += o->second->GetTypeName();
415 Utilities::html_format(type);
417 std::string descr(o->second->GetDescription());
418 Utilities::html_format(descr);
421 "<TR><TD style='vertical-align: top;' bgcolor=\"" + col
422 +"\"><B><PRE> "+name+" </PRE></B></TD>"
423 + "<TD style='vertical-align: top;' bgcolor=\""+col
424 +"\"><I><PRE> "+type+" </PRE></I></TD>"
425 + "<TD style='vertical-align: top;' bgcolor=\""+col
426 +"\">"+descr+"</TD></TR>\n";
428 if (iotype==0) user_defined.push_back(out);
429 else if (iotype==1) ubb_defined.push_back(out);
430 else if (iotype==2) wxbb_defined.push_back(out);
434 for (hi=user_defined.begin();hi!=user_defined.end();++hi) s << *hi;
435 for (hi=wxbb_defined.begin();hi!=wxbb_defined.end();++hi) s << *hi;
436 for (hi=ubb_defined.begin();hi!=ubb_defined.end();++hi) s << *hi;
443 bbtkDebugDecTab("Kernel",9);
445 //=========================================================================