bbtkTranscriptor.cxx

Go to the documentation of this file.
00001 /*=========================================================================                                                                               
00002   Program:   bbtk
00003   Module:    $RCSfile: bbtkTranscriptor.cxx,v $
00004   Language:  C++
00005   Date:      $Date: 2009/06/08 14:50:04 $
00006   Version:   $Revision: 1.17 $
00007 =========================================================================*/
00008 
00009 /* ---------------------------------------------------------------------
00010 
00011 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
00012 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
00013 *
00014 *  This software is governed by the CeCILL-B license under French law and 
00015 *  abiding by the rules of distribution of free software. You can  use, 
00016 *  modify and/ or redistribute the software under the terms of the CeCILL-B 
00017 *  license as circulated by CEA, CNRS and INRIA at the following URL 
00018 *  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html 
00019 *  or in the file LICENSE.txt.
00020 *
00021 *  As a counterpart to the access to the source code and  rights to copy,
00022 *  modify and redistribute granted by the license, users are provided only
00023 *  with a limited warranty  and the software's author,  the holder of the
00024 *  economic rights,  and the successive licensors  have only  limited
00025 *  liability. 
00026 *
00027 *  The fact that you are presently reading this means that you have had
00028 *  knowledge of the CeCILL-B license and that you accept its terms.
00029 * ------------------------------------------------------------------------ */                                                                         
00030 
00036 #include "bbtkTranscriptor.h"
00037 #include "bbtkMessageManager.h"
00038 #include "bbtkFactory.h"
00039 #include "bbtkUtilities.h"
00040 #include <fstream>
00041 
00042 //#ifdef _USE_WXWIDGETS_
00043 //#include <wx/textdlg.h>
00044 //#endif
00045 
00046 //#include "bbtkWxBlackBox.h"
00047 
00048 #include "bbtkConfigurationFile.h"
00049 
00050 namespace bbtk
00051 {
00052   Transcriptor::Pointer Transcriptor::New(const std::string& filename)
00053   {
00054     return MakePointer(new Transcriptor(filename));
00055   }
00056 
00060   Transcriptor::Transcriptor(const std::string& filename)
00061     :
00062       mDialogMode(NoDialog)
00063   {
00064     //VirtualExec();    
00065     bbtkDebugMessageInc("kernel",9,"Transcriptor()" <<std::endl);
00066  
00067      //std::ofstream *m_Fp = new std::ofstream();
00068     m_Fp.open (filename.c_str(), std::ios::out );
00069 
00070     std::string file,path;
00071     file = bbtk::Utilities::ExtractScriptName(filename,path);
00072     
00073     m_Fp << "#include \"bbtkExecuter.h\"" << std::endl; 
00074     m_Fp << "void " << file << "(bbtk::Executer::Pointer e)"<<std::endl;
00075     m_Fp << "{"<<std::endl;
00076 
00077     /*
00078 #ifdef _USE_WXWIDGETS_
00079     m_Fp << "#ifdef _USE_WXWIDGETS_"<<std::endl;
00080     m_Fp << "#include \"bbtkWx.h\""<< std::endl<<std::endl;
00081     m_Fp << "class myApp : public wxApp"<<std::endl;
00082     m_Fp << "{"<<std::endl;
00083     m_Fp << "public:"<<std::endl;
00084     m_Fp << "  bool OnInit( );"<<std::endl;
00085     m_Fp << "  int  OnExit() { delete e; return true; }"<<std::endl;
00086     m_Fp << "  bbtk::Executer* e;"<<std::endl;
00087     m_Fp << "};"<<std::endl<<std::endl;
00088     m_Fp << "IMPLEMENT_APP(myApp);"<<std::endl<<std::endl;
00089     m_Fp << "bool myApp::OnInit( )"<<std::endl;
00090     m_Fp << "{"<<std::endl;
00091     m_Fp << "  wxApp::OnInit();"<<std::endl;
00092     m_Fp << "#ifdef __WXGTK__"<<std::endl;
00093     m_Fp << "  //See http://www.wxwindows.org/faqgtk.htm#locale"<<std::endl;
00094     m_Fp << "  setlocale(LC_NUMERIC, \"C\");"<<std::endl;
00095     m_Fp << "#endif"<<std::endl;
00096     m_Fp << "  wxInitAllImageHandlers();"<<std::endl;
00097     m_Fp << "  bbtk::Wx::CreateInvisibleTopWindow();"<<std::endl;
00098     m_Fp << "  try {"<<std::endl;
00099     m_Fp << "  e = new bbtk::Executer();"<<std::endl;
00100 #else
00101     m_Fp << "main(int argc, char *argv[]) {"                << std::endl;
00102     m_Fp << "  bbtk::Executer *e = new bbtk::Executer();"   << std::endl;
00103 #endif 
00104     */
00105     bbtkDebugDecTab("kernel",9);
00106  }
00107 
00111   Transcriptor::~Transcriptor()
00112   {
00113   
00114     bbtkDebugMessageInc("kernel",9,"~Transcriptor()" <<std::endl);
00115     /*
00116 #ifdef _USE_WXWIDGETS_
00117     m_Fp << "  }"<<std::endl;
00118     m_Fp << "  catch (bbtk::Exception err)"<<std::endl;
00119     m_Fp << "  {"<<std::endl;
00120     m_Fp << "    err.Print();"<<std::endl;
00121     m_Fp << "  } "<<std::endl;
00122     m_Fp << "  return true;"<<std::endl;
00123     m_Fp << "}"   << std::endl;
00124     m_Fp << "#endif"<<std::endl;
00125 #else 
00126     m_Fp << "}"   << std::endl;
00127 #endif
00128     */
00129     m_Fp << "}"   << std::endl;
00130     m_Fp.close();
00131 
00132     bbtkDebugDecTab("kernel",9);
00133   }
00134   
00135 
00136   void Transcriptor::Reset()
00137   {
00138      m_Fp << "  e->Reset( );" << std::endl;
00139   }
00140 
00141   void Transcriptor::Clear()
00142   {
00143      m_Fp << "  e->Clear( );" << std::endl;
00144   }
00145 
00146   void Transcriptor::SetWorkspaceName( const std::string& name )
00147   {
00148   
00149     m_Fp << "  e->SetWorkspaceName( \"" << name << "\" );" << std::endl;
00150   }
00151 
00152   void Transcriptor::BeginPackage (const std::string &name)
00153   {
00154      m_Fp << "  e->BeginPackage( \"" << name << "\" );" << std::endl;
00155   }
00156 
00157   void Transcriptor::EndPackage()
00158   {
00159      m_Fp << "  e->EndPackage( );" << std::endl;
00160   }
00161 
00162   void Transcriptor::Define (const std::string &name,
00163                              const std::string &pack,
00164                              const std::string &scriptfilename)
00165   {
00166      m_Fp << "  e->Define(\"" << name << "\", \"" <<  pack << "\", \""
00167           << scriptfilename  << "\" );" << std::endl;
00168   }
00169 
00170   void Transcriptor::SetCurrentFileName (const std::string &name )
00171   {
00172      m_Fp << "  e->SetCurrentFileName( \"" << name << "\" );" << std::endl;
00173   }
00174 
00175   void Transcriptor::EndDefine ()
00176   {
00177      m_Fp << "  e->EndDefine( );" << std::endl;
00178   }
00179 
00180   void Transcriptor::Kind(const std::string& kind)
00181   {
00182     m_Fp << "  e->Kind( \""<<kind<<"\" );" << std::endl;
00183   }
00184 
00185 
00186   void Transcriptor::Create ( const std::string& nodeType, 
00187                               const std::string& nodeName)
00188   {
00189     m_Fp << "  e->Create(\"" << nodeType << "\", \"" 
00190          <<  nodeName << "\");" << std::endl;
00191   }
00192 
00193 
00194   void Transcriptor::Destroy (const std::string &nodeName)
00195   {
00196     m_Fp << "  e->Destroy(" <<  nodeName << ");" << std::endl;
00197   }
00198 
00199   void Transcriptor::Connect (const std::string &nodeFrom,
00200                               const std::string &outputLabel,
00201                               const std::string &nodeTo, 
00202                               const std::string &inputLabel)
00203   {
00204     m_Fp << "  e->Connect(\""<< nodeFrom << "\", \"" 
00205          <<  outputLabel << "\", \""
00206          << nodeTo  << "\", \"" << inputLabel<< "\");" << std::endl;
00207   }
00208 
00209 
00210   void Transcriptor::Execute (const std::string &nodeName)
00211   {
00212      m_Fp << "  e->Execute(\"" << nodeName << "\");" << std::endl;
00213   }
00214 
00215   void Transcriptor::DefineInput ( const std::string &name,
00216                                    const std::string &box,
00217                                    const std::string &input,
00218                                    const std::string& help)
00219   {
00220   
00221     m_Fp << "  e->DefineInput(\""<< name << "\", \"" <<  box << "\", \""
00222          << input << "\", \"" << help << "\");" << std::endl;
00223   }
00224 
00225   
00226   void Transcriptor::DefineOutput ( const std::string &name,
00227                                     const std::string &box,
00228                                     const std::string &output,
00229                                     const std::string& help)
00230   {
00231     m_Fp << "  e->DefineOutput(\""<< name << "\", \"" <<  box << "\", \""
00232          << output << "\", \"" << help << "\");" << std::endl;
00233   }
00234 
00235  
00236   void Transcriptor::Set (const std::string &box,
00237                           const std::string &input,
00238                           const std::string &value)
00239   {
00240     m_Fp << "  e->Set(\""<< box << "\", \"" << input
00241          << "\", \"" << value << "\");"
00242          << std::endl;
00243   }
00244 
00245   std::string Transcriptor::Get(const std::string &box,
00246                                 const std::string &output)
00247   {
00248   
00249     m_Fp << "  e->Get(\""<< box << "\", \"" << output << "\");"
00250          << std::endl;
00251     return "";
00252   }
00253 
00254 
00255   void Transcriptor::Author(const std::string &authorName)
00256   {
00257     
00258     m_Fp << "  e->Author(\"" << authorName << "\");" << std::endl;
00259   }
00260 
00261   void Transcriptor::Category(const std::string &category)
00262   {
00263     m_Fp << "  e->Category(\"" << category << "\");" << std::endl;
00264   }
00265 
00266   void Transcriptor::Description(const std::string &d)
00267   {
00268     m_Fp << "  e->Description(\"" << d << "\");" << std::endl;
00269   }
00270 
00272   void Transcriptor::PrintHelpListBoxes()
00273   {
00274      m_Fp << "  e->PrintBoxes( );" << std::endl;
00275  }
00276 
00277   std::string Transcriptor::ShowGraph(const std::string &nameblackbox,
00278                                   const std::string &detailStr,
00279                                   const std::string &levelStr,
00280                                   const std::string &output_html,
00281                                   const std::string &custom_header,
00282                                   const std::string &custom_title,
00283                                   bool system_display )
00284   {
00285 
00286        m_Fp << "  e->ShowGraph(\"" << nameblackbox  << "\", \"" 
00287                                       << detailStr     << "\", \""
00288                                       << levelStr      << "\", \""
00289                                       << output_html   << "\", \""
00290                                       << custom_header << "\", \""
00291                                       <<  custom_title << "\");"                                     
00292                                       << std::endl;
00293 
00294     return ""; 
00295   }
00296 
00297    std::string Transcriptor::ShowGraphInstances(const std::string &nameblackbox, int detail, int level,
00298                                                bool system_display)
00299   {
00300     return "";
00301   
00302   }
00303 
00304 void Transcriptor::PrintHelpBlackBox(const std::string &nameblackbox, const std::string &detailStr, const std::string &levelStr)
00305   {
00306      
00307   }
00308 
00309   void Transcriptor::Print(const std::string & message)
00310   {
00311     m_Fp << "  e->Print(\"" <<message<<"\");"<<std::endl;
00312   }
00313 
00314 
00315   
00316   void Transcriptor::SetMessageLevel(const std::string &kind,
00317                        int level)
00318   {
00319     m_Fp << "  e->SetMessageLevel(\"" <<kind<<"\","<<level<<");"<<std::endl;
00320   }
00321   
00322 
00323   void Transcriptor::HelpMessages()
00324   {
00325     m_Fp << "  e->HelpMessages();"<<std::endl;
00326   }
00327   
00328   void Transcriptor::LoadPackage(const std::string &name )
00329   {
00330     m_Fp << "  e->LoadPackage(\"" <<name<<"\");"<<std::endl;
00331   }
00332   
00333   
00334   void Transcriptor::UnLoadPackage(const std::string &name )
00335   {
00336     m_Fp << "  e->UnLoadPackage(\"" <<name<<"\");"<<std::endl;
00337   }
00338 
00339  //==========================================================================
00340   std::string Transcriptor::GetObjectName() const
00341   {
00342     return std::string("Transcriptor");
00343   }
00344   //==========================================================================
00345   
00346   //==========================================================================
00347   std::string  Transcriptor::GetObjectInfo() const 
00348   {
00349     std::stringstream i;
00350     return i.str();
00351   }
00352   //==========================================================================
00353 
00354  //==========================================================================
00355 size_t  Transcriptor::GetObjectSize() const 
00356 {
00357   size_t s = Superclass::GetObjectSize();
00358   s += Transcriptor::GetObjectInternalSize();
00359   return s;
00360   }
00361   //==========================================================================
00362   //==========================================================================
00363 size_t  Transcriptor::GetObjectInternalSize() const 
00364 {
00365   size_t s = sizeof(Transcriptor);
00366   return s;
00367   }
00368   //==========================================================================
00369   //==========================================================================
00370   size_t  Transcriptor::GetObjectRecursiveSize() const 
00371   {
00372     size_t s = Superclass::GetObjectRecursiveSize();
00373     s += Transcriptor::GetObjectInternalSize();
00374     return s;
00375   }
00376   //==========================================================================
00377 
00378 
00379 }//namespace

Generated on Thu May 31 14:12:03 2012 for BBTK by  doxygen 1.5.7.1