]> Creatis software - bbtk.git/blob - bbtkBlackBoxDescriptor.cxx
050231eccab747e7a3b638cf2666e732d50bd51c
[bbtk.git] / bbtkBlackBoxDescriptor.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   bbtk
4   Module:    $RCSfile: bbtkBlackBoxDescriptor.cxx,v $
5   Language:  C++
6   Date:      $Date: 2008/01/30 09:28:15 $
7   Version:   $Revision: 1.2 $
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   }  
95   //=========================================================================
96
97   //=========================================================================
98   const BlackBoxDescriptor::InputDescriptor* 
99   BlackBoxDescriptor::GetInputDescriptor(const std::string & name) const
100   {
101     bbtkDebugMessageInc("Core",9,"BlackBoxDescriptor::GetInputDescriptor('"
102                         <<name<<"') ["<<GetTypeName()<<"]"<<std::endl);
103
104     InputDescriptorMapType::const_iterator i;
105     i = mInput.find(name);
106     if ( i == mInput.end() ) 
107     {
108             bbtkError("input '"<<name<<"' does not exist");
109     }
110     bbtkDebugDecTab("Core",9);
111     return i->second;
112   }
113   //=========================================================================
114
115   //=========================================================================
116   const BlackBoxDescriptor::OutputDescriptor* 
117   BlackBoxDescriptor::GetOutputDescriptor(const std::string & name) const
118   {
119     bbtkDebugMessageInc("Core",9,"BlackBoxDescriptor::GetOutputDescriptor('"
120                         <<name<<"') ["<<GetTypeName()<<"]"<<std::endl);
121
122     OutputDescriptorMapType::const_iterator i;
123     i = mOutput.find(name);
124     if ( i == mOutput.end() ) 
125     {
126             bbtkError("output '"<<name<<"' does not exist");
127     }
128     bbtkDebugDecTab("Core",9);
129     return i->second;
130   }
131   //=========================================================================
132
133   //=========================================================================
134   void BlackBoxDescriptor::GetHelp(bool full) const
135   {
136     bbtkDebugMessageInc("Core",9,"BlackBoxDescriptor::GetHelp() ["<<GetTypeName()<<"]"<<std::endl);
137     if (GetPackage()) 
138          {
139        bbtkMessage("Help",1,"Black Box <"<<
140                      GetPackage()->GetName()<<"::"<<GetTypeName()<<">"<<std::endl);
141     }
142     else 
143     {
144            bbtkMessage("Help",1,"Black Box <::"<<GetTypeName()<<">"<<std::endl);
145         }
146     bbtkMessage("Help",1," "<<GetDescription()<<std::endl);
147     bbtkMessage("Help",1," By : "<<GetAuthor()<<std::endl);
148     if (mInput.size()) 
149       bbtkMessage("Help",1," * Inputs : "<<std::endl);
150     else 
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 ) 
156       {
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();
161       }
162     OutputDescriptorMapType::const_iterator o;
163     for ( o = mOutput.begin();  o != mOutput.end(); ++o ) 
164       {
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();
169       }
170     //
171     for ( i = mInput.begin();  i != mInput.end(); ++i ) 
172       {
173         std::string name(i->second->GetName());
174         name += "'";
175         name.append(1+namelmax-name.size(),' ');
176         std::string type(i->second->GetHumanTypeName());
177         type += ">";
178         type.append(1+typelmax-type.size(),' ');
179         bbtkMessage("Help",1,
180                     "    '"<<name
181                     <<" <"<<type
182                     <<" : "<<i->second->GetDescription()<<std::endl);
183       }
184     if (mOutput.size()) 
185       bbtkMessage("Help",1," * Outputs : "<<std::endl);
186     else 
187       bbtkMessage("Help",1," * No outputs"<<std::endl);
188     for ( o = mOutput.begin();  o != mOutput.end(); ++o ) 
189       {
190         std::string name(o->second->GetName());
191         name += "'";
192         name.append(1+namelmax-name.size(),' ');
193         std::string type(o->second->GetHumanTypeName());
194         type += ">";
195         type.append(1+typelmax-type.size(),' ');
196         bbtkMessage("Help",1,
197                     "    '"<<name
198                     <<" <"<<type
199                     <<" : "<<o->second->GetDescription()<<std::endl);
200       }
201    
202      bbtkDebugDecTab("Core",9);
203   
204
205   }
206   //=========================================================================
207
208   //=========================================================================
209   void BlackBoxDescriptor::InsertHtmlHelp ( std::ofstream& s, 
210                                             int detail, int level,
211                                             const std::string& output_dir,
212                                             bool relative_link )
213   {
214     bbtkDebugMessageInc("Core",9,"BlackBoxDescriptor::InsertHtmlHelp() ["<<GetTypeName()<<"]"<<std::endl);
215     
216     //-------------
217     // General info 
218     std::string name = GetTypeName();
219     Utilities::html_format(name);
220
221     (s) << "<p><hr>\n";
222     (s) << "<a name=\""<<name<<"\"></a>\n";
223     (s) << //"Top:&nbsp;
224       "<a rel=\"top\" accesskey=\"t\" href=\"#Top\">Top</a>\n";
225     // (s) << "Previous:&nbsp;<a rel="previous" accesskey="p" href="#dir">(dir)</a>,
226     // (s) << "Up:&nbsp;<a rel="up" accesskey="u" href="#dir">(dir)</a>
227     (s) << "<h2 class=\"section\">"<<name<<"</h2>\n";
228
229
230     std::string descr = GetDescription();
231     //Utilities::html_format(descr);
232     std::string author = GetAuthor();
233     Utilities::html_format(author);
234     
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";
240     (s) << "</TABLE>\n";
241     
242     //-------------
243     // Graph
244     //i->second->InsertHTMLGraph( &s , detail,level,dir);
245     
246     //-------------
247     // Inputs
248     std::string col("#CCCCFF");
249     
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();
256     
257     InputDescriptorMapType::const_iterator in;
258     
259     for ( in = imap.begin();  in != imap.end(); ++in ) 
260       {
261         std::string name(in->second->GetName());
262         Utilities::html_format(name);
263         
264         std::string type("<");
265         type += in->second->GetTypeName();    
266         type += ">";
267         Utilities::html_format(type);
268         
269         std::string descr(in->second->GetDescription());
270         //Utilities::html_format(descr);
271
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";
275         
276       }
277     //  (s) << "</TABLE>\n";
278     
279     
280     //-------------
281     // Outputs
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";
286     
287     const BlackBoxDescriptor::OutputDescriptorMapType& omap = 
288       GetOutputDescriptorMap();
289     
290     BlackBoxDescriptor::OutputDescriptorMapType::const_iterator o;
291     
292     for ( o = omap.begin();  o != omap.end(); ++o ) 
293       {
294         std::string name(o->second->GetName());
295         Utilities::html_format(name);
296         
297         std::string type("<");
298         type += o->second->GetTypeName();    
299         type += ">";
300         Utilities::html_format(type);
301         
302         std::string descr(o->second->GetDescription());
303         //Utilities::html_format(descr);
304         
305         
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";
309         
310       }
311     (s) << "</TABLE>\n";
312
313     //------------
314     // End
315
316     bbtkDebugDecTab("Core",9);
317    }
318   //=========================================================================
319  
320 }