]> Creatis software - bbtk.git/blob - kernel/src/bbtkTranscriptor.cxx
ff0785b392013d6ce23a9ee1ebc91e20167cba8a
[bbtk.git] / kernel / src / bbtkTranscriptor.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   bbtk
4   Module:    $RCSfile: bbtkTranscriptor.cxx,v $ $
5   Language:  C++
6   Date:      $Date: 2008/03/26 08:27:19 $
7   Version:   $Revision: 1.8 $
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 /**
40  *
41  */
42   Transcriptor::Transcriptor(std::string filename)
43     : mPackage(0),
44       mRoot(0),
45       mNoExecMode(false),
46       mDialogMode(NoDialog)
47   {
48     //VirtualExec();    
49     bbtkDebugMessageInc("Kernel",9,"Transcriptor::Transcriptor()" <<std::endl);
50     Reset();
51     bbtkDebugDecTab("Kernel",9);
52
53     //std::ofstream *m_Fp = new std::ofstream();
54     m_Fp.open (filename.c_str(), std::ios::out );
55
56     m_Fp << "#include \"bbtkExecuter.h\""                   << std::endl;
57     m_Fp << "main(int argc, char *argv[]) {"                << std::endl;
58     m_Fp << "  bbtk::Executer *e = new bbtk::Executer();"   << std::endl;
59   }
60
61 /**
62  *
63  */
64   Transcriptor::~Transcriptor()
65   {
66   
67 std::cout << "====================================================== delete Transcriptor\n";
68      bbtkDebugMessageInc("Kernel",9,"Transcriptor::~Transcriptor()" <<std::endl);
69      if (mRoot) 
70      {
71         mPackage->UnRegisterBlackBox("workspace");
72         delete mRoot;
73      }
74      if (mPackage)
75      {
76         //GetGlobalFactory()->UnLoadPackage("user");
77      }
78
79      if(m_Fp)
80      {
81         bbtkDebugDecTab("Kernel",9);
82         m_Fp << " }"   << std::endl;
83         m_Fp.close();
84        // delete m_Fp;
85      }
86   }
87
88
89   // ================= Begin of Battlefield =============================
90   void Transcriptor::Reset()
91   {
92      m_Fp << "  e->Reset( );" << std::endl;
93   }
94
95   void Transcriptor::SetWorkspaceName( const std::string& name )
96   {
97   
98     m_Fp << "  e->SetWorkspaceName( \"" << name << "\" );" << std::endl;
99   }
100
101   void Transcriptor::BeginPackage (const std::string &name)
102   {
103      m_Fp << "  e->BeginPackage( \"" << name << "\" );" << std::endl;
104   }
105
106   void Transcriptor::EndPackage()
107   {
108      m_Fp << "  e->EndPackage( );" << std::endl;
109   }
110
111   void Transcriptor::Define (const std::string &name,
112                              const std::string &pack,
113                              const std::string &scriptfilename)
114   {
115      m_Fp << "  e->Define(\"" << name << "\", \"" <<  pack << "\", \""
116           << scriptfilename  << "\" );" << std::endl;
117   }
118
119   void Transcriptor::SetCurrentFileName (const std::string &name )
120   {
121      m_Fp << "  e->SetCurrentFileName( \"" << name << "\" );" << std::endl;
122   }
123
124   void Transcriptor::EndDefine ()
125   {
126      m_Fp << "  e->EndDefine( );" << std::endl;
127   }
128
129
130   void Transcriptor::Create ( const std::string& nodeType, 
131                               const std::string& nodeName)
132   {
133     m_Fp << "  e->Add(\"" << nodeType << "\", \"" 
134          <<  nodeName << "\");" << std::endl;
135   }
136
137
138   void Transcriptor::Destroy (const std::string &nodeName)
139   {
140     m_Fp << "  e->Destroy(" <<  nodeName << ");" << std::endl;
141   }
142
143   void Transcriptor::Connect (const std::string &nodeFrom,
144                               const std::string &outputLabel,
145                               const std::string &nodeTo, 
146                               const std::string &inputLabel)
147   {
148     m_Fp << "  e->Connect(\""<< nodeFrom << "\", \"" 
149          <<  outputLabel << "\", \""
150          << nodeTo  << "\", \"" << inputLabel<< "\");" << std::endl;
151   }
152
153
154   void Transcriptor::Execute (const std::string &nodeName)
155   {
156      m_Fp << "  e->Execute(\"" << nodeName << "\");" << std::endl;
157   }
158
159   void Transcriptor::DefineInput ( const std::string &name,
160                                    const std::string &box,
161                                    const std::string &input,
162                                    const std::string& help)
163   {
164   
165     m_Fp << "  e->DefineInput(\""<< name << "\", " <<  box << ", "
166          << input << ", \"" << help << "\");" << std::endl;
167   }
168
169   
170   void Transcriptor::DefineOutput ( const std::string &name,
171                                     const std::string &box,
172                                     const std::string &output,
173                                     const std::string& help)
174   {
175     m_Fp << "  e->DefineOutput(\""<< name << "\", \"" <<  box << "\", \""
176          << output << "\", \"" << help << "\");" << std::endl;
177   }
178
179  
180   void Transcriptor::Set (const std::string &box,
181                           const std::string &input,
182                           const std::string &value)
183   {
184     m_Fp << "  e->Set(\""<< box << "\", \"" << input
185          << "\", \"" << value << "\");"
186          << std::endl;
187   }
188
189   std::string Transcriptor::Get(const std::string &box,
190                                 const std::string &output)
191   {
192   
193     m_Fp << "  e->Get(\""<< box << "\", \"" << output << "\");"
194          << std::endl;
195     return "";
196   }
197
198
199   void Transcriptor::Author(const std::string &authorName)
200   {
201     
202     m_Fp << "  e->AddToAuthor(\"" << authorName << "\")" << std::endl;
203   }
204
205   void Transcriptor::Category(const std::string &category)
206   {
207     m_Fp << "  e->AddToCategory(\"" << category << "\")" << std::endl;
208   }
209
210   void Transcriptor::Description(const std::string &d)
211   {
212     m_Fp << "  e->AddToDescription(\"" << d << "\")" << std::endl;
213   }
214
215   /// prints the list of the boxes of the current descriptor
216   void Transcriptor::PrintBoxes()
217   {
218      m_Fp << "  e->PrintBoxes( )" << std::endl;
219  }
220
221 // =========================End of Battlefield ========================================================================
222
223   std::string Transcriptor::ShowGraph(const std::string &nameblackbox,
224                                   const std::string &detailStr,
225                                   const std::string &levelStr,
226                                   const std::string &output_html,
227                                   const std::string &custom_header,
228                                   const std::string &custom_title,
229                                   bool system_display )
230   {
231
232        m_Fp << "  e->ShowGraph(\"" << nameblackbox  << "\", \"" 
233                                       << detailStr     << "\", \""
234                                       << levelStr      << "\", \""
235                                       << output_html   << "\", \""
236                                       << custom_header << "\", \""
237                                       <<  custom_title << "\");"                                     
238                                       << std::endl;
239
240     return ""; 
241   }
242
243    std::string Transcriptor::ShowGraphInstances(const std::string &nameblackbox, int detail, int level,
244                                                bool system_display)
245   {
246     return "";
247   
248   }
249
250 void Transcriptor::ShowRelations(const std::string &nameblackbox, const std::string &detailStr, const std::string &levelStr)
251   {
252      
253   }
254
255   void Transcriptor::Print(const std::string & message)
256   {
257     m_Fp << "  e->Print(\"" <<message<<"\")"<<std::endl;
258   }
259
260
261   
262   void Transcriptor::SetMessageLevel(const std::string &kind,
263                        int level)
264   {
265     m_Fp << "  e->SetMessageLevel(\"" <<kind<<"\","<<level<<")"<<std::endl;
266   }
267   
268
269   void Transcriptor::HelpMessages()
270   {
271     m_Fp << "  e->HelpMessages()"<<std::endl;
272   }
273   
274   void Transcriptor::LoadPackage(const std::string &name )
275   {
276     m_Fp << "  e->LoadPackage(\"" <<name<<"\")"<<std::endl;
277   }
278   
279   
280   void Transcriptor::UnLoadPackage(const std::string &name )
281   {
282     m_Fp << "  e->UnLoadPackage(\"" <<name<<"\")"<<std::endl;
283   }
284
285
286
287 }//namespace