]> Creatis software - bbtk.git/blobdiff - kernel/appli/bbs2cpp/bbs2.cxx
#3498 Export to Python code for 3DSlicer
[bbtk.git] / kernel / appli / bbs2cpp / bbs2.cxx
similarity index 60%
rename from kernel/appli/bbs2cpp/bbs2cpp.cxx
rename to kernel/appli/bbs2cpp/bbs2.cxx
index 501a461965be8ca128e1f4318d9cf010bafff702..c193d24bf6c8103749b99d678feef37da3e2fc3d 100644 (file)
 =========================================================================*/
 
 
+#include <stdio.h>
+
 #include "bbtkInterpreter.h"
+#include "bbtkInterpreterPy.h"
 #include "bbtkUtilities.h"
 
 int main(int argc, char* argv[])
 {  
-  if (argc<2) return 1;
-
-  std::string file,path;
-  file = bbtk::Utilities::ExtractScriptName(argv[1],path);
-  file += ".h";
-  bbtk::Interpreter::Pointer I = bbtk::Interpreter::New(file);
-
-  I->SetThrow(true);
-
-  try
+    if (argc<3)
     {
-      I->InterpretFile(argv[1]);
-    }
-  catch (bbtk::Exception e)
-    {
-      e.Print();
+        printf("bbs2 <filename.bbs> <cxx|py>\n");
+        return 1;
     }
+    std::string file,path;
+    std::string extention( argv[2] );
+    file = bbtk::Utilities::ExtractScriptName(argv[1],path);
+    file += std::string(".")+extention;
 
+    if ( extention.compare("cxx")==0)
+    {
+        printf("bbs -> cxx\n");
+        bbtk::Interpreter::Pointer I = bbtk::Interpreter::New(file);
+        I->SetThrow(true);
+        try
+        {
+            I->InterpretFile(argv[1]);
+        } catch (bbtk::Exception e) {
+            e.Print();
+        } // try
+    } // if cxx
+    
+    if ( extention.compare("py")==0)
+    {
+        printf("bbs -> py\n");
+         bbtk::InterpreterPy::Pointer I = bbtk::InterpreterPy::New();
+         I->SetThrow(true);
+         try
+         {
+             I->InterpretFile(argv[1]);
+             std::vector<std::string> pythonBBTK=  ((bbtk::InterpreterPy*)(I.get()))->pythonBBTK  ;
+             FILE *ff=fopen(file.c_str(),"w+");
+             fprintf(ff,"from bbtk.bbtkBlackBox import *\n" );
+             fprintf(ff,"class appliTest02:\n" );
+             fprintf(ff,"    def Run(self):\n" );
+             fprintf(ff,"        mCB  = ComplexBlackBox('appliTest02')\n");
+             int i,size=pythonBBTK.size();
+             for (i=0; i<size;i++)
+             {
+                 fprintf(ff,"        mCB.%s\n", pythonBBTK[i].c_str() );
+             }// for i
+             fprintf(ff,"        mCB.Execute()\n" );
+             fclose(ff);
+         } catch (bbtk::Exception e) {
+             e.Print();
+         } // try
+    } // py
+    
   return 0;
 }