1 /*=========================================================================
4 Module: $RCSfile: bbtkBlackBoxDescriptor.cxx,v $
6 Date: $Date: 2008/02/05 12:16:55 $
7 Version: $Revision: 1.6 $
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"
31 //=========================================================================
33 BlackBoxDescriptor::BlackBoxDescriptor()
34 : mTypeName("Unknown"),
41 bbtkDebugMessage("Core",9,
42 "BlackBoxDescriptor::BlackBoxDescriptor()"<<std::endl);
44 //=========================================================================
46 //=========================================================================
48 BlackBoxDescriptor::~BlackBoxDescriptor()
50 bbtkDebugMessageInc("Core",9,
51 "BlackBoxDescriptor::~BlackBoxDescriptor() ["
52 <<mTypeName<<"]"<<std::endl);
54 // deletes all I/O descriptors
55 InputDescriptorMapType::iterator i;
56 for (i=mInput.begin(); i!=mInput.end(); ++i) delete i->second;
57 OutputDescriptorMapType::iterator o;
58 for (o=mOutput.begin(); o!=mOutput.end(); ++o) delete o->second;
60 bbtkDebugDecTab("Core",9);
62 //=========================================================================
64 //=========================================================================
65 /// Adds the string to the BlackBox description
66 void BlackBoxDescriptor::AddToDescription( const std::string& s, bool clear)
68 bbtkDebugMessage("Core",9,"BlackBoxDescriptor::AddToDescription(\""<<s<<
69 "\") ["<<GetTypeName()<<"]"<<std::endl);
70 if (clear) mDescription = s;
71 else mDescription += s;
73 //=========================================================================
75 //=========================================================================
76 /// Adds the string to the BlackBox author list
77 void BlackBoxDescriptor::AddToAuthor( const std::string& s, bool clear)
79 bbtkDebugMessage("Core",9,"BlackBoxDescriptor::AddToAuthor(\""<<s<<"\") ["
80 <<GetTypeName()<<"]"<<std::endl);
81 if (clear) mAuthor = s;
84 //=========================================================================
86 //=========================================================================
87 /// Adds the string to the BlackBox category list
88 void BlackBoxDescriptor::AddToCategory( const std::string& s, bool clear)
90 bbtkDebugMessage("Core",9,"BlackBoxDescriptor::AddToCategory(\""<<s<<"\") ["
91 <<GetTypeName()<<"]"<<std::endl);
92 if (clear) mCategory = s;
96 //=========================================================================
98 //=========================================================================
99 const BlackBoxDescriptor::InputDescriptor*
100 BlackBoxDescriptor::GetInputDescriptor(const std::string & name) const
102 bbtkDebugMessageInc("Core",9,"BlackBoxDescriptor::GetInputDescriptor('"
103 <<name<<"') ["<<GetTypeName()<<"]"<<std::endl);
105 InputDescriptorMapType::const_iterator i;
106 i = mInput.find(name);
107 if ( i == mInput.end() )
109 bbtkError("input '"<<name<<"' does not exist");
111 bbtkDebugDecTab("Core",9);
114 //=========================================================================
116 //=========================================================================
117 const BlackBoxDescriptor::OutputDescriptor*
118 BlackBoxDescriptor::GetOutputDescriptor(const std::string & name) const
120 bbtkDebugMessageInc("Core",9,"BlackBoxDescriptor::GetOutputDescriptor('"
121 <<name<<"') ["<<GetTypeName()<<"]"<<std::endl);
123 OutputDescriptorMapType::const_iterator i;
124 i = mOutput.find(name);
125 if ( i == mOutput.end() )
127 bbtkError("output '"<<name<<"' does not exist");
129 bbtkDebugDecTab("Core",9);
132 //=========================================================================
134 //=========================================================================
135 void BlackBoxDescriptor::GetHelp(bool full) const
137 bbtkDebugMessageInc("Core",9,"BlackBoxDescriptor::GetHelp() ["<<GetTypeName()<<"]"<<std::endl);
140 bbtkMessage("Help",1,"Black Box <"<<
141 GetPackage()->GetName()<<"::"<<GetTypeName()<<">"<<std::endl);
145 bbtkMessage("Help",1,"Black Box <::"<<GetTypeName()<<">"<<std::endl);
147 bbtkMessage("Help",1," " <<GetDescription()<<std::endl);
148 bbtkMessage("Help",1," By : " <<GetAuthor() <<std::endl);
149 bbtkMessage("Help",1," Categories : " <<GetCategory() <<std::endl);
151 bbtkMessage("Help",1," * Inputs : "<<std::endl);
153 bbtkMessage("Help",1," * No inputs"<<std::endl);
154 InputDescriptorMapType::const_iterator i;
155 unsigned int namelmax = 0;
156 unsigned int typelmax = 0;
157 for ( i = mInput.begin(); i != mInput.end(); ++i )
159 if (i->second->GetName().size()>namelmax)
160 namelmax = i->second->GetName().size();
161 if (i->second->GetHumanTypeName().size()>typelmax)
162 typelmax = i->second->GetHumanTypeName().size();
164 OutputDescriptorMapType::const_iterator o;
165 for ( o = mOutput.begin(); o != mOutput.end(); ++o )
167 if (o->second->GetName().size()>namelmax)
168 namelmax = o->second->GetName().size();
169 if (o->second->GetHumanTypeName().size()>typelmax)
170 typelmax = o->second->GetHumanTypeName().size();
173 for ( i = mInput.begin(); i != mInput.end(); ++i )
175 std::string name(i->second->GetName());
177 name.append(1+namelmax-name.size(),' ');
178 std::string type(i->second->GetHumanTypeName());
180 type.append(1+typelmax-type.size(),' ');
181 bbtkMessage("Help",1,
184 <<" : "<<i->second->GetDescription()<<std::endl);
187 bbtkMessage("Help",1," * Outputs : "<<std::endl);
189 bbtkMessage("Help",1," * No outputs"<<std::endl);
190 for ( o = mOutput.begin(); o != mOutput.end(); ++o )
192 std::string name(o->second->GetName());
194 name.append(1+namelmax-name.size(),' ');
195 std::string type(o->second->GetHumanTypeName());
197 type.append(1+typelmax-type.size(),' ');
198 bbtkMessage("Help",1,
201 <<" : "<<o->second->GetDescription()<<std::endl);
204 bbtkDebugDecTab("Core",9);
208 //=========================================================================
210 //=========================================================================
211 void BlackBoxDescriptor::InsertHtmlHelp ( std::ofstream& s,
212 int detail, int level,
213 const std::string& output_dir,
216 bbtkDebugMessageInc("Core",9,"BlackBoxDescriptor::InsertHtmlHelp() ["<<GetTypeName()<<"]"<<std::endl);
220 std::string name = GetTypeName();
221 Utilities::html_format(name);
224 (s) << "<a name=\""<<name<<"\"></a>\n";
226 "<a rel=\"top\" accesskey=\"t\" href=\"#Top\">Top</a>\n";
227 // (s) << "Previous: <a rel="previous" accesskey="p" href="#dir">(dir)</a>,
228 // (s) << "Up: <a rel="up" accesskey="u" href="#dir">(dir)</a>
229 (s) << "<h2 class=\"section\">"<<name<<"</h2>\n";
232 std::string descr = GetDescription();
233 //Utilities::html_format(descr);
234 std::string author = GetAuthor();
235 Utilities::html_format(author);
237 std::string category = GetCategory();
238 Utilities::html_format(category);
240 (s) << "<p><TABLE cellspacing=0 cellpadding=3>\n";
241 (s) << "<TR><TD style='vertical-align: top;'><b> Description </b></TD><TD style='vertical-align: top;'> : </TD><TD style='vertical-align: top;'> "
242 << descr << "</TD></TR>\n";
243 (s) << "<TR><TD style='vertical-align: top;'><b> Author(s) </b></TD><TD style='vertical-align: top;'> : </TD><TD style='vertical-align: top;'> "
244 << author << "</TD></TR>\n";
249 //i->second->InsertHTMLGraph( &s , detail,level,dir);
253 std::string col("#CCCCFF");
255 // (s) << "<h3 class=\"subsection\">Inputs</h3>\n";
256 (s) << "<p><TABLE border=1 cellspacing=0 cellpadding=3>\n";
257 (s) << "<TR><TD colspan=3 align=center bgcolor=\""<<col
258 <<"\">Inputs</TD></TR>\n";
259 const BlackBoxDescriptor::InputDescriptorMapType& imap =
260 GetInputDescriptorMap();
262 InputDescriptorMapType::const_iterator in;
264 for ( in = imap.begin(); in != imap.end(); ++in )
266 std::string name(in->second->GetName());
267 Utilities::html_format(name);
269 std::string type("<");
270 type += in->second->GetTypeName();
272 Utilities::html_format(type);
274 std::string descr(in->second->GetDescription());
275 //Utilities::html_format(descr);
277 (s) << "<TR><TD style='vertical-align: top;'><B><PRE> "<<name<<" </PRE></B></TD>"
278 << "<TD style='vertical-align: top;'><I><PRE> "<<type<<" </PRE></I></TD>"
279 << "<TD style='vertical-align: top;'>"<<descr<<"</TD></TR>\n";
282 // (s) << "</TABLE>\n";
287 // (s) << "<h3 class=\"subsection\">Outputs</h3>\n";
288 // (s) << "<TABLE border=1 cellspacing=0>\n";
289 (s) << "<TR><TD colspan=3 align=center bgcolor=\""<<col
290 <<"\">Outputs</TD></TR>\n";
292 const BlackBoxDescriptor::OutputDescriptorMapType& omap =
293 GetOutputDescriptorMap();
295 BlackBoxDescriptor::OutputDescriptorMapType::const_iterator o;
297 for ( o = omap.begin(); o != omap.end(); ++o )
299 std::string name(o->second->GetName());
300 Utilities::html_format(name);
302 std::string type("<");
303 type += o->second->GetTypeName();
305 Utilities::html_format(type);
307 std::string descr(o->second->GetDescription());
308 //Utilities::html_format(descr);
311 (s) << "<TR><TD style='vertical-align: top;'><B><PRE> "<<name<<" </PRE></B></TD>"
312 << "<TD style='vertical-align: top;'><I><PRE> "<<type<<" </PRE></I></TD>"
313 << "<TD style='vertical-align: top;'>"<<descr<<"</TD></TR>\n";
321 bbtkDebugDecTab("Core",9);
323 //=========================================================================