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