]> Creatis software - bbtk.git/blobdiff - kernel/src/bbtkInterpreterPython.cxx
Clean code for Python
[bbtk.git] / kernel / src / bbtkInterpreterPython.cxx
index 68cce9441c264f434304a0ab7a4b459a2ebbfadb..593b672a1cd68a12a4db83f7a9cbfacba494ef35 100644 (file)
@@ -37,7 +37,6 @@ Version:   $Revision$
  *  \brief Class bbtk::BBPInterpreter
  */
 
-
 #include "bbtkInterpreterPython.h"
 
 #include "bbtkExecuter.h"
@@ -55,8 +54,6 @@ namespace bbtk
     }
   //=========================================================================
 
-
-
   //=========================================================================
     InterpreterPython::InterpreterPython()
     {
@@ -70,7 +67,6 @@ namespace bbtk
     }
   //=========================================================================
 
-
   //=========================================================================
   /// Creates a new black box in current complex box
   void InterpreterPython::commandNew( const std::string& boxType, const std::string& boxName) // virtual
@@ -79,12 +75,11 @@ namespace bbtk
       std::string boxTypeTmp=boxType;
       boxTypeTmp.replace(pos,1,"_");
       // ex:   mCB.New( bbtkBlackBox.std_ConcatString("Box10") )
-      std::string  code("New( "+boxTypeTmp+"('"+boxName+"') )");
+      std::string  code("        self.New( "+boxTypeTmp+"('"+boxName+"') )");
       this->pythonBBTK.push_back(code);
   }
   //=========================================================================
 
-
   //=========================================================================
   /// Connects the output boxOutput to the input boxInput
   void InterpreterPython::commandConnection (const std::string &boxfrom,
@@ -93,7 +88,7 @@ namespace bbtk
       const std::string &input)                        // virtual
   {
       //ex: mCB.Connection( "Box10" , "Out", "Box11", "In")
-      std::string  code("Connection('"+boxfrom+"','"+output+"','"+boxto+"','"+input+"')");
+      std::string  code("        self.Connection('"+boxfrom+"','"+output+"','"+boxto+"','"+input+"')");
       this->pythonBBTK.push_back(code);
   }
   //=========================================================================
@@ -101,30 +96,44 @@ namespace bbtk
   //=========================================================================
   void InterpreterPython::commandInput(const std::string &name,const std::string &box,const std::string &input,const std::string  &help)
   {
+      std::string  code("        self.DECLARE_INPUT('"+name+"','"+box+"."+input+"')");
+      this->pythonBBTK.push_back(code);
   }
   //=========================================================================
 
   //=========================================================================
   void InterpreterPython::commandOutput(const std::string &name,const std::string &box,const std::string &output,const std::string  &help)
   {
+      std::string  code("        self.DECLARE_OUTPUT('"+name+"','"+box+"."+output+"')");
+      this->pythonBBTK.push_back(code);
   }
   //=========================================================================
 
-
   //=========================================================================
   /// sets the input of the box with the value
   void InterpreterPython::commandSet(const std::string &box,const std::string &input,const std::string &value) // virtual
   {
       //ex:     mCB.Set("Box10","In2","/hola.mhd")
-      std::string  code("Set('"+box+"','"+input+"','"+value+"')");
+      std::string  code("        self.Set('"+box+"','"+input+"','"+value+"')");
       this->pythonBBTK.push_back(code);
   }
   //=========================================================================
 
-
   //=========================================================================
   void InterpreterPython::commandDefine(const std::string &name,const std::string &pack,const std::string &scriptfilename) // virtual
   {
+
+      this->pythonBBTK.push_back(" ");
+      this->pythonBBTK.push_back("from bbtk.bbtkBlackBox import *");
+      this->pythonBBTK.push_back(" ");
+      this->pythonBBTK.push_back("class "+pack+"_"+name+"(ComplexBlackBox):");
+      this->pythonBBTK.push_back(" ");
+      this->pythonBBTK.push_back("    def __init__(self, nameBox):");
+      this->pythonBBTK.push_back("        super().__init__(nameBox)");
+      this->pythonBBTK.push_back("        self.Init()");
+      this->pythonBBTK.push_back(" ");
+      this->pythonBBTK.push_back("    def Init(self):");
+      
   }
   //=========================================================================
 
@@ -140,7 +149,7 @@ namespace bbtk
   void InterpreterPython::commandExec(const std::string &word) // virtual
   {
       //Ex:     mCB.AddToExecutableLst("Box13")
-      std::string  code("AddToExecutableLst('"+word+"')");
+      std::string  code("        self.AddToExecutableLst('"+word+"')");
       this->pythonBBTK.push_back(code);
   }
   //=========================================================================