]> Creatis software - bbtk.git/blob - kernel/src/bbtkBlackBoxDescriptor.cxx
Recreated the complete cvs tree because the project architecture deeply changed
[bbtk.git] / kernel / src / bbtkBlackBoxDescriptor.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   bbtk
4   Module:    $RCSfile: bbtkBlackBoxDescriptor.cxx,v $
5   Language:  C++
6   Date:      $Date: 2008/01/22 15:02:00 $
7   Version:   $Revision: 1.1.1.1 $
8                                                                                 
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.
12                                                                                 
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.
16                                                                                 
17 =========================================================================*/
18
19 /**
20  *  \file 
21  *  \brief Class bbtk::BlackBoxDescriptor : (abstract) describes a BlackBox (name, description, author) and is able to create an instance of it.
22  */
23 #include "bbtkBlackBoxDescriptor.h"
24 #include "bbtkMessageManager.h"
25 #include "bbtkPackage.h"
26 #include "bbtkUtilities.h"
27
28 namespace bbtk
29 {
30   
31   //=========================================================================
32   /// Default ctor
33   BlackBoxDescriptor::BlackBoxDescriptor()  
34     : mTypeName("Unknown"), 
35       mDescription(""), 
36       mAuthor(""),
37       mCategory(STANDARD),
38       mPackage(NULL)
39   {
40     bbtkDebugMessage("Core",9,
41                      "BlackBoxDescriptor::BlackBoxDescriptor()"<<std::endl);
42   }
43   //=========================================================================
44
45   //=========================================================================
46   /// Dtor
47   BlackBoxDescriptor::~BlackBoxDescriptor()
48   {
49     bbtkDebugMessageInc("Core",9,
50                         "BlackBoxDescriptor::~BlackBoxDescriptor() ["
51                         <<mTypeName<<"]"<<std::endl);
52
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;
58
59     bbtkDebugDecTab("Core",9);
60   }
61   //=========================================================================
62
63   //=========================================================================
64   /// Adds the string to the BlackBox's description
65   void BlackBoxDescriptor::AddToDescription( const std::string& s, bool clear)
66   {
67     bbtkDebugMessage("Core",9,"BlackBoxDescriptor::AddToDescription(\""<<s<<
68                      "\") ["<<GetTypeName()<<"]"<<std::endl);
69     if (clear) mDescription = s; 
70     else mDescription += s;
71    }
72   /// Adds the string to the BlackBox's author list
73   void BlackBoxDescriptor::AddToAuthor( const std::string& s, bool clear)
74   {
75     bbtkDebugMessage("Core",9,"BlackBoxDescriptor::AddToAuthor(\""<<s<<"\") ["
76                      <<GetTypeName()<<"]"<<std::endl);
77     if (clear) mAuthor = s;
78     else mAuthor += s;
79   }
80   //=========================================================================
81
82   //=========================================================================
83   const BlackBoxDescriptor::InputDescriptor* 
84   BlackBoxDescriptor::GetInputDescriptor(const std::string & name) const
85   {
86     bbtkDebugMessageInc("Core",9,"BlackBoxDescriptor::GetInputDescriptor('"
87                         <<name<<"') ["<<GetTypeName()<<"]"<<std::endl);
88
89     InputDescriptorMapType::const_iterator i;
90     i = mInput.find(name);
91     if ( i == mInput.end() ) 
92       {
93         bbtkError("input '"<<name<<"' does not exist");
94       }
95     bbtkDebugDecTab("Core",9);
96     return i->second;
97   }
98   //=========================================================================
99
100   //=========================================================================
101   const BlackBoxDescriptor::OutputDescriptor* 
102   BlackBoxDescriptor::GetOutputDescriptor(const std::string & name) const
103   {
104     bbtkDebugMessageInc("Core",9,"BlackBoxDescriptor::GetOutputDescriptor('"
105                         <<name<<"') ["<<GetTypeName()<<"]"<<std::endl);
106
107     OutputDescriptorMapType::const_iterator i;
108     i = mOutput.find(name);
109     if ( i == mOutput.end() ) 
110       {
111         bbtkError("output '"<<name<<"' does not exist");
112       }
113     bbtkDebugDecTab("Core",9);
114     return i->second;
115   }
116   //=========================================================================
117
118   //=========================================================================
119   void BlackBoxDescriptor::GetHelp(bool full) const
120   {
121     bbtkDebugMessageInc("Core",9,"BlackBoxDescriptor::GetHelp() ["<<GetTypeName()<<"]"<<std::endl);
122     if (GetPackage()) 
123          {
124     bbtkMessage("Help",1,"Black Box <"<<
125                 GetPackage()->GetName()<<"::"<<GetTypeName()<<">"<<std::endl);
126                 }
127                 else 
128                 {
129            bbtkMessage("Help",1,"Black Box <::"<<GetTypeName()<<">"<<std::endl);
130         }
131     bbtkMessage("Help",1," "<<GetDescription()<<std::endl);
132     bbtkMessage("Help",1," By : "<<GetAuthor()<<std::endl);
133     if (mInput.size()) 
134       bbtkMessage("Help",1," * Inputs : "<<std::endl);
135     else 
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 ) 
141       {
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();
146       }
147     OutputDescriptorMapType::const_iterator o;
148     for ( o = mOutput.begin();  o != mOutput.end(); ++o ) 
149       {
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();
154       }
155     //
156     for ( i = mInput.begin();  i != mInput.end(); ++i ) 
157       {
158         std::string name(i->second->GetName());
159         name += "'";
160         name.append(1+namelmax-name.size(),' ');
161         std::string type(i->second->GetHumanTypeName());
162         type += ">";
163         type.append(1+typelmax-type.size(),' ');
164         bbtkMessage("Help",1,
165                     "    '"<<name
166                     <<" <"<<type
167                     <<" : "<<i->second->GetDescription()<<std::endl);
168       }
169     if (mOutput.size()) 
170       bbtkMessage("Help",1," * Outputs : "<<std::endl);
171     else 
172       bbtkMessage("Help",1," * No outputs"<<std::endl);
173     for ( o = mOutput.begin();  o != mOutput.end(); ++o ) 
174       {
175         std::string name(o->second->GetName());
176         name += "'";
177         name.append(1+namelmax-name.size(),' ');
178         std::string type(o->second->GetHumanTypeName());
179         type += ">";
180         type.append(1+typelmax-type.size(),' ');
181         bbtkMessage("Help",1,
182                     "    '"<<name
183                     <<" <"<<type
184                     <<" : "<<o->second->GetDescription()<<std::endl);
185       }
186    
187      bbtkDebugDecTab("Core",9);
188   
189
190   }
191   //=========================================================================
192
193   //=========================================================================
194   void BlackBoxDescriptor::InsertHtmlHelp ( std::ofstream& s, 
195                                             int detail, int level,
196                                             const std::string& output_dir,
197                                             bool relative_link )
198   {
199     bbtkDebugMessageInc("Core",9,"BlackBoxDescriptor::InsertHtmlHelp() ["<<GetTypeName()<<"]"<<std::endl);
200     
201     //-------------
202     // General info 
203     std::string name = GetTypeName();
204     Utilities::html_format(name);
205
206     (s) << "<p><hr>\n";
207     (s) << "<a name=\""<<name<<"\"></a>\n";
208     (s) << //"Top:&nbsp;
209       "<a rel=\"top\" accesskey=\"t\" href=\"#Top\">Top</a>\n";
210     // (s) << "Previous:&nbsp;<a rel="previous" accesskey="p" href="#dir">(dir)</a>,
211     // (s) << "Up:&nbsp;<a rel="up" accesskey="u" href="#dir">(dir)</a>
212     (s) << "<h2 class=\"section\">"<<name<<"</h2>\n";
213
214
215     std::string descr = GetDescription();
216     //Utilities::html_format(descr);
217     std::string author = GetAuthor();
218     Utilities::html_format(author);
219     
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";
225     (s) << "</TABLE>\n";
226     
227     //-------------
228     // Graph
229     //i->second->InsertHTMLGraph( &s , detail,level,dir);
230     
231     //-------------
232     // Inputs
233     std::string col("#CCCCFF");
234     
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();
241     
242     InputDescriptorMapType::const_iterator in;
243     
244     for ( in = imap.begin();  in != imap.end(); ++in ) 
245       {
246         std::string name(in->second->GetName());
247         Utilities::html_format(name);
248         
249         std::string type("<");
250         type += in->second->GetTypeName();    
251         type += ">";
252         Utilities::html_format(type);
253         
254         std::string descr(in->second->GetDescription());
255         //Utilities::html_format(descr);
256
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";
260         
261       }
262     //  (s) << "</TABLE>\n";
263     
264     
265     //-------------
266     // Outputs
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";
271     
272     const BlackBoxDescriptor::OutputDescriptorMapType& omap = 
273       GetOutputDescriptorMap();
274     
275     BlackBoxDescriptor::OutputDescriptorMapType::const_iterator o;
276     
277     for ( o = omap.begin();  o != omap.end(); ++o ) 
278       {
279         std::string name(o->second->GetName());
280         Utilities::html_format(name);
281         
282         std::string type("<");
283         type += o->second->GetTypeName();    
284         type += ">";
285         Utilities::html_format(type);
286         
287         std::string descr(o->second->GetDescription());
288         //Utilities::html_format(descr);
289         
290         
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";
294         
295       }
296     (s) << "</TABLE>\n";
297
298     //------------
299     // End
300
301     bbtkDebugDecTab("Core",9);
302    }
303   //=========================================================================
304  
305 }