1 /*=========================================================================
3 Module: $RCSfile: bbtkTranscriptor.cxx,v $
5 Date: $Date: 2008/10/17 08:18:14 $
6 Version: $Revision: 1.14 $
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::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::~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::SetWorkspaceName( const std::string& name )
144 m_Fp << " e->SetWorkspaceName( \"" << name << "\" );" << std::endl;
147 void Transcriptor::BeginPackage (const std::string &name)
149 m_Fp << " e->BeginPackage( \"" << name << "\" );" << std::endl;
152 void Transcriptor::EndPackage()
154 m_Fp << " e->EndPackage( );" << std::endl;
157 void Transcriptor::Define (const std::string &name,
158 const std::string &pack,
159 const std::string &scriptfilename)
161 m_Fp << " e->Define(\"" << name << "\", \"" << pack << "\", \""
162 << scriptfilename << "\" );" << std::endl;
165 void Transcriptor::SetCurrentFileName (const std::string &name )
167 m_Fp << " e->SetCurrentFileName( \"" << name << "\" );" << std::endl;
170 void Transcriptor::EndDefine ()
172 m_Fp << " e->EndDefine( );" << std::endl;
175 void Transcriptor::Kind(const std::string& kind)
177 m_Fp << " e->Kind( \""<<kind<<"\" );" << std::endl;
181 void Transcriptor::Create ( const std::string& nodeType,
182 const std::string& nodeName)
184 m_Fp << " e->Create(\"" << nodeType << "\", \""
185 << nodeName << "\");" << std::endl;
189 void Transcriptor::Destroy (const std::string &nodeName)
191 m_Fp << " e->Destroy(" << nodeName << ");" << std::endl;
194 void Transcriptor::Connect (const std::string &nodeFrom,
195 const std::string &outputLabel,
196 const std::string &nodeTo,
197 const std::string &inputLabel)
199 m_Fp << " e->Connect(\""<< nodeFrom << "\", \""
200 << outputLabel << "\", \""
201 << nodeTo << "\", \"" << inputLabel<< "\");" << std::endl;
205 void Transcriptor::Execute (const std::string &nodeName)
207 m_Fp << " e->Execute(\"" << nodeName << "\");" << std::endl;
210 void Transcriptor::DefineInput ( const std::string &name,
211 const std::string &box,
212 const std::string &input,
213 const std::string& help)
216 m_Fp << " e->DefineInput(\""<< name << "\", \"" << box << "\", \""
217 << input << "\", \"" << help << "\");" << std::endl;
221 void Transcriptor::DefineOutput ( const std::string &name,
222 const std::string &box,
223 const std::string &output,
224 const std::string& help)
226 m_Fp << " e->DefineOutput(\""<< name << "\", \"" << box << "\", \""
227 << output << "\", \"" << help << "\");" << std::endl;
231 void Transcriptor::Set (const std::string &box,
232 const std::string &input,
233 const std::string &value)
235 m_Fp << " e->Set(\""<< box << "\", \"" << input
236 << "\", \"" << value << "\");"
240 std::string Transcriptor::Get(const std::string &box,
241 const std::string &output)
244 m_Fp << " e->Get(\""<< box << "\", \"" << output << "\");"
250 void Transcriptor::Author(const std::string &authorName)
253 m_Fp << " e->Author(\"" << authorName << "\");" << std::endl;
256 void Transcriptor::Category(const std::string &category)
258 m_Fp << " e->Category(\"" << category << "\");" << std::endl;
261 void Transcriptor::Description(const std::string &d)
263 m_Fp << " e->Description(\"" << d << "\");" << std::endl;
266 /// prints the list of the boxes of the current descriptor
267 void Transcriptor::PrintBoxes()
269 m_Fp << " e->PrintBoxes( );" << std::endl;
272 std::string Transcriptor::ShowGraph(const std::string &nameblackbox,
273 const std::string &detailStr,
274 const std::string &levelStr,
275 const std::string &output_html,
276 const std::string &custom_header,
277 const std::string &custom_title,
278 bool system_display )
281 m_Fp << " e->ShowGraph(\"" << nameblackbox << "\", \""
282 << detailStr << "\", \""
283 << levelStr << "\", \""
284 << output_html << "\", \""
285 << custom_header << "\", \""
286 << custom_title << "\");"
292 std::string Transcriptor::ShowGraphInstances(const std::string &nameblackbox, int detail, int level,
299 void Transcriptor::ShowRelations(const std::string &nameblackbox, const std::string &detailStr, const std::string &levelStr)
304 void Transcriptor::Print(const std::string & message)
306 m_Fp << " e->Print(\"" <<message<<"\");"<<std::endl;
311 void Transcriptor::SetMessageLevel(const std::string &kind,
314 m_Fp << " e->SetMessageLevel(\"" <<kind<<"\","<<level<<");"<<std::endl;
318 void Transcriptor::HelpMessages()
320 m_Fp << " e->HelpMessages();"<<std::endl;
323 void Transcriptor::LoadPackage(const std::string &name )
325 m_Fp << " e->LoadPackage(\"" <<name<<"\");"<<std::endl;
329 void Transcriptor::UnLoadPackage(const std::string &name )
331 m_Fp << " e->UnLoadPackage(\"" <<name<<"\");"<<std::endl;
334 //==========================================================================
335 std::string Transcriptor::GetObjectName() const
337 return std::string("Transcriptor");
339 //==========================================================================
341 //==========================================================================
342 std::string Transcriptor::GetObjectInfo() const
347 //==========================================================================
349 //==========================================================================
350 size_t Transcriptor::GetObjectSize() const
352 size_t s = Superclass::GetObjectSize();
353 s += Transcriptor::GetObjectInternalSize();
356 //==========================================================================
357 //==========================================================================
358 size_t Transcriptor::GetObjectInternalSize() const
360 size_t s = sizeof(Transcriptor);
363 //==========================================================================
364 //==========================================================================
365 size_t Transcriptor::GetObjectRecursiveSize() const
367 size_t s = Superclass::GetObjectRecursiveSize();
368 s += Transcriptor::GetObjectInternalSize();
371 //==========================================================================