1 /*=========================================================================
4 Module: $RCSfile: bbtkTranscriptor.cxx,v $ $
6 Date: $Date: 2008/04/08 06:59:30 $
7 Version: $Revision: 1.10 $
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.
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.
17 =========================================================================*/
20 * \brief class Transcriptor: level 0 of script execution (code)
23 #include "bbtkTranscriptor.h"
24 #include "bbtkMessageManager.h"
25 #include "bbtkFactory.h"
26 #include "bbtkUtilities.h"
29 //#ifdef _USE_WXWIDGETS_
30 //#include <wx/textdlg.h>
33 //#include "bbtkWxBlackBox.h"
35 #include "bbtkConfigurationFile.h"
42 Transcriptor::Transcriptor(std::string filename)
48 bbtkDebugMessageInc("Kernel",9,"Transcriptor::Transcriptor()" <<std::endl);
50 //std::ofstream *m_Fp = new std::ofstream();
51 m_Fp.open (filename.c_str(), std::ios::out );
53 std::string file,path;
54 file = bbtk::Utilities::ExtractScriptName(filename,path);
56 m_Fp << "#include \"bbtkExecuter.h\"" << std::endl;
57 m_Fp << "void " << file << "(bbtk::Executer* e)"<<std::endl;
58 m_Fp << "{"<<std::endl;
61 #ifdef _USE_WXWIDGETS_
62 m_Fp << "#ifdef _USE_WXWIDGETS_"<<std::endl;
63 m_Fp << "#include \"bbtkWx.h\""<< std::endl<<std::endl;
64 m_Fp << "class myApp : public wxApp"<<std::endl;
65 m_Fp << "{"<<std::endl;
66 m_Fp << "public:"<<std::endl;
67 m_Fp << " bool OnInit( );"<<std::endl;
68 m_Fp << " int OnExit() { delete e; return true; }"<<std::endl;
69 m_Fp << " bbtk::Executer* e;"<<std::endl;
70 m_Fp << "};"<<std::endl<<std::endl;
71 m_Fp << "IMPLEMENT_APP(myApp);"<<std::endl<<std::endl;
72 m_Fp << "bool myApp::OnInit( )"<<std::endl;
73 m_Fp << "{"<<std::endl;
74 m_Fp << " wxApp::OnInit();"<<std::endl;
75 m_Fp << "#ifdef __WXGTK__"<<std::endl;
76 m_Fp << " //See http://www.wxwindows.org/faqgtk.htm#locale"<<std::endl;
77 m_Fp << " setlocale(LC_NUMERIC, \"C\");"<<std::endl;
78 m_Fp << "#endif"<<std::endl;
79 m_Fp << " wxInitAllImageHandlers();"<<std::endl;
80 m_Fp << " bbtk::Wx::CreateInvisibleTopWindow();"<<std::endl;
81 m_Fp << " try {"<<std::endl;
82 m_Fp << " e = new bbtk::Executer();"<<std::endl;
84 m_Fp << "main(int argc, char *argv[]) {" << std::endl;
85 m_Fp << " bbtk::Executer *e = new bbtk::Executer();" << std::endl;
88 bbtkDebugDecTab("Kernel",9);
94 Transcriptor::~Transcriptor()
97 bbtkDebugMessageInc("Kernel",9,"Transcriptor::~Transcriptor()" <<std::endl);
99 #ifdef _USE_WXWIDGETS_
100 m_Fp << " }"<<std::endl;
101 m_Fp << " catch (bbtk::Exception err)"<<std::endl;
102 m_Fp << " {"<<std::endl;
103 m_Fp << " err.Print();"<<std::endl;
104 m_Fp << " } "<<std::endl;
105 m_Fp << " return true;"<<std::endl;
106 m_Fp << "}" << std::endl;
107 m_Fp << "#endif"<<std::endl;
109 m_Fp << "}" << std::endl;
112 m_Fp << "}" << std::endl;
115 bbtkDebugDecTab("Kernel",9);
119 void Transcriptor::Reset()
121 m_Fp << " e->Reset( );" << std::endl;
124 void Transcriptor::SetWorkspaceName( const std::string& name )
127 m_Fp << " e->SetWorkspaceName( \"" << name << "\" );" << std::endl;
130 void Transcriptor::BeginPackage (const std::string &name)
132 m_Fp << " e->BeginPackage( \"" << name << "\" );" << std::endl;
135 void Transcriptor::EndPackage()
137 m_Fp << " e->EndPackage( );" << std::endl;
140 void Transcriptor::Define (const std::string &name,
141 const std::string &pack,
142 const std::string &scriptfilename)
144 m_Fp << " e->Define(\"" << name << "\", \"" << pack << "\", \""
145 << scriptfilename << "\" );" << std::endl;
148 void Transcriptor::SetCurrentFileName (const std::string &name )
150 m_Fp << " e->SetCurrentFileName( \"" << name << "\" );" << std::endl;
153 void Transcriptor::EndDefine ()
155 m_Fp << " e->EndDefine( );" << std::endl;
158 void Transcriptor::Kind(const std::string& kind)
160 m_Fp << " e->Kind( \""<<kind<<"\" );" << std::endl;
164 void Transcriptor::Create ( const std::string& nodeType,
165 const std::string& nodeName)
167 m_Fp << " e->Create(\"" << nodeType << "\", \""
168 << nodeName << "\");" << std::endl;
172 void Transcriptor::Destroy (const std::string &nodeName)
174 m_Fp << " e->Destroy(" << nodeName << ");" << std::endl;
177 void Transcriptor::Connect (const std::string &nodeFrom,
178 const std::string &outputLabel,
179 const std::string &nodeTo,
180 const std::string &inputLabel)
182 m_Fp << " e->Connect(\""<< nodeFrom << "\", \""
183 << outputLabel << "\", \""
184 << nodeTo << "\", \"" << inputLabel<< "\");" << std::endl;
188 void Transcriptor::Execute (const std::string &nodeName)
190 m_Fp << " e->Execute(\"" << nodeName << "\");" << std::endl;
193 void Transcriptor::DefineInput ( const std::string &name,
194 const std::string &box,
195 const std::string &input,
196 const std::string& help)
199 m_Fp << " e->DefineInput(\""<< name << "\", \"" << box << "\", \""
200 << input << "\", \"" << help << "\");" << std::endl;
204 void Transcriptor::DefineOutput ( const std::string &name,
205 const std::string &box,
206 const std::string &output,
207 const std::string& help)
209 m_Fp << " e->DefineOutput(\""<< name << "\", \"" << box << "\", \""
210 << output << "\", \"" << help << "\");" << std::endl;
214 void Transcriptor::Set (const std::string &box,
215 const std::string &input,
216 const std::string &value)
218 m_Fp << " e->Set(\""<< box << "\", \"" << input
219 << "\", \"" << value << "\");"
223 std::string Transcriptor::Get(const std::string &box,
224 const std::string &output)
227 m_Fp << " e->Get(\""<< box << "\", \"" << output << "\");"
233 void Transcriptor::Author(const std::string &authorName)
236 m_Fp << " e->Author(\"" << authorName << "\");" << std::endl;
239 void Transcriptor::Category(const std::string &category)
241 m_Fp << " e->Category(\"" << category << "\");" << std::endl;
244 void Transcriptor::Description(const std::string &d)
246 m_Fp << " e->Description(\"" << d << "\");" << std::endl;
249 /// prints the list of the boxes of the current descriptor
250 void Transcriptor::PrintBoxes()
252 m_Fp << " e->PrintBoxes( );" << std::endl;
255 std::string Transcriptor::ShowGraph(const std::string &nameblackbox,
256 const std::string &detailStr,
257 const std::string &levelStr,
258 const std::string &output_html,
259 const std::string &custom_header,
260 const std::string &custom_title,
261 bool system_display )
264 m_Fp << " e->ShowGraph(\"" << nameblackbox << "\", \""
265 << detailStr << "\", \""
266 << levelStr << "\", \""
267 << output_html << "\", \""
268 << custom_header << "\", \""
269 << custom_title << "\");"
275 std::string Transcriptor::ShowGraphInstances(const std::string &nameblackbox, int detail, int level,
282 void Transcriptor::ShowRelations(const std::string &nameblackbox, const std::string &detailStr, const std::string &levelStr)
287 void Transcriptor::Print(const std::string & message)
289 m_Fp << " e->Print(\"" <<message<<"\");"<<std::endl;
294 void Transcriptor::SetMessageLevel(const std::string &kind,
297 m_Fp << " e->SetMessageLevel(\"" <<kind<<"\","<<level<<");"<<std::endl;
301 void Transcriptor::HelpMessages()
303 m_Fp << " e->HelpMessages();"<<std::endl;
306 void Transcriptor::LoadPackage(const std::string &name )
308 m_Fp << " e->LoadPackage(\"" <<name<<"\");"<<std::endl;
312 void Transcriptor::UnLoadPackage(const std::string &name )
314 m_Fp << " e->UnLoadPackage(\"" <<name<<"\");"<<std::endl;