]> Creatis software - bbtk.git/commitdiff
#3522 javascript ComplexBoxes
authoreduardo.davila@creatis.insa-lyon.fr <eduardo.davila@creatis.insa-lyon.fr>
Tue, 23 Jul 2024 08:26:31 +0000 (10:26 +0200)
committereduardo.davila@creatis.insa-lyon.fr <eduardo.davila@creatis.insa-lyon.fr>
Tue, 23 Jul 2024 08:26:31 +0000 (10:26 +0200)
15 files changed:
kernel/appli/bbs2cpp/bbs2.cxx
kernel/src/bbtkInterpreterJavaScript.cxx
kernel/src/bbtkInterpreterPython.cxx
packages/std/src/bbstdGetVectorElement.h
packages/std/src/bbstdMagicBox.h
packages/std/src/bbstdMultipleInputs.xml
packages/std/src/bbstdSplitFilePathVector.h
packages/toolsbbtk/bbs/boxes/imageVtkPropertiesWidget.bbg
packages/toolsbbtk/bbs/boxes/imageVtkPropertiesWidget.bbs
packages/vtk/src/bbvtkGetVectorElement.h
packages/vtk/src/bbvtkImageVtkProperties.h
packages/vtk/src/bbvtkMarchingCubes.cxx
packages/wx/src/bbwxLayoutLine.h
packages/wx/src/bbwxOutputText.xml
packages/wx/src/bbwxSlider.h

index 2b881d2..e206442 100644 (file)
@@ -120,20 +120,21 @@ int main(int argc, char* argv[])
                I->InterpretFile(argv[1]);
             std::vector<std::string> javascriptBBTK=  ((bbtk::InterpreterJavaScript*)(I.get()))->javascriptBBTK  ;
             FILE *ff=fopen(file.c_str(),"w+");
-            fprintf(ff,"import * as bbtk from './bbtk.js' \n" );
 //clean this code
+//            fprintf(ff,"import * as bbtk from './bbtk.js' \n" );
 //            fprintf(ff,"export  class %s{\n",fileBase.c_str() );
-            fprintf(ff,"    Run(){\n" );
+//            fprintf(ff,"    Run(){\n" );
 //clean this code
 //            fprintf(ff,"        let mCBjs  = new bbtk.ComplexBlackBox('%s')\n",fileBase.c_str());
             int i,size=javascriptBBTK.size();
             for (i=0; i<size;i++)
             {
-                fprintf(ff,"        mCBjs.%s\n", javascriptBBTK[i].c_str() );
+                //              fprintf(ff,"        mCBjs.%s\n", javascriptBBTK[i].c_str() );
+                fprintf(ff,"%s\n", javascriptBBTK[i].c_str() );
             }// for i
-            fprintf(ff,"        mCBjs.Execute()\n" );
-            fprintf(ff,"    } \n" );
-            fprintf(ff,"} \n" );
+//          fprintf(ff,"        mCBjs.Execute()\n" );
+//            fprintf(ff,"    } \n" );
+//            fprintf(ff,"} \n" );
             fclose(ff);
         } catch (bbtk::Exception e) {
             e.Print();
index 1927b2d..eed5a94 100644 (file)
@@ -77,9 +77,9 @@ namespace bbtk
   {
       int pos = boxType.find( std::string(":") );
       std::string boxTypeTmp=boxType;
-      boxTypeTmp.replace(pos,1,"_");
+      boxTypeTmp.replace(pos,1,".");
       // ex:   mCB.New( bbtkBlackBox.std_ConcatString("Box10") )
-      std::string  code("New( new bbtk."+boxTypeTmp+"('"+boxName+"') )");
+      std::string  code("       this.New( new bbtk.bb"+boxTypeTmp+"('"+boxName+"') )");
       this->javascriptBBTK.push_back(code);
   }
   //=========================================================================
@@ -93,7 +93,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("       this.Connection('"+boxfrom+"','"+output+"','"+boxto+"','"+input+"')");
       this->javascriptBBTK.push_back(code);
   }
   //=========================================================================
@@ -101,12 +101,17 @@ namespace bbtk
   //=========================================================================
   void InterpreterJavaScript::commandInput(const std::string &name,const std::string &box,const std::string &input,const std::string  &help)
   {
+      std::string  code("       this.DECLARE_INPUT('"+name+"','"+box+"."+input+"')");
+      this->javascriptBBTK.push_back(code);
+
   }
   //=========================================================================
 
   //=========================================================================
   void InterpreterJavaScript::commandOutput(const std::string &name,const std::string &box,const std::string &output,const std::string  &help)
   {
+      std::string  code("       this.DECLARE_OUTPUT('"+name+"','"+box+"."+output+"')");
+      this->javascriptBBTK.push_back(code);
   }
   //=========================================================================
 
@@ -116,7 +121,7 @@ namespace bbtk
   void InterpreterJavaScript::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("       this.Set('"+box+"','"+input+"','"+value+"')");
       this->javascriptBBTK.push_back(code);
   }
   //=========================================================================
@@ -125,6 +130,35 @@ namespace bbtk
   //=========================================================================
   void InterpreterJavaScript::commandDefine(const std::string &name,const std::string &pack,const std::string &scriptfilename) // virtual
   {
+      //            fprintf(ff,"import * as bbtk from './bbtk.js' \n" );
+
+      
+      
+          
+      this->javascriptBBTK.push_back(" ");
+      this->javascriptBBTK.push_back("import * as bbtk from '/bbtk/bbtk.js' ");
+      this->javascriptBBTK.push_back(" ");
+//      this->javascriptBBTK.push_back("export class "+pack+"_"+name+" extends bbtk.bbkernel.ComplexBlackBox {");
+      this->javascriptBBTK.push_back("export class "+name+" extends bbtk.bbkernel.ComplexBlackBox {");
+      this->javascriptBBTK.push_back(" ");
+      this->javascriptBBTK.push_back("    constructor(nameBox) {");
+      this->javascriptBBTK.push_back("        super(nameBox)");
+      this->javascriptBBTK.push_back("        this.Init()");
+      this->javascriptBBTK.push_back("    }");
+      this->javascriptBBTK.push_back(" ");
+      this->javascriptBBTK.push_back("    async Init() {");
+/*
+      this->javascriptBBTK.push_back(" ");
+      this->javascriptBBTK.push_back("from bbtk.bbtkBlackBox import *");
+      this->javascriptBBTK.push_back(" ");
+      this->javascriptBBTK.push_back("class "+pack+"_"+name+"(ComplexBlackBox):");
+      this->javascriptBBTK.push_back(" ");
+      this->javascriptBBTK.push_back("    def __init__(self, nameBox):");
+      this->javascriptBBTK.push_back("        super().__init__(nameBox)");
+      this->javascriptBBTK.push_back("        self.Init()");
+      this->javascriptBBTK.push_back(" ");
+      this->javascriptBBTK.push_back("    def Init(self):");
+*/
   }
   //=========================================================================
 
@@ -132,6 +166,8 @@ namespace bbtk
   //=========================================================================
   void InterpreterJavaScript::commandEndDefine() // virtual
   {
+      this->javascriptBBTK.push_back("    } // Init ");
+      this->javascriptBBTK.push_back("} // class");
   }
   //=========================================================================
 
@@ -140,7 +176,7 @@ namespace bbtk
   void InterpreterJavaScript::commandExec(const std::string &word) // virtual
   {
       //Ex:     mCB.AddToExecutableLst("Box13")
-      std::string  code("AddToExecutableLst('"+word+"')");
+      std::string  code("       this.AddToExecutableLst('"+word+"')");
       this->javascriptBBTK.push_back(code);
   }
   //=========================================================================
index 593b672..e47966f 100644 (file)
@@ -122,7 +122,6 @@ 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(" ");
@@ -133,7 +132,6 @@ namespace bbtk
       this->pythonBBTK.push_back("        self.Init()");
       this->pythonBBTK.push_back(" ");
       this->pythonBBTK.push_back("    def Init(self):");
-      
   }
   //=========================================================================
 
index 64353a6..452b43c 100644 (file)
@@ -63,7 +63,7 @@ namespace bbstd
   BBTK_NAME("Get"+bbtk::HumanTypeName<std::vector<T> >()+"Element");
   BBTK_AUTHOR("info-dev@creatis.insa-lyon.fr");
  // BBTK_DEFAULT_ADAPTOR();
-  BBTK_DESCRIPTION("(C++,Python) Gets the i-th element from the input vector ("+bbtk::TypeName<std::vector<T> >());
+  BBTK_DESCRIPTION("(C++,Python,JavaScript) Gets the i-th element from the input vector ("+bbtk::TypeName<std::vector<T> >());
   typedef std::vector<T> Tvector;
   BBTK_TEMPLATE_INPUT(GetVectorElement, In,"Input",Tvector);
   BBTK_TEMPLATE_INPUT(GetVectorElement, I, "iElement (default 0)",int);  
index 20c964f..05435d5 100644 (file)
@@ -107,7 +107,7 @@ namespace bbstd
   BBTK_NAME("MagicBox");
   BBTK_AUTHOR("laurent.guigues@creatis.insa-lyon.fr");
   BBTK_CATEGORY("misc");
-  BBTK_DESCRIPTION("(C++,Python) Takes *any kind* of data and copies it to its output. Is a magic box as any box output can be plugged into it and its output can be plugged into any other box input (dynamic type checking, see below), hence it can be put between **any** two boxes. Type matching between its output and the input of the box(es) to which it is connected is made at *run-time*. The pipeline will be executed if the data types : i) match exactly ii) can be transformed by an adaptor iii) are related pointers, i.e. if the output pointer can be upcasted (static_cast) or downcasted (dynamic_cast) to an input type pointer (see the bbtk::any output connection rule in the guide for details). Important uses of the MagicBox are : 1) performing run-time pointer cast, either upward or backward an object hierarchy 2) perform data adaptation (adaptor creation) at run-time vs. pipeline creation time.");
+  BBTK_DESCRIPTION("(C++,Python,JavaScript) Takes *any kind* of data and copies it to its output. Is a magic box as any box output can be plugged into it and its output can be plugged into any other box input (dynamic type checking, see below), hence it can be put between **any** two boxes. Type matching between its output and the input of the box(es) to which it is connected is made at *run-time*. The pipeline will be executed if the data types : i) match exactly ii) can be transformed by an adaptor iii) are related pointers, i.e. if the output pointer can be upcasted (static_cast) or downcasted (dynamic_cast) to an input type pointer (see the bbtk::any output connection rule in the guide for details). Important uses of the MagicBox are : 1) performing run-time pointer cast, either upward or backward an object hierarchy 2) perform data adaptation (adaptor creation) at run-time vs. pipeline creation time.");
  
  AddInputDescriptor
   (new bbtk::AtomicBlackBoxInputDescriptor
index 2d01e05..df2a9ef 100644 (file)
@@ -3,7 +3,7 @@
 <blackbox name="MultipleInputs">
 
   <author>laurent.guigues@creatis.insa-lyon.fr</author>
-  <description>(C++,Python) This box has multiple Void inputs and one Void output. Hence it relays any input modification to its output. It is usefull to plug different BoxChange outputs into the same BoxExecute input.</description>
+  <description>(C++,Python,JavaScript) This box has multiple Void inputs and one Void output. Hence it relays any input modification to its output. It is usefull to plug different BoxChange outputs into the same BoxExecute input.</description>
   <category>misc</category>
 
   <input name="In1"  type="bbtk::Void" description="Input 1"/>
index 8e71238..631d874 100644 (file)
@@ -34,7 +34,7 @@ class bbstd_EXPORT SplitFilePathVector
 BBTK_BEGIN_DESCRIBE_BLACK_BOX(SplitFilePathVector,bbtk::AtomicBlackBox);
   BBTK_NAME("SplitFilePathVector");
   BBTK_AUTHOR("Info-Dev");
-  BBTK_DESCRIPTION("No Description.");
+  BBTK_DESCRIPTION("(C++,JavaScript) No Description.");
   BBTK_CATEGORY("empty");
 
   BBTK_INPUT(SplitFilePathVector,In,"PathFileName",std::vector<std::string>,"");
index b35d0ba..e642777 100644 (file)
@@ -5,7 +5,7 @@
 
 APP_START
 CATEGORY:<VOID>
-DESCRIPTION:(C++,Python) Description ??
+DESCRIPTION:(C++,Python,JavaScript) Description ??
 AUTHOR:Author ??
 EXPORTFORMAT:0
 COMPLEXBOX:TRUE
index bfcf1e4..91a09a8 100644 (file)
@@ -12,7 +12,7 @@ include std
 define ImageVtkPropertiesWidget toolsbbtk
 
 author "Author ??"
-description "(C++,Python) Description ??"
+description "(C++,Python,JavaScript) Description ??"
 
 category "<VOID>"
 
index d8dd729..6a766dc 100644 (file)
@@ -85,7 +85,7 @@ namespace bbvtk
 //   BBTK_NAME("GetVectorVtkImageDataElement");
   BBTK_AUTHOR("info-dev@creatis.insa-lyon.fr");
  // BBTK_DEFAULT_ADAPTOR();
-  BBTK_DESCRIPTION("Gets the i-th element from the input vector ("+bbtk::TypeName<std::vector<T> >());
+  BBTK_DESCRIPTION("(C++,JavaScript) Gets the i-th element from the input vector ("+bbtk::TypeName<std::vector<T> >());
   typedef std::vector<T> Tvector;
   BBTK_TEMPLATE_INPUT(GetVectorElement, In,"(default NULL) Input",Tvector);
   BBTK_TEMPLATE_INPUT(GetVectorElement, I, "iElement (default 0)",int);
index 23d43ea..815beba 100644 (file)
@@ -68,7 +68,7 @@ class bbvtk_EXPORT ImageVtkProperties
 BBTK_BEGIN_DESCRIBE_BLACK_BOX(ImageVtkProperties,bbtk::AtomicBlackBox);
  BBTK_NAME("ImageVtkProperties");
  BBTK_AUTHOR("Info-Dev Creatis");
- BBTK_DESCRIPTION("(C++,Python) Image information Dim, Spc, Type, MinMax");
+ BBTK_DESCRIPTION("(C++,Python,JavaScript) Image information Dim, Spc, Type, MinMax");
  BBTK_CATEGORY("filter");
  BBTK_INPUT(ImageVtkProperties,In,"Input image (vtk)",vtkImageData*,"");
  BBTK_OUTPUT(ImageVtkProperties,Origin,"Origin", std::vector<double>  ,"");
index c82ca61..3e4c117 100644 (file)
 
 namespace bbvtk
 {
-
    BBTK_ADD_BLACK_BOX_TO_PACKAGE(vtk,MarchingCubes)
    BBTK_BLACK_BOX_IMPLEMENTATION(MarchingCubes,bbtk::AtomicBlackBox);
 
-
        void MarchingCubes::Process()
        {
             if (bbGetInputActive()==true)
@@ -71,29 +69,25 @@ namespace bbvtk
                 bbGetVtkObject()->Update();
             } // Active
        }
-       
        //-----------------------------------------------------------------     
        void MarchingCubes::bbUserSetDefaultValues()
        {
-                BBTK_VTK_SET_DEFAULT_VALUES();
+        BBTK_VTK_SET_DEFAULT_VALUES();
                bbSetInputActive(true);
                bbSetInputValue(400);
                bbSetInputComputeNormalsOn(true);
                bbSetInputComputeScalarsOn(true);
        }
-       
-       //-----------------------------------------------------------------     
+       //-----------------------------------------------------------------
        void MarchingCubes::bbUserInitializeProcessing()
        {
                BBTK_VTK_INITIALIZE_PROCESSING();
        }
-       
        //-----------------------------------------------------------------     
        void MarchingCubes::bbUserFinalizeProcessing()
        {
                BBTK_VTK_FINALIZE_PROCESSING();
        }       
-       
 } // EO namespace bbvtk
 #endif //_USE_VTK_
 
index e4889b4..1992f32 100644 (file)
@@ -100,7 +100,7 @@ namespace bbwx
   BBTK_BEGIN_DESCRIBE_BLACK_BOX(LayoutLine,bbtk::WxBlackBox);
   BBTK_NAME("LayoutLine");
   BBTK_AUTHOR("eduardo.davila@creatis.insa-lyon.fr");
-  BBTK_DESCRIPTION("(C++,Python) LayoutLine widget (wxBoxSizer)");
+  BBTK_DESCRIPTION("(C++,Python,JavaScript) LayoutLine widget (wxBoxSizer)");
   // Already inserted for any WxBlackBox  BBTK_CATEGORY("widget");  
   BBTK_INPUT(LayoutLine,Widget1,"widget 1",wxWindow*,"");
   BBTK_INPUT(LayoutLine,Widget2,"widget 2",wxWindow*,"");
index 97c4704..5b6b016 100644 (file)
@@ -3,7 +3,7 @@
 <blackbox name="OutputText" widget>
 
   <author>laurent.guigues at creatis.insa-lyon.fr</author>
-  <description>(C++,Python) Text zone to be inserted into a window (wxStaticText)</description>
+  <description>(C++,Python,JavaScript) Text zone to be inserted into a window (wxStaticText)</description>
   <category></category>
 
   <input name="Title" type="std::string" description="Title prepended to the text"/>
index d5cc04d..37d5c2b 100644 (file)
@@ -99,7 +99,7 @@ namespace bbwx
   BBTK_NAME("Slider");
   BBTK_AUTHOR("eduardo.davila@creatis.insa-lyon.fr");
   // Already inserted for any WxBlackBox  BBTK_CATEGORY("widget");
-  BBTK_DESCRIPTION("(C++,Python) Slider widget (wxSlider)");
+  BBTK_DESCRIPTION("(C++,Python,JavaScript) Slider widget (wxSlider)");
   BBTK_INPUT(Slider,In,               "Initial position of the slider (default 0)",                          int,         "");
   BBTK_INPUT(Slider,Min,              "Minimum value of the slider (default 0)",                             int,         "");
   BBTK_INPUT(Slider,Max,              "Maximum value of the slider (default 500)",                           int,         "");