From 24ee513bec6243728f40b7ee634c1b573d82f296 Mon Sep 17 00:00:00 2001 From: caremoli Date: Mon, 31 Jan 2011 16:26:01 +0000 Subject: [PATCH] CCAR: add basic types from KERNEL SALOME_TYPES module add 1 example types1 that uses these types add 2 functions to module_generator package (add_type and add_module) to be able to customize YACSGEN for non builtin modules --- Examples/context.py | 2 + Examples/types1/Makefile | 21 ++ Examples/types1/README.txt | 25 ++ Examples/types1/components.py | 170 ++++++++++++++ Examples/types1/coupling.xml | 364 ++++++++++++++++++++++++++++++ Examples/types1/geom_coupling.xml | 93 ++++++++ module_generator/__init__.py | 2 + module_generator/cata_tmpl.py | 1 + module_generator/salomemodules.py | 17 +- module_generator/yacstypes.py | 24 +- 10 files changed, 712 insertions(+), 7 deletions(-) create mode 100644 Examples/types1/Makefile create mode 100644 Examples/types1/README.txt create mode 100644 Examples/types1/components.py create mode 100644 Examples/types1/coupling.xml create mode 100644 Examples/types1/geom_coupling.xml diff --git a/Examples/context.py b/Examples/context.py index 35f4d86..d1e63ad 100644 --- a/Examples/context.py +++ b/Examples/context.py @@ -23,12 +23,14 @@ sys.path.insert(0,"../..") KERNEL_ROOT_DIR=os.getenv("KERNEL_ROOT_DIR","/local/cchris/Salome/Install/KERNEL_V6") GUI_ROOT_DIR=os.getenv("GUI_ROOT_DIR","/local/cchris/Salome/Install/GUI_V6") YACS_ROOT_DIR=os.getenv("YACS_ROOT_DIR","/local/cchris/Salome/Install/YACS_V6") +GEOM_ROOT_DIR=os.getenv("GEOM_ROOT_DIR","/local/cchris/Salome/Install/GEOM_V6") context={'update':1, "makeflags":"", "prerequisites":"/local/cchris/.packages.d/envSalome6main", "kernel":KERNEL_ROOT_DIR, "gui":GUI_ROOT_DIR, + "geom":GEOM_ROOT_DIR, } diff --git a/Examples/types1/Makefile b/Examples/types1/Makefile new file mode 100644 index 0000000..afdabd3 --- /dev/null +++ b/Examples/types1/Makefile @@ -0,0 +1,21 @@ +# Copyright (C) 2009-2010 EDF R&D +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# + +clean: + rm -rf *.o *.so module_SRC module_SRC.bak appli appli.bak install install.bak traceExec_proc diff --git a/Examples/types1/README.txt b/Examples/types1/README.txt new file mode 100644 index 0000000..7769282 --- /dev/null +++ b/Examples/types1/README.txt @@ -0,0 +1,25 @@ +A test for several YACS types SALOME_TYPES and others +========================================================= + +To build this example, modify the ../context.py file +to take into account your configuration. + +1- your prerequisite file +2- your KERNEL_ROOT_DIR + +Then set the environment (including PYTHONPATH for YACSGEN, ../.. from here and execute components.py :: + + source + python components.py + +You should get a SALOME module in source form (module_SRC), its installation (install) and +a SALOME application (appli) composed of modules KERNEL, GUI, YACS and the new module module. + +To run a coupling: + + 1. start SALOME in background : ./appli/runAppli -t + 2. start a SALOME session : ./appli/runSession + 3. start YACS coupler with coupling file : driver coupling.xml + 4. examine output files in /tmp + 5. shutdown SALOME : shutdowSalome.py + 6. exit session : CTRL-D (or exit) diff --git a/Examples/types1/components.py b/Examples/types1/components.py new file mode 100644 index 0000000..550815a --- /dev/null +++ b/Examples/types1/components.py @@ -0,0 +1,170 @@ +# Copyright (C) 2009-2010 EDF R&D +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# + +import os + +#import context from .. +execfile("../context.py") + +from module_generator import Generator,Module,Service,CPPComponent,PYComponent,add_type,add_module + +#overload module GEOM definition +idldefs=""" +#include "GEOM_Gen.idl" +""" +makefiledefs=""" +#module GEOM +GEOM_IDL_INCLUDES = -I$(GEOM_ROOT_DIR)/idl/salome +GEOM_INCLUDES= -I$(GEOM_ROOT_DIR)/include/salome +GEOM_IDL_LIBS= -L$(GEOM_ROOT_DIR)/lib/salome -lSalomeIDLGEOM +GEOM_LIBS= -L$(GEOM_ROOT_DIR)/lib/salome +SALOME_LIBS += ${GEOM_LIBS} +SALOME_IDL_LIBS += ${GEOM_IDL_LIBS} +SALOME_INCLUDES += ${GEOM_INCLUDES} +IDL_INCLUDES += ${GEOM_IDL_INCLUDES} +""" +configdefs=""" +if test "x${GEOM_ROOT_DIR}" != "x" && test -d ${GEOM_ROOT_DIR} ; then + AC_MSG_RESULT(Using GEOM installation in ${GEOM_ROOT_DIR}) +else + AC_MSG_ERROR([Cannot find module GEOM. Have you set GEOM_ROOT_DIR ?],1) +fi +""" +add_module("GEOM",idldefs,makefiledefs,configdefs) + +#overload GEOM_Object definition +add_type("GEOM_Object", "GEOM::GEOM_Object_ptr", "GEOM::GEOM_Object_out", "GEOM", "GEOM::GEOM_Object","GEOM::GEOM_Object_ptr") + + +cwd=os.getcwd() + +defs=""" +""" + +body=""" +//inputs +//Parameter +std::cerr << "a: " << a.name << "=" << a.value << std::endl; + +//ParameterList +for(CORBA::ULong i = 0;iname << "=" << aa->value << std::endl; +//ParameterList +ab=new SALOME_TYPES::ParameterList; +ac= new SALOME_TYPES::Value; +ad= new SALOME_TYPES::VarList; +ae= new SALOME_TYPES::ValueList; +af= new SALOME_TYPES::ParametricInput; +ag= new SALOME_TYPES::ParametricOutput; +""" +c1=CPPComponent("compo1",services=[ + Service("s1",inport=[("a","SALOME_TYPES/Parameter"),("b","SALOME_TYPES/ParameterList"),("c","SALOME_TYPES/Value"), + ("d","SALOME_TYPES/VarList"),("e","SALOME_TYPES/ValueList"),("f","SALOME_TYPES/ParametricInput"), + ("g","SALOME_TYPES/ParametricOutput"), + ], + outport=[("aa","SALOME_TYPES/Parameter"), + ("ab","SALOME_TYPES/ParameterList"), + ("ac","SALOME_TYPES/Value"), + ("ad","SALOME_TYPES/VarList"),("ae","SALOME_TYPES/ValueList"),("af","SALOME_TYPES/ParametricInput"), + ("ag","SALOME_TYPES/ParametricOutput"), + ], + defs=defs,body=body, + ), + Service("s2",inport=[("a","GEOM_Object"),],outport=[("aa","GEOM_Object"),],body="aa=GEOM::GEOM_Object::_duplicate(a);",), + ], + ) + +pydefs="""import SALOME_TYPES""" + +pybody=""" +print a,b,c,d,e,f,g +aa=SALOME_TYPES.Parameter(name="a",value="45.") +ab=[] +ac=[[1,2,3]] +ad=["aaa","bbb"] +ae=[[[1,2,3]]] +af=SALOME_TYPES.ParametricInput(inputVarList=ad,outputVarList=ad, inputValues=[[[1,2,3]]],specificParameters=[]) +ag=SALOME_TYPES.ParametricOutput(outputValues=[[[1,2,3]]], specificOutputInfos=[], returnCode=1, errorMessage="error") +print aa,ab,ac,ad,ae,af,ag +""" +c2=PYComponent("compo2",services=[ + Service("s1",inport=[("a","SALOME_TYPES/Parameter"),("b","SALOME_TYPES/ParameterList"),("c","SALOME_TYPES/Value"), + ("d","SALOME_TYPES/VarList"),("e","SALOME_TYPES/ValueList"),("f","SALOME_TYPES/ParametricInput"), + ("g","SALOME_TYPES/ParametricOutput"), + ], + outport=[("aa","SALOME_TYPES/Parameter"), + ("ab","SALOME_TYPES/ParameterList"), + ("ac","SALOME_TYPES/Value"), + ("ad","SALOME_TYPES/VarList"),("ae","SALOME_TYPES/ValueList"),("af","SALOME_TYPES/ParametricInput"), + ("ag","SALOME_TYPES/ParametricOutput"), + ], + body=pybody,defs=pydefs, + ), + ], + ) + + +g=Generator(Module("mymodule",components=[c1,c2],prefix="./install"),context) +g.generate() +g.bootstrap() +g.configure() +g.make() +g.install() +g.make_appli("appli", restrict=["KERNEL"], altmodules={"GUI":GUI_ROOT_DIR, "YACS":YACS_ROOT_DIR, "GEOM":GEOM_ROOT_DIR}) + diff --git a/Examples/types1/coupling.xml b/Examples/types1/coupling.xml new file mode 100644 index 0000000..a850548 --- /dev/null +++ b/Examples/types1/coupling.xml @@ -0,0 +1,364 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + compo1 + + s1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + compo2 + + s1 + + + + + + + + + + + + + + + + + compo1 + + s1 + + + + + + + + + + + + + + + + + + + + + + + + + + + compo2 + + s1 + + + + + + + + + + + + + + + + s10 s13 + s10 PyScript0 + PyScript1 s10 + PyScript1 s11 + s11 PyScript00 + s11 s12 + + s10 aa + s13 a + + + s10 aa + PyScript0 i1 + + + s10 ab + PyScript0 i2 + + + s10 ab + s13 b + + + s10 ac + s13 c + + + s10 ac + PyScript0 i3 + + + s10 ad + s13 d + + + s10 ad + PyScript0 i5 + + + s10 ae + PyScript0 i4 + + + s10 ae + s13 e + + + s10 af + s13 f + + + s10 af + PyScript0 i6 + + + s10 ag + s13 g + + + s10 ag + PyScript0 i7 + + + PyScript1 o2 + s11 a + + + PyScript1 o2 + s10 a + + + PyScript1 o3 + s11 b + + + PyScript1 o3 + s10 b + + + PyScript1 o4 + s11 c + + + PyScript1 o4 + s10 c + + + PyScript1 o5 + s10 d + + + PyScript1 o5 + s11 d + + + PyScript1 o6 + s11 e + + + PyScript1 o6 + s10 e + + + PyScript1 o7 + s10 f + + + PyScript1 o7 + s11 f + + + PyScript1 o8 + s11 g + + + PyScript1 o8 + s10 g + + + s11 aa + s12 a + + + s11 aa + PyScript00 i1 + + + s11 ab + PyScript00 i2 + + + s11 ab + s12 b + + + s11 ac + s12 c + + + s11 ac + PyScript00 i3 + + + s11 ad + s12 d + + + s11 ad + PyScript00 i5 + + + s11 ae + s12 e + + + s11 ae + PyScript00 i4 + + + s11 af + s12 f + + + s11 af + PyScript00 i6 + + + s11 ag + s12 g + + + s11 ag + PyScript00 i7 + + + + + + + + + + diff --git a/Examples/types1/geom_coupling.xml b/Examples/types1/geom_coupling.xml new file mode 100644 index 0000000..b1e65dc --- /dev/null +++ b/Examples/types1/geom_coupling.xml @@ -0,0 +1,93 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + GEOM_Superv + + MakeBoxDXDYDZ + + + + + + + compo1 + + s2 + + + + + + + MakeBoxDXDYDZ0 s21 + s21 StudyOutNode2 + + MakeBoxDXDYDZ0 return + s21 a + + + s21 aa + StudyOutNode2 i3 + + + MakeBoxDXDYDZ0theDX + 10 + + + MakeBoxDXDYDZ0theDY + 10 + + + MakeBoxDXDYDZ0theDZ + 10 + + + + + + diff --git a/module_generator/__init__.py b/module_generator/__init__.py index e79531f..695e209 100644 --- a/module_generator/__init__.py +++ b/module_generator/__init__.py @@ -29,3 +29,5 @@ from pacocompo import PACOComponent from pycompo import PYComponent from astcompo import ASTERComponent from hxxcompo import HXX2SALOMEComponent +from yacstypes import add_type +from salomemodules import add_module diff --git a/module_generator/cata_tmpl.py b/module_generator/cata_tmpl.py index c8feeff..c9ca28e 100644 --- a/module_generator/cata_tmpl.py +++ b/module_generator/cata_tmpl.py @@ -33,6 +33,7 @@ idl=""" #include "SALOME_PACOExtension.idl" #include "SALOME_Component.idl" #include "SALOME_Comm.idl" +#include "SALOME_Parametric.idl" ${idldefs} diff --git a/module_generator/salomemodules.py b/module_generator/salomemodules.py index bddf0f9..d74d300 100644 --- a/module_generator/salomemodules.py +++ b/module_generator/salomemodules.py @@ -22,6 +22,20 @@ ####################################################################### salome_modules={} +def add_module(module,idldefs="",makefiledefs="",configdefs=""): + """ add a module configuration for other module than KERNEL + + :param module: module name (GEOM, SMESH, VISU, ...) + :type module: string + :param idldefs: definition instructions to add to idl files when using this module + :type idldefs: string + :param makefiledefs: definition instructions to add to Makefile files when using this module + :type makefiledefs: string + :param configdefs: instructions to add to configure file when using this module + :type configdefs: string + """ + salome_modules[module]={"idldefs" : idldefs, "makefiledefs" : makefiledefs, "configdefs" : configdefs} + #module GEOM idldefs=""" #include "GEOM_Gen.idl" @@ -44,8 +58,7 @@ else AC_MSG_ERROR([Cannot find module GEOM. Have you set GEOM_ROOT_DIR ?],1) fi """ - -salome_modules["GEOM"]={"idldefs" : idldefs, "makefiledefs" : makefiledefs, "configdefs" : configdefs} +add_module("GEOM",idldefs,makefiledefs,configdefs) #module MED idldefs=""" diff --git a/module_generator/yacstypes.py b/module_generator/yacstypes.py index 8aa90f1..2d3f59a 100644 --- a/module_generator/yacstypes.py +++ b/module_generator/yacstypes.py @@ -65,7 +65,7 @@ def corba_rtn_type(typ, module): ValidTypes = corbaTypes.keys() PyValidTypes = ValidTypes+["pyobj"] -def add_type(typename, corbaType, corbaOutType, module, idltype, corbaRtnType): +def add_type(typename, corbaType=None, corbaOutType=None, module="", idltype=None, corbaRtnType=None): """ add a data type YACS from other module than KERNEL to the list of available types :param typename: YACS data type name @@ -81,11 +81,11 @@ def add_type(typename, corbaType, corbaOutType, module, idltype, corbaRtnType): :param corbaRtnType: representation for C++ CORBA return parameter :type corbaRtnType: string """ - corbaTypes[typename] = corbaType - corbaOutTypes[typename] = corbaOutType - corbaRtnTypes[typename] = corbaRtnType + corbaTypes[typename] = corbaType or "const "+typename.replace("/","::")+"&" + corbaOutTypes[typename] = corbaOutType or typename.replace("/","::")+"_out" + corbaRtnTypes[typename] = corbaRtnType or typename.replace("/","::")+"*" moduleTypes[typename] = module - idlTypes[typename] = idltype + idlTypes[typename] = idltype or typename.replace("/","::") ValidTypes.append(typename) PyValidTypes.append(typename) @@ -106,10 +106,24 @@ ValidStreamTypes = calciumTypes.keys() ValidParallelStreamTypes = DatastreamParallelTypes.keys() ValidDependencies = ("I", "T") +#Add KERNEL YACS types : YACS name, c++ corba arg in, c++ corba arg out,defining module, repr corba idl, c++ corba return add_type("dataref", "const Engines::dataref&", "Engines::dataref_out", "", "dataref","Engines::dataref*") +add_type("SALOME_TYPES/Parameter") +add_type("SALOME_TYPES/ParameterList", "const SALOME_TYPES::ParameterList&", "SALOME_TYPES::ParameterList_out", "", "SALOME_TYPES::ParameterList","SALOME_TYPES::ParameterList*") +add_type("SALOME_TYPES/Value", "const SALOME_TYPES::Value&", "SALOME_TYPES::Value_out", "", "SALOME_TYPES::Value","SALOME_TYPES::Value*") +add_type("SALOME_TYPES/VarList", "const SALOME_TYPES::VarList&", "SALOME_TYPES::VarList_out", "", "SALOME_TYPES::VarList","SALOME_TYPES::VarList*") +add_type("SALOME_TYPES/ValueList", "const SALOME_TYPES::ValueList&", "SALOME_TYPES::ValueList_out", "", "SALOME_TYPES::ValueList","SALOME_TYPES::ValueList*") +add_type("SALOME_TYPES/ParametricInput", "const SALOME_TYPES::ParametricInput&", "SALOME_TYPES::ParametricInput_out", "", "SALOME_TYPES::ParametricInput","SALOME_TYPES::ParametricInput*") +add_type("SALOME_TYPES/ParametricOutput", "const SALOME_TYPES::ParametricOutput&", "SALOME_TYPES::ParametricOutput_out", "", "SALOME_TYPES::ParametricOutput","SALOME_TYPES::ParametricOutput*") + +#Add GEOM YACS types add_type("GEOM_Object", "GEOM::GEOM_Object_ptr", "GEOM::GEOM_Object_out", "GEOM", "GEOM::GEOM_Object","GEOM::GEOM_Object_ptr") + +#Add SMESH YACS types add_type("SMESH_Mesh", "SMESH::SMESH_Mesh_ptr", "SMESH::SMESH_Mesh_out", "SMESH", "SMESH::SMESH_Mesh","SMESH::SMESH_Mesh_ptr") add_type("SMESH_Hypothesis", "SMESH::SMESH_Hypothesis_ptr", "SMESH::SMESH_Hypothesis_out", "SMESH", "SMESH::SMESH_Hypothesis", "SMESH::SMESH_Hypothesis_ptr") + +#Add MED YACS types add_type("SALOME_MED/MED", "SALOME_MED::MED_ptr", "SALOME_MED::MED_out", "MED", "SALOME_MED::MED", "SALOME_MED::MED_ptr") add_type("SALOME_MED/MESH", "SALOME_MED::MESH_ptr", "SALOME_MED::MESH_out", "MED", "SALOME_MED::MESH", "SALOME_MED::MESH_ptr") add_type("SALOME_MED/SUPPORT", "SALOME_MED::SUPPORT_ptr", "SALOME_MED::SUPPORT_out", "MED", "SALOME_MED::SUPPORT", "SALOME_MED::SUPPORT_ptr") -- 2.39.2