From 218494269b7edd29971bd3ca5f0698dd627b5c37 Mon Sep 17 00:00:00 2001 From: "eduardo.davila@creatis.insa-lyon.fr" Date: Tue, 23 Jul 2024 10:26:31 +0200 Subject: [PATCH] #3522 javascript ComplexBoxes --- kernel/appli/bbs2cpp/bbs2.cxx | 13 +++--- kernel/src/bbtkInterpreterJavaScript.cxx | 46 +++++++++++++++++-- kernel/src/bbtkInterpreterPython.cxx | 2 - packages/std/src/bbstdGetVectorElement.h | 2 +- packages/std/src/bbstdMagicBox.h | 2 +- packages/std/src/bbstdMultipleInputs.xml | 2 +- packages/std/src/bbstdSplitFilePathVector.h | 2 +- .../bbs/boxes/imageVtkPropertiesWidget.bbg | 2 +- .../bbs/boxes/imageVtkPropertiesWidget.bbs | 2 +- packages/vtk/src/bbvtkGetVectorElement.h | 2 +- packages/vtk/src/bbvtkImageVtkProperties.h | 2 +- packages/vtk/src/bbvtkMarchingCubes.cxx | 10 +--- packages/wx/src/bbwxLayoutLine.h | 2 +- packages/wx/src/bbwxOutputText.xml | 2 +- packages/wx/src/bbwxSlider.h | 2 +- 15 files changed, 61 insertions(+), 32 deletions(-) diff --git a/kernel/appli/bbs2cpp/bbs2.cxx b/kernel/appli/bbs2cpp/bbs2.cxx index 2b881d2..e206442 100644 --- a/kernel/appli/bbs2cpp/bbs2.cxx +++ b/kernel/appli/bbs2cpp/bbs2.cxx @@ -120,20 +120,21 @@ int main(int argc, char* argv[]) I->InterpretFile(argv[1]); std::vector 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; ijavascriptBBTK.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); } //========================================================================= diff --git a/kernel/src/bbtkInterpreterPython.cxx b/kernel/src/bbtkInterpreterPython.cxx index 593b672..e47966f 100644 --- a/kernel/src/bbtkInterpreterPython.cxx +++ b/kernel/src/bbtkInterpreterPython.cxx @@ -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):"); - } //========================================================================= diff --git a/packages/std/src/bbstdGetVectorElement.h b/packages/std/src/bbstdGetVectorElement.h index 64353a6..452b43c 100644 --- a/packages/std/src/bbstdGetVectorElement.h +++ b/packages/std/src/bbstdGetVectorElement.h @@ -63,7 +63,7 @@ namespace bbstd BBTK_NAME("Get"+bbtk::HumanTypeName >()+"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 >()); + BBTK_DESCRIPTION("(C++,Python,JavaScript) Gets the i-th element from the input vector ("+bbtk::TypeName >()); typedef std::vector Tvector; BBTK_TEMPLATE_INPUT(GetVectorElement, In,"Input",Tvector); BBTK_TEMPLATE_INPUT(GetVectorElement, I, "iElement (default 0)",int); diff --git a/packages/std/src/bbstdMagicBox.h b/packages/std/src/bbstdMagicBox.h index 20c964f..05435d5 100644 --- a/packages/std/src/bbstdMagicBox.h +++ b/packages/std/src/bbstdMagicBox.h @@ -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 diff --git a/packages/std/src/bbstdMultipleInputs.xml b/packages/std/src/bbstdMultipleInputs.xml index 2d01e05..df2a9ef 100644 --- a/packages/std/src/bbstdMultipleInputs.xml +++ b/packages/std/src/bbstdMultipleInputs.xml @@ -3,7 +3,7 @@ laurent.guigues@creatis.insa-lyon.fr - (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. + (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. misc diff --git a/packages/std/src/bbstdSplitFilePathVector.h b/packages/std/src/bbstdSplitFilePathVector.h index 8e71238..631d874 100644 --- a/packages/std/src/bbstdSplitFilePathVector.h +++ b/packages/std/src/bbstdSplitFilePathVector.h @@ -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,""); diff --git a/packages/toolsbbtk/bbs/boxes/imageVtkPropertiesWidget.bbg b/packages/toolsbbtk/bbs/boxes/imageVtkPropertiesWidget.bbg index b35d0ba..e642777 100644 --- a/packages/toolsbbtk/bbs/boxes/imageVtkPropertiesWidget.bbg +++ b/packages/toolsbbtk/bbs/boxes/imageVtkPropertiesWidget.bbg @@ -5,7 +5,7 @@ APP_START CATEGORY: -DESCRIPTION:(C++,Python) Description ?? +DESCRIPTION:(C++,Python,JavaScript) Description ?? AUTHOR:Author ?? EXPORTFORMAT:0 COMPLEXBOX:TRUE diff --git a/packages/toolsbbtk/bbs/boxes/imageVtkPropertiesWidget.bbs b/packages/toolsbbtk/bbs/boxes/imageVtkPropertiesWidget.bbs index bfcf1e4..91a09a8 100644 --- a/packages/toolsbbtk/bbs/boxes/imageVtkPropertiesWidget.bbs +++ b/packages/toolsbbtk/bbs/boxes/imageVtkPropertiesWidget.bbs @@ -12,7 +12,7 @@ include std define ImageVtkPropertiesWidget toolsbbtk author "Author ??" -description "(C++,Python) Description ??" +description "(C++,Python,JavaScript) Description ??" category "" diff --git a/packages/vtk/src/bbvtkGetVectorElement.h b/packages/vtk/src/bbvtkGetVectorElement.h index d8dd729..6a766dc 100644 --- a/packages/vtk/src/bbvtkGetVectorElement.h +++ b/packages/vtk/src/bbvtkGetVectorElement.h @@ -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 >()); + BBTK_DESCRIPTION("(C++,JavaScript) Gets the i-th element from the input vector ("+bbtk::TypeName >()); typedef std::vector Tvector; BBTK_TEMPLATE_INPUT(GetVectorElement, In,"(default NULL) Input",Tvector); BBTK_TEMPLATE_INPUT(GetVectorElement, I, "iElement (default 0)",int); diff --git a/packages/vtk/src/bbvtkImageVtkProperties.h b/packages/vtk/src/bbvtkImageVtkProperties.h index 23d43ea..815beba 100644 --- a/packages/vtk/src/bbvtkImageVtkProperties.h +++ b/packages/vtk/src/bbvtkImageVtkProperties.h @@ -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 ,""); diff --git a/packages/vtk/src/bbvtkMarchingCubes.cxx b/packages/vtk/src/bbvtkMarchingCubes.cxx index c82ca61..3e4c117 100644 --- a/packages/vtk/src/bbvtkMarchingCubes.cxx +++ b/packages/vtk/src/bbvtkMarchingCubes.cxx @@ -46,11 +46,9 @@ 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_ diff --git a/packages/wx/src/bbwxLayoutLine.h b/packages/wx/src/bbwxLayoutLine.h index e4889b4..1992f32 100644 --- a/packages/wx/src/bbwxLayoutLine.h +++ b/packages/wx/src/bbwxLayoutLine.h @@ -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*,""); diff --git a/packages/wx/src/bbwxOutputText.xml b/packages/wx/src/bbwxOutputText.xml index 97c4704..5b6b016 100644 --- a/packages/wx/src/bbwxOutputText.xml +++ b/packages/wx/src/bbwxOutputText.xml @@ -3,7 +3,7 @@ laurent.guigues at creatis.insa-lyon.fr - (C++,Python) Text zone to be inserted into a window (wxStaticText) + (C++,Python,JavaScript) Text zone to be inserted into a window (wxStaticText) diff --git a/packages/wx/src/bbwxSlider.h b/packages/wx/src/bbwxSlider.h index d5cc04d..37d5c2b 100644 --- a/packages/wx/src/bbwxSlider.h +++ b/packages/wx/src/bbwxSlider.h @@ -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, ""); -- 2.47.1