]> Creatis software - bbtk.git/blob - kernel/src/bbtkBlackBoxDescriptor.cxx
*** empty log message ***
[bbtk.git] / kernel / src / bbtkBlackBoxDescriptor.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   bbtk
4   Module:    $RCSfile: bbtkBlackBoxDescriptor.cxx,v $
5   Language:  C++
6   Date:      $Date: 2008/02/04 13:02:57 $
7   Version:   $Revision: 1.4 $
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       mKeyword(""),
38       mCategory(STANDARD),
39       mPackage(NULL)
40   {
41     bbtkDebugMessage("Core",9,
42                      "BlackBoxDescriptor::BlackBoxDescriptor()"<<std::endl);
43   }
44   //=========================================================================
45
46   //=========================================================================
47   /// Dtor
48   BlackBoxDescriptor::~BlackBoxDescriptor()
49   {
50     bbtkDebugMessageInc("Core",9,
51                         "BlackBoxDescriptor::~BlackBoxDescriptor() ["
52                         <<mTypeName<<"]"<<std::endl);
53
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;
59
60     bbtkDebugDecTab("Core",9);
61   }
62   //=========================================================================
63
64   //=========================================================================
65   /// Adds the string to the BlackBox description
66   void BlackBoxDescriptor::AddToDescription( const std::string& s, bool clear)
67   {
68     bbtkDebugMessage("Core",9,"BlackBoxDescriptor::AddToDescription(\""<<s<<
69                      "\") ["<<GetTypeName()<<"]"<<std::endl);
70     if (clear) mDescription = s; 
71     else mDescription += s;
72    }
73   //=========================================================================
74
75   //=========================================================================   
76   /// Adds the string to the BlackBox author list
77   void BlackBoxDescriptor::AddToAuthor( const std::string& s, bool clear)
78   {
79     bbtkDebugMessage("Core",9,"BlackBoxDescriptor::AddToAuthor(\""<<s<<"\") ["
80                      <<GetTypeName()<<"]"<<std::endl);
81     if (clear) mAuthor = s;
82     else mAuthor += s;
83   }
84   //=========================================================================
85
86   //=========================================================================  
87   /// Adds the string to the BlackBox keyword list
88   void BlackBoxDescriptor::AddToKeyword( const std::string& s, bool clear)
89   {
90     bbtkDebugMessage("Core",9,"BlackBoxDescriptor::AddToKeyword(\""<<s<<"\") ["
91                      <<GetTypeName()<<"]"<<std::endl);  
92     if (clear) mKeyword = s;
93     else mKeyword += s;
94     mKeyword += ";";
95   }  
96   //=========================================================================
97   
98   //=========================================================================
99   const BlackBoxDescriptor::InputDescriptor* 
100   BlackBoxDescriptor::GetInputDescriptor(const std::string & name) const
101   {
102     bbtkDebugMessageInc("Core",9,"BlackBoxDescriptor::GetInputDescriptor('"
103                         <<name<<"') ["<<GetTypeName()<<"]"<<std::endl);
104
105     InputDescriptorMapType::const_iterator i;
106     i = mInput.find(name);
107     if ( i == mInput.end() ) 
108     {
109             bbtkError("input '"<<name<<"' does not exist");
110     }
111     bbtkDebugDecTab("Core",9);
112     return i->second;
113   }
114   //=========================================================================
115
116   //=========================================================================
117   const BlackBoxDescriptor::OutputDescriptor* 
118   BlackBoxDescriptor::GetOutputDescriptor(const std::string & name) const
119   {
120     bbtkDebugMessageInc("Core",9,"BlackBoxDescriptor::GetOutputDescriptor('"
121                         <<name<<"') ["<<GetTypeName()<<"]"<<std::endl);
122
123     OutputDescriptorMapType::const_iterator i;
124     i = mOutput.find(name);
125     if ( i == mOutput.end() ) 
126     {
127             bbtkError("output '"<<name<<"' does not exist");
128     }
129     bbtkDebugDecTab("Core",9);
130     return i->second;
131   }
132   //=========================================================================
133
134   //=========================================================================
135   void BlackBoxDescriptor::GetHelp(bool full) const
136   {
137     bbtkDebugMessageInc("Core",9,"BlackBoxDescriptor::GetHelp() ["<<GetTypeName()<<"]"<<std::endl);
138     if (GetPackage()) 
139          {
140        bbtkMessage("Help",1,"Black Box <"<<
141                      GetPackage()->GetName()<<"::"<<GetTypeName()<<">"<<std::endl);
142     }
143     else 
144     {
145            bbtkMessage("Help",1,"Black Box <::"<<GetTypeName()<<">"<<std::endl);
146          }
147     bbtkMessage("Help",1," "           <<GetDescription()<<std::endl);
148     bbtkMessage("Help",1," By : "      <<GetAuthor()     <<std::endl);
149     bbtkMessage("Help",1," Keywords : "<<GetKeyword()    <<std::endl);
150     if (mInput.size()) 
151       bbtkMessage("Help",1," * Inputs : "<<std::endl);
152     else 
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 ) 
158     {
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();
163     }
164     OutputDescriptorMapType::const_iterator o;
165     for ( o = mOutput.begin();  o != mOutput.end(); ++o ) 
166     {
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();
171     }
172     //
173     for ( i = mInput.begin();  i != mInput.end(); ++i ) 
174     {
175            std::string name(i->second->GetName());
176            name += "'";
177            name.append(1+namelmax-name.size(),' ');
178            std::string type(i->second->GetHumanTypeName());
179            type += ">";
180            type.append(1+typelmax-type.size(),' ');
181            bbtkMessage("Help",1,
182                     "    '"<<name
183                     <<" <"<<type
184                     <<" : "<<i->second->GetDescription()<<std::endl);
185     }
186     if (mOutput.size()) 
187       bbtkMessage("Help",1," * Outputs : "<<std::endl);
188     else 
189       bbtkMessage("Help",1," * No outputs"<<std::endl);
190     for ( o = mOutput.begin();  o != mOutput.end(); ++o ) 
191     {
192            std::string name(o->second->GetName());
193            name += "'";
194            name.append(1+namelmax-name.size(),' ');
195            std::string type(o->second->GetHumanTypeName());
196            type += ">";
197            type.append(1+typelmax-type.size(),' ');
198            bbtkMessage("Help",1,
199                     "    '"<<name
200                     <<" <"<<type
201                     <<" : "<<o->second->GetDescription()<<std::endl);
202       }
203    
204      bbtkDebugDecTab("Core",9);
205   
206
207   }
208   //=========================================================================
209
210   //=========================================================================
211   void BlackBoxDescriptor::InsertHtmlHelp ( std::ofstream& s, 
212                                             int detail, int level,
213                                             const std::string& output_dir,
214                                             bool relative_link )
215   {
216     bbtkDebugMessageInc("Core",9,"BlackBoxDescriptor::InsertHtmlHelp() ["<<GetTypeName()<<"]"<<std::endl);
217     
218     //-------------
219     // General info 
220     std::string name = GetTypeName();
221     Utilities::html_format(name);
222
223     (s) << "<p><hr>\n";
224     (s) << "<a name=\""<<name<<"\"></a>\n";
225     (s) << //"Top:&nbsp;
226       "<a rel=\"top\" accesskey=\"t\" href=\"#Top\">Top</a>\n";
227     // (s) << "Previous:&nbsp;<a rel="previous" accesskey="p" href="#dir">(dir)</a>,
228     // (s) << "Up:&nbsp;<a rel="up" accesskey="u" href="#dir">(dir)</a>
229     (s) << "<h2 class=\"section\">"<<name<<"</h2>\n";
230
231
232     std::string descr = GetDescription();
233     //Utilities::html_format(descr);
234     std::string author = GetAuthor();
235     Utilities::html_format(author);
236
237     std::string keyword = GetKeyword();
238     Utilities::html_format(keyword);    
239     
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";
245     (s) << "</TABLE>\n";
246
247     //-------------
248     // Graph
249     //i->second->InsertHTMLGraph( &s , detail,level,dir);
250     
251     //-------------
252     // Inputs
253     std::string col("#CCCCFF");
254     
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();
261     
262     InputDescriptorMapType::const_iterator in;
263     
264     for ( in = imap.begin();  in != imap.end(); ++in ) 
265     {
266            std::string name(in->second->GetName());
267            Utilities::html_format(name);
268         
269            std::string type("<");
270            type += in->second->GetTypeName();    
271            type += ">";
272            Utilities::html_format(type);
273
274            std::string descr(in->second->GetDescription());
275            //Utilities::html_format(descr);
276
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";
280         
281     }
282     //  (s) << "</TABLE>\n";
283     
284     
285     //-------------
286     // Outputs
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";
291     
292     const BlackBoxDescriptor::OutputDescriptorMapType& omap = 
293       GetOutputDescriptorMap();
294     
295     BlackBoxDescriptor::OutputDescriptorMapType::const_iterator o;
296     
297     for ( o = omap.begin();  o != omap.end(); ++o ) 
298     {
299            std::string name(o->second->GetName());
300            Utilities::html_format(name);
301
302            std::string type("<");
303            type += o->second->GetTypeName();    
304            type += ">";
305            Utilities::html_format(type);
306         
307            std::string descr(o->second->GetDescription());
308            //Utilities::html_format(descr);
309         
310         
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";
314         
315     }
316     (s) << "</TABLE>\n";
317
318     //------------
319     // End
320
321     bbtkDebugDecTab("Core",9);
322    }
323   //=========================================================================
324  
325 }