]> Creatis software - bbtk.git/blobdiff - kernel/src/bbtkExecuter.cxx
Fixed :
[bbtk.git] / kernel / src / bbtkExecuter.cxx
index 5244a04a60d26bd355ed841d66040a5ca40e03a0..9be94bf19a29e4252a311401935b665dbb99ed5a 100644 (file)
@@ -3,8 +3,8 @@
   Program:   bbtk
   Module:    $RCSfile: bbtkExecuter.cxx,v $ $
   Language:  C++
-  Date:      $Date: 2008/03/07 11:15:15 $
-  Version:   $Revision: 1.14 $
+  Date:      $Date: 2008/03/26 08:27:19 $
+  Version:   $Revision: 1.15 $
 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -36,9 +36,7 @@
 
 namespace bbtk
 {
-/**
- *
- */
+  //=======================================================================
   Executer::Executer()
     : 
     mFactory(0),
@@ -53,13 +51,11 @@ namespace bbtk
     Reset();
     bbtkDebugDecTab("Kernel",9);
   }
+  //=======================================================================
 
-/**
- *
- */
+  //=======================================================================
   Executer::~Executer()
   {
-    //std::cout << "===================================== delete Executer\n";  
      bbtkDebugMessageInc("Kernel",9,"Executer::~Executer()" <<std::endl);
      if (mRootCBB) 
      {
@@ -74,11 +70,25 @@ namespace bbtk
 
      bbtkDebugDecTab("Kernel",9);
   }
+  //=======================================================================
+
+  //=======================================================================
+   /// Loads a package
+    void Executer::LoadPackage(const std::string &name )
+   {
+     GetFactory()->LoadPackage(name);
+   }
+  //=======================================================================
+
+  //=======================================================================
+    /// Unloads a package
+    void Executer::UnLoadPackage(const std::string &name )
+    {
+      GetFactory()->UnLoadPackage(name);
+    }
+  //=======================================================================
 
-
-/**
- *
- */
+  //=======================================================================
   void Executer::Reset()
   {
     bbtkDebugMessageInc("Kernel",9,"Executer::Reset()" <<std::endl);
@@ -120,13 +130,17 @@ namespace bbtk
 
     bbtkDebugDecTab("Kernel",9);
   }
+  //=======================================================================
 
+  //=======================================================================
   /// changes the workspace name
   void Executer::SetWorkspaceName( const std::string& n )
   {
     mRootPackage->ChangeBlackBoxName( mRootCBB->GetTypeName(), n );
   }
-  
+  //=======================================================================
+
+  //=======================================================================
   void Executer::BeginPackage (const std::string &name)
   {
      bbtkDebugMessageInc("Kernel",9,"Executer::BeginPackage(\""<<name<<"\")"
@@ -147,12 +161,16 @@ namespace bbtk
       }
      mOpenPackage.push_back(p);
   }
+  //=======================================================================
 
+  //=======================================================================
   void Executer::EndPackage()
   {
     if (mOpenPackage.size()>1) mOpenPackage.pop_back();
   }
+  //=======================================================================
 
+  //=======================================================================
   void Executer::Define (const std::string &name,
                          const std::string &pack,
                          const std::string &scriptfilename)
@@ -168,14 +186,18 @@ namespace bbtk
     
     bbtkDebugDecTab("Kernel",9);
   }
+  //=======================================================================
 
+  //=======================================================================
   /// Sets the file name to use for the current definition
   /// (Used to set it after the Define command)
   void Executer::SetCurrentFileName (const std::string &name )
   {
     mOpenDefinition.back().box->SetScriptFileName(name);
   }
+  //=======================================================================
 
+  //=======================================================================
   void Executer::EndDefine ()
   {
     bbtkDebugMessageInc("Kernel",9,"Executer::EndDefine(\""
@@ -208,24 +230,24 @@ namespace bbtk
     
     mOpenDefinition.pop_back();
   }
-  
+  //======================================================================= 
 
+  //=======================================================================
   void Executer::Create ( const std::string& nodeType, 
                           const std::string& nodeName)
   {
      Current()->Add(nodeType,nodeName);
   }
+  //=======================================================================
 
-  /*
-    void Executer::Remove (const std::string &nodeName)
+  //=======================================================================
+  void Executer::Destroy(const std::string &boxName)
   {
-    // Current()->RemoveBlackBox(nodeName);
+    bbtkError("Executer::Destroy : NOT IMPLEMENTED !");
   }
-  */
+  //=======================================================================
 
-/**
- *
- */
+  //=======================================================================
   void Executer::Connect (const std::string &nodeFrom,
                           const std::string &outputLabel,
                           const std::string &nodeTo, 
@@ -233,13 +255,12 @@ namespace bbtk
   {
     Current()->Connect(nodeFrom, outputLabel, nodeTo, inputLabel);
   }
+  //=======================================================================
 
- /**
- *
- */ 
-  void Executer::Update (const std::string &nodeName) // would 'Execute' be more meaningfull ?
+  //=======================================================================
+  void Executer::Execute (const std::string &nodeName) 
   {
- // if in root
   // if in root
      if (Current()==mRootCBB) 
      {
         if (!mNoExecMode) 
@@ -252,10 +273,9 @@ namespace bbtk
         Current()->AddToExecutionList(nodeName) ;
      }
   }
+  //=======================================================================
 
-/**
- *
- */
+  //=======================================================================
   void Executer::DefineInput ( const std::string &name,
                                const std::string &box,
                                const std::string &input,
@@ -307,10 +327,9 @@ namespace bbtk
     Current()->DefineInput(name,box,input,help);
 
   }
+  //=======================================================================
 
- /**
- *  
- */ 
+  //=======================================================================
    void Executer::DefineOutput ( const std::string &name,
                                  const std::string &box,
                                  const std::string &output,
@@ -318,10 +337,9 @@ namespace bbtk
   {
     Current()->DefineOutput(name,box,output,help);
   }
+  //=======================================================================
 
-  /**
-   *  
-   */ 
+  //=======================================================================
   void Executer::Set (const std::string &box,
                       const std::string &input,
                       const std::string &value)
@@ -353,10 +371,9 @@ namespace bbtk
       b->bbSetInput(input,v);
       }
   }
+  //=======================================================================
 
-  /**
-   *
-   */
+  //=======================================================================
   std::string Executer::Get(const std::string &box,
                             const std::string &output)
   {
@@ -398,24 +415,30 @@ namespace bbtk
        // b->bbSetInput(input,&v);
       }
   }
+  //=======================================================================
 
-
+  //=======================================================================
   void Executer::Author(const std::string &authorName)
   {
     Current()->AddToAuthor(authorName,Current()==mRootCBB);
   }
+  //=======================================================================
 
+  //=======================================================================
   void Executer::Category(const std::string &category)
   {
     Current()->AddToCategory(category,Current()==mRootCBB);
   }
+  //=======================================================================
 
+  //=======================================================================
   void Executer::Description(const std::string &d)
   {
     Current()->AddToDescription(d,Current()==mRootCBB);
   }
+  //=======================================================================
 
-
+  //=======================================================================
   /// prints the list of the boxes of the current descriptor
   void Executer::PrintBoxes()
   {
@@ -424,7 +447,9 @@ namespace bbtk
     Current()->PrintBlackBoxes();
     bbtkDecTab("Help",1);
  }
+  //=======================================================================
 
+  //=======================================================================
   std::string Executer::ShowGraph(const std::string &nameblackbox, 
                                  const std::string &detailStr, 
                                  const std::string &levelStr,
@@ -492,7 +517,9 @@ namespace bbtk
     */
     return page;
   }
+  //=======================================================================
 
+  //=======================================================================
   /// Generate a png file with the actual pipeline (Graphviz-dot needed)
   std::string Executer::ShowGraphInstances(const std::string &nameblackbox, int detail, int level,
                                            bool system_display)
@@ -562,43 +589,126 @@ namespace bbtk
       }
     return page;
   }
+  //=======================================================================
 
-void Executer::ShowRelations(const std::string &nameblackbox, const std::string &detailStr, const std::string &levelStr)
+  //=======================================================================
+  void Executer::ShowRelations(const std::string &nameblackbox, 
+                              const std::string &detailStr, 
+                              const std::string &levelStr)
   {
-       bool found=false;
+    bool found=false;
+    
+    int detail = atoi(detailStr.c_str());
+    int level  = atoi(levelStr.c_str());
+    BlackBox* blackbox=NULL;
+    if (nameblackbox.compare(".")==0)
+      {
+       blackbox=Current()->GetPrototype();
+      } 
+    else 
+      {
+       blackbox = Current()->GetPrototype()->bbFindBlackBox(nameblackbox);
+      }
+    
+    if (blackbox)
+      {
+       found=true;
+       blackbox->bbShowRelations(blackbox,detail,level); //,mFactory);
+      }
+    
+    if (!found) 
+      {
+       bbtkError("Blackbox Name not found.. <"  <<nameblackbox<<">");
+      }
+  }
+  //=======================================================================
 
-       int detail = atoi(detailStr.c_str());
-       int level  = atoi(levelStr.c_str());
-       BlackBox* blackbox=NULL;
-       if (nameblackbox.compare(".")==0)
-       {
-          blackbox=Current()->GetPrototype();
-       } else {
-          blackbox = Current()->GetPrototype()->bbFindBlackBox(nameblackbox);
-       }
+  //=======================================================================
+  /// sets the level of message
+  void Executer::SetMessageLevel(const std::string &kind,
+                                int level)
+  {
+    bbtk::MessageManager::SetMessageLevel(kind,level);
+  }
+  //=======================================================================
+
+  //=======================================================================
+  /// Prints help on the messages
+  void  Executer::HelpMessages()
+  {
+    bbtk::MessageManager::PrintInfo();
+  }
+  //=======================================================================
+
+  //=======================================================================
+  ///
+  void Executer::Print(const std::string &str)
+  {  
+    if (GetNoExecMode() &&  (Current()==mRootCBB) ) return;
+    if (Current()!=mRootCBB) return;
+
+    bbtkDebugMessageInc("Interpreter",9,"Interpreter::Print(\""<<str<<"\")"<<std::endl);
+
+ // TO DO :
+ // InterpretLine ("load std")
+ // InterpretLine("new ConcatStrings _C_ ") -> trouver un nom unique : # commande 
+ // InterpretLine("new Print _P_") 
+ // InterpretLine("connect _C_.Out _P_.In")
+ // int num = 1
+
+    std::vector<std::string> chains;
+    std::string delimiters("$");
 
-       if (blackbox)
+    // Skip delimiters at beginning.
+    std::string::size_type lastPos = str.find_first_not_of(delimiters, 0);
+    bool is_text = true;
+    if (lastPos>0) is_text = false;
+
+    // Find first delimiter.
+    std::string::size_type pos     = str.find_first_of(delimiters, lastPos);
+
+    while (std::string::npos != pos || std::string::npos != lastPos)
+    {
+       if (is_text) 
        {
-          found=true;
-          blackbox->bbShowRelations(blackbox,detail,level); //,mFactory);
+          // Found a text token, add it to the vector.
+          chains.push_back(str.substr(lastPos, pos - lastPos));
+ // std::string token = str.substr(lastPos, pos - lastPos)
+ // InterpretLine("set _C_.In%num% %token%")
        }
-
-       if (!found) 
+       else 
        {
-          bbtkError("Blackbox Name not found.. <"  <<nameblackbox<<">");
+
+       // is an output (between $$) : decode 
+         std::string tok,box,output;
+         tok = str.substr(lastPos, pos - lastPos);
+         Utilities::SplitAroundFirstDot(tok,box,output);
+         chains.push_back( Get(box,output) );
+
+// InterpretLine("connect %tok% _C_.In%num%") 
+
        }
-  }
+        // Skip delimiters.  Note the "not_of"
+       lastPos = str.find_first_not_of(delimiters, pos);
+        // Find next delimiter
+       pos = str.find_first_of(delimiters, lastPos);
+    //
+       is_text = !is_text;
+// num ++;
+     }
+// InterpretLine("exec _P_")
+// if (IS_IN_WORKSPACE) InterpretLine("delete _C_; delete _P_");
 
-  /*
-  /// sets the level of message
-  void Executer::Message(const std::string &kind,
-                         const std::string& level)
-  {
-    int l;
-    sscanf(level.c_str(),"%d",&l);
-    bbtk::MessageManager::SetMessageLevel(kind,l);
+    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);
+      }
+    bbtkMessage("Output",1,std::endl);
   }
-  */
-
 
 }//namespace