2 # ---------------------------------------------------------------------
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
10 # This software is governed by the CeCILL-B license under French law and
11 # abiding by the rules of distribution of free software. You can use,
12 # modify and/ or redistribute the software under the terms of the CeCILL-B
13 # license as circulated by CEA, CNRS and INRIA at the following URL
14 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
15 # or in the file LICENSE.txt.
17 # As a counterpart to the access to the source code and rights to copy,
18 # modify and redistribute granted by the license, users are provided only
19 # with a limited warranty and the software's author, the holder of the
20 # economic rights, and the successive licensors have only limited
23 # The fact that you are presently reading this means that you have had
24 # knowledge of the CeCILL-B license and that you accept its terms.
25 # ------------------------------------------------------------------------ */
28 /*=========================================================================
30 Module: $RCSfile: bbtkBlackBoxDescriptor.cxx,v $
32 Date: $Date: 2012/11/16 08:49:01 $
33 Version: $Revision: 1.24 $
34 =========================================================================*/
40 * \brief Class bbtk::BlackBoxDescriptor : (abstract) describes a BlackBox (name, description, author) and is able to create an instance of it.
42 #include "bbtkBlackBoxDescriptor.h"
43 #include "bbtkMessageManager.h"
44 #include "bbtkPackage.h"
45 #include "bbtkUtilities.h"
46 #include "bbtkAtomicBlackBoxDescriptor.h"
47 #include "bbtkWxBlackBox.h"
48 // JFGA 12/12/2014 Adding libraries for Wt
49 //#include "bbtkWtBlackBox.h"
54 typedef Package::Pointer PackagePointer;
56 #define bbtkDMessage(key,level,mess) \
57 bbtkMessage(key,level,"["<<GetFullTypeName()<<"] "<<mess)
58 #define bbtkDDebugMessage(key,level,mess) \
59 bbtkDebugMessage(key,level,"["<<GetFullTypeName()<<"] "<<mess)
62 //=========================================================================
64 BlackBoxDescriptor::BlackBoxDescriptor()
65 : mTypeName("Unknown"),
70 mTypeOfScript(TS_BINARY),
73 bbtkDDebugMessage("object",4,
74 "==> BlackBoxDescriptor()"<<std::endl);
75 bbtkDDebugMessage("object",4,
76 "<== BlackBoxDescriptor()"<<std::endl);
78 //=========================================================================
80 //=========================================================================
82 BlackBoxDescriptor::BlackBoxDescriptor(const BlackBoxDescriptor&)
86 //=========================================================================
88 BlackBoxDescriptor::~BlackBoxDescriptor()
90 bbtkDDebugMessage("object",4,
91 "==> ~BlackBoxDescriptor()"
94 // deletes all I/O descriptors
95 InputDescriptorMapType::iterator i;
96 for (i=mInput.begin(); i!=mInput.end(); ++i) delete i->second;
97 OutputDescriptorMapType::iterator o;
98 for (o=mOutput.begin(); o!=mOutput.end(); ++o) delete o->second;
100 bbtkDDebugMessage("object",4,
101 "<== ~BlackBoxDescriptor()"
104 //=========================================================================
107 //=======================================================================
109 void BlackBoxDescriptor::Release(BlackBoxDescriptor::WeakPointer desc)
111 bbtkMessage("object",2,"==> BlackBoxDescriptor::Release('"
112 <<desc.lock()->GetTypeName()<<"')"<<std::endl);
113 long c = desc.use_count();
114 bbtkMessage("object",3," - ref count = "<<c<<std::endl);
116 if ((c == 1) && (desc.lock()->mPackage))
118 bbtkMessage("object",2," --> No more instance alive = releasing from package"<<std::endl);
120 Package::WeakPointer pack = desc.lock()->mPackage;
121 Package::ReleaseBlackBoxDescriptor(pack,desc);
125 bbtkMessage("object",2," --> Still some instances alive = Keeping it alive"<<std::endl);
127 bbtkMessage("object",2,"<== BlackBoxDescriptor::Release('"
128 <<desc.lock()->GetTypeName()<<"')"<<std::endl);
131 //=========================================================================
135 //=========================================================================
137 void BlackBoxDescriptor::UnReference()
139 bbtkDDebugMessageInc("kernel",1,
140 "BlackBoxDescriptor::UnReference() ["
141 <<mTypeName<<"] #"<<mRefCount-1<<std::endl);
145 bbtkDDebugMessage("kernel",1,"--> Destructing BlackBoxDescriptor ["<<mTypeName<<"]"<<std::endl);
149 //=========================================================================
151 //=========================================================================
153 void BlackBoxDescriptor::Check(bool) const
157 //=========================================================================
159 //=========================================================================
160 /// Adds the string to the BlackBox description
161 void BlackBoxDescriptor::AddToDescription( const std::string& s, bool clear)
163 bbtkDDebugMessage("kernel",9,"BlackBoxDescriptor::AddToDescription(\""
164 <<s<<"\")"<<std::endl);
165 if (clear) mDescription = s;
166 else mDescription += s;
168 //=========================================================================
170 //=========================================================================
171 /// Adds the string to the BlackBox author list
172 void BlackBoxDescriptor::AddToAuthor( const std::string& s, bool clear)
174 bbtkDDebugMessage("kernel",9,"BlackBoxDescriptor::AddToAuthor(\""
177 if (clear) mAuthor = s;
180 //=========================================================================
182 //=========================================================================
183 /// Adds the string to the BlackBox category list
184 void BlackBoxDescriptor::AddToCategory( const std::string& s, bool clear)
186 bbtkDDebugMessage("kernel",9,"BlackBoxDescriptor::AddToCategory(\""
189 if (clear) mCategory = s;
193 //=========================================================================
195 //=========================================================================
196 const BlackBoxDescriptor::InputDescriptor*
197 BlackBoxDescriptor::GetInputDescriptor(const std::string & name) const
199 bbtkDDebugMessage("kernel",9,"BlackBoxDescriptor::GetInputDescriptor('"
200 <<name<<"')"<<std::endl);
202 InputDescriptorMapType::const_iterator i;
203 i = mInput.find(name);
204 if ( i == mInput.end() )
206 bbtkError("input '"<<name<<"' does not exist");
211 //=========================================================================
213 //=========================================================================
214 const BlackBoxDescriptor::OutputDescriptor*
215 BlackBoxDescriptor::GetOutputDescriptor(const std::string & name) const
217 bbtkDDebugMessage("kernel",9,"BlackBoxDescriptor::GetOutputDescriptor('"
218 <<name<<"')"<<std::endl);
220 OutputDescriptorMapType::const_iterator i;
221 i = mOutput.find(name);
222 if ( i == mOutput.end() )
224 bbtkError("output '"<<name<<"' does not exist");
229 //=========================================================================
231 //=========================================================================
232 void BlackBoxDescriptor::GetHelp(bool full) const
234 bbtkDDebugMessage("kernel",9,"BlackBoxDescriptor::GetHelp()"
237 bbtkMessage("help",1,"Black Box <"<<GetFullTypeName()<<">"<<std::endl);
238 bbtkMessage("help",1," " <<GetDescription()<<std::endl);
239 bbtkMessage("help",1," By : " <<GetAuthor() <<std::endl);
240 bbtkMessage("help",1," Categories : " <<GetCategory() <<std::endl);
242 bbtkMessage("help",1," * Inputs : "<<std::endl);
244 bbtkMessage("help",1," * No inputs"<<std::endl);
245 InputDescriptorMapType::const_iterator i;
246 unsigned int namelmax = 0;
247 unsigned int typelmax = 0;
248 unsigned int natlmax = 0;
249 for ( i = mInput.begin(); i != mInput.end(); ++i )
251 if (i->second->GetName().size()>namelmax)
252 namelmax = i->second->GetName().size();
253 if (i->second->GetHumanTypeName().size()>typelmax)
254 typelmax = i->second->GetHumanTypeName().size();
255 if (i->second->GetNature().size()>natlmax)
256 natlmax = i->second->GetNature().size();
258 OutputDescriptorMapType::const_iterator o;
259 for ( o = mOutput.begin(); o != mOutput.end(); ++o )
261 if (o->second->GetName().size()>namelmax)
262 namelmax = o->second->GetName().size();
263 if (o->second->GetHumanTypeName().size()>typelmax)
264 typelmax = o->second->GetHumanTypeName().size();
265 if (o->second->GetNature().size()>natlmax)
266 natlmax = o->second->GetNature().size();
269 for ( i = mInput.begin(); i != mInput.end(); ++i )
271 std::string name(i->second->GetName());
273 name.append(1+namelmax-name.size(),' ');
274 std::string type(i->second->GetHumanTypeName());
276 type.append(1+typelmax-type.size(),' ');
277 std::string nature(i->second->GetNature());
279 nature.append(1+natlmax-nature.size(),' ');
280 bbtkMessage("help",1,
284 <<" : "<<i->second->GetDescription()<<std::endl);
287 bbtkMessage("help",1," * Outputs : "<<std::endl);
289 bbtkMessage("help",1," * No outputs"<<std::endl);
290 for ( o = mOutput.begin(); o != mOutput.end(); ++o )
292 std::string name(o->second->GetName());
294 name.append(1+namelmax-name.size(),' ');
295 std::string type(o->second->GetHumanTypeName());
297 type.append(1+typelmax-type.size(),' ');
298 std::string nature(o->second->GetNature());
300 nature.append(1+natlmax-nature.size(),' ');
301 bbtkMessage("help",1,
305 <<" : "<<o->second->GetDescription()<<std::endl);
310 //=========================================================================
312 //=========================================================================
313 /// Returns the full name of the **TYPE** of the black box (+package name)
314 std::string BlackBoxDescriptor::GetFullTypeName() const
316 if (GetPackage()!=0) return GetPackage()->GetName() + "::" + mTypeName;
317 return "::" + mTypeName;
319 //=========================================================================
320 void BlackBoxDescriptor::GetBoxesInside (NodeTreeC& tree, int cont){
323 //=========================================================================
324 void BlackBoxDescriptor::InsertHtmlHelp ( std::ofstream& s,
325 int detail, int level,
326 const std::string& output_dir,
329 bbtkDDebugMessage("kernel",9,"BlackBoxDescriptor::InsertHtmlHelp()"
334 std::string name = GetTypeName();
335 Utilities::html_format(name);
338 (s) << "<a name=\""<<name<<"\"></a>\n";
340 "<a rel=\"top\" accesskey=\"t\" href=\"#Top\">Top</a>\n";
341 // (s) << "Previous: <a rel="previous" accesskey="p" href="#dir">(dir)</a>,
342 // (s) << "Up: <a rel="up" accesskey="u" href="#dir">(dir)</a>
343 (s) << "<h2 class=\"section\">"<<name<<"</h2>\n";
346 std::string descr = GetDescription();
347 //Utilities::html_format(descr);
348 std::string author = GetAuthor();
349 Utilities::html_format(author);
351 std::vector<std::string> categories;
352 // Split the category string
353 std::string delimiters = ";,";
354 Utilities::SplitString(GetCategory(),
355 delimiters,categories);
358 (s) << "<p><TABLE cellspacing=0 cellpadding=3>\n";
359 (s) << "<TR><TD style='vertical-align: top;'><b> Description </b></TD><TD style='vertical-align: top;'> : </TD><TD style='vertical-align: top;'> "
360 << descr << "</TD></TR>\n";
361 (s) << "<TR><TD style='vertical-align: top;'><b> Author(s) </b></TD><TD style='vertical-align: top;'> : </TD><TD style='vertical-align: top;'> "
362 << author << "</TD></TR>\n";
363 (s) << "<TR><TD style='vertical-align: top;'><b> Category(s) </b></TD><TD style='vertical-align: top;'> : </TD><TD style='vertical-align: top;'> ";
364 std::vector<std::string>::iterator ci;
365 for (ci=categories.begin(); ci!=categories.end(); ++ci)
367 s << "<a href=\"../index-category.html#"<< *ci <<"\">" << *ci
372 (s) << "<TR><TD style='vertical-align: top;'><b> To use it </b></TD><TD style='vertical-align: top;'> : </TD><TD style='vertical-align: top;'> include "
373 << GetPackage()->GetName() << "</TD></TR>\n";
378 //i->second->InsertHTMLGraph( &s , detail,level,dir);
382 std::string titlecol("#BBBBFF");
383 std::string usercol("#FFFFFF");
384 std::string ubbcol("#DDFFFF");
385 std::string wxbbcol("#EEFFFF");
386 // JFGA 12/12/2014 Adding new variable
387 // std::string wtbbcol("#CCFFFF");
389 // (s) << "<h3 class=\"subsection\">Inputs</h3>\n";
390 (s) << "<p><TABLE border=1 cellspacing=0 cellpadding=3>\n";
391 (s) << "<TR><TD colspan=3 align=center bgcolor=\""<<titlecol
392 <<"\">Inputs</TD></TR>\n";
394 std::vector<std::string> user_defined;
395 std::vector<std::string> ubb_defined;
396 std::vector<std::string> wxbb_defined;
398 const BlackBoxDescriptor::InputDescriptorMapType& imap =
399 GetInputDescriptorMap();
400 InputDescriptorMapType::const_iterator in;
401 for ( in = imap.begin(); in != imap.end(); ++in )
403 // Skips system-defined inputs
404 std::string col(usercol);
406 if (in->second->GetCreatorTypeInfo() ==
407 typeid(AtomicBlackBoxDescriptor))
413 else if (in->second->GetCreatorTypeInfo() ==
414 typeid(WxBlackBoxDescriptor))
421 std::string name(in->second->GetName());
422 Utilities::html_format(name);
424 std::string type("<");
425 type += in->second->GetTypeName();
427 Utilities::html_format(type);
429 std::string descr(in->second->GetDescription());
430 //Utilities::html_format(descr);
434 "<TR><TD style='vertical-align: top;' bgcolor=\"" + col
435 +"\"><B><PRE> "+name+" </PRE></B></TD>"
436 + "<TD style='vertical-align: top;' bgcolor=\""+col
437 +"\"><I><PRE> "+type+" </PRE></I></TD>"
438 + "<TD style='vertical-align: top;' bgcolor=\""+col
439 +"\">"+descr+"</TD></TR>\n";
443 "<TR><TD style='vertical-align: top;' bgcolor=\"" + col
444 +"\"><B><PRE> "+name+" </PRE></B></TD>"
445 + "<TD style='vertical-align: top;' bgcolor=\""+col
446 +"\"><I><PRE> "+descr+" </PRE></I></TD>"
447 + "<TD style='vertical-align: top;' bgcolor=\""+col
448 +"\">"+type+"</TD></TR>\n";
450 if (iotype==0) user_defined.push_back(out);
451 else if (iotype==1) ubb_defined.push_back(out);
452 else if (iotype==2) wxbb_defined.push_back(out);
456 std::vector<std::string>::iterator hi;
457 for (hi=user_defined.begin();hi!=user_defined.end();++hi) s << *hi;
458 for (hi=wxbb_defined.begin();hi!=wxbb_defined.end();++hi) s << *hi;
459 for (hi=ubb_defined.begin();hi!=ubb_defined.end();++hi) s << *hi;
461 user_defined.clear();
463 wxbb_defined.clear();
467 // (s) << "<h3 class=\"subsection\">Outputs</h3>\n";
468 // (s) << "<TABLE border=1 cellspacing=0>\n";
469 (s) << "<TR><TD colspan=3 align=center bgcolor=\""<<titlecol
470 <<"\">Outputs</TD></TR>\n";
472 const BlackBoxDescriptor::OutputDescriptorMapType& omap =
473 GetOutputDescriptorMap();
475 BlackBoxDescriptor::OutputDescriptorMapType::const_iterator o;
477 for ( o = omap.begin(); o != omap.end(); ++o )
479 std::string col(usercol);
481 if (o->second->GetCreatorTypeInfo() ==
482 typeid(AtomicBlackBoxDescriptor))
488 else if (o->second->GetCreatorTypeInfo() ==
489 typeid(WxBlackBoxDescriptor))
496 std::string name(o->second->GetName());
497 Utilities::html_format(name);
499 std::string type("<");
500 type += o->second->GetTypeName();
502 Utilities::html_format(type);
504 std::string descr(o->second->GetDescription());
505 //Utilities::html_format(descr);
509 "<TR><TD style='vertical-align: top;' bgcolor=\"" + col
510 +"\"><B><PRE> "+name+" </PRE></B></TD>"
511 + "<TD style='vertical-align: top;' bgcolor=\""+col
512 +"\"><I><PRE> "+type+" </PRE></I></TD>"
513 + "<TD style='vertical-align: top;' bgcolor=\""+col
514 +"\">"+descr+"</TD></TR>\n";
517 "<TR><TD style='vertical-align: top;' bgcolor=\"" + col
518 +"\"><B><PRE> "+name+" </PRE></B></TD>"
519 + "<TD style='vertical-align: top;' bgcolor=\""+col
520 +"\"><I><PRE> "+descr+" </PRE></I></TD>"
521 + "<TD style='vertical-align: top;' bgcolor=\""+col
522 +"\">"+type+"</TD></TR>\n";
524 if (iotype==0) user_defined.push_back(out);
525 else if (iotype==1) ubb_defined.push_back(out);
526 else if (iotype==2) wxbb_defined.push_back(out);
530 for (hi=user_defined.begin();hi!=user_defined.end();++hi) s << *hi;
531 for (hi=wxbb_defined.begin();hi!=wxbb_defined.end();++hi) s << *hi;
532 for (hi=ubb_defined.begin();hi!=ubb_defined.end();++hi) s << *hi;
541 //=========================================================================
544 //==========================================================================
545 void BlackBoxDescriptor::SetTypeOfScript_Application()
547 SetTypeOfScript(TS_SCRIPT_APPLICATION);
549 //==========================================================================
552 //==========================================================================
553 bool BlackBoxDescriptor::IsTypeOfScript_Application()
555 return (GetTypeOfScript()==TS_SCRIPT_APPLICATION);
557 //==========================================================================
560 //==========================================================================
561 bool BlackBoxDescriptor::IsTypeOfScript_ComplexBox()
563 return (GetTypeOfScript()==TS_SCRIPT_COMPLEXBOX);
565 //==========================================================================