From 8ba18df584ba0a409fb042663be9fa76ccb0e0b0 Mon Sep 17 00:00:00 2001
From: "eduardo.davila@creatis.insa-lyon.fr"
 <eduardo.davila@creatis.insa-lyon.fr>
Date: Tue, 31 Oct 2023 13:04:44 +0100
Subject: [PATCH] #3498 Export to Python code for 3DSlicer

---
 kernel/appli/bbs2cpp/bbs2.cxx              | 11 ++++++++---
 kernel/src/bbtkInterpreterPython.cxx       |  9 ++-------
 packages/std/src/bbstdFilesFromDirectory.h |  2 +-
 3 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/kernel/appli/bbs2cpp/bbs2.cxx b/kernel/appli/bbs2cpp/bbs2.cxx
index e0b303c..305efbf 100644
--- a/kernel/appli/bbs2cpp/bbs2.cxx
+++ b/kernel/appli/bbs2cpp/bbs2.cxx
@@ -86,16 +86,21 @@ int main(int argc, char* argv[])
              I->InterpretFile(argv[1]);
              std::vector<std::string> pythonBBTK=  ((bbtk::InterpreterPython*)(I.get()))->pythonBBTK  ;
              FILE *ff=fopen(file.c_str(),"w+");
+             fprintf(ff,"\n" );
              fprintf(ff,"from bbtk.bbtkBlackBox import *\n" );
+             fprintf(ff,"\n" );
              fprintf(ff,"class %s:\n",fileBase.c_str() );
+             fprintf(ff,"\n" );
+             fprintf(ff,"    def __init__(self):\n" );
+             fprintf(ff,"        self.mCBpy  =  ComplexBlackBox('appliTest03')\n" );
+             fprintf(ff,"\n" );
              fprintf(ff,"    def Run(self):\n" );
-             fprintf(ff,"        mCBpy  =  ComplexBlackBox('%s')\n",fileBase.c_str());
              int i,size=pythonBBTK.size();
              for (i=0; i<size;i++)
              {
-                 fprintf(ff,"        mCBpy.%s\n", pythonBBTK[i].c_str() );
+                 fprintf(ff,"        self.mCBpy.%s\n", pythonBBTK[i].c_str() );
              }// for i
-             fprintf(ff,"        mCBpy.Execute()\n" );
+             fprintf(ff,"        self.mCBpy.Execute()\n" );
              fclose(ff);
          } catch (bbtk::Exception e) {
              e.Print();
diff --git a/kernel/src/bbtkInterpreterPython.cxx b/kernel/src/bbtkInterpreterPython.cxx
index 68cce94..f13ded8 100644
--- a/kernel/src/bbtkInterpreterPython.cxx
+++ b/kernel/src/bbtkInterpreterPython.cxx
@@ -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
@@ -84,7 +80,6 @@ namespace bbtk
   }
   //=========================================================================
 
-
   //=========================================================================
   /// Connects the output boxOutput to the input boxInput
   void InterpreterPython::commandConnection (const std::string &boxfrom,
@@ -107,10 +102,11 @@ 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+"')");
+      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
@@ -121,7 +117,6 @@ namespace bbtk
   }
   //=========================================================================
 
-
   //=========================================================================
   void InterpreterPython::commandDefine(const std::string &name,const std::string &pack,const std::string &scriptfilename) // virtual
   {
diff --git a/packages/std/src/bbstdFilesFromDirectory.h b/packages/std/src/bbstdFilesFromDirectory.h
index f3b8671..3ba18ea 100644
--- a/packages/std/src/bbstdFilesFromDirectory.h
+++ b/packages/std/src/bbstdFilesFromDirectory.h
@@ -67,7 +67,7 @@ namespace bbstd
   BBTK_BEGIN_DESCRIBE_BLACK_BOX(FilesFromDirectory,bbtk::AtomicBlackBox);
    BBTK_NAME("FilesFromDirectory");
    BBTK_AUTHOR("jpr@creatis.univ-lyon1.fr");
-   BBTK_DESCRIPTION("returns the fullPathNames of the files in a Directory");
+   BBTK_DESCRIPTION("returns the fullPathNames of the files in a Directory (C++,Python)");
    BBTK_CATEGORY("");
 
    BBTK_INPUT(FilesFromDirectory,Active,"(default true) Active true/false ",bool,"");
-- 
2.49.0