]> Creatis software - bbtk.git/blob - kernel/src/bbtkTranscriptor.cxx
*** empty log message ***
[bbtk.git] / kernel / src / bbtkTranscriptor.cxx
1 /*=========================================================================                                                                               
2   Program:   bbtk
3   Module:    $RCSfile: bbtkTranscriptor.cxx,v $
4   Language:  C++
5   Date:      $Date: 2008/10/17 08:18:14 $
6   Version:   $Revision: 1.14 $
7 =========================================================================*/
8
9 /* ---------------------------------------------------------------------
10
11 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
12 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
13 *
14 *  This software is governed by the CeCILL-B license under French law and 
15 *  abiding by the rules of distribution of free software. You can  use, 
16 *  modify and/ or redistribute the software under the terms of the CeCILL-B 
17 *  license as circulated by CEA, CNRS and INRIA at the following URL 
18 *  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html 
19 *  or in the file LICENSE.txt.
20 *
21 *  As a counterpart to the access to the source code and  rights to copy,
22 *  modify and redistribute granted by the license, users are provided only
23 *  with a limited warranty  and the software's author,  the holder of the
24 *  economic rights,  and the successive licensors  have only  limited
25 *  liability. 
26 *
27 *  The fact that you are presently reading this means that you have had
28 *  knowledge of the CeCILL-B license and that you accept its terms.
29 * ------------------------------------------------------------------------ */                                                                         
30
31 /**
32  *  \file 
33  *  \brief class Transcriptor: level 0 of script execution (code)
34  */
35
36 #include "bbtkTranscriptor.h"
37 #include "bbtkMessageManager.h"
38 #include "bbtkFactory.h"
39 #include "bbtkUtilities.h"
40 #include <fstream>
41
42 //#ifdef _USE_WXWIDGETS_
43 //#include <wx/textdlg.h>
44 //#endif
45
46 //#include "bbtkWxBlackBox.h"
47
48 #include "bbtkConfigurationFile.h"
49
50 namespace bbtk
51 {
52   Transcriptor::Pointer Transcriptor::New(const std::string& filename)
53   {
54     return MakePointer(new Transcriptor(filename));
55   }
56
57 /**
58  *
59  */
60   Transcriptor::Transcriptor(const std::string& filename)
61     :
62       mDialogMode(NoDialog)
63   {
64     //VirtualExec();    
65     bbtkDebugMessageInc("Kernel",9,"Transcriptor::Transcriptor()" <<std::endl);
66  
67      //std::ofstream *m_Fp = new std::ofstream();
68     m_Fp.open (filename.c_str(), std::ios::out );
69
70     std::string file,path;
71     file = bbtk::Utilities::ExtractScriptName(filename,path);
72     
73     m_Fp << "#include \"bbtkExecuter.h\"" << std::endl; 
74     m_Fp << "void " << file << "(bbtk::Executer::Pointer e)"<<std::endl;
75     m_Fp << "{"<<std::endl;
76
77     /*
78 #ifdef _USE_WXWIDGETS_
79     m_Fp << "#ifdef _USE_WXWIDGETS_"<<std::endl;
80     m_Fp << "#include \"bbtkWx.h\""<< std::endl<<std::endl;
81     m_Fp << "class myApp : public wxApp"<<std::endl;
82     m_Fp << "{"<<std::endl;
83     m_Fp << "public:"<<std::endl;
84     m_Fp << "  bool OnInit( );"<<std::endl;
85     m_Fp << "  int  OnExit() { delete e; return true; }"<<std::endl;
86     m_Fp << "  bbtk::Executer* e;"<<std::endl;
87     m_Fp << "};"<<std::endl<<std::endl;
88     m_Fp << "IMPLEMENT_APP(myApp);"<<std::endl<<std::endl;
89     m_Fp << "bool myApp::OnInit( )"<<std::endl;
90     m_Fp << "{"<<std::endl;
91     m_Fp << "  wxApp::OnInit();"<<std::endl;
92     m_Fp << "#ifdef __WXGTK__"<<std::endl;
93     m_Fp << "  //See http://www.wxwindows.org/faqgtk.htm#locale"<<std::endl;
94     m_Fp << "  setlocale(LC_NUMERIC, \"C\");"<<std::endl;
95     m_Fp << "#endif"<<std::endl;
96     m_Fp << "  wxInitAllImageHandlers();"<<std::endl;
97     m_Fp << "  bbtk::Wx::CreateInvisibleTopWindow();"<<std::endl;
98     m_Fp << "  try {"<<std::endl;
99     m_Fp << "  e = new bbtk::Executer();"<<std::endl;
100 #else
101     m_Fp << "main(int argc, char *argv[]) {"                << std::endl;
102     m_Fp << "  bbtk::Executer *e = new bbtk::Executer();"   << std::endl;
103 #endif 
104     */
105     bbtkDebugDecTab("Kernel",9);
106  }
107
108 /**
109  *
110  */
111   Transcriptor::~Transcriptor()
112   {
113   
114     bbtkDebugMessageInc("Kernel",9,"Transcriptor::~Transcriptor()" <<std::endl);
115     /*
116 #ifdef _USE_WXWIDGETS_
117     m_Fp << "  }"<<std::endl;
118     m_Fp << "  catch (bbtk::Exception err)"<<std::endl;
119     m_Fp << "  {"<<std::endl;
120     m_Fp << "    err.Print();"<<std::endl;
121     m_Fp << "  } "<<std::endl;
122     m_Fp << "  return true;"<<std::endl;
123     m_Fp << "}"   << std::endl;
124     m_Fp << "#endif"<<std::endl;
125 #else 
126     m_Fp << "}"   << std::endl;
127 #endif
128     */
129     m_Fp << "}"   << std::endl;
130     m_Fp.close();
131
132     bbtkDebugDecTab("Kernel",9);
133   }
134   
135
136   void Transcriptor::Reset()
137   {
138      m_Fp << "  e->Reset( );" << std::endl;
139   }
140
141   void Transcriptor::SetWorkspaceName( const std::string& name )
142   {
143   
144     m_Fp << "  e->SetWorkspaceName( \"" << name << "\" );" << std::endl;
145   }
146
147   void Transcriptor::BeginPackage (const std::string &name)
148   {
149      m_Fp << "  e->BeginPackage( \"" << name << "\" );" << std::endl;
150   }
151
152   void Transcriptor::EndPackage()
153   {
154      m_Fp << "  e->EndPackage( );" << std::endl;
155   }
156
157   void Transcriptor::Define (const std::string &name,
158                              const std::string &pack,
159                              const std::string &scriptfilename)
160   {
161      m_Fp << "  e->Define(\"" << name << "\", \"" <<  pack << "\", \""
162           << scriptfilename  << "\" );" << std::endl;
163   }
164
165   void Transcriptor::SetCurrentFileName (const std::string &name )
166   {
167      m_Fp << "  e->SetCurrentFileName( \"" << name << "\" );" << std::endl;
168   }
169
170   void Transcriptor::EndDefine ()
171   {
172      m_Fp << "  e->EndDefine( );" << std::endl;
173   }
174
175   void Transcriptor::Kind(const std::string& kind)
176   {
177     m_Fp << "  e->Kind( \""<<kind<<"\" );" << std::endl;
178   }
179
180
181   void Transcriptor::Create ( const std::string& nodeType, 
182                               const std::string& nodeName)
183   {
184     m_Fp << "  e->Create(\"" << nodeType << "\", \"" 
185          <<  nodeName << "\");" << std::endl;
186   }
187
188
189   void Transcriptor::Destroy (const std::string &nodeName)
190   {
191     m_Fp << "  e->Destroy(" <<  nodeName << ");" << std::endl;
192   }
193
194   void Transcriptor::Connect (const std::string &nodeFrom,
195                               const std::string &outputLabel,
196                               const std::string &nodeTo, 
197                               const std::string &inputLabel)
198   {
199     m_Fp << "  e->Connect(\""<< nodeFrom << "\", \"" 
200          <<  outputLabel << "\", \""
201          << nodeTo  << "\", \"" << inputLabel<< "\");" << std::endl;
202   }
203
204
205   void Transcriptor::Execute (const std::string &nodeName)
206   {
207      m_Fp << "  e->Execute(\"" << nodeName << "\");" << std::endl;
208   }
209
210   void Transcriptor::DefineInput ( const std::string &name,
211                                    const std::string &box,
212                                    const std::string &input,
213                                    const std::string& help)
214   {
215   
216     m_Fp << "  e->DefineInput(\""<< name << "\", \"" <<  box << "\", \""
217          << input << "\", \"" << help << "\");" << std::endl;
218   }
219
220   
221   void Transcriptor::DefineOutput ( const std::string &name,
222                                     const std::string &box,
223                                     const std::string &output,
224                                     const std::string& help)
225   {
226     m_Fp << "  e->DefineOutput(\""<< name << "\", \"" <<  box << "\", \""
227          << output << "\", \"" << help << "\");" << std::endl;
228   }
229
230  
231   void Transcriptor::Set (const std::string &box,
232                           const std::string &input,
233                           const std::string &value)
234   {
235     m_Fp << "  e->Set(\""<< box << "\", \"" << input
236          << "\", \"" << value << "\");"
237          << std::endl;
238   }
239
240   std::string Transcriptor::Get(const std::string &box,
241                                 const std::string &output)
242   {
243   
244     m_Fp << "  e->Get(\""<< box << "\", \"" << output << "\");"
245          << std::endl;
246     return "";
247   }
248
249
250   void Transcriptor::Author(const std::string &authorName)
251   {
252     
253     m_Fp << "  e->Author(\"" << authorName << "\");" << std::endl;
254   }
255
256   void Transcriptor::Category(const std::string &category)
257   {
258     m_Fp << "  e->Category(\"" << category << "\");" << std::endl;
259   }
260
261   void Transcriptor::Description(const std::string &d)
262   {
263     m_Fp << "  e->Description(\"" << d << "\");" << std::endl;
264   }
265
266   /// prints the list of the boxes of the current descriptor
267   void Transcriptor::PrintBoxes()
268   {
269      m_Fp << "  e->PrintBoxes( );" << std::endl;
270  }
271
272   std::string Transcriptor::ShowGraph(const std::string &nameblackbox,
273                                   const std::string &detailStr,
274                                   const std::string &levelStr,
275                                   const std::string &output_html,
276                                   const std::string &custom_header,
277                                   const std::string &custom_title,
278                                   bool system_display )
279   {
280
281        m_Fp << "  e->ShowGraph(\"" << nameblackbox  << "\", \"" 
282                                       << detailStr     << "\", \""
283                                       << levelStr      << "\", \""
284                                       << output_html   << "\", \""
285                                       << custom_header << "\", \""
286                                       <<  custom_title << "\");"                                     
287                                       << std::endl;
288
289     return ""; 
290   }
291
292    std::string Transcriptor::ShowGraphInstances(const std::string &nameblackbox, int detail, int level,
293                                                bool system_display)
294   {
295     return "";
296   
297   }
298
299 void Transcriptor::ShowRelations(const std::string &nameblackbox, const std::string &detailStr, const std::string &levelStr)
300   {
301      
302   }
303
304   void Transcriptor::Print(const std::string & message)
305   {
306     m_Fp << "  e->Print(\"" <<message<<"\");"<<std::endl;
307   }
308
309
310   
311   void Transcriptor::SetMessageLevel(const std::string &kind,
312                        int level)
313   {
314     m_Fp << "  e->SetMessageLevel(\"" <<kind<<"\","<<level<<");"<<std::endl;
315   }
316   
317
318   void Transcriptor::HelpMessages()
319   {
320     m_Fp << "  e->HelpMessages();"<<std::endl;
321   }
322   
323   void Transcriptor::LoadPackage(const std::string &name )
324   {
325     m_Fp << "  e->LoadPackage(\"" <<name<<"\");"<<std::endl;
326   }
327   
328   
329   void Transcriptor::UnLoadPackage(const std::string &name )
330   {
331     m_Fp << "  e->UnLoadPackage(\"" <<name<<"\");"<<std::endl;
332   }
333
334  //==========================================================================
335   std::string Transcriptor::GetObjectName() const
336   {
337     return std::string("Transcriptor");
338   }
339   //==========================================================================
340   
341   //==========================================================================
342   std::string  Transcriptor::GetObjectInfo() const 
343   {
344     std::stringstream i;
345     return i.str();
346   }
347   //==========================================================================
348
349  //==========================================================================
350 size_t  Transcriptor::GetObjectSize() const 
351 {
352   size_t s = Superclass::GetObjectSize();
353   s += Transcriptor::GetObjectInternalSize();
354   return s;
355   }
356   //==========================================================================
357   //==========================================================================
358 size_t  Transcriptor::GetObjectInternalSize() const 
359 {
360   size_t s = sizeof(Transcriptor);
361   return s;
362   }
363   //==========================================================================
364   //==========================================================================
365   size_t  Transcriptor::GetObjectRecursiveSize() const 
366   {
367     size_t s = Superclass::GetObjectRecursiveSize();
368     s += Transcriptor::GetObjectInternalSize();
369     return s;
370   }
371   //==========================================================================
372
373
374 }//namespace