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