Salome HOME
Copyright update 2022
[tools/yacsgen.git] / Examples / types1 / components.py
1 # Copyright (C) 2009-2022  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, or (at your option) any later version.
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 exec(compile(open("../context.py").read(), "../context.py", 'exec'))
24
25 from module_generator import Generator,Module,Service,CPPComponent,PYComponent,add_type,add_module
26
27 #overload GEOM_Object definition
28 add_type("GEOM_Object", "GEOM::GEOM_Object_ptr", "GEOM::GEOM_Object_out", "GEOM", "GEOM::GEOM_Object","GEOM::GEOM_Object_ptr")
29
30
31 cwd=os.getcwd()
32
33 defs="""
34 """
35
36 body="""
37 //inputs
38 //Parameter
39 std::cerr << "Parameter:" << std::endl;
40 std::cerr << "a: " << a.name << "=" << a.value << std::endl;
41 std::cerr << "" << std::endl;
42
43 //ParameterList
44 std::cerr << "ParameterList:" << std::endl;
45 for(CORBA::ULong i = 0;i<b.length();i++)
46   std::cerr << "b["<<i<<"]:"<<b[i].name <<"="<<b[i].value << std::endl;
47 std::cerr << "" << std::endl;
48
49 //Variable
50 std::cerr << "Variable:" << std::endl;
51 for(CORBA::ULong i = 0;i<c.length();i++)
52   std::cerr << "c["<<i<<"]="<<c[i] << std::endl;
53 std::cerr << "" << std::endl;
54
55 //VariableSequence
56 std::cerr << "VariableSequence:" << std::endl;
57 for(CORBA::ULong i = 0;i<d.length();i++)
58   for(CORBA::ULong j = 0;j<d[i].length();j++)
59     std::cerr << "d["<<i<<"]["<< j<< "]="<<d[i][j] << std::endl;
60 std::cerr << "" << std::endl;
61
62 //StateSequence
63 std::cerr << "StateSequence:" << std::endl;
64 for(CORBA::ULong i = 0;i<d2.length();i++)
65   for(CORBA::ULong j = 0;j<d2[i].length();j++)
66     for(CORBA::ULong k = 0;k<d2[i][j].length();k++)
67       std::cerr << "d2["<<i<<"]["<< j<< "]["<<k<<"]="<<d2[i][j][k] << std::endl;
68 std::cerr << "" << std::endl;
69
70 //TimeSequence
71 std::cerr << "TimeSequence:" << std::endl;
72 for(CORBA::ULong i = 0;i<d3.length();i++)
73   for(CORBA::ULong j = 0;j<d3[i].length();j++)
74     for(CORBA::ULong k = 0;k<d3[i][j].length();k++)
75       for(CORBA::ULong l = 0;l<d3[i][j][k].length();l++)
76       std::cerr << "d3["<<i<<"]["<< j<< "]["<<k<<"]["<<l<<"]="<<d3[i][j][k][l] << std::endl;
77 std::cerr << "" << std::endl;
78
79 //ParametricInput
80 for(CORBA::ULong i = 0;i<f.inputVarList.length();i++)
81   std::cerr << "f.inputVarList["<<i<<"]="<<f.inputVarList[i] << std::endl;
82 for(CORBA::ULong i = 0;i<f.outputVarList.length();i++)
83   std::cerr << "f.outputVarList["<<i<<"]="<<f.outputVarList[i] << std::endl;
84 for(CORBA::ULong i = 0;i<f.inputValues.length();i++)
85   for(CORBA::ULong j = 0;j<f.inputValues[i].length();j++)
86     for(CORBA::ULong k = 0;k<f.inputValues[i][j].length();k++)
87       for(CORBA::ULong l = 0;l<f.inputValues[i][j][k].length();l++)
88       std::cerr << "f.inputValues["<<i<<"]["<< j<< "]["<<k<<"]["<<l<<"]="<<f.inputValues[i][j][k][l] << std::endl;
89 for(CORBA::ULong i = 0;i<f.specificParameters.length();i++)
90   std::cerr << "f.specificParameters["<<i<<"]:"<<f.specificParameters[i].name <<"="<<f.specificParameters[i].value << std::endl;
91
92 //ParametricOutput
93 for(CORBA::ULong i = 0;i<g.outputValues.length();i++)
94   for(CORBA::ULong j = 0;j<g.outputValues[i].length();j++)
95     for(CORBA::ULong k = 0;k<g.outputValues[i][j].length();k++)
96       for(CORBA::ULong l = 0;l<g.outputValues[i][j][k].length();l++)
97       std::cerr << "g.outputValues["<<i<<"]["<< j<< "]["<<k<<"]["<<l<<"]="<<g.outputValues[i][j][k][l] << std::endl;
98
99 //outputs
100 //Parameter
101 aa=new SALOME_TYPES::Parameter;
102 aa->name=CORBA::string_dup(a.name);
103 aa->value=CORBA::string_dup(a.value);
104 std::cerr << "aa: " << aa->name << "=" << aa->value << std::endl;
105 //ParameterList
106 ab=new SALOME_TYPES::ParameterList;
107 ac= new SALOME_TYPES::Variable;
108 ad= new SALOME_TYPES::VariableSequence;
109 ad2= new SALOME_TYPES::StateSequence;
110 ad3= new SALOME_TYPES::TimeSequence;
111 ae= new SALOME_TYPES::VarList;
112 af= new SALOME_TYPES::ParametricInput;
113 ag= new SALOME_TYPES::ParametricOutput;
114 """
115
116 s2body="""
117 std::cerr << "service s2 C++ component" << std::endl;
118 aa=GEOM::GEOM_Object::_duplicate(a);
119 a->Register();
120 """
121
122 c1=CPPComponent("compo1",services=[
123           Service("s1",inport=[("a","SALOME_TYPES/Parameter"),
124                                ("b","SALOME_TYPES/ParameterList"),
125                                ("c","SALOME_TYPES/Variable"),
126                                ("d","SALOME_TYPES/VariableSequence"),
127                                ("d2","SALOME_TYPES/StateSequence"),
128                                ("d3","SALOME_TYPES/TimeSequence"),
129                                ("e","SALOME_TYPES/VarList"),
130                                ("f","SALOME_TYPES/ParametricInput"),
131                                ("g","SALOME_TYPES/ParametricOutput"),
132                               ],
133                        outport=[("aa","SALOME_TYPES/Parameter"),
134                                 ("ab","SALOME_TYPES/ParameterList"),
135                                 ("ac","SALOME_TYPES/Variable"),
136                                 ("ad","SALOME_TYPES/VariableSequence"),
137                                 ("ad2","SALOME_TYPES/StateSequence"),
138                                 ("ad3","SALOME_TYPES/TimeSequence"),
139                                 ("ae","SALOME_TYPES/VarList"),
140                                 ("af","SALOME_TYPES/ParametricInput"),
141                                 ("ag","SALOME_TYPES/ParametricOutput"),
142                                ],
143                        defs=defs,body=body,
144                  ),
145           Service("s2",inport=[("a","GEOM_Object"),],outport=[("aa","GEOM_Object"),],body=s2body,),
146                                   ],
147          )
148
149 pydefs="""import SALOME_TYPES"""
150
151 pybody="""
152 print (a,b,c,d,d2,d3,e,f,g)
153 aa=SALOME_TYPES.Parameter(name="a",value="45.")
154 ab=[]
155 ac=[1,2,3]
156 ad=[[1,2,3]]
157 ad2=[[[1,2,3]]]
158 ad3=[[[[1,2,3]]]]
159 ae=["aaa","bbb"]
160 af=SALOME_TYPES.ParametricInput(inputVarList=ae,outputVarList=ae, inputValues=[[[[1,2,3]]]],specificParameters=[])
161 ag=SALOME_TYPES.ParametricOutput(outputValues=[[[[1,2,3]]]], specificOutputInfos=[], returnCode=1, errorMessage="error")
162 print (aa,ab,ac,ad,ad2,ad3,ae,af,ag)
163 """
164
165 s2pybody="""
166 print ("service s2 python component")
167 aa=a
168 a.Register()
169 """
170
171 c2=PYComponent("compo2",services=[
172           Service("s1",inport=[("a","SALOME_TYPES/Parameter"),
173                                ("b","SALOME_TYPES/ParameterList"),
174                                ("c","SALOME_TYPES/Variable"),
175                                ("d","SALOME_TYPES/VariableSequence"),
176                                ("d2","SALOME_TYPES/StateSequence"),
177                                ("d3","SALOME_TYPES/TimeSequence"),
178                                ("e","SALOME_TYPES/VarList"),
179                                ("f","SALOME_TYPES/ParametricInput"),
180                                ("g","SALOME_TYPES/ParametricOutput"),
181                               ],
182                        outport=[("aa","SALOME_TYPES/Parameter"),
183                                 ("ab","SALOME_TYPES/ParameterList"),
184                                 ("ac","SALOME_TYPES/Variable"),
185                                 ("ad","SALOME_TYPES/VariableSequence"),
186                                 ("ad2","SALOME_TYPES/StateSequence"),
187                                 ("ad3","SALOME_TYPES/TimeSequence"),
188                                 ("ae","SALOME_TYPES/VarList"),
189                                 ("af","SALOME_TYPES/ParametricInput"),
190                                 ("ag","SALOME_TYPES/ParametricOutput"),
191                                ],
192                        body=pybody,defs=pydefs,
193                  ),
194           Service("s2",inport=[("a","GEOM_Object"),],outport=[("aa","GEOM_Object"),],body=s2pybody,),
195                                  ],
196               )
197
198
199 g=Generator(Module("mymodule",components=[c1,c2],prefix="./install"),context)
200 g.generate()
201 g.configure()
202 g.make()
203 g.install()
204 g.make_appli("appli", restrict=["KERNEL"],
205              altmodules={"GUI":GUI_ROOT_DIR,
206                          "YACS":YACS_ROOT_DIR,
207                          "GEOM":GEOM_ROOT_DIR},
208              sys_modules=SYS_MODULES)
209