]> Creatis software - bbtk.git/blobdiff - kernel/src/bbtkInterpreterPython.cxx
Clean code for Python
[bbtk.git] / kernel / src / bbtkInterpreterPython.cxx
index e0daa2cb17c35a3f1620d42156c0354a5c2a958d..593b672a1cd68a12a4db83f7a9cbfacba494ef35 100644 (file)
@@ -75,7 +75,7 @@ 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);
   }
   //=========================================================================
@@ -88,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);
   }
   //=========================================================================
@@ -96,7 +96,7 @@ namespace bbtk
   //=========================================================================
   void InterpreterPython::commandInput(const std::string &name,const std::string &box,const std::string &input,const std::string  &help)
   {
-      std::string  code("DECLARE_INPUT('"+name+"','"+box+"."+input+"')");
+      std::string  code("        self.DECLARE_INPUT('"+name+"','"+box+"."+input+"')");
       this->pythonBBTK.push_back(code);
   }
   //=========================================================================
@@ -104,7 +104,7 @@ namespace bbtk
   //=========================================================================
   void InterpreterPython::commandOutput(const std::string &name,const std::string &box,const std::string &output,const std::string  &help)
   {
-      std::string  code("DECLARE_OUTPUT('"+name+"','"+box+"."+output+"')");
+      std::string  code("        self.DECLARE_OUTPUT('"+name+"','"+box+"."+output+"')");
       this->pythonBBTK.push_back(code);
   }
   //=========================================================================
@@ -114,7 +114,7 @@ namespace bbtk
   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);
   }
   //=========================================================================
@@ -122,6 +122,18 @@ namespace bbtk
   //=========================================================================
   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):");
+      
   }
   //=========================================================================
 
@@ -137,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);
   }
   //=========================================================================