]> Creatis software - bbtk.git/blobdiff - kernel/src/bbtkExecuter.cxx
BUG MACOS
[bbtk.git] / kernel / src / bbtkExecuter.cxx
index ee60d2e992e98ea035c9615581be167c7e39777b..519a264eec6eb7bb3017a38ae007d33df0cf4c89 100644 (file)
@@ -1,20 +1,33 @@
-/*=========================================================================
-         
+/*=========================================================================                                                                               
   Program:   bbtk
-  Module:    $RCSfile: bbtkExecuter.cxx,v $ $
+  Module:    $RCSfile: bbtkExecuter.cxx,v $
   Language:  C++
-  Date:      $Date: 2008/04/22 06:59:31 $
-  Version:   $Revision: 1.19 $
-
-  Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
-  l'Image). All rights reserved. See Doc/License.txt or
-  http://www.creatis.insa-lyon.fr/Public/bbtk/License.html for details.
+  Date:      $Date: 2009/03/30 15:22:51 $
+  Version:   $Revision: 1.29 $
+=========================================================================*/
 
-     This software is distributed WITHOUT ANY WARRANTY; without even
-     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
-     PURPOSE.  See the above copyright notices for more information.
+/* ---------------------------------------------------------------------
+
+* Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
+* Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
+*
+*  This software is governed by the CeCILL-B license under French law and 
+*  abiding by the rules of distribution of free software. You can  use, 
+*  modify and/ or redistribute the software under the terms of the CeCILL-B 
+*  license as circulated by CEA, CNRS and INRIA at the following URL 
+*  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html 
+*  or in the file LICENSE.txt.
+*
+*  As a counterpart to the access to the source code and  rights to copy,
+*  modify and redistribute granted by the license, users are provided only
+*  with a limited warranty  and the software's author,  the holder of the
+*  economic rights,  and the successive licensors  have only  limited
+*  liability. 
+*
+*  The fact that you are presently reading this means that you have had
+*  knowledge of the CeCILL-B license and that you accept its terms.
+* ------------------------------------------------------------------------ */                                                                         
 
-=========================================================================*/
 /**
  *  \file 
  *  \brief class Executer: level 0 of script execution (code)
@@ -26,7 +39,7 @@
 #include "bbtkUtilities.h"
 #include <fstream>
 
-#ifdef _USE_WXWIDGETS_
+#ifdef USE_WXWIDGETS
 #include <wx/textdlg.h>
 #endif
 
@@ -51,7 +64,8 @@ namespace bbtk
     mRootPackage(),
     mRootCBB(),
     mNoExecMode(false),
-    mDialogMode(NoDialog)
+    mDialogMode(NoDialog),
+    mNoErrorMode(false)
   {
     bbtkDebugMessageInc("Kernel",9,"Executer::Executer()" <<std::endl);
     mFactory = Factory::New();
@@ -107,10 +121,7 @@ namespace bbtk
 
     // Create user package
     Package::Pointer p =
-      Package::New("user","internal to bbi",
-                  "User defined black boxes",
-                  "",
-                  BBTK_STRINGIFY_SYMBOL(BBTK_VERSION));
+      Package::New("user","internal","User defined black boxes","");
     // Insert the user package in the factory
     GetFactory()->InsertPackage(p);
     // And in the list of open packages
@@ -122,7 +133,7 @@ namespace bbtk
       ComplexBlackBoxDescriptor::New("workspace"); 
     //    mRootCBB->Reference();
     r->SetFactory(GetFactory());
-    r->AddToAuthor("bbi (internal)");
+    r->AddToAuthor("bbtk");
     r->AddToDescription("User's workspace");
     mOpenDefinition.push_back(CBBDefinition(r,"user"));
     // Register it into the user package
@@ -136,6 +147,7 @@ namespace bbtk
   }
   //=======================================================================
 
+
   //=======================================================================
   /// changes the workspace name
   void Executer::SetWorkspaceName( const std::string& n )
@@ -156,11 +168,7 @@ namespace bbtk
       }
     catch (Exception e)
       {
-       p = Package::New(name,
-                         "",
-                         "",
-                         "",
-                         BBTK_STRINGIFY_SYMBOL(BBTK_VERSION));
+       p = Package::New(name,"","","");
        GetFactory()->InsertPackage(p);
       }
      mOpenPackage.push_back(p);
@@ -202,11 +210,20 @@ namespace bbtk
   }
   //=======================================================================
 
+  //=======================================================================
+  void Executer::Clear()
+  {
+    bbtkDebugMessageInc("Kernel",9,"Executer::Clear()" <<std::endl);
+    GetCurrentDescriptor()->GetPrototype()->Clear();
+
+  }
+  //=======================================================================
+
   //=======================================================================
   void Executer::EndDefine ()
   {
     bbtkDebugMessageInc("Kernel",9,"Executer::EndDefine(\""
-                        <<Current()->GetTypeName()<<"\")" 
+                        <<GetCurrentDescriptor()->GetTypeName()<<"\")" 
                         <<std::endl);
     // Does current package exist ?
     Package::Pointer p;
@@ -219,11 +236,7 @@ namespace bbtk
          }
        catch (Exception e)
          {
-           p = Package::New(pname,
-                            "",
-                            "",
-                            "",
-                            BBTK_STRINGIFY_SYMBOL(BBTK_VERSION));
+           p = Package::New(pname,"","","");
            GetFactory()->InsertPackage(p);
          }
       }
@@ -231,7 +244,7 @@ namespace bbtk
       {
        p = mOpenPackage.back().lock();
       }
-    p->RegisterBlackBox(Current());
+    p->RegisterBlackBox(GetCurrentDescriptor());
     
     mOpenDefinition.pop_back();
   }
@@ -242,23 +255,23 @@ namespace bbtk
   {
     if (kind=="ADAPTOR")
       {
-       Current()->AddToCategory("adaptor");
-       Current()->SetKind(bbtk::BlackBoxDescriptor::ADAPTOR);
+       GetCurrentDescriptor()->AddToCategory("adaptor");
+       GetCurrentDescriptor()->SetKind(bbtk::BlackBoxDescriptor::ADAPTOR);
       }
     else if (kind=="DEFAULT_ADAPTOR")
       {
-       Current()->AddToCategory("adaptor");
-       Current()->SetKind(bbtk::BlackBoxDescriptor::DEFAULT_ADAPTOR);
+       GetCurrentDescriptor()->AddToCategory("adaptor");
+       GetCurrentDescriptor()->SetKind(bbtk::BlackBoxDescriptor::DEFAULT_ADAPTOR);
       }
     if (kind=="GUI")
       {
-       Current()->AddToCategory("gui");
-       Current()->SetKind(bbtk::BlackBoxDescriptor::GUI);
+       GetCurrentDescriptor()->AddToCategory("gui");
+       GetCurrentDescriptor()->SetKind(bbtk::BlackBoxDescriptor::GUI);
       }
     else if (kind=="DEFAULT_GUI")
       {
-       Current()->AddToCategory("gui");
-       Current()->SetKind(bbtk::BlackBoxDescriptor::DEFAULT_GUI);
+       GetCurrentDescriptor()->AddToCategory("gui");
+       GetCurrentDescriptor()->SetKind(bbtk::BlackBoxDescriptor::DEFAULT_GUI);
       }
     else
       {
@@ -273,14 +286,14 @@ namespace bbtk
   void Executer::Create ( const std::string& nodeType, 
                           const std::string& nodeName)
   {
-     Current()->Add(nodeType,nodeName);
+     GetCurrentDescriptor()->Add(nodeType,nodeName);
   }
   //=======================================================================
 
   //=======================================================================
   void Executer::Destroy(const std::string &boxName)
   {
-    Current()->Remove(boxName,true);
+    GetCurrentDescriptor()->Remove(boxName,true);
   }
   //=======================================================================
 
@@ -290,7 +303,7 @@ namespace bbtk
                           const std::string &nodeTo, 
                           const std::string &inputLabel)
   {
-    Current()->Connect(nodeFrom, outputLabel, nodeTo, inputLabel);
+    GetCurrentDescriptor()->Connect(nodeFrom, outputLabel, nodeTo, inputLabel);
   }
   //=======================================================================
 
@@ -298,16 +311,16 @@ namespace bbtk
   void Executer::Execute (const std::string &nodeName) 
   {
     // if in root
-    if (Current()==GetWorkspace()) 
+    if (GetCurrentDescriptor()==GetWorkspace()) 
      {
         if (!mNoExecMode) 
         {
-           Current()->GetPrototype()->bbGetBlackBox(nodeName)->bbExecute(true);
+           GetCurrentDescriptor()->GetPrototype()->bbGetBlackBox(nodeName)->bbExecute(true);
         }
      }
      else 
      {
-        Current()->AddToExecutionList(nodeName) ;
+        GetCurrentDescriptor()->AddToExecutionList(nodeName) ;
      }
   }
   //=======================================================================
@@ -319,7 +332,7 @@ namespace bbtk
                                const std::string& help)
   {
     // If the input is defined in the Root box
-    if (Current()==GetWorkspace()) 
+    if (GetCurrentDescriptor()==GetWorkspace()) 
       {
       // If the dialog mode is set to NoDialog
       // and the user passed the name in the Inputs map 
@@ -343,7 +356,7 @@ namespace bbtk
            std::cin >> ans;
            Set(box,input,ans);
         }
-#ifdef _USE_WXWIDGETS_
+#ifdef USE_WXWIDGETS
        // If the dialog mode is set to GraphicalDialog
        // A dialog box is pop up
        else if (mDialogMode == GraphicalDialog) 
@@ -361,7 +374,7 @@ namespace bbtk
 #endif
     }
 
-    Current()->DefineInput(name,box,input,help);
+    GetCurrentDescriptor()->DefineInput(name,box,input,help);
 
   }
   //=======================================================================
@@ -372,7 +385,7 @@ namespace bbtk
                                  const std::string &output,
                                  const std::string& help)
   {
-    Current()->DefineOutput(name,box,output,help);
+    GetCurrentDescriptor()->DefineOutput(name,box,output,help);
   }
   //=======================================================================
 
@@ -381,10 +394,11 @@ namespace bbtk
                       const std::string &input,
                       const std::string &value)
   {
-    BlackBox::Pointer b = Current()->GetPrototype()->bbGetBlackBox(box);
+    BlackBox::Pointer b = GetCurrentDescriptor()->GetPrototype()->bbGetBlackBox(box);
     // Looks for the adaptor
 
-    if ( b->bbGetInputType(input) !=  typeid(std::string) ) 
+    if ( ( b->bbGetInputType(input) != typeid(bbtk::any<bbtk::thing>) )&&
+        ( b->bbGetInputType(input) != typeid(std::string) ) )
       {
        BlackBox::Pointer a =
           GetFactory()->NewAdaptor(typeid(std::string),
@@ -414,7 +428,7 @@ namespace bbtk
   std::string Executer::Get(const std::string &box,
                             const std::string &output)
   {
-    BlackBox::Pointer b = Current()->GetPrototype()->bbGetBlackBox(box);
+    BlackBox::Pointer b = GetCurrentDescriptor()->GetPrototype()->bbGetBlackBox(box);
     // Looks for the adaptor
     if (b->bbGetOutputType(output) != typeid(std::string)) 
       {
@@ -457,21 +471,21 @@ namespace bbtk
   //=======================================================================
   void Executer::Author(const std::string &authorName)
   {
-    Current()->AddToAuthor(authorName,Current()==GetWorkspace());
+    GetCurrentDescriptor()->AddToAuthor(authorName,GetCurrentDescriptor()==GetWorkspace());
   }
   //=======================================================================
 
   //=======================================================================
   void Executer::Category(const std::string &category)
   {
-    Current()->AddToCategory(category,Current()==GetWorkspace());
+    GetCurrentDescriptor()->AddToCategory(category,GetCurrentDescriptor()==GetWorkspace());
   }
   //=======================================================================
 
   //=======================================================================
   void Executer::Description(const std::string &d)
   {
-    Current()->AddToDescription(d,Current()==GetWorkspace());
+    GetCurrentDescriptor()->AddToDescription(d,GetCurrentDescriptor()==GetWorkspace());
   }
   //=======================================================================
 
@@ -480,8 +494,8 @@ namespace bbtk
   void Executer::PrintBoxes()
   {
     bbtkMessageInc("Help",1,"The black box descriptor \""
-                   <<Current()->GetTypeName()<<"\" contains : "<<std::endl);
-    Current()->PrintBlackBoxes();
+                   <<GetCurrentDescriptor()->GetTypeName()<<"\" contains : "<<std::endl);
+    GetCurrentDescriptor()->PrintBlackBoxes();
     bbtkDecTab("Help",1);
  }
   //=======================================================================
@@ -497,33 +511,7 @@ namespace bbtk
   {
     int detail =       atoi(detailStr.c_str());
     int level  =       atoi(levelStr.c_str());
-
-    std::string filename_rootHtml (output_html) ;
-    std::string simplefilename_rootHtml ( Utilities::get_file_name(output_html));
-
-    bool relative_link = true;
-
-    // No output provided : automatic generation
-    if (output_html.length() == 0)
-      {
-       // 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";    
-       
-       filename_rootHtml = directory + "/" + "User.html";
-       simplefilename_rootHtml = "User.html" ;
-
-       // Creating directory
-       std::string command0("mkdir \"" +directory + "\"");
-       system( command0.c_str() );
-
-       relative_link = false;
-      }
+         bool relative_link = true;
 
     Package::Pointer p;
     try
@@ -534,13 +522,30 @@ namespace bbtk
     {
       p = GetUserPackage();
     }
+         
+      std::string doc_path = bbtk::ConfigurationFile::GetInstance().Get_doc_path();
+      doc_path += bbtk::ConfigurationFile::GetInstance().Get_file_separator();
+      doc_path += "bbdoc";
+      doc_path += bbtk::ConfigurationFile::GetInstance().Get_file_separator();
+         
+         std::string pack_name(p->GetName());
+         std::string pack_path = doc_path + pack_name;
+         // Creating directory
+         if ( ! bbtk::Utilities::FileExists(pack_path) )
+         {
+                 std::string command("mkdir \"" +pack_path+ "\"");
+                 system( command.c_str() );
+         }
+         std::string pack_index(pack_path);
+         pack_index += bbtk::ConfigurationFile::GetInstance().Get_file_separator();
+         pack_index += "index.html"; 
+         
+         
     // Generating documentation-help of workspace
-    p->SetDocURL(filename_rootHtml);
-    p->SetDocRelativeURL(simplefilename_rootHtml);
-
-    p->CreateHtmlPage(filename_rootHtml,"bbi","user package",custom_header,custom_title,detail,level,relative_link);
-
-    std::string page = filename_rootHtml;
+       p->SetDocURL(pack_index);
+    p->SetDocRelativeURL("index.html");
+       p->CreateHtmlPage(pack_index,"bbtk","user package",custom_header,custom_title,detail,level,relative_link);
+         
     /*
     try 
     {
@@ -552,7 +557,7 @@ namespace bbtk
        page = ShowGraphInstances(nameblackbox,detail,level,system_display);
     }
     */
-    return page;
+    return pack_index;
   }
   //=======================================================================
 
@@ -565,11 +570,11 @@ namespace bbtk
     BlackBox::Pointer blackbox;
     if (nameblackbox==".")
     {
-       blackbox = Current()->GetPrototype();
+       blackbox = GetCurrentDescriptor()->GetPrototype();
     }
     else
     {
-       blackbox = Current()->GetPrototype()->bbFindBlackBox(nameblackbox);
+       blackbox = GetCurrentDescriptor()->GetPrototype()->bbFindBlackBox(nameblackbox);
     }
     
     std::string page;
@@ -610,7 +615,6 @@ namespace bbtk
              } else {
              s << "<center>" << blackbox->bbGetName()<< "</center>";
            } 
-
            blackbox->bbInsertHTMLGraph( s, detail, level, true, directory, false );
            s << "</body></html>\n";
          }
@@ -640,11 +644,11 @@ namespace bbtk
     BlackBox::Pointer blackbox;
     if (nameblackbox.compare(".")==0)
       {
-       blackbox=Current()->GetPrototype();
+       blackbox=GetCurrentDescriptor()->GetPrototype();
       } 
     else 
       {
-       blackbox = Current()->GetPrototype()->bbFindBlackBox(nameblackbox);
+       blackbox = GetCurrentDescriptor()->GetPrototype()->bbFindBlackBox(nameblackbox);
       }
     
     if (blackbox)
@@ -681,8 +685,8 @@ namespace bbtk
   ///
   void Executer::Print(const std::string &str)
   {  
-    if (GetNoExecMode() &&  (Current()==GetWorkspace()) ) return;
-    if (Current()!=GetWorkspace()) return;
+    if (GetNoExecMode() &&  (GetCurrentDescriptor()==GetWorkspace()) ) return;
+    if (GetCurrentDescriptor()!=GetWorkspace()) return;
 
     bbtkDebugMessageInc("Interpreter",9,"Interpreter::Print(\""<<str<<"\")"<<std::endl);
 
@@ -741,7 +745,6 @@ namespace bbtk
     std::vector<std::string>::iterator i;
     for (i= chains.begin(); i!=chains.end(); ++i) 
       {
-       //  bbtkMessage("Echo",1,*i);
        Utilities::SubsBackslashN(*i);
        bbtkMessage("Output",1,*i);
       }