1 /*=========================================================================
3 Module: $RCSfile: bbtkTranscriptor.cxx,v $
5 Date: $Date: 2009/06/08 14:50:04 $
6 Version: $Revision: 1.17 $
7 =========================================================================*/
9 /* ---------------------------------------------------------------------
11 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
12 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
14 * This software is governed by the CeCILL-B license under French law and
15 * abiding by the rules of distribution of free software. You can use,
16 * modify and/ or redistribute the software under the terms of the CeCILL-B
17 * license as circulated by CEA, CNRS and INRIA at the following URL
18 * http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
19 * or in the file LICENSE.txt.
21 * As a counterpart to the access to the source code and rights to copy,
22 * modify and redistribute granted by the license, users are provided only
23 * with a limited warranty and the software's author, the holder of the
24 * economic rights, and the successive licensors have only limited
27 * The fact that you are presently reading this means that you have had
28 * knowledge of the CeCILL-B license and that you accept its terms.
29 * ------------------------------------------------------------------------ */
33 * \brief class Transcriptor: level 0 of script execution (code)
36 #include "bbtkTranscriptor.h"
37 #include "bbtkMessageManager.h"
38 #include "bbtkFactory.h"
39 #include "bbtkUtilities.h"
42 //#ifdef _USE_WXWIDGETS_
43 //#include <wx/textdlg.h>
46 //#include "bbtkWxBlackBox.h"
48 #include "bbtkConfigurationFile.h"
52 Transcriptor::Pointer Transcriptor::New(const std::string& filename)
54 return MakePointer(new Transcriptor(filename));
60 Transcriptor::Transcriptor(const std::string& filename)
65 bbtkDebugMessageInc("kernel",9,"Transcriptor()" <<std::endl);
67 //std::ofstream *m_Fp = new std::ofstream();
68 m_Fp.open (filename.c_str(), std::ios::out );
70 std::string file,path;
71 file = bbtk::Utilities::ExtractScriptName(filename,path);
73 m_Fp << "#include \"bbtkExecuter.h\"" << std::endl;
74 m_Fp << "void " << file << "(bbtk::Executer::Pointer e)"<<std::endl;
75 m_Fp << "{"<<std::endl;
78 #ifdef _USE_WXWIDGETS_
79 m_Fp << "#ifdef _USE_WXWIDGETS_"<<std::endl;
80 m_Fp << "#include \"bbtkWx.h\""<< std::endl<<std::endl;
81 m_Fp << "class myApp : public wxApp"<<std::endl;
82 m_Fp << "{"<<std::endl;
83 m_Fp << "public:"<<std::endl;
84 m_Fp << " bool OnInit( );"<<std::endl;
85 m_Fp << " int OnExit() { delete e; return true; }"<<std::endl;
86 m_Fp << " bbtk::Executer* e;"<<std::endl;
87 m_Fp << "};"<<std::endl<<std::endl;
88 m_Fp << "IMPLEMENT_APP(myApp);"<<std::endl<<std::endl;
89 m_Fp << "bool myApp::OnInit( )"<<std::endl;
90 m_Fp << "{"<<std::endl;
91 m_Fp << " wxApp::OnInit();"<<std::endl;
92 m_Fp << "#ifdef __WXGTK__"<<std::endl;
93 m_Fp << " //See http://www.wxwindows.org/faqgtk.htm#locale"<<std::endl;
94 m_Fp << " setlocale(LC_NUMERIC, \"C\");"<<std::endl;
95 m_Fp << "#endif"<<std::endl;
96 m_Fp << " wxInitAllImageHandlers();"<<std::endl;
97 m_Fp << " bbtk::Wx::CreateInvisibleTopWindow();"<<std::endl;
98 m_Fp << " try {"<<std::endl;
99 m_Fp << " e = new bbtk::Executer();"<<std::endl;
101 m_Fp << "main(int argc, char *argv[]) {" << std::endl;
102 m_Fp << " bbtk::Executer *e = new bbtk::Executer();" << std::endl;
105 bbtkDebugDecTab("kernel",9);
111 Transcriptor::~Transcriptor()
114 bbtkDebugMessageInc("kernel",9,"~Transcriptor()" <<std::endl);
116 #ifdef _USE_WXWIDGETS_
117 m_Fp << " }"<<std::endl;
118 m_Fp << " catch (bbtk::Exception err)"<<std::endl;
119 m_Fp << " {"<<std::endl;
120 m_Fp << " err.Print();"<<std::endl;
121 m_Fp << " } "<<std::endl;
122 m_Fp << " return true;"<<std::endl;
123 m_Fp << "}" << std::endl;
124 m_Fp << "#endif"<<std::endl;
126 m_Fp << "}" << std::endl;
129 m_Fp << "}" << std::endl;
132 bbtkDebugDecTab("kernel",9);
136 void Transcriptor::Reset()
138 m_Fp << " e->Reset( );" << std::endl;
141 void Transcriptor::Clear()
143 m_Fp << " e->Clear( );" << std::endl;
146 void Transcriptor::SetWorkspaceName( const std::string& name )
149 m_Fp << " e->SetWorkspaceName( \"" << name << "\" );" << std::endl;
152 void Transcriptor::BeginPackage (const std::string &name)
154 m_Fp << " e->BeginPackage( \"" << name << "\" );" << std::endl;
157 void Transcriptor::EndPackage()
159 m_Fp << " e->EndPackage( );" << std::endl;
162 void Transcriptor::Define (const std::string &name,
163 const std::string &pack,
164 const std::string &scriptfilename)
166 m_Fp << " e->Define(\"" << name << "\", \"" << pack << "\", \""
167 << scriptfilename << "\" );" << std::endl;
170 void Transcriptor::SetCurrentFileName (const std::string &name )
172 m_Fp << " e->SetCurrentFileName( \"" << name << "\" );" << std::endl;
175 void Transcriptor::EndDefine ()
177 m_Fp << " e->EndDefine( );" << std::endl;
180 void Transcriptor::Kind(const std::string& kind)
182 m_Fp << " e->Kind( \""<<kind<<"\" );" << std::endl;
186 void Transcriptor::Create ( const std::string& nodeType,
187 const std::string& nodeName)
189 m_Fp << " e->Create(\"" << nodeType << "\", \""
190 << nodeName << "\");" << std::endl;
194 void Transcriptor::Destroy (const std::string &nodeName)
196 m_Fp << " e->Destroy(" << nodeName << ");" << std::endl;
199 void Transcriptor::Connect (const std::string &nodeFrom,
200 const std::string &outputLabel,
201 const std::string &nodeTo,
202 const std::string &inputLabel)
204 m_Fp << " e->Connect(\""<< nodeFrom << "\", \""
205 << outputLabel << "\", \""
206 << nodeTo << "\", \"" << inputLabel<< "\");" << std::endl;
210 void Transcriptor::Execute (const std::string &nodeName)
212 m_Fp << " e->Execute(\"" << nodeName << "\");" << std::endl;
215 void Transcriptor::DefineInput ( const std::string &name,
216 const std::string &box,
217 const std::string &input,
218 const std::string& help)
221 m_Fp << " e->DefineInput(\""<< name << "\", \"" << box << "\", \""
222 << input << "\", \"" << help << "\");" << std::endl;
226 void Transcriptor::DefineOutput ( const std::string &name,
227 const std::string &box,
228 const std::string &output,
229 const std::string& help)
231 m_Fp << " e->DefineOutput(\""<< name << "\", \"" << box << "\", \""
232 << output << "\", \"" << help << "\");" << std::endl;
236 void Transcriptor::Set (const std::string &box,
237 const std::string &input,
238 const std::string &value)
240 m_Fp << " e->Set(\""<< box << "\", \"" << input
241 << "\", \"" << value << "\");"
245 std::string Transcriptor::Get(const std::string &box,
246 const std::string &output)
249 m_Fp << " e->Get(\""<< box << "\", \"" << output << "\");"
255 void Transcriptor::Author(const std::string &authorName)
258 m_Fp << " e->Author(\"" << authorName << "\");" << std::endl;
261 void Transcriptor::Category(const std::string &category)
263 m_Fp << " e->Category(\"" << category << "\");" << std::endl;
266 void Transcriptor::Description(const std::string &d)
268 m_Fp << " e->Description(\"" << d << "\");" << std::endl;
271 /// prints the list of the boxes of the current descriptor
272 void Transcriptor::PrintHelpListBoxes()
274 m_Fp << " e->PrintBoxes( );" << std::endl;
277 std::string Transcriptor::ShowGraph(const std::string &nameblackbox,
278 const std::string &detailStr,
279 const std::string &levelStr,
280 const std::string &output_html,
281 const std::string &custom_header,
282 const std::string &custom_title,
283 bool system_display )
286 m_Fp << " e->ShowGraph(\"" << nameblackbox << "\", \""
287 << detailStr << "\", \""
288 << levelStr << "\", \""
289 << output_html << "\", \""
290 << custom_header << "\", \""
291 << custom_title << "\");"
297 std::string Transcriptor::ShowGraphInstances(const std::string &nameblackbox, int detail, int level,
304 void Transcriptor::PrintHelpBlackBox(const std::string &nameblackbox, const std::string &detailStr, const std::string &levelStr)
309 void Transcriptor::Print(const std::string & message)
311 m_Fp << " e->Print(\"" <<message<<"\");"<<std::endl;
316 void Transcriptor::SetMessageLevel(const std::string &kind,
319 m_Fp << " e->SetMessageLevel(\"" <<kind<<"\","<<level<<");"<<std::endl;
323 void Transcriptor::HelpMessages()
325 m_Fp << " e->HelpMessages();"<<std::endl;
328 void Transcriptor::LoadPackage(const std::string &name )
330 m_Fp << " e->LoadPackage(\"" <<name<<"\");"<<std::endl;
334 void Transcriptor::UnLoadPackage(const std::string &name )
336 m_Fp << " e->UnLoadPackage(\"" <<name<<"\");"<<std::endl;
339 //==========================================================================
340 std::string Transcriptor::GetObjectName() const
342 return std::string("Transcriptor");
344 //==========================================================================
346 //==========================================================================
347 std::string Transcriptor::GetObjectInfo() const
352 //==========================================================================
354 //==========================================================================
355 size_t Transcriptor::GetObjectSize() const
357 size_t s = Superclass::GetObjectSize();
358 s += Transcriptor::GetObjectInternalSize();
361 //==========================================================================
362 //==========================================================================
363 size_t Transcriptor::GetObjectInternalSize() const
365 size_t s = sizeof(Transcriptor);
368 //==========================================================================
369 //==========================================================================
370 size_t Transcriptor::GetObjectRecursiveSize() const
372 size_t s = Superclass::GetObjectRecursiveSize();
373 s += Transcriptor::GetObjectInternalSize();
376 //==========================================================================