]> Creatis software - bbtk.git/blob - kernel/src/bbtkTranscriptor.cxx
Feature #1774
[bbtk.git] / kernel / src / bbtkTranscriptor.cxx
1 /*
2  # ---------------------------------------------------------------------
3  #
4  # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5  #                        pour la SantÈ)
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
9  #
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.
16  #
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
21  #  liability.
22  #
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  # ------------------------------------------------------------------------ */
26
27
28 /*=========================================================================
29   Program:   bbtk
30   Module:    $RCSfile: bbtkTranscriptor.cxx,v $
31   Language:  C++
32   Date:      $Date: 2012/11/16 08:49:01 $
33   Version:   $Revision: 1.19 $
34 =========================================================================*/
35
36
37
38 /**
39  *  \file 
40  *  \brief class Transcriptor: level 0 of script execution (code)
41  */
42
43 #include "bbtkTranscriptor.h"
44 #include "bbtkMessageManager.h"
45 #include "bbtkFactory.h"
46 #include "bbtkUtilities.h"
47 #include <fstream>
48
49 //#ifdef _USE_WXWIDGETS_
50 //#include <wx/textdlg.h>
51 //#endif
52
53 //#include "bbtkWxBlackBox.h"
54
55 #include "bbtkConfigurationFile.h"
56
57 namespace bbtk
58 {
59   Transcriptor::Pointer Transcriptor::New(const std::string& filename)
60   {
61     return MakePointer(new Transcriptor(filename));
62   }
63
64 /**
65  *
66  */
67   Transcriptor::Transcriptor(const std::string& filename)
68     :
69       mDialogMode(NoDialog)
70   {
71     //VirtualExec();    
72     bbtkDebugMessageInc("kernel",9,"Transcriptor()" <<std::endl);
73  
74      //std::ofstream *m_Fp = new std::ofstream();
75     m_Fp.open (filename.c_str(), std::ios::out );
76
77     std::string file,path;
78     file = bbtk::Utilities::ExtractScriptName(filename,path);
79     
80     m_Fp << "#include \"bbtkExecuter.h\"" << std::endl; 
81     m_Fp << "void " << file << "(bbtk::Executer::Pointer e)"<<std::endl;
82     m_Fp << "{"<<std::endl;
83
84     /*
85 #ifdef _USE_WXWIDGETS_
86     m_Fp << "#ifdef _USE_WXWIDGETS_"<<std::endl;
87     m_Fp << "#include \"bbtkWx.h\""<< std::endl<<std::endl;
88     m_Fp << "class myApp : public wxApp"<<std::endl;
89     m_Fp << "{"<<std::endl;
90     m_Fp << "public:"<<std::endl;
91     m_Fp << "  bool OnInit( );"<<std::endl;
92     m_Fp << "  int  OnExit() { delete e; return true; }"<<std::endl;
93     m_Fp << "  bbtk::Executer* e;"<<std::endl;
94     m_Fp << "};"<<std::endl<<std::endl;
95     m_Fp << "IMPLEMENT_APP(myApp);"<<std::endl<<std::endl;
96     m_Fp << "bool myApp::OnInit( )"<<std::endl;
97     m_Fp << "{"<<std::endl;
98     m_Fp << "  wxApp::OnInit();"<<std::endl;
99     m_Fp << "#ifdef __WXGTK__"<<std::endl;
100     m_Fp << "  //See http://www.wxwindows.org/faqgtk.htm#locale"<<std::endl;
101     m_Fp << "  setlocale(LC_NUMERIC, \"C\");"<<std::endl;
102     m_Fp << "#endif"<<std::endl;
103     m_Fp << "  wxInitAllImageHandlers();"<<std::endl;
104     m_Fp << "  bbtk::Wx::CreateInvisibleTopWindow();"<<std::endl;
105     m_Fp << "  try {"<<std::endl;
106     m_Fp << "  e = new bbtk::Executer();"<<std::endl;
107 #else
108     m_Fp << "main(int argc, char *argv[]) {"                << std::endl;
109     m_Fp << "  bbtk::Executer *e = new bbtk::Executer();"   << std::endl;
110 #endif 
111     */
112     bbtkDebugDecTab("kernel",9);
113  }
114
115 /**
116  *
117  */
118   Transcriptor::~Transcriptor()
119   {
120   
121     bbtkDebugMessageInc("kernel",9,"~Transcriptor()" <<std::endl);
122     /*
123 #ifdef _USE_WXWIDGETS_
124     m_Fp << "  }"<<std::endl;
125     m_Fp << "  catch (bbtk::Exception err)"<<std::endl;
126     m_Fp << "  {"<<std::endl;
127     m_Fp << "    err.Print();"<<std::endl;
128     m_Fp << "  } "<<std::endl;
129     m_Fp << "  return true;"<<std::endl;
130     m_Fp << "}"   << std::endl;
131     m_Fp << "#endif"<<std::endl;
132 #else 
133     m_Fp << "}"   << std::endl;
134 #endif
135     */
136     m_Fp << "}"   << std::endl;
137     m_Fp.close();
138
139     bbtkDebugDecTab("kernel",9);
140   }
141   
142
143   void Transcriptor::Reset()
144   {
145      m_Fp << "  e->Reset( );" << std::endl;
146   }
147
148   void Transcriptor::Clear()
149   {
150      m_Fp << "  e->Clear( );" << std::endl;
151   }
152
153   void Transcriptor::SetWorkspaceName( const std::string& name )
154   {
155   
156     m_Fp << "  e->SetWorkspaceName( \"" << name << "\" );" << std::endl;
157   }
158
159   void Transcriptor::BeginPackage (const std::string &name)
160   {
161      m_Fp << "  e->BeginPackage( \"" << name << "\" );" << std::endl;
162   }
163
164   void Transcriptor::EndPackage()
165   {
166      m_Fp << "  e->EndPackage( );" << std::endl;
167   }
168
169   void Transcriptor::Define (const std::string &name,
170                              const std::string &pack,
171                              const std::string &scriptfilename)
172   {
173      m_Fp << "  e->Define(\"" << name << "\", \"" <<  pack << "\", \""
174           << scriptfilename  << "\" );" << std::endl;
175   }
176
177   void Transcriptor::SetCurrentFileName (const std::string &name )
178   {
179      m_Fp << "  e->SetCurrentFileName( \"" << name << "\" );" << std::endl;
180   }
181
182   void Transcriptor::EndDefine ()
183   {
184      m_Fp << "  e->EndDefine( );" << std::endl;
185   }
186
187   void Transcriptor::Kind(const std::string& kind)
188   {
189     m_Fp << "  e->Kind( \""<<kind<<"\" );" << std::endl;
190   }
191
192
193   void Transcriptor::Create ( const std::string& nodeType, 
194                               const std::string& nodeName)
195   {
196     m_Fp << "  e->Create(\"" << nodeType << "\", \"" 
197          <<  nodeName << "\");" << std::endl;
198   }
199
200
201   void Transcriptor::Destroy (const std::string &nodeName)
202   {
203     m_Fp << "  e->Destroy(" <<  nodeName << ");" << std::endl;
204   }
205
206   void Transcriptor::Connect (const std::string &nodeFrom,
207                               const std::string &outputLabel,
208                               const std::string &nodeTo, 
209                               const std::string &inputLabel)
210   {
211     m_Fp << "  e->Connect(\""<< nodeFrom << "\", \"" 
212          <<  outputLabel << "\", \""
213          << nodeTo  << "\", \"" << inputLabel<< "\");" << std::endl;
214   }
215
216
217   void Transcriptor::Execute (const std::string &nodeName)
218   {
219      m_Fp << "  e->Execute(\"" << nodeName << "\");" << std::endl;
220   }
221
222   void Transcriptor::DefineInput ( const std::string &name,
223                                    const std::string &box,
224                                    const std::string &input,
225                                    const std::string& help)
226   {
227   
228     m_Fp << "  e->DefineInput(\""<< name << "\", \"" <<  box << "\", \""
229          << input << "\", \"" << help << "\");" << std::endl;
230   }
231
232   
233   void Transcriptor::DefineOutput ( const std::string &name,
234                                     const std::string &box,
235                                     const std::string &output,
236                                     const std::string& help)
237   {
238     m_Fp << "  e->DefineOutput(\""<< name << "\", \"" <<  box << "\", \""
239          << output << "\", \"" << help << "\");" << std::endl;
240   }
241
242  
243   void Transcriptor::Set (const std::string &box,
244                           const std::string &input,
245                           const std::string &value)
246   {
247     m_Fp << "  e->Set(\""<< box << "\", \"" << input
248          << "\", \"" << value << "\");"
249          << std::endl;
250   }
251
252   std::string Transcriptor::Get(const std::string &box,
253                                 const std::string &output)
254   {
255   
256     m_Fp << "  e->Get(\""<< box << "\", \"" << output << "\");"
257          << std::endl;
258     return "";
259   }
260
261
262   void Transcriptor::Author(const std::string &authorName)
263   {
264     
265     m_Fp << "  e->Author(\"" << authorName << "\");" << std::endl;
266   }
267
268   void Transcriptor::Category(const std::string &category)
269   {
270     m_Fp << "  e->Category(\"" << category << "\");" << std::endl;
271   }
272
273   void Transcriptor::Description(const std::string &d)
274   {
275     m_Fp << "  e->Description(\"" << d << "\");" << std::endl;
276   }
277
278   /// prints the list of the boxes of the current descriptor
279   void Transcriptor::PrintHelpListBoxes()
280   {
281      m_Fp << "  e->PrintBoxes( );" << std::endl;
282  }
283
284   std::string Transcriptor::ShowGraph(const std::string &nameblackbox,
285                                   const std::string &detailStr,
286                                   const std::string &levelStr,
287                                   const std::string &output_html,
288                                   const std::string &custom_header,
289                                   const std::string &custom_title,
290                                   bool system_display )
291   {
292
293        m_Fp << "  e->ShowGraph(\"" << nameblackbox  << "\", \"" 
294                                       << detailStr     << "\", \""
295                                       << levelStr      << "\", \""
296                                       << output_html   << "\", \""
297                                       << custom_header << "\", \""
298                                       <<  custom_title << "\");"                                     
299                                       << std::endl;
300
301     return ""; 
302   }
303
304    std::string Transcriptor::ShowGraphInstances(const std::string &nameblackbox, int detail, int level,
305                                                bool system_display)
306   {
307     return "";
308   
309   }
310
311 void Transcriptor::PrintHelpBlackBox(const std::string &nameblackbox, const std::string &detailStr, const std::string &levelStr)
312   {
313      
314   }
315
316   void Transcriptor::Print(const std::string & message)
317   {
318     m_Fp << "  e->Print(\"" <<message<<"\");"<<std::endl;
319   }
320
321
322   
323   void Transcriptor::SetMessageLevel(const std::string &kind,
324                        int level)
325   {
326     m_Fp << "  e->SetMessageLevel(\"" <<kind<<"\","<<level<<");"<<std::endl;
327   }
328   
329
330   void Transcriptor::HelpMessages()
331   {
332     m_Fp << "  e->HelpMessages();"<<std::endl;
333   }
334   
335   void Transcriptor::LoadPackage(const std::string &name )
336   {
337     m_Fp << "  e->LoadPackage(\"" <<name<<"\");"<<std::endl;
338   }
339   
340   
341   void Transcriptor::UnLoadPackage(const std::string &name )
342   {
343     m_Fp << "  e->UnLoadPackage(\"" <<name<<"\");"<<std::endl;
344   }
345
346  //==========================================================================
347   std::string Transcriptor::GetObjectName() const
348   {
349     return std::string("Transcriptor");
350   }
351   //==========================================================================
352   
353   //==========================================================================
354   std::string  Transcriptor::GetObjectInfo() const 
355   {
356     std::stringstream i;
357     return i.str();
358   }
359   //==========================================================================
360
361  //==========================================================================
362 size_t  Transcriptor::GetObjectSize() const 
363 {
364   size_t s = Superclass::GetObjectSize();
365   s += Transcriptor::GetObjectInternalSize();
366   return s;
367   }
368   //==========================================================================
369   //==========================================================================
370 size_t  Transcriptor::GetObjectInternalSize() const 
371 {
372   size_t s = sizeof(Transcriptor);
373   return s;
374   }
375   //==========================================================================
376   //==========================================================================
377   size_t  Transcriptor::GetObjectRecursiveSize() const 
378   {
379     size_t s = Superclass::GetObjectRecursiveSize();
380     s += Transcriptor::GetObjectInternalSize();
381     return s;
382   }
383   //==========================================================================
384
385         
386   //==========================================================================
387         void Transcriptor::SetTypeOfScript_Application()
388         {
389         }
390   //==========================================================================
391
392
393 }//namespace