]> 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/12/12 12:11:21 $
6   Version:   $Revision: 1.15 $
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::Clear()
142   {
143      m_Fp << "  e->Clear( );" << std::endl;
144   }
145
146   void Transcriptor::SetWorkspaceName( const std::string& name )
147   {
148   
149     m_Fp << "  e->SetWorkspaceName( \"" << name << "\" );" << std::endl;
150   }
151
152   void Transcriptor::BeginPackage (const std::string &name)
153   {
154      m_Fp << "  e->BeginPackage( \"" << name << "\" );" << std::endl;
155   }
156
157   void Transcriptor::EndPackage()
158   {
159      m_Fp << "  e->EndPackage( );" << std::endl;
160   }
161
162   void Transcriptor::Define (const std::string &name,
163                              const std::string &pack,
164                              const std::string &scriptfilename)
165   {
166      m_Fp << "  e->Define(\"" << name << "\", \"" <<  pack << "\", \""
167           << scriptfilename  << "\" );" << std::endl;
168   }
169
170   void Transcriptor::SetCurrentFileName (const std::string &name )
171   {
172      m_Fp << "  e->SetCurrentFileName( \"" << name << "\" );" << std::endl;
173   }
174
175   void Transcriptor::EndDefine ()
176   {
177      m_Fp << "  e->EndDefine( );" << std::endl;
178   }
179
180   void Transcriptor::Kind(const std::string& kind)
181   {
182     m_Fp << "  e->Kind( \""<<kind<<"\" );" << std::endl;
183   }
184
185
186   void Transcriptor::Create ( const std::string& nodeType, 
187                               const std::string& nodeName)
188   {
189     m_Fp << "  e->Create(\"" << nodeType << "\", \"" 
190          <<  nodeName << "\");" << std::endl;
191   }
192
193
194   void Transcriptor::Destroy (const std::string &nodeName)
195   {
196     m_Fp << "  e->Destroy(" <<  nodeName << ");" << std::endl;
197   }
198
199   void Transcriptor::Connect (const std::string &nodeFrom,
200                               const std::string &outputLabel,
201                               const std::string &nodeTo, 
202                               const std::string &inputLabel)
203   {
204     m_Fp << "  e->Connect(\""<< nodeFrom << "\", \"" 
205          <<  outputLabel << "\", \""
206          << nodeTo  << "\", \"" << inputLabel<< "\");" << std::endl;
207   }
208
209
210   void Transcriptor::Execute (const std::string &nodeName)
211   {
212      m_Fp << "  e->Execute(\"" << nodeName << "\");" << std::endl;
213   }
214
215   void Transcriptor::DefineInput ( const std::string &name,
216                                    const std::string &box,
217                                    const std::string &input,
218                                    const std::string& help)
219   {
220   
221     m_Fp << "  e->DefineInput(\""<< name << "\", \"" <<  box << "\", \""
222          << input << "\", \"" << help << "\");" << std::endl;
223   }
224
225   
226   void Transcriptor::DefineOutput ( const std::string &name,
227                                     const std::string &box,
228                                     const std::string &output,
229                                     const std::string& help)
230   {
231     m_Fp << "  e->DefineOutput(\""<< name << "\", \"" <<  box << "\", \""
232          << output << "\", \"" << help << "\");" << std::endl;
233   }
234
235  
236   void Transcriptor::Set (const std::string &box,
237                           const std::string &input,
238                           const std::string &value)
239   {
240     m_Fp << "  e->Set(\""<< box << "\", \"" << input
241          << "\", \"" << value << "\");"
242          << std::endl;
243   }
244
245   std::string Transcriptor::Get(const std::string &box,
246                                 const std::string &output)
247   {
248   
249     m_Fp << "  e->Get(\""<< box << "\", \"" << output << "\");"
250          << std::endl;
251     return "";
252   }
253
254
255   void Transcriptor::Author(const std::string &authorName)
256   {
257     
258     m_Fp << "  e->Author(\"" << authorName << "\");" << std::endl;
259   }
260
261   void Transcriptor::Category(const std::string &category)
262   {
263     m_Fp << "  e->Category(\"" << category << "\");" << std::endl;
264   }
265
266   void Transcriptor::Description(const std::string &d)
267   {
268     m_Fp << "  e->Description(\"" << d << "\");" << std::endl;
269   }
270
271   /// prints the list of the boxes of the current descriptor
272   void Transcriptor::PrintBoxes()
273   {
274      m_Fp << "  e->PrintBoxes( );" << std::endl;
275  }
276
277   std::string Transcriptor::ShowGraph(const std::string &nameblackbox,
278                                   const std::string &detailStr,
279                                   const std::string &levelStr,
280                                   const std::string &output_html,
281                                   const std::string &custom_header,
282                                   const std::string &custom_title,
283                                   bool system_display )
284   {
285
286        m_Fp << "  e->ShowGraph(\"" << nameblackbox  << "\", \"" 
287                                       << detailStr     << "\", \""
288                                       << levelStr      << "\", \""
289                                       << output_html   << "\", \""
290                                       << custom_header << "\", \""
291                                       <<  custom_title << "\");"                                     
292                                       << std::endl;
293
294     return ""; 
295   }
296
297    std::string Transcriptor::ShowGraphInstances(const std::string &nameblackbox, int detail, int level,
298                                                bool system_display)
299   {
300     return "";
301   
302   }
303
304 void Transcriptor::ShowRelations(const std::string &nameblackbox, const std::string &detailStr, const std::string &levelStr)
305   {
306      
307   }
308
309   void Transcriptor::Print(const std::string & message)
310   {
311     m_Fp << "  e->Print(\"" <<message<<"\");"<<std::endl;
312   }
313
314
315   
316   void Transcriptor::SetMessageLevel(const std::string &kind,
317                        int level)
318   {
319     m_Fp << "  e->SetMessageLevel(\"" <<kind<<"\","<<level<<");"<<std::endl;
320   }
321   
322
323   void Transcriptor::HelpMessages()
324   {
325     m_Fp << "  e->HelpMessages();"<<std::endl;
326   }
327   
328   void Transcriptor::LoadPackage(const std::string &name )
329   {
330     m_Fp << "  e->LoadPackage(\"" <<name<<"\");"<<std::endl;
331   }
332   
333   
334   void Transcriptor::UnLoadPackage(const std::string &name )
335   {
336     m_Fp << "  e->UnLoadPackage(\"" <<name<<"\");"<<std::endl;
337   }
338
339  //==========================================================================
340   std::string Transcriptor::GetObjectName() const
341   {
342     return std::string("Transcriptor");
343   }
344   //==========================================================================
345   
346   //==========================================================================
347   std::string  Transcriptor::GetObjectInfo() const 
348   {
349     std::stringstream i;
350     return i.str();
351   }
352   //==========================================================================
353
354  //==========================================================================
355 size_t  Transcriptor::GetObjectSize() const 
356 {
357   size_t s = Superclass::GetObjectSize();
358   s += Transcriptor::GetObjectInternalSize();
359   return s;
360   }
361   //==========================================================================
362   //==========================================================================
363 size_t  Transcriptor::GetObjectInternalSize() const 
364 {
365   size_t s = sizeof(Transcriptor);
366   return s;
367   }
368   //==========================================================================
369   //==========================================================================
370   size_t  Transcriptor::GetObjectRecursiveSize() const 
371   {
372     size_t s = Superclass::GetObjectRecursiveSize();
373     s += Transcriptor::GetObjectInternalSize();
374     return s;
375   }
376   //==========================================================================
377
378
379 }//namespace