2 # ---------------------------------------------------------------------
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
10 # This software is governed by the CeCILL-B license under French law and
11 # abiding by the rules of distribution of free software. You can use,
12 # modify and/ or redistribute the software under the terms of the CeCILL-B
13 # license as circulated by CEA, CNRS and INRIA at the following URL
14 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
15 # or in the file LICENSE.txt.
17 # As a counterpart to the access to the source code and rights to copy,
18 # modify and redistribute granted by the license, users are provided only
19 # with a limited warranty and the software's author, the holder of the
20 # economic rights, and the successive licensors have only limited
23 # The fact that you are presently reading this means that you have had
24 # knowledge of the CeCILL-B license and that you accept its terms.
25 # ------------------------------------------------------------------------ */
28 /*=========================================================================
30 Module: $RCSfile: bbtkTranscriptor.cxx,v $
32 Date: $Date: 2012/11/16 08:49:01 $
33 Version: $Revision: 1.19 $
34 =========================================================================*/
40 * \brief class Transcriptor: level 0 of script execution (code)
43 #include "bbtkTranscriptor.h"
44 #include "bbtkMessageManager.h"
45 #include "bbtkFactory.h"
46 #include "bbtkUtilities.h"
49 //#ifdef _USE_WXWIDGETS_
50 //#include <wx/textdlg.h>
53 //#include "bbtkWxBlackBox.h"
55 #include "bbtkConfigurationFile.h"
59 Transcriptor::Pointer Transcriptor::New(const std::string& filename)
61 return MakePointer(new Transcriptor(filename));
67 Transcriptor::Transcriptor(const std::string& filename)
72 bbtkDebugMessageInc("kernel",9,"Transcriptor()" <<std::endl);
74 //std::ofstream *m_Fp = new std::ofstream();
75 m_Fp.open (filename.c_str(), std::ios::out );
77 std::string file,path;
78 file = bbtk::Utilities::ExtractScriptName(filename,path);
80 m_Fp << "#include \"bbtkExecuter.h\"" << std::endl;
81 m_Fp << "void " << file << "(bbtk::Executer::Pointer e)"<<std::endl;
82 m_Fp << "{"<<std::endl;
85 #ifdef _USE_WXWIDGETS_
86 m_Fp << "#ifdef _USE_WXWIDGETS_"<<std::endl;
87 m_Fp << "#include \"bbtkWx.h\""<< std::endl<<std::endl;
88 m_Fp << "class myApp : public wxApp"<<std::endl;
89 m_Fp << "{"<<std::endl;
90 m_Fp << "public:"<<std::endl;
91 m_Fp << " bool OnInit( );"<<std::endl;
92 m_Fp << " int OnExit() { delete e; return true; }"<<std::endl;
93 m_Fp << " bbtk::Executer* e;"<<std::endl;
94 m_Fp << "};"<<std::endl<<std::endl;
95 m_Fp << "IMPLEMENT_APP(myApp);"<<std::endl<<std::endl;
96 m_Fp << "bool myApp::OnInit( )"<<std::endl;
97 m_Fp << "{"<<std::endl;
98 m_Fp << " wxApp::OnInit();"<<std::endl;
99 m_Fp << "#ifdef __WXGTK__"<<std::endl;
100 m_Fp << " //See http://www.wxwindows.org/faqgtk.htm#locale"<<std::endl;
101 m_Fp << " setlocale(LC_NUMERIC, \"C\");"<<std::endl;
102 m_Fp << "#endif"<<std::endl;
103 m_Fp << " wxInitAllImageHandlers();"<<std::endl;
104 m_Fp << " bbtk::Wx::CreateInvisibleTopWindow();"<<std::endl;
105 m_Fp << " try {"<<std::endl;
106 m_Fp << " e = new bbtk::Executer();"<<std::endl;
108 m_Fp << "main(int argc, char *argv[]) {" << std::endl;
109 m_Fp << " bbtk::Executer *e = new bbtk::Executer();" << std::endl;
112 bbtkDebugDecTab("kernel",9);
118 Transcriptor::~Transcriptor()
121 bbtkDebugMessageInc("kernel",9,"~Transcriptor()" <<std::endl);
123 #ifdef _USE_WXWIDGETS_
124 m_Fp << " }"<<std::endl;
125 m_Fp << " catch (bbtk::Exception err)"<<std::endl;
126 m_Fp << " {"<<std::endl;
127 m_Fp << " err.Print();"<<std::endl;
128 m_Fp << " } "<<std::endl;
129 m_Fp << " return true;"<<std::endl;
130 m_Fp << "}" << std::endl;
131 m_Fp << "#endif"<<std::endl;
133 m_Fp << "}" << std::endl;
136 m_Fp << "}" << std::endl;
139 bbtkDebugDecTab("kernel",9);
143 void Transcriptor::Reset()
145 m_Fp << " e->Reset( );" << std::endl;
148 void Transcriptor::Clear()
150 m_Fp << " e->Clear( );" << std::endl;
153 void Transcriptor::SetWorkspaceName( const std::string& name )
156 m_Fp << " e->SetWorkspaceName( \"" << name << "\" );" << std::endl;
159 void Transcriptor::BeginPackage (const std::string &name)
161 m_Fp << " e->BeginPackage( \"" << name << "\" );" << std::endl;
164 void Transcriptor::EndPackage()
166 m_Fp << " e->EndPackage( );" << std::endl;
169 void Transcriptor::Define (const std::string &name,
170 const std::string &pack,
171 const std::string &scriptfilename)
173 m_Fp << " e->Define(\"" << name << "\", \"" << pack << "\", \""
174 << scriptfilename << "\" );" << std::endl;
177 void Transcriptor::SetCurrentFileName (const std::string &name )
179 m_Fp << " e->SetCurrentFileName( \"" << name << "\" );" << std::endl;
182 void Transcriptor::EndDefine ()
184 m_Fp << " e->EndDefine( );" << std::endl;
187 void Transcriptor::Kind(const std::string& kind)
189 m_Fp << " e->Kind( \""<<kind<<"\" );" << std::endl;
193 void Transcriptor::Create ( const std::string& nodeType,
194 const std::string& nodeName)
196 m_Fp << " e->Create(\"" << nodeType << "\", \""
197 << nodeName << "\");" << std::endl;
201 void Transcriptor::Destroy (const std::string &nodeName)
203 m_Fp << " e->Destroy(" << nodeName << ");" << std::endl;
206 void Transcriptor::Connect (const std::string &nodeFrom,
207 const std::string &outputLabel,
208 const std::string &nodeTo,
209 const std::string &inputLabel)
211 m_Fp << " e->Connect(\""<< nodeFrom << "\", \""
212 << outputLabel << "\", \""
213 << nodeTo << "\", \"" << inputLabel<< "\");" << std::endl;
217 void Transcriptor::Execute (const std::string &nodeName)
219 m_Fp << " e->Execute(\"" << nodeName << "\");" << std::endl;
222 void Transcriptor::DefineInput ( const std::string &name,
223 const std::string &box,
224 const std::string &input,
225 const std::string& help)
228 m_Fp << " e->DefineInput(\""<< name << "\", \"" << box << "\", \""
229 << input << "\", \"" << help << "\");" << std::endl;
233 void Transcriptor::DefineOutput ( const std::string &name,
234 const std::string &box,
235 const std::string &output,
236 const std::string& help)
238 m_Fp << " e->DefineOutput(\""<< name << "\", \"" << box << "\", \""
239 << output << "\", \"" << help << "\");" << std::endl;
243 void Transcriptor::Set (const std::string &box,
244 const std::string &input,
245 const std::string &value)
247 m_Fp << " e->Set(\""<< box << "\", \"" << input
248 << "\", \"" << value << "\");"
252 std::string Transcriptor::Get(const std::string &box,
253 const std::string &output)
256 m_Fp << " e->Get(\""<< box << "\", \"" << output << "\");"
262 void Transcriptor::Author(const std::string &authorName)
265 m_Fp << " e->Author(\"" << authorName << "\");" << std::endl;
268 void Transcriptor::Category(const std::string &category)
270 m_Fp << " e->Category(\"" << category << "\");" << std::endl;
273 void Transcriptor::Description(const std::string &d)
275 m_Fp << " e->Description(\"" << d << "\");" << std::endl;
278 /// prints the list of the boxes of the current descriptor
279 void Transcriptor::PrintHelpListBoxes()
281 m_Fp << " e->PrintBoxes( );" << std::endl;
284 std::string Transcriptor::ShowGraph(const std::string &nameblackbox,
285 const std::string &detailStr,
286 const std::string &levelStr,
287 const std::string &output_html,
288 const std::string &custom_header,
289 const std::string &custom_title,
290 bool system_display )
293 m_Fp << " e->ShowGraph(\"" << nameblackbox << "\", \""
294 << detailStr << "\", \""
295 << levelStr << "\", \""
296 << output_html << "\", \""
297 << custom_header << "\", \""
298 << custom_title << "\");"
304 std::string Transcriptor::ShowGraphInstances(const std::string &nameblackbox, int detail, int level,
311 void Transcriptor::PrintHelpBlackBox(const std::string &nameblackbox, const std::string &detailStr, const std::string &levelStr)
316 void Transcriptor::Print(const std::string & message)
318 m_Fp << " e->Print(\"" <<message<<"\");"<<std::endl;
323 void Transcriptor::SetMessageLevel(const std::string &kind,
326 m_Fp << " e->SetMessageLevel(\"" <<kind<<"\","<<level<<");"<<std::endl;
330 void Transcriptor::HelpMessages()
332 m_Fp << " e->HelpMessages();"<<std::endl;
335 void Transcriptor::LoadPackage(const std::string &name )
337 m_Fp << " e->LoadPackage(\"" <<name<<"\");"<<std::endl;
341 void Transcriptor::UnLoadPackage(const std::string &name )
343 m_Fp << " e->UnLoadPackage(\"" <<name<<"\");"<<std::endl;
346 //==========================================================================
347 std::string Transcriptor::GetObjectName() const
349 return std::string("Transcriptor");
351 //==========================================================================
353 //==========================================================================
354 std::string Transcriptor::GetObjectInfo() const
359 //==========================================================================
361 //==========================================================================
362 size_t Transcriptor::GetObjectSize() const
364 size_t s = Superclass::GetObjectSize();
365 s += Transcriptor::GetObjectInternalSize();
368 //==========================================================================
369 //==========================================================================
370 size_t Transcriptor::GetObjectInternalSize() const
372 size_t s = sizeof(Transcriptor);
375 //==========================================================================
376 //==========================================================================
377 size_t Transcriptor::GetObjectRecursiveSize() const
379 size_t s = Superclass::GetObjectRecursiveSize();
380 s += Transcriptor::GetObjectInternalSize();
383 //==========================================================================
386 //==========================================================================
387 void Transcriptor::SetTypeOfScript_Application()
390 //==========================================================================