/* # --------------------------------------------------------------------- # # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image # pour la SantÈ) # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton # Previous Authors : Laurent Guigues, Jean-Pierre Roux # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil # # This software is governed by the CeCILL-B license under French law and # abiding by the rules of distribution of free software. You can use, # modify and/ or redistribute the software under the terms of the CeCILL-B # license as circulated by CEA, CNRS and INRIA at the following URL # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html # or in the file LICENSE.txt. # # As a counterpart to the access to the source code and rights to copy, # modify and redistribute granted by the license, users are provided only # with a limited warranty and the software's author, the holder of the # economic rights, and the successive licensors have only limited # liability. # # The fact that you are presently reading this means that you have had # knowledge of the CeCILL-B license and that you accept its terms. # ------------------------------------------------------------------------ */ /*========================================================================= Program: bbtk Module: $RCSfile: bbs2cpp.cxx,v $ Language: C++ Date: $Date: 2012/11/16 08:48:18 $ Version: $Revision: 1.5 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or http://www.creatis.insa-lyon.fr/Public/bbtk/License.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #include #include "bbtkUtilities.h" #include "bbtkInterpreter.h" #include "bbtkInterpreterJavaScript.h" #include "bbtkInterpreterPython.h" int main(int argc, char* argv[]) { if (argc<3) { printf("bbs2 \n"); return 1; } //EED 2023-11-07 // std::string fileBase,file,path; // std::string extention( argv[2] ); // fileBase = bbtk::Utilities::ExtractScriptName(argv[1],path); // file = fileBase + std::string(".") + extention; std::string fileBase,path; std::string extention( argv[2] ); fileBase = bbtk::Utilities::ExtractScriptName(argv[1],path); std::string file(path+"/"+fileBase+"."+extention); printf("file %s \n",file.c_str() ); 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::InterpreterPython::Pointer I = bbtk::InterpreterPython::New(); I->SetThrow(true); try { I->InterpretFile(argv[1]); std::vector 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(ComplexBlackBox):\n",fileBase.c_str() ); fprintf(ff,"\n" ); fprintf(ff," def __init__(self, nameBox):\n" ); fprintf(ff," super().__init__(nameBox)\n" ); fprintf(ff,"\n" ); fprintf(ff," def Run(self):\n" ); int i,size=pythonBBTK.size(); for (i=0; i js\n"); bbtk::InterpreterJavaScript::Pointer I = bbtk::InterpreterJavaScript::New(); I->SetThrow(true); try { 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" ); fprintf(ff,"export class %s{\n",fileBase.c_str() ); fprintf(ff," Run(){\n" ); fprintf(ff," let mCBjs = new bbtk.ComplexBlackBox('%s')\n",fileBase.c_str()); int i,size=javascriptBBTK.size(); for (i=0; i