]> Creatis software - bbtk.git/blobdiff - kernel/src/bbtkExecuter.cxx
#2536 BBTK Feature New Normal wt-version Package
[bbtk.git] / kernel / src / bbtkExecuter.cxx
index 9fa297fef97255169453154daae0800cf02c359c..bf51fe564d3a1b644ee850f9bbc044d9b3abfa08 100644 (file)
@@ -1,20 +1,40 @@
+/*
+ # ---------------------------------------------------------------------
+ #
+ # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
+ #                        pour la SantÈ)
+ # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
+ # Previous Authors : Laurent Guigues, Jean-Pierre Roux
+ # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
+ #
+ #  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.
+ # ------------------------------------------------------------------------ */
+
+
 /*=========================================================================
-         
   Program:   bbtk
-  Module:    $RCSfile: bbtkExecuter.cxx,v $ $
+  Module:    $RCSfile: bbtkExecuter.cxx,v $
   Language:  C++
-  Date:      $Date: 2008/04/22 09:40:10 $
-  Version:   $Revision: 1.20 $
-
-  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: 2012/11/16 08:49:01 $
+  Version:   $Revision: 1.34 $
+=========================================================================*/
 
-     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.
+                                                                      
 
-=========================================================================*/
 /**
  *  \file 
  *  \brief class Executer: level 0 of script execution (code)
 #include "bbtkMessageManager.h"
 #include "bbtkFactory.h"
 #include "bbtkUtilities.h"
+//#include "bbtkWx.h"
 #include <fstream>
 
-#ifdef _USE_WXWIDGETS_
+#ifdef USE_WXWIDGETS
 #include <wx/textdlg.h>
 #endif
 
@@ -39,7 +60,7 @@ namespace bbtk
   //=======================================================================
   Executer::Pointer Executer::New()
   {
-    bbtkDebugMessage("Kernel",9,"Executer::New()"<<std::endl);
+    bbtkDebugMessage("object",9,"Executer::New()"<<std::endl);
     return MakePointer(new Executer());
   }
   //=======================================================================
@@ -51,9 +72,10 @@ namespace bbtk
     mRootPackage(),
     mRootCBB(),
     mNoExecMode(false),
-    mDialogMode(NoDialog)
+    mDialogMode(NoDialog),
+    mNoErrorMode(false)
   {
-    bbtkDebugMessageInc("Kernel",9,"Executer::Executer()" <<std::endl);
+    bbtkDebugMessage("object",2,"==> Executer()" <<std::endl);
     mFactory = Factory::New();
     // The smart pointer on this is not made yet (is made by New) 
     // -> create it to pass it to the factory
@@ -62,19 +84,19 @@ namespace bbtk
     // -> this would auto-destroy !!
     mFactory->SetExecuter(MakePointer(this,true));
     Reset();
-    bbtkDebugDecTab("Kernel",9);
+    bbtkDebugMessage("object",2,"<== Executer()" <<std::endl);
   }
   //=======================================================================
 
   //=======================================================================
   Executer::~Executer()
   {
-     bbtkDebugMessageInc("Kernel",9,"==> Executer::~Executer()" <<std::endl);
+     bbtkDebugMessage("object",2,"==> ~Executer()" <<std::endl);
      mOpenDefinition.clear();
      mOpenPackage.clear();
      mFactory->Reset();
      mFactory.reset();
-     bbtkDebugDecTab("Kernel",9);
+     bbtkDebugMessage("object",2,"<== ~Executer()" <<std::endl);
   }
   //=======================================================================
 
@@ -97,20 +119,24 @@ namespace bbtk
   //=======================================================================
   void Executer::Reset()
   {
-    bbtkDebugMessageInc("Kernel",9,"Executer::Reset()" <<std::endl);
+    bbtkDebugMessage("kernel",9,"==> Executer::Reset()" <<std::endl);
 
-    GetFactory()->CheckPackages();
+    //    GetFactory()->Check();
  
     mOpenDefinition.clear();
     mOpenPackage.clear();
+
+    //  Wx::DestroyTopWindow();
+
     GetFactory()->Reset();
+#if(USE_WXWIDGETS)
+    Wx::ProcessPendingEvents();
+#endif
 
     // 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,32 +148,32 @@ 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
-    p->RegisterBlackBox(r);
+    p->Register(r);
     mRootCBB = r;
 
     //    Object::PrintObjectListInfo();
     //  GetFactory()->CheckPackages();
-
-    bbtkDebugDecTab("Kernel",9);
+    bbtkDebugMessage("kernel",9,"<== Executer::Reset()" <<std::endl);
   }
   //=======================================================================
 
+
   //=======================================================================
   /// changes the workspace name
   void Executer::SetWorkspaceName( const std::string& n )
   {
-    GetUserPackage()->ChangeBlackBoxName( GetWorkspace()->GetTypeName(), n );
+    GetUserPackage()->ChangeDescriptorName( GetWorkspace()->GetTypeName(), n );
   }
   //=======================================================================
 
   //=======================================================================
   void Executer::BeginPackage (const std::string &name)
   {
-     bbtkDebugMessageInc("Kernel",9,"Executer::BeginPackage(\""<<name<<"\")"
+     bbtkDebugMessage("kernel",9,"==> Executer::BeginPackage(\""<<name<<"\")"
                         <<std::endl);
      Package::Pointer p;
      try 
@@ -156,14 +182,13 @@ 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);
+
+     bbtkDebugMessage("kernel",9,"<== Executer::BeginPackage(\""<<name<<"\")"
+                     <<std::endl);
   }
   //=======================================================================
 
@@ -179,9 +204,9 @@ namespace bbtk
                          const std::string &pack,
                          const std::string &scriptfilename)
   {
-    bbtkDebugMessageInc("Kernel",9,"Executer::Define(\""<<name<<
-                        ","<<pack<<"\")"
-                        <<std::endl);
+    bbtkDebugMessage("kernel",9,"==> Executer::Define(\""<<name<<
+                    ","<<pack<<"\")"
+                    <<std::endl);
 
     ComplexBlackBoxDescriptor::Pointer b 
       = ComplexBlackBoxDescriptor::New(name);
@@ -189,7 +214,9 @@ namespace bbtk
     b->SetScriptFileName(scriptfilename);
     mOpenDefinition.push_back( CBBDefinition( b, pack ) );
     
-    bbtkDebugDecTab("Kernel",9);
+    bbtkDebugMessage("kernel",9,"<== Executer::Define(\""<<name<<
+                    ","<<pack<<"\")"
+                    <<std::endl);
   }
   //=======================================================================
 
@@ -200,14 +227,30 @@ namespace bbtk
   {
     mOpenDefinition.back().box->SetScriptFileName(name);
   }
+  //=======================================================================
+
+       void Executer::SetTypeOfScript_Application ()
+       {
+               mOpenDefinition.back().box->SetTypeOfScript_Application();
+       }
+       
+       
+       
+  //=======================================================================
+  void Executer::Clear()
+  {
+    bbtkDebugMessage("kernel",9,"==> Executer::Clear()" <<std::endl);
+    GetCurrentDescriptor()->GetPrototype()->Clear();
+    bbtkDebugMessage("kernel",9,"<== Executer::Clear()" <<std::endl);
+  }
   //=======================================================================
 
   //=======================================================================
   void Executer::EndDefine ()
   {
-    bbtkDebugMessageInc("Kernel",9,"Executer::EndDefine(\""
-                        <<GetCurrentDescriptor()->GetTypeName()<<"\")" 
-                        <<std::endl);
+    bbtkDebugMessage("kernel",9,"==> Executer::EndDefine(\""
+                    <<GetCurrentDescriptor()->GetTypeName()<<"\")" 
+                    <<std::endl);
     // Does current package exist ?
     Package::Pointer p;
     std::string pname(mOpenDefinition.back().package);
@@ -219,11 +262,7 @@ namespace bbtk
          }
        catch (Exception e)
          {
-           p = Package::New(pname,
-                            "",
-                            "",
-                            "",
-                            BBTK_STRINGIFY_SYMBOL(BBTK_VERSION));
+           p = Package::New(pname,"","","");
            GetFactory()->InsertPackage(p);
          }
       }
@@ -231,8 +270,12 @@ namespace bbtk
       {
        p = mOpenPackage.back().lock();
       }
-    p->RegisterBlackBox(GetCurrentDescriptor());
+    // Register the descriptor in the current package
+    p->Register(GetCurrentDescriptor());
     
+    bbtkDebugMessage("kernel",9,"<== Executer::EndDefine(\""
+                    <<GetCurrentDescriptor()->GetTypeName()<<"\")" 
+                    <<std::endl);
     mOpenDefinition.pop_back();
   }
   //======================================================================= 
@@ -343,7 +386,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) 
@@ -384,7 +427,8 @@ namespace bbtk
     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),
@@ -475,14 +519,15 @@ namespace bbtk
   }
   //=======================================================================
 
+
+
   //=======================================================================
   /// prints the list of the boxes of the current descriptor
-  void Executer::PrintBoxes()
+  void Executer::PrintHelpListBoxes()
   {
-    bbtkMessageInc("Help",1,"The black box descriptor \""
-                   <<GetCurrentDescriptor()->GetTypeName()<<"\" contains : "<<std::endl);
+    bbtkMessage("help",1,"The black box descriptor \""
+               <<GetCurrentDescriptor()->GetTypeName()<<"\" contains : "<<std::endl);
     GetCurrentDescriptor()->PrintBlackBoxes();
-    bbtkDecTab("Help",1);
  }
   //=======================================================================
 
@@ -497,33 +542,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 +553,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 +588,7 @@ namespace bbtk
        page = ShowGraphInstances(nameblackbox,detail,level,system_display);
     }
     */
-    return page;
+    return pack_index;
   }
   //=======================================================================
 
@@ -610,7 +646,6 @@ namespace bbtk
              } else {
              s << "<center>" << blackbox->bbGetName()<< "</center>";
            } 
-
            blackbox->bbInsertHTMLGraph( s, detail, level, true, directory, false );
            s << "</body></html>\n";
          }
@@ -621,15 +656,15 @@ namespace bbtk
       } 
     else 
       {
-       bbtkMessageInc("Help",1,"No black box: \""
-                      <<nameblackbox<<"\" " <<std::endl);
+       bbtkMessage("help",1,"No black box: \""
+                   <<nameblackbox<<"\" " <<std::endl);
       }
     return page;
   }
   //=======================================================================
 
   //=======================================================================
-  void Executer::ShowRelations(const std::string &nameblackbox, 
+  void Executer::PrintHelpBlackBox(const std::string &nameblackbox, 
                               const std::string &detailStr, 
                               const std::string &levelStr)
   {
@@ -650,12 +685,12 @@ namespace bbtk
     if (blackbox)
       {
        found=true;
-       blackbox->bbShowRelations(blackbox,detail,level); //,mFactory);
+       blackbox->bbPrintHelp(blackbox,detail,level); //,mFactory);
       }
     
     if (!found) 
       {
-       bbtkError("Blackbox Name not found.. <"  <<nameblackbox<<">");
+       bbtkError("box with name '"  <<nameblackbox<<"' unknown");
       }
   }
   //=======================================================================
@@ -684,7 +719,7 @@ namespace bbtk
     if (GetNoExecMode() &&  (GetCurrentDescriptor()==GetWorkspace()) ) return;
     if (GetCurrentDescriptor()!=GetWorkspace()) return;
 
-    bbtkDebugMessageInc("Interpreter",9,"Interpreter::Print(\""<<str<<"\")"<<std::endl);
+    bbtkDebugMessage("kernel",9,"Executer::Print(\""<<str<<"\")"<<std::endl);
 
  // TO DO :
  // InterpretLine ("load std")
@@ -742,9 +777,9 @@ namespace bbtk
     for (i= chains.begin(); i!=chains.end(); ++i) 
       {
        Utilities::SubsBackslashN(*i);
-       bbtkMessage("Output",1,*i);
+       bbtkMessage("output",1,*i);
       }
-    bbtkMessage("Output",1,std::endl);
+    bbtkMessage("output",1,std::endl);
   }
   //==========================================================================