Salome HOME
Increment version of 7.1.0
[tools/yacsgen.git] / Examples / types1 / components.py
1 # Copyright (C) 2009-2012  EDF R&D
2 #
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License.
7 #
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 # Lesser General Public License for more details.
12 #
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 #
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 #
19
20 import os
21
22 #import context from ..
23 execfile("../context.py")
24
25 from module_generator import Generator,Module,Service,CPPComponent,PYComponent,add_type,add_module
26
27 #overload module GEOM definition
28 idldefs="""
29 #include "GEOM_Gen.idl"
30 """
31 makefiledefs="""
32 #module GEOM
33 GEOM_IDL_INCLUDES = -I$(GEOM_ROOT_DIR)/idl/salome
34 GEOM_INCLUDES= -I$(GEOM_ROOT_DIR)/include/salome
35 GEOM_IDL_LIBS= -L$(GEOM_ROOT_DIR)/lib/salome -lSalomeIDLGEOM
36 GEOM_LIBS= -L$(GEOM_ROOT_DIR)/lib/salome
37 SALOME_LIBS += ${GEOM_LIBS}
38 SALOME_IDL_LIBS += ${GEOM_IDL_LIBS}
39 SALOME_INCLUDES += ${GEOM_INCLUDES}
40 IDL_INCLUDES += ${GEOM_IDL_INCLUDES}
41 """
42 configdefs="""
43 if test "x${GEOM_ROOT_DIR}" != "x" && test -d ${GEOM_ROOT_DIR} ; then
44   AC_MSG_RESULT(Using GEOM installation in ${GEOM_ROOT_DIR})
45 else
46   AC_MSG_ERROR([Cannot find module GEOM. Have you set GEOM_ROOT_DIR ?],1)
47 fi
48 """
49 add_module("GEOM",idldefs,makefiledefs,configdefs)
50
51 #overload GEOM_Object definition
52 add_type("GEOM_Object", "GEOM::GEOM_Object_ptr", "GEOM::GEOM_Object_out", "GEOM", "GEOM::GEOM_Object","GEOM::GEOM_Object_ptr")
53
54
55 cwd=os.getcwd()
56
57 defs="""
58 """
59
60 body="""
61 //inputs
62 //Parameter
63 std::cerr << "Parameter:" << std::endl;
64 std::cerr << "a: " << a.name << "=" << a.value << std::endl;
65 std::cerr << "" << std::endl;
66
67 //ParameterList
68 std::cerr << "ParameterList:" << std::endl;
69 for(CORBA::ULong i = 0;i<b.length();i++)
70   std::cerr << "b["<<i<<"]:"<<b[i].name <<"="<<b[i].value << std::endl;
71 std::cerr << "" << std::endl;
72
73 //Variable
74 std::cerr << "Variable:" << std::endl;
75 for(CORBA::ULong i = 0;i<c.length();i++)
76   std::cerr << "c["<<i<<"]="<<c[i] << std::endl;
77 std::cerr << "" << std::endl;
78
79 //VariableSequence
80 std::cerr << "VariableSequence:" << std::endl;
81 for(CORBA::ULong i = 0;i<d.length();i++)
82   for(CORBA::ULong j = 0;j<d[i].length();j++)
83     std::cerr << "d["<<i<<"]["<< j<< "]="<<d[i][j] << std::endl;
84 std::cerr << "" << std::endl;
85
86 //StateSequence
87 std::cerr << "StateSequence:" << std::endl;
88 for(CORBA::ULong i = 0;i<d2.length();i++)
89   for(CORBA::ULong j = 0;j<d2[i].length();j++)
90     for(CORBA::ULong k = 0;k<d2[i][j].length();k++)
91       std::cerr << "d2["<<i<<"]["<< j<< "]["<<k<<"]="<<d2[i][j][k] << std::endl;
92 std::cerr << "" << std::endl;
93
94 //TimeSequence
95 std::cerr << "TimeSequence:" << std::endl;
96 for(CORBA::ULong i = 0;i<d3.length();i++)
97   for(CORBA::ULong j = 0;j<d3[i].length();j++)
98     for(CORBA::ULong k = 0;k<d3[i][j].length();k++)
99       for(CORBA::ULong l = 0;l<d3[i][j][k].length();l++)
100       std::cerr << "d3["<<i<<"]["<< j<< "]["<<k<<"]["<<l<<"]="<<d3[i][j][k][l] << std::endl;
101 std::cerr << "" << std::endl;
102
103 //ParametricInput
104 for(CORBA::ULong i = 0;i<f.inputVarList.length();i++)
105   std::cerr << "f.inputVarList["<<i<<"]="<<f.inputVarList[i] << std::endl;
106 for(CORBA::ULong i = 0;i<f.outputVarList.length();i++)
107   std::cerr << "f.outputVarList["<<i<<"]="<<f.outputVarList[i] << std::endl;
108 for(CORBA::ULong i = 0;i<f.inputValues.length();i++)
109   for(CORBA::ULong j = 0;j<f.inputValues[i].length();j++)
110     for(CORBA::ULong k = 0;k<f.inputValues[i][j].length();k++)
111       for(CORBA::ULong l = 0;l<f.inputValues[i][j][k].length();l++)
112       std::cerr << "f.inputValues["<<i<<"]["<< j<< "]["<<k<<"]["<<l<<"]="<<f.inputValues[i][j][k][l] << std::endl;
113 for(CORBA::ULong i = 0;i<f.specificParameters.length();i++)
114   std::cerr << "f.specificParameters["<<i<<"]:"<<f.specificParameters[i].name <<"="<<f.specificParameters[i].value << std::endl;
115
116 //ParametricOutput
117 for(CORBA::ULong i = 0;i<g.outputValues.length();i++)
118   for(CORBA::ULong j = 0;j<g.outputValues[i].length();j++)
119     for(CORBA::ULong k = 0;k<g.outputValues[i][j].length();k++)
120       for(CORBA::ULong l = 0;l<g.outputValues[i][j][k].length();l++)
121       std::cerr << "g.outputValues["<<i<<"]["<< j<< "]["<<k<<"]["<<l<<"]="<<g.outputValues[i][j][k][l] << std::endl;
122
123 //outputs
124 //Parameter
125 aa=new SALOME_TYPES::Parameter;
126 aa->name=CORBA::string_dup(a.name);
127 aa->value=CORBA::string_dup(a.value);
128 std::cerr << "aa: " << aa->name << "=" << aa->value << std::endl;
129 //ParameterList
130 ab=new SALOME_TYPES::ParameterList;
131 ac= new SALOME_TYPES::Variable;
132 ad= new SALOME_TYPES::VariableSequence;
133 ad2= new SALOME_TYPES::StateSequence;
134 ad3= new SALOME_TYPES::TimeSequence;
135 ae= new SALOME_TYPES::VarList;
136 af= new SALOME_TYPES::ParametricInput;
137 ag= new SALOME_TYPES::ParametricOutput;
138 """
139
140 s2body="""
141 std::cerr << "service s2 C++ component" << std::endl;
142 aa=GEOM::GEOM_Object::_duplicate(a);
143 a->Register();
144 """
145
146 c1=CPPComponent("compo1",services=[
147           Service("s1",inport=[("a","SALOME_TYPES/Parameter"),
148                                ("b","SALOME_TYPES/ParameterList"),
149                                ("c","SALOME_TYPES/Variable"),
150                                ("d","SALOME_TYPES/VariableSequence"),
151                                ("d2","SALOME_TYPES/StateSequence"),
152                                ("d3","SALOME_TYPES/TimeSequence"),
153                                ("e","SALOME_TYPES/VarList"),
154                                ("f","SALOME_TYPES/ParametricInput"),
155                                ("g","SALOME_TYPES/ParametricOutput"),
156                               ],
157                        outport=[("aa","SALOME_TYPES/Parameter"),
158                                 ("ab","SALOME_TYPES/ParameterList"),
159                                 ("ac","SALOME_TYPES/Variable"),
160                                 ("ad","SALOME_TYPES/VariableSequence"),
161                                 ("ad2","SALOME_TYPES/StateSequence"),
162                                 ("ad3","SALOME_TYPES/TimeSequence"),
163                                 ("ae","SALOME_TYPES/VarList"),
164                                 ("af","SALOME_TYPES/ParametricInput"),
165                                 ("ag","SALOME_TYPES/ParametricOutput"),
166                                ],
167                        defs=defs,body=body,
168                  ),
169           Service("s2",inport=[("a","GEOM_Object"),],outport=[("aa","GEOM_Object"),],body=s2body,),
170                                   ],
171          )
172
173 pydefs="""import SALOME_TYPES"""
174
175 pybody="""
176 print a,b,c,d,d2,d3,e,f,g
177 aa=SALOME_TYPES.Parameter(name="a",value="45.")
178 ab=[]
179 ac=[1,2,3]
180 ad=[[1,2,3]]
181 ad2=[[[1,2,3]]]
182 ad3=[[[[1,2,3]]]]
183 ae=["aaa","bbb"]
184 af=SALOME_TYPES.ParametricInput(inputVarList=ae,outputVarList=ae, inputValues=[[[[1,2,3]]]],specificParameters=[])
185 ag=SALOME_TYPES.ParametricOutput(outputValues=[[[[1,2,3]]]], specificOutputInfos=[], returnCode=1, errorMessage="error")
186 print aa,ab,ac,ad,ad2,ad3,ae,af,ag
187 """
188
189 s2pybody="""
190 print "service s2 python component"
191 aa=a
192 a.Register()
193 """
194
195 c2=PYComponent("compo2",services=[
196           Service("s1",inport=[("a","SALOME_TYPES/Parameter"),
197                                ("b","SALOME_TYPES/ParameterList"),
198                                ("c","SALOME_TYPES/Variable"),
199                                ("d","SALOME_TYPES/VariableSequence"),
200                                ("d2","SALOME_TYPES/StateSequence"),
201                                ("d3","SALOME_TYPES/TimeSequence"),
202                                ("e","SALOME_TYPES/VarList"),
203                                ("f","SALOME_TYPES/ParametricInput"),
204                                ("g","SALOME_TYPES/ParametricOutput"),
205                               ],
206                        outport=[("aa","SALOME_TYPES/Parameter"),
207                                 ("ab","SALOME_TYPES/ParameterList"),
208                                 ("ac","SALOME_TYPES/Variable"),
209                                 ("ad","SALOME_TYPES/VariableSequence"),
210                                 ("ad2","SALOME_TYPES/StateSequence"),
211                                 ("ad3","SALOME_TYPES/TimeSequence"),
212                                 ("ae","SALOME_TYPES/VarList"),
213                                 ("af","SALOME_TYPES/ParametricInput"),
214                                 ("ag","SALOME_TYPES/ParametricOutput"),
215                                ],
216                        body=pybody,defs=pydefs,
217                  ),
218           Service("s2",inport=[("a","GEOM_Object"),],outport=[("aa","GEOM_Object"),],body=s2pybody,),
219                                  ],
220               )
221
222
223 g=Generator(Module("mymodule",components=[c1,c2],prefix="./install"),context)
224 g.generate()
225 g.bootstrap()
226 g.configure()
227 g.make()
228 g.install()
229 g.make_appli("appli", restrict=["KERNEL"], altmodules={"GUI":GUI_ROOT_DIR, "YACS":YACS_ROOT_DIR, "GEOM":GEOM_ROOT_DIR})
230