]> Creatis software - bbtk.git/blobdiff - kernel/src/bbtkTranscriptor.cxx
Windows compilation
[bbtk.git] / kernel / src / bbtkTranscriptor.cxx
index 48fffe21e9617add10a461884607ef4f0406b558..0609b5fb065e01d34a41f00a964f0f177436a93b 100644 (file)
@@ -3,8 +3,8 @@
   Program:   bbtk
   Module:    $RCSfile: bbtkTranscriptor.cxx,v $ $
   Language:  C++
-  Date:      $Date: 2008/02/14 13:53:01 $
-  Version:   $Revision: 1.3 $
+  Date:      $Date: 2008/02/18 10:41:02 $
+  Version:   $Revision: 1.6 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -49,27 +49,29 @@ namespace bbtk
     bbtkDebugMessageInc("Kernel",9,"Transcriptor::Transcriptor()" <<std::endl);
     Reset();
     bbtkDebugDecTab("Kernel",9);
-    
+
     //std::ofstream *m_Fp = new std::ofstream();
     m_Fp.open (filename.c_str(), std::ios::out );
 
     m_Fp << "#include \"bbtkExecuter.h\""                   << std::endl;
     m_Fp << "main(int argc, char *argv[]) {"                << std::endl;
     m_Fp << "  bbtk::Executer *e = new bbtk::Executer();"   << std::endl;
-  } 
+  }
 
 /**
  *
  */
   Transcriptor::~Transcriptor()
   {
+  
+std::cout << "====================================================== delete Transcriptor\n";
      bbtkDebugMessageInc("Kernel",9,"Transcriptor::~Transcriptor()" <<std::endl);
      if (mRoot) 
      {
         mPackage->UnRegisterBlackBox("workspace");
-        delete mRoot;    
+        delete mRoot;
      }
-     if (mPackage) 
+     if (mPackage)
      {
         GetGlobalFactory()->UnLoadPackage("user");
      }
@@ -84,16 +86,16 @@ namespace bbtk
   }
 
 
-// ========================= Begin of Battelfield ========================================================================
+// ========================= Begin of Battlefield ========================================================================
 
 
 /**
- *  
+ *
  */
   void Transcriptor::Reset()
   {
+     m_Fp << "  e->Reset( );" << std::endl;
 
-     m_Fp << "e->Reset( );" << std::endl;
   /*
     bbtkDebugMessageInc("Kernel",9,"Transcriptor::Reset()" <<std::endl);
 
@@ -103,12 +105,12 @@ namespace bbtk
     // all user defined CBB otherwise any instance 
     // of a user CBB that is in the 'workspace' would try to 
     // access a user CBB descriptor which has been previously freed
-    if (mRoot) 
+    if (mRoot)
     {
        mPackage->UnRegisterBlackBox(mRoot->GetTypeName());
-       delete mRoot;    
+       delete mRoot;
     }
-    if (mPackage) 
+    if (mPackage)
     {
        GetGlobalFactory()->UnLoadPackage("user");
     }
@@ -133,32 +135,33 @@ namespace bbtk
   }
 
   /// changes the workspace name
-  void Transcriptor::SetWorkspaceName( const std::string& n )
+  void Transcriptor::SetWorkspaceName( const std::string& name )
   {
   
-     m_Fp << "// ==> SetWorkspaceName() called here" << std::endl;    
-   // mPackage->ChangeBlackBoxName( mRoot->GetTypeName(), n );
+     m_Fp << "  e->SetWorkspaceName( \"" << name << "\" );" << std::endl;
+
+   // mPackage->ChangeBlackBoxName( mRoot->GetTypeName(), name );
   }
 
   void Transcriptor::BeginPackage (const std::string &name)
   {
-     m_Fp << "// ==> BeginPackage() called here" << std::endl;  
+     m_Fp << "  e->BeginPackage( \"" << name << "\" );" << std::endl;
   /*
      bbtkDebugMessageInc("Kernel",9,"Executer::BeginPackage(\""<<name<<"\")"
                         <<std::endl);
      Package* p;
      try 
       {
-       p = GetGlobalFactory()->GetPackage(name);
+         p = GetGlobalFactory()->GetPackage(name);
       }
     catch (Exception e)
       {
-       p = new Package(name,
-                       "",
-                       "",
-                       "",
-                       BBTK_STRINGIFY_SYMBOL(BBTK_VERSION));
-       InsertPackage(p);
+         p = new Package(name,
+                         "",
+                         "",
+                         "",
+                         BBTK_STRINGIFY_SYMBOL(BBTK_VERSION));
+         InsertPackage(p);
       }
      mOpenPackage.push_back(p);
  */
@@ -166,18 +169,19 @@ namespace bbtk
 
   void Transcriptor::EndPackage()
   {
-     m_Fp << "// ==> EndPackage() called here" << std::endl;    
+     m_Fp << "  e->EndPackage( );" << std::endl;
    // if (mOpenPackage.size()>1) mOpenPackage.pop_back();
   }
 
   void Transcriptor::Define (const std::string &name,
-                        const std::string &pack,
-                        const std::string &scriptfilename)
+                             const std::string &pack,
+                             const std::string &scriptfilename)
   {
-     m_Fp << "// on Define, Define() called here" << std::endl;   
+     m_Fp << "  e->Define(\"" << name << "\", \"" <<  pack << "\", \""
+          << scriptfilename  << "\" );" << std::endl;
   /*
     bbtkDebugMessageInc("Kernel",9,"Executer::Define(\""<<name<<
-                       ","<<pack<<"\")" 
+                        ","<<pack<<"\")"
                         <<std::endl);
 
     ComplexBlackBoxDescriptor* b = new ComplexBlackBoxDescriptor(name);
@@ -191,15 +195,14 @@ namespace bbtk
   /// Sets the file name to use for the current definition
   /// (Used to set it after the Define command)
   void Transcriptor::SetCurrentFileName (const std::string &name )
-  
   {
-    m_Fp << "// ==>on Include : SetCurrentFileName( ) called here" << std::endl;
+     m_Fp << "  e->SetCurrentFileName( \"" << name << "\" );" << std::endl;
    // mOpenDefinition.back().box->SetScriptFileName(name);
   }
 
   void Transcriptor::EndDefine ()
   {
-    m_Fp << "// ==> on EndDefine, EndDefine( ); called here " << std::endl;
+     m_Fp << "  e->EndDefine( );" << std::endl;
 
   /*
     bbtkDebugMessageInc("Kernel",9,"Executer::EndDefine(\""
@@ -212,7 +215,7 @@ namespace bbtk
     {
       try
       {
-           p = GetGlobalFactory()->GetPackage(pname);
+         p = GetGlobalFactory()->GetPackage(pname);
       }
       catch (Exception e)
       {
@@ -226,7 +229,7 @@ namespace bbtk
     }
     else
     {
-          p = mOpenPackage.back();
+       p = mOpenPackage.back();
     }
     p->RegisterBlackBox(Current());
 
@@ -240,7 +243,7 @@ namespace bbtk
                               const std::string& nodeName)
   {
     // Current()->Add(nodeType,nodeName);\"
-     m_Fp << "e->Add(\"" << nodeType << "\", \"" <<  nodeName << "\");" << std::endl;
+     m_Fp << "  e->Add(\"" << nodeType << "\", \"" <<  nodeName << "\");" << std::endl;
   }
 
 
@@ -249,61 +252,59 @@ namespace bbtk
   {
     /// \todo Remove
     // Current()->RemoveBlackBox(nodeName);
-    //  m_Fp << "e->Remove(" <<  nodeName << ");" << std::endl;
+    //  m_Fp << "  e->Remove(" <<  nodeName << ");" << std::endl;
   }
-  */ 
+  */
 
 /**
- *  
+ *
  */
-  void Transcriptor::Connect (const std::string &nodeFrom, 
-                          const std::string &outputLabel, 
-                          const std::string &nodeTo, 
-                          const std::string &inputLabel)
+  void Transcriptor::Connect (const std::string &nodeFrom,
+                              const std::string &outputLabel,
+                              const std::string &nodeTo, 
+                              const std::string &inputLabel)
   {
     //Current()->Connect(nodeFrom, outputLabel, nodeTo, inputLabel);
-     m_Fp << "e->Connect("<< nodeFrom << "\", \"" <<  outputLabel << "\", \""
+     m_Fp << "  e->Connect(\""<< nodeFrom << "\", \"" <<  outputLabel << "\", \""
           << nodeTo  << "\", \"" << inputLabel<< "\");" << std::endl;
   }
 
  /**
- *  
+ *
  */ 
   void Transcriptor::Update (const std::string &nodeName) // would 'Execute' be more meaningfull ?
   {
+  
+     m_Fp << "  e->Update(\"" << nodeName << "\");" << std::endl;
+/*     
  // if in root
      if (Current()==mRoot) 
      {
         if (!mNoExecMode) 
         {
            //Current()->GetPrototype()->bbGetBlackBox(nodeName)->bbExecute(true);
-           m_Fp << "e->GetPrototype()->bbGetBlackBox(\"" << nodeName << "\", true );" << std::endl;
+           m_Fp << "  e->GetPrototype()->bbGetBlackBox(\"" << nodeName << "\", true );" << std::endl;
         }
      }
      else 
      {
         //Current()->AddToExecutionList(nodeName) ;
-       m_Fp << "e->AddToExecutionList(\"" << nodeName << "\");" << std::endl;
+        m_Fp << "  e->AddToExecutionList(\"" << nodeName << "\");" << std::endl;
      }
+*/
   }
-    
+
 /**
- *  
+ *
  */
   void Transcriptor::DefineInput ( const std::string &name,
-                               const std::string &box,
-                               const std::string &input,
-                               const std::string& help)
+                                   const std::string &box,
+                                   const std::string &input,
+                                   const std::string& help)
   {
-    // If the input is defined in the Root box
-    if (Current()==mRoot) 
-    {  
-       m_Fp << "// ==> Some extra work to do when Current()==mRoot" << std::endl;
-
-    }
-       m_Fp << "e->DefineInput(\""<< name << "\", " <<  box << ", "
-            << input << ", \"" << help << "\");" << std::endl;
-
+  
+    m_Fp << "  e->DefineInput(\""<< name << "\", " <<  box << ", "
+         << input << ", \"" << help << "\");" << std::endl;
 
   /*
     // If the input is defined in the Root box
@@ -343,7 +344,6 @@ namespace bbtk
           mess += ")";
           std::string title(name);
           title += " ?";
-
           std::string ans = wx2std ( wxGetTextFromUser( std2wx (mess), std2wx(title)));
           Set(box,input,ans); 
        }
@@ -354,17 +354,17 @@ namespace bbtk
 */
 
   }
-  
+
  /**
  *  
  */ 
    void Transcriptor::DefineOutput ( const std::string &name,
-                                 const std::string &box,
-                                 const std::string &output,
-                                 const std::string& help)
+                                     const std::string &box,
+                                     const std::string &output,
+                                     const std::string& help)
   {
    // Current()->DefineOutput(name,box,output,help);
-       m_Fp << "e->DefineOutput(\""<< name << "\", \"" <<  box << "\", \""
+       m_Fp << "  e->DefineOutput(\""<< name << "\", \"" <<  box << "\", \""
             << output << "\", \"" << help << "\");" << std::endl;
   }
 
@@ -372,18 +372,19 @@ namespace bbtk
    *  
    */ 
   void Transcriptor::Set (const std::string &box,
-                      const std::string &input,
-                      const std::string &value)
+                          const std::string &input,
+                          const std::string &value)
   {
-  
-    m_Fp << "// ==> Set() called here"                   << std::endl;  
+    m_Fp << "  e->Set(\""<< box << "\", \"" << input<< "\", \"" << value << "\");"
+         << std::endl;
+
 /*
     BlackBox* b = Current()->GetPrototype()->bbGetBlackBox(box);
     // Looks for the adaptor
 
     if ( b->bbGetInputType(input) !=  typeid(std::string) ) 
       {
-         BlackBox* a = 
+         BlackBox* a =
          NewAdaptor(typeid(std::string),
                     b->bbGetInputType(input),
                     "tmp");
@@ -408,19 +409,20 @@ namespace bbtk
   }
 
   /**
-   *  
-   */ 
+   *
+   */
   std::string Transcriptor::Get(const std::string &box,
-                            const std::string &output)
+                                const std::string &output)
   {
   
-    m_Fp << "// ==> Get() called here"                   << std::endl;  
+    m_Fp << "  e->Get(\""<< box << "\", \"" << output << "\");"
+         << std::endl;
 /*    
     BlackBox* b = Current()->GetPrototype()->bbGetBlackBox(box);
     // Looks for the adaptor
     if (b->bbGetOutputType(output) != typeid(std::string)) 
       {
-      BlackBox* a = 
+      BlackBox* a =
           NewAdaptor(
              b->bbGetOutputType(output),
              typeid(std::string),
@@ -444,7 +446,7 @@ namespace bbtk
         a->bbDelete();
         return r;
       }
-    else 
+    else
       {
        b->bbExecute();
        return b->bbGetOutput(output).unsafe_get<std::string>();
@@ -454,41 +456,36 @@ namespace bbtk
        // b->bbSetInput(input,&v);
       }
 */
+// EED Windows
+return "";
   }
 
 
   void Transcriptor::Author(const std::string &authorName)
   {
+
+  m_Fp << "  e->AddToAuthor(\"" << authorName << "\")" << std::endl;
+  return; // just to see
+
     //Current()->AddToAuthor(authorName,Current()==mRoot);
-    if (Current()==mRoot)    
-       m_Fp << "e->AddToAuthor(\"" << authorName << "\", true)" << std::endl;
-    else
-       m_Fp << "e->AddToAuthor(\"" << authorName << "\", false)" << std::endl;
   }
 
   void Transcriptor::Category(const std::string &category)
-  {           
+  {
+      m_Fp << "  e->AddToCategory(\"" << category << "\")" << std::endl;
     //Current()->AddToCategory(category,Current()==mRoot);
-    if (Current()==mRoot)    
-       m_Fp << "e->AddToCategory(\"" << category << "\", true)" << std::endl;
-    else
-       m_Fp << "e->AddToCategory(\"" << category << "\", false)" << std::endl;
   }
 
   void Transcriptor::Description(const std::string &d)
   {
+     m_Fp << "  e->AddToDescription(\"" << d << "\")" << std::endl;
     // Current()->AddToDescription(d,Current()==mRoot);
-    if (Current()==mRoot)    
-       m_Fp << "e->AddToDescription(\"" << d << "\", true)" << std::endl;
-    else
-       m_Fp << "e->AddToDescription(\"" << d << "\", false)" << std::endl;    
   }
 
-
   /// prints the list of the boxes of the current descriptor
   void Transcriptor::PrintBoxes()
-  { 
-    m_Fp << "// ==> :PrintBoxes() called here"                   << std::endl;           
+  {
+     m_Fp << "  e->PrintBoxes( )" << std::endl;
  /* 
     bbtkMessageInc("Help",1,"The black box descriptor \""
                    <<Current()->GetTypeName()<<"\" contains : "<<std::endl);
@@ -497,16 +494,25 @@ namespace bbtk
  */
  }
 
-// =========================End of Battelfield ========================================================================
+// =========================End of Battlefield ========================================================================
 
-  std::string Transcriptor::ShowGraph(const std::string &nameblackbox, 
-                                 const std::string &detailStr, 
+  std::string Transcriptor::ShowGraph(const std::string &nameblackbox,
+                                 const std::string &detailStr,
                                  const std::string &levelStr,
                                  const std::string &output_html,
                                  const std::string &custom_header,
                                  const std::string &custom_title,
                                  bool system_display )
   {
+
+       m_Fp << "  e->DefineOutput(\"" << nameblackbox  << "\", \"" 
+                                      << detailStr     << "\", \""
+                                      << levelStr      << "\", \""
+                                      << output_html   << "\", \""
+                                      << custom_header << "\", \""
+                                      <<  custom_title << "\");"                                     
+                                      << std::endl;
+  /*
     int detail =       atoi(detailStr.c_str());
     int level  =       atoi(levelStr.c_str());
 
@@ -540,11 +546,11 @@ namespace bbtk
     Package* p;
     try
     {
-          p = GetGlobalFactory()->GetPackage(nameblackbox);
+       p = GetGlobalFactory()->GetPackage(nameblackbox);
     }
     catch (Exception e)
     {
-          p = mPackage;
+       p = mPackage;
     }
     // Generating documentation-help of workspace
     p->SetDocURL(filename_rootHtml);
@@ -556,51 +562,51 @@ namespace bbtk
     /*
     try 
     {
-         ShowGraphTypes(nameblackbox);
+       ShowGraphTypes(nameblackbox);
     }
     catch (bbtk::Exception a)
     {
-         std::cout <<"EXC"<<std::endl;
-         page = ShowGraphInstances(nameblackbox,detail,level,system_display);
+       std::cout <<"EXC"<<std::endl;
+       page = ShowGraphInstances(nameblackbox,detail,level,system_display);
     }
     */
-    return page;
+    //return page;
+    return ""; // to avoid warnings
   }
 
   /// Generate a png file with the actual pipeline (Graphviz-dot needed)
   std::string Transcriptor::ShowGraphInstances(const std::string &nameblackbox, int detail, int level,
-                                   bool system_display)
+                                               bool system_display)
   {
 
     BlackBox* blackbox=NULL;
     if (nameblackbox==".")
     {
-         blackbox=Current()->GetPrototype();
+       blackbox=Current()->GetPrototype();
     }
-    else 
+    else
     {
-         blackbox = Current()->GetPrototype()->bbFindBlackBox(nameblackbox);
+       blackbox = Current()->GetPrototype()->bbFindBlackBox(nameblackbox);
     }
     
     std::string page;
 
     if (blackbox)
       {      
-       // Don't pollute the file store with  "temp_dir" directories ...    
+       // Don't pollute the file store with  "temp_dir" directories ...
        std::string default_doc_dir = ConfigurationFile::GetInstance().Get_default_temp_dir();
        char c = default_doc_dir.c_str()[strlen(default_doc_dir.c_str())-1];
-       
+
        std::string directory = default_doc_dir; 
        if (c != '/' && c !='\\') directory = directory + "/";
 
-       directory = directory +  "temp_dir"; 
-       
+       directory = directory +  "temp_dir";
        //std::string directory("temp_dir");
        std::string filename(directory + "/" + "bbtk_graph_pipeline");
        std::string filename_html(filename+".html");
        std::string command0("mkdir \""+directory + "\"");
 
-#if defined(_WIN32)  
+#if defined(_WIN32)
        std::string command2("start ");
 #else 
        std::string command2("gnome-open ");
@@ -623,7 +629,7 @@ namespace bbtk
            } 
 
            blackbox->bbInsertHTMLGraph( s, detail, level, true, directory, false );
-           s << "</body></html>\n";      
+           s << "</body></html>\n";
          }
        s.close();
        
@@ -634,7 +640,6 @@ namespace bbtk
       {
        bbtkMessageInc("Help",1,"No black box: \""
                       <<nameblackbox<<"\" " <<std::endl);
-       
       }
     return page;
   }