1 /*=========================================================================
4 Module: $RCSfile: bbtkBlackBoxDescriptor.cxx,v $
6 Date: $Date: 2008/01/22 15:02:00 $
7 Version: $Revision: 1.1 $
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"),
40 bbtkDebugMessage("Core",9,
41 "BlackBoxDescriptor::BlackBoxDescriptor()"<<std::endl);
43 //=========================================================================
45 //=========================================================================
47 BlackBoxDescriptor::~BlackBoxDescriptor()
49 bbtkDebugMessageInc("Core",9,
50 "BlackBoxDescriptor::~BlackBoxDescriptor() ["
51 <<mTypeName<<"]"<<std::endl);
53 // deletes all I/O descriptors
54 InputDescriptorMapType::iterator i;
55 for (i=mInput.begin(); i!=mInput.end(); ++i) delete i->second;
56 OutputDescriptorMapType::iterator o;
57 for (o=mOutput.begin(); o!=mOutput.end(); ++o) delete o->second;
59 bbtkDebugDecTab("Core",9);
61 //=========================================================================
63 //=========================================================================
64 /// Adds the string to the BlackBox's description
65 void BlackBoxDescriptor::AddToDescription( const std::string& s, bool clear)
67 bbtkDebugMessage("Core",9,"BlackBoxDescriptor::AddToDescription(\""<<s<<
68 "\") ["<<GetTypeName()<<"]"<<std::endl);
69 if (clear) mDescription = s;
70 else mDescription += s;
72 /// Adds the string to the BlackBox's author list
73 void BlackBoxDescriptor::AddToAuthor( const std::string& s, bool clear)
75 bbtkDebugMessage("Core",9,"BlackBoxDescriptor::AddToAuthor(\""<<s<<"\") ["
76 <<GetTypeName()<<"]"<<std::endl);
77 if (clear) mAuthor = s;
80 //=========================================================================
82 //=========================================================================
83 const BlackBoxDescriptor::InputDescriptor*
84 BlackBoxDescriptor::GetInputDescriptor(const std::string & name) const
86 bbtkDebugMessageInc("Core",9,"BlackBoxDescriptor::GetInputDescriptor('"
87 <<name<<"') ["<<GetTypeName()<<"]"<<std::endl);
89 InputDescriptorMapType::const_iterator i;
90 i = mInput.find(name);
91 if ( i == mInput.end() )
93 bbtkError("input '"<<name<<"' does not exist");
95 bbtkDebugDecTab("Core",9);
98 //=========================================================================
100 //=========================================================================
101 const BlackBoxDescriptor::OutputDescriptor*
102 BlackBoxDescriptor::GetOutputDescriptor(const std::string & name) const
104 bbtkDebugMessageInc("Core",9,"BlackBoxDescriptor::GetOutputDescriptor('"
105 <<name<<"') ["<<GetTypeName()<<"]"<<std::endl);
107 OutputDescriptorMapType::const_iterator i;
108 i = mOutput.find(name);
109 if ( i == mOutput.end() )
111 bbtkError("output '"<<name<<"' does not exist");
113 bbtkDebugDecTab("Core",9);
116 //=========================================================================
118 //=========================================================================
119 void BlackBoxDescriptor::GetHelp(bool full) const
121 bbtkDebugMessageInc("Core",9,"BlackBoxDescriptor::GetHelp() ["<<GetTypeName()<<"]"<<std::endl);
124 bbtkMessage("Help",1,"Black Box <"<<
125 GetPackage()->GetName()<<"::"<<GetTypeName()<<">"<<std::endl);
129 bbtkMessage("Help",1,"Black Box <::"<<GetTypeName()<<">"<<std::endl);
131 bbtkMessage("Help",1," "<<GetDescription()<<std::endl);
132 bbtkMessage("Help",1," By : "<<GetAuthor()<<std::endl);
134 bbtkMessage("Help",1," * Inputs : "<<std::endl);
136 bbtkMessage("Help",1," * No inputs"<<std::endl);
137 InputDescriptorMapType::const_iterator i;
138 unsigned int namelmax = 0;
139 unsigned int typelmax = 0;
140 for ( i = mInput.begin(); i != mInput.end(); ++i )
142 if (i->second->GetName().size()>namelmax)
143 namelmax = i->second->GetName().size();
144 if (i->second->GetHumanTypeName().size()>typelmax)
145 typelmax = i->second->GetHumanTypeName().size();
147 OutputDescriptorMapType::const_iterator o;
148 for ( o = mOutput.begin(); o != mOutput.end(); ++o )
150 if (o->second->GetName().size()>namelmax)
151 namelmax = o->second->GetName().size();
152 if (o->second->GetHumanTypeName().size()>typelmax)
153 typelmax = o->second->GetHumanTypeName().size();
156 for ( i = mInput.begin(); i != mInput.end(); ++i )
158 std::string name(i->second->GetName());
160 name.append(1+namelmax-name.size(),' ');
161 std::string type(i->second->GetHumanTypeName());
163 type.append(1+typelmax-type.size(),' ');
164 bbtkMessage("Help",1,
167 <<" : "<<i->second->GetDescription()<<std::endl);
170 bbtkMessage("Help",1," * Outputs : "<<std::endl);
172 bbtkMessage("Help",1," * No outputs"<<std::endl);
173 for ( o = mOutput.begin(); o != mOutput.end(); ++o )
175 std::string name(o->second->GetName());
177 name.append(1+namelmax-name.size(),' ');
178 std::string type(o->second->GetHumanTypeName());
180 type.append(1+typelmax-type.size(),' ');
181 bbtkMessage("Help",1,
184 <<" : "<<o->second->GetDescription()<<std::endl);
187 bbtkDebugDecTab("Core",9);
191 //=========================================================================
193 //=========================================================================
194 void BlackBoxDescriptor::InsertHtmlHelp ( std::ofstream& s,
195 int detail, int level,
196 const std::string& output_dir,
199 bbtkDebugMessageInc("Core",9,"BlackBoxDescriptor::InsertHtmlHelp() ["<<GetTypeName()<<"]"<<std::endl);
203 std::string name = GetTypeName();
204 Utilities::html_format(name);
207 (s) << "<a name=\""<<name<<"\"></a>\n";
209 "<a rel=\"top\" accesskey=\"t\" href=\"#Top\">Top</a>\n";
210 // (s) << "Previous: <a rel="previous" accesskey="p" href="#dir">(dir)</a>,
211 // (s) << "Up: <a rel="up" accesskey="u" href="#dir">(dir)</a>
212 (s) << "<h2 class=\"section\">"<<name<<"</h2>\n";
215 std::string descr = GetDescription();
216 //Utilities::html_format(descr);
217 std::string author = GetAuthor();
218 Utilities::html_format(author);
220 (s) << "<p><TABLE cellspacing=0 cellpadding=3>\n";
221 (s) << "<TR><TD style='vertical-align: top;'><b> Description </b></TD><TD style='vertical-align: top;'> : </TD><TD style='vertical-align: top;'> "
222 << descr << "</TD></TR>\n";
223 (s) << "<TR><TD style='vertical-align: top;'><b> Author(s) </b></TD><TD style='vertical-align: top;'> : </TD><TD style='vertical-align: top;'> "
224 << author << "</TD></TR>\n";
229 //i->second->InsertHTMLGraph( &s , detail,level,dir);
233 std::string col("#CCCCFF");
235 // (s) << "<h3 class=\"subsection\">Inputs</h3>\n";
236 (s) << "<p><TABLE border=1 cellspacing=0 cellpadding=3>\n";
237 (s) << "<TR><TD colspan=3 align=center bgcolor=\""<<col
238 <<"\">Inputs</TD></TR>\n";
239 const BlackBoxDescriptor::InputDescriptorMapType& imap =
240 GetInputDescriptorMap();
242 InputDescriptorMapType::const_iterator in;
244 for ( in = imap.begin(); in != imap.end(); ++in )
246 std::string name(in->second->GetName());
247 Utilities::html_format(name);
249 std::string type("<");
250 type += in->second->GetTypeName();
252 Utilities::html_format(type);
254 std::string descr(in->second->GetDescription());
255 //Utilities::html_format(descr);
257 (s) << "<TR><TD style='vertical-align: top;'><B><PRE> "<<name<<" </PRE></B></TD>"
258 << "<TD style='vertical-align: top;'><I><PRE> "<<type<<" </PRE></I></TD>"
259 << "<TD style='vertical-align: top;'>"<<descr<<"</TD></TR>\n";
262 // (s) << "</TABLE>\n";
267 // (s) << "<h3 class=\"subsection\">Outputs</h3>\n";
268 // (s) << "<TABLE border=1 cellspacing=0>\n";
269 (s) << "<TR><TD colspan=3 align=center bgcolor=\""<<col
270 <<"\">Outputs</TD></TR>\n";
272 const BlackBoxDescriptor::OutputDescriptorMapType& omap =
273 GetOutputDescriptorMap();
275 BlackBoxDescriptor::OutputDescriptorMapType::const_iterator o;
277 for ( o = omap.begin(); o != omap.end(); ++o )
279 std::string name(o->second->GetName());
280 Utilities::html_format(name);
282 std::string type("<");
283 type += o->second->GetTypeName();
285 Utilities::html_format(type);
287 std::string descr(o->second->GetDescription());
288 //Utilities::html_format(descr);
291 (s) << "<TR><TD style='vertical-align: top;'><B><PRE> "<<name<<" </PRE></B></TD>"
292 << "<TD style='vertical-align: top;'><I><PRE> "<<type<<" </PRE></I></TD>"
293 << "<TD style='vertical-align: top;'>"<<descr<<"</TD></TR>\n";
301 bbtkDebugDecTab("Core",9);
303 //=========================================================================