1 /*=========================================================================
4 Module: $RCSfile: bbtkBlackBoxDescriptor.cxx,v $
6 Date: $Date: 2008/01/30 09:28:15 $
7 Version: $Revision: 1.2 $
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 keyword list
88 void BlackBoxDescriptor::AddToKeyword( const std::string& s, bool clear)
90 bbtkDebugMessage("Core",9,"BlackBoxDescriptor::AddToKeyword(\""<<s<<"\") ["
91 <<GetTypeName()<<"]"<<std::endl);
92 if (clear) mKeyword = s;
95 //=========================================================================
97 //=========================================================================
98 const BlackBoxDescriptor::InputDescriptor*
99 BlackBoxDescriptor::GetInputDescriptor(const std::string & name) const
101 bbtkDebugMessageInc("Core",9,"BlackBoxDescriptor::GetInputDescriptor('"
102 <<name<<"') ["<<GetTypeName()<<"]"<<std::endl);
104 InputDescriptorMapType::const_iterator i;
105 i = mInput.find(name);
106 if ( i == mInput.end() )
108 bbtkError("input '"<<name<<"' does not exist");
110 bbtkDebugDecTab("Core",9);
113 //=========================================================================
115 //=========================================================================
116 const BlackBoxDescriptor::OutputDescriptor*
117 BlackBoxDescriptor::GetOutputDescriptor(const std::string & name) const
119 bbtkDebugMessageInc("Core",9,"BlackBoxDescriptor::GetOutputDescriptor('"
120 <<name<<"') ["<<GetTypeName()<<"]"<<std::endl);
122 OutputDescriptorMapType::const_iterator i;
123 i = mOutput.find(name);
124 if ( i == mOutput.end() )
126 bbtkError("output '"<<name<<"' does not exist");
128 bbtkDebugDecTab("Core",9);
131 //=========================================================================
133 //=========================================================================
134 void BlackBoxDescriptor::GetHelp(bool full) const
136 bbtkDebugMessageInc("Core",9,"BlackBoxDescriptor::GetHelp() ["<<GetTypeName()<<"]"<<std::endl);
139 bbtkMessage("Help",1,"Black Box <"<<
140 GetPackage()->GetName()<<"::"<<GetTypeName()<<">"<<std::endl);
144 bbtkMessage("Help",1,"Black Box <::"<<GetTypeName()<<">"<<std::endl);
146 bbtkMessage("Help",1," "<<GetDescription()<<std::endl);
147 bbtkMessage("Help",1," By : "<<GetAuthor()<<std::endl);
149 bbtkMessage("Help",1," * Inputs : "<<std::endl);
151 bbtkMessage("Help",1," * No inputs"<<std::endl);
152 InputDescriptorMapType::const_iterator i;
153 unsigned int namelmax = 0;
154 unsigned int typelmax = 0;
155 for ( i = mInput.begin(); i != mInput.end(); ++i )
157 if (i->second->GetName().size()>namelmax)
158 namelmax = i->second->GetName().size();
159 if (i->second->GetHumanTypeName().size()>typelmax)
160 typelmax = i->second->GetHumanTypeName().size();
162 OutputDescriptorMapType::const_iterator o;
163 for ( o = mOutput.begin(); o != mOutput.end(); ++o )
165 if (o->second->GetName().size()>namelmax)
166 namelmax = o->second->GetName().size();
167 if (o->second->GetHumanTypeName().size()>typelmax)
168 typelmax = o->second->GetHumanTypeName().size();
171 for ( i = mInput.begin(); i != mInput.end(); ++i )
173 std::string name(i->second->GetName());
175 name.append(1+namelmax-name.size(),' ');
176 std::string type(i->second->GetHumanTypeName());
178 type.append(1+typelmax-type.size(),' ');
179 bbtkMessage("Help",1,
182 <<" : "<<i->second->GetDescription()<<std::endl);
185 bbtkMessage("Help",1," * Outputs : "<<std::endl);
187 bbtkMessage("Help",1," * No outputs"<<std::endl);
188 for ( o = mOutput.begin(); o != mOutput.end(); ++o )
190 std::string name(o->second->GetName());
192 name.append(1+namelmax-name.size(),' ');
193 std::string type(o->second->GetHumanTypeName());
195 type.append(1+typelmax-type.size(),' ');
196 bbtkMessage("Help",1,
199 <<" : "<<o->second->GetDescription()<<std::endl);
202 bbtkDebugDecTab("Core",9);
206 //=========================================================================
208 //=========================================================================
209 void BlackBoxDescriptor::InsertHtmlHelp ( std::ofstream& s,
210 int detail, int level,
211 const std::string& output_dir,
214 bbtkDebugMessageInc("Core",9,"BlackBoxDescriptor::InsertHtmlHelp() ["<<GetTypeName()<<"]"<<std::endl);
218 std::string name = GetTypeName();
219 Utilities::html_format(name);
222 (s) << "<a name=\""<<name<<"\"></a>\n";
224 "<a rel=\"top\" accesskey=\"t\" href=\"#Top\">Top</a>\n";
225 // (s) << "Previous: <a rel="previous" accesskey="p" href="#dir">(dir)</a>,
226 // (s) << "Up: <a rel="up" accesskey="u" href="#dir">(dir)</a>
227 (s) << "<h2 class=\"section\">"<<name<<"</h2>\n";
230 std::string descr = GetDescription();
231 //Utilities::html_format(descr);
232 std::string author = GetAuthor();
233 Utilities::html_format(author);
235 (s) << "<p><TABLE cellspacing=0 cellpadding=3>\n";
236 (s) << "<TR><TD style='vertical-align: top;'><b> Description </b></TD><TD style='vertical-align: top;'> : </TD><TD style='vertical-align: top;'> "
237 << descr << "</TD></TR>\n";
238 (s) << "<TR><TD style='vertical-align: top;'><b> Author(s) </b></TD><TD style='vertical-align: top;'> : </TD><TD style='vertical-align: top;'> "
239 << author << "</TD></TR>\n";
244 //i->second->InsertHTMLGraph( &s , detail,level,dir);
248 std::string col("#CCCCFF");
250 // (s) << "<h3 class=\"subsection\">Inputs</h3>\n";
251 (s) << "<p><TABLE border=1 cellspacing=0 cellpadding=3>\n";
252 (s) << "<TR><TD colspan=3 align=center bgcolor=\""<<col
253 <<"\">Inputs</TD></TR>\n";
254 const BlackBoxDescriptor::InputDescriptorMapType& imap =
255 GetInputDescriptorMap();
257 InputDescriptorMapType::const_iterator in;
259 for ( in = imap.begin(); in != imap.end(); ++in )
261 std::string name(in->second->GetName());
262 Utilities::html_format(name);
264 std::string type("<");
265 type += in->second->GetTypeName();
267 Utilities::html_format(type);
269 std::string descr(in->second->GetDescription());
270 //Utilities::html_format(descr);
272 (s) << "<TR><TD style='vertical-align: top;'><B><PRE> "<<name<<" </PRE></B></TD>"
273 << "<TD style='vertical-align: top;'><I><PRE> "<<type<<" </PRE></I></TD>"
274 << "<TD style='vertical-align: top;'>"<<descr<<"</TD></TR>\n";
277 // (s) << "</TABLE>\n";
282 // (s) << "<h3 class=\"subsection\">Outputs</h3>\n";
283 // (s) << "<TABLE border=1 cellspacing=0>\n";
284 (s) << "<TR><TD colspan=3 align=center bgcolor=\""<<col
285 <<"\">Outputs</TD></TR>\n";
287 const BlackBoxDescriptor::OutputDescriptorMapType& omap =
288 GetOutputDescriptorMap();
290 BlackBoxDescriptor::OutputDescriptorMapType::const_iterator o;
292 for ( o = omap.begin(); o != omap.end(); ++o )
294 std::string name(o->second->GetName());
295 Utilities::html_format(name);
297 std::string type("<");
298 type += o->second->GetTypeName();
300 Utilities::html_format(type);
302 std::string descr(o->second->GetDescription());
303 //Utilities::html_format(descr);
306 (s) << "<TR><TD style='vertical-align: top;'><B><PRE> "<<name<<" </PRE></B></TD>"
307 << "<TD style='vertical-align: top;'><I><PRE> "<<type<<" </PRE></I></TD>"
308 << "<TD style='vertical-align: top;'>"<<descr<<"</TD></TR>\n";
316 bbtkDebugDecTab("Core",9);
318 //=========================================================================