]> SALOME platform Git repositories - modules/kernel.git/blob - src/KERNEL_PY/salome_test.py
Salome HOME
Modify basic salome test for series 6x
[modules/kernel.git] / src / KERNEL_PY / salome_test.py
1 #  -*- coding: iso-8859-1 -*-
2 #  Copyright (C) 2007-2010  CEA/DEN, EDF R&D, OPEN CASCADE
3 #
4 #  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
5 #  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 #
7 #  This library is free software; you can redistribute it and/or
8 #  modify it under the terms of the GNU Lesser General Public
9 #  License as published by the Free Software Foundation; either
10 #  version 2.1 of the License.
11 #
12 #  This library is distributed in the hope that it will be useful,
13 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
14 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 #  Lesser General Public License for more details.
16 #
17 #  You should have received a copy of the GNU Lesser General Public
18 #  License along with this library; if not, write to the Free Software
19 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
20 #
21 #  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 #
23
24 print
25 print "Perform quick test of the application by loading of the GEOM, SMESH, VISU, MED"
26 print "components and doing some operation within the components."
27 print
28
29 import salome
30 import SALOMEDS
31 import os
32 import sys
33 import SALOME_ModuleCatalog
34
35 step = 1
36
37 print "======================================================================"
38 print "           %d. Initialize study " % step; step+=1
39 print "======================================================================"
40
41 # initialize study
42 salome.salome_init()
43 # get study builder
44 builder = salome.myStudy.NewBuilder()
45 print "OK"
46
47 print 
48
49 print "======================================================================"
50 print "           %d. Retrieve module catalog " % step; step+=1
51 print "======================================================================"
52
53 obj = salome.naming_service.Resolve('Kernel/ModulCatalog')
54 catalog = obj._narrow(SALOME_ModuleCatalog.ModuleCatalog)
55 if not catalog:
56     raise RuntimeError, "Can't accesss module catalog"
57 print "OK"
58
59 print
60
61 print "======================================================================"
62 print "           %d. Check modules availability in the module catalog " % step; step+=1
63 print "======================================================================"
64
65 print
66 print "--- Check GEOM ..."
67 comp = catalog.GetComponent("GEOM")
68 if not comp:
69     raise RuntimeError, "Component GEOM is not found in Module Catalog."
70 print "OK"
71
72 print
73 print "--- Check SMESH ..."
74 comp = catalog.GetComponent("SMESH")
75 if not comp:
76     raise RuntimeError, "Component SMESH is not found in Module Catalog."
77 print "OK"
78
79 print
80 print "--- Check MED ..."
81 comp = catalog.GetComponent("MED")
82 if not comp:
83     raise RuntimeError, "Component MED is not found in Module Catalog."
84 print "OK"
85
86 print
87 print "--- Check VISU ..."
88 comp = catalog.GetComponent("VISU")
89 if not comp:
90     raise RuntimeError, "Component VISU is not found in Module Catalog."
91 print "OK"
92
93 print
94
95 print "======================================================================"
96 print "           %d. Check, that there is no data of MED component in the Study " % step; step+=1
97 print "======================================================================"
98
99 MedComp = salome.myStudy.FindComponent("MED")
100 if not comp:
101     print ""
102     print "This script cannot work properly, because there is"
103     print "some MED component data already existing in the study."
104     print "Execution aborted."
105     print ""
106     raise RuntimeError, "Please, run this script only in a new empty study."
107
108 print
109
110 print "======================================================================"
111 print "           %d. Test Data Server " % step; step+=1
112 print "======================================================================"
113
114 print
115 print "--- Create new component ..."
116 comp = builder.NewComponent("TEST")
117 if not comp:
118     raise RuntimeError, "Can't create new component"
119 print "OK"
120
121 print
122 print "--- Create AttributeName ..."
123 A = builder.FindOrCreateAttribute(comp, "AttributeName")
124 if not A:
125     raise RuntimeError, "Can't create AttributeName attribute"
126 A.SetValue("TEST")
127 if A.Value() != "TEST":
128     raise RuntimeError, "Error : wrong value of  AttributeName"
129 print "OK"
130
131 print
132 print "--- Create AttributeReal ..."
133 A = builder.FindOrCreateAttribute(comp, "AttributeReal")
134 if not A:
135     raise RuntimeError, "Can't create AttributeReal attribute"
136 A.SetValue(0.0001)
137 if A.Value() != 0.0001:
138     raise RuntimeError, "Error : wrong value of  AttributeReal"
139 print "OK"
140
141 print
142
143 print "======================================================================"
144 print "           %d. Test Geometry " % step; step+=1
145 print "======================================================================"
146
147 import geompy
148
149 ShapeTypeCompSolid = 1
150 ShapeTypeSolid = 2
151 ShapeTypeShell = 3
152 ShapeTypeFace = 4
153 ShapeTypeWire = 5
154 ShapeTypeEdge = 6
155 ShapeTypeVertex = 7
156
157 print
158 print "--- Create a box ..."
159 box = geompy.MakeBox(0., 0., 0., 100., 200., 300.)
160 idbox = geompy.addToStudy(box, "box")
161 box_obj = salome.myStudy.FindObjectByPath("/Geometry/box")
162 if not box_obj:
163     raise RuntimeError, "Error : wrong value of  AttributeReal"
164 print "OK"
165
166 # ---- add shell from box in study
167 print 
168 print "--- Extract shell ..."
169 subShellList = geompy.SubShapeAll(box, ShapeTypeShell)
170 shell = subShellList[0]
171 name = geompy.SubShapeName(shell, box)
172 idshell = geompy.addToStudyInFather(box, shell, name)
173 print name
174 print "OK"
175
176 # ---- add first face of box in study
177 print 
178 print "--- Extract face ..."
179 subShapeList = geompy.SubShapeAll(box, ShapeTypeFace)
180 face = subShapeList[0]
181 name = geompy.SubShapeName(face, box)
182 idface = geompy.addToStudyInFather(box, face, name)
183 print name
184 print "OK"
185
186 # ---- add first edge of face in study
187 print 
188 print "--- Extract edge ..."
189 edgeList = geompy.SubShapeAll(face, ShapeTypeEdge)
190 edge = edgeList[0];
191 name = geompy.SubShapeName(edge, face)
192 idedge = geompy.addToStudyInFather(face, edge, name)
193 print name
194 print "OK"
195
196 print
197
198 print "======================================================================"
199 print "           %d. Test Mesh " % step; step+=1
200 print "======================================================================"
201
202 import StdMeshers
203 import SMESH
204
205 smesh = salome.lcc.FindOrLoadComponent("FactoryServer", "SMESH")
206 smeshgui = salome.ImportComponentGUI("SMESH")
207 smeshgui.Init(salome.myStudyId);
208
209 # ---- create hypotheses 
210
211 if sys.platform == "win32":
212   stdMeshersEngine = "StdMeshersEngine"
213 else:
214   stdMeshersEngine = "libStdMeshersEngine.so"
215
216 print
217 print "--- Create hypotheses ..."
218
219 print
220 print "------ LocalLength ..."
221 hypLen1 = smesh.CreateHypothesis( "LocalLength", stdMeshersEngine )
222 hypLen1.SetLength(100)
223 print hypLen1.GetName()
224 print hypLen1.GetId()
225 print hypLen1.GetLength()
226 smeshgui.SetName(salome.ObjectToID(hypLen1), "Local_Length_100")
227 print "OK"
228
229 print
230 print "------ NumberOfSegments ..."
231 hypNbSeg1= smesh.CreateHypothesis( "NumberOfSegments", stdMeshersEngine )
232 hypNbSeg1.SetNumberOfSegments(7)
233 print hypNbSeg1.GetName()
234 print hypNbSeg1.GetId()
235 print hypNbSeg1.GetNumberOfSegments()
236 smeshgui.SetName(salome.ObjectToID(hypNbSeg1), "NumberOfSegments_7")
237 print "OK"
238
239 print
240 print "------ MaxElementArea [1] ..."
241 hypArea1 = smesh.CreateHypothesis( "MaxElementArea", stdMeshersEngine )
242 hypArea1.SetMaxElementArea(2500)
243 print hypArea1.GetName()
244 print hypArea1.GetId()
245 print hypArea1.GetMaxElementArea()
246 smeshgui.SetName(salome.ObjectToID(hypArea1), "MaxElementArea_2500")
247 print "OK"
248
249 print
250 print "------ MaxElementArea [2] ..."
251 hypArea2 = smesh.CreateHypothesis( "MaxElementArea", stdMeshersEngine )
252 hypArea2.SetMaxElementArea(500)
253 print hypArea2.GetName()
254 print hypArea2.GetId()
255 print hypArea2.GetMaxElementArea()
256 smeshgui.SetName(salome.ObjectToID(hypArea2), "MaxElementArea_500")
257 print "OK"
258
259 # ---- create algorithms
260
261 print
262 print "--- Create algorithms ..."
263
264 print
265 print "------ Regular_1D ..."
266 algoReg = smesh.CreateHypothesis( "Regular_1D", stdMeshersEngine )
267 listHyp = algoReg.GetCompatibleHypothesis()
268 for hyp in listHyp:
269     print hyp
270 print algoReg.GetName()
271 print algoReg.GetId()
272 smeshgui.SetName(salome.ObjectToID(algoReg), "Regular_1D" )
273 print "OK"
274
275 print
276 print "------ MEFISTO_2D ..."
277 algoMef = smesh.CreateHypothesis( "MEFISTO_2D", stdMeshersEngine )
278 listHyp=algoMef.GetCompatibleHypothesis()
279 for hyp in listHyp:
280     print hyp
281 print algoMef.GetName()
282 print algoMef.GetId()
283 smeshgui.SetName(salome.ObjectToID(algoMef), "MEFISTO_2D" )
284 print "OK"
285
286 # ---- create mesh on the box, apply hypotheses / algorithms
287
288 print
289 print "--- Create mesh on the box ..."
290 mesh = smesh.CreateMesh(box)
291 smeshgui.SetName( salome.ObjectToID(mesh), "MeshBox" );
292 ret = mesh.AddHypothesis(box, algoReg)
293 ret = mesh.AddHypothesis(box, algoMef)
294 ret = mesh.AddHypothesis(box, hypNbSeg1)
295 ret = mesh.AddHypothesis(box, hypArea1)
296 print "OK"
297
298 # ---- create submesh on the edge, add hypothesis
299
300 print
301 print "--- Add 1D sub-mesh on the edge ..."
302 submesh = mesh.GetSubMesh(edge, "SubMeshEdge")
303 ret = mesh.AddHypothesis(edge, algoReg)
304 ret = mesh.AddHypothesis(edge, hypLen1)
305 print "OK"
306
307 # ---- create submesh on the edge, add hypothesis
308
309 print
310 print "--- Add 2D sub-mesh on the face ..."
311 submesh = mesh.GetSubMesh(face, "SubMeshFace")
312 ret = mesh.AddHypothesis(face, hypArea2)
313 print "OK"
314
315 # ---- compute mesh
316 print
317 print "--- Compute mesh ..."
318 smesh.Compute(mesh, box)
319 salome.sg.updateObjBrowser(1);
320 print "OK"
321
322 print
323
324 print "======================================================================"
325 print "           %d. Test Post-Pro and Med " % step; step+=1
326 print "======================================================================"
327
328 import sys
329 import SALOMEDS
330 import SALOME
331 import SALOME_MED
332 import VISU
333 import visu_gui
334
335 med  = salome.lcc.FindOrLoadComponent("FactoryServer", "MED")
336 visu = salome.lcc.FindOrLoadComponent("FactoryServer", "VISU")
337
338 medFileName = "pointe.med"
339 medFile = os.path.join(os.getenv('DATA_DIR'), 'MedFiles', medFileName)
340
341 print
342 print "--- Read med file structure from %s ..." % medFile
343 med.readStructFileWithFieldType(medFile, salome.myStudyName)
344 print "OK"
345
346 print
347 print "--- Get med object from study ..."
348 med_obj = visu_gui.visu.getMedObjectFromStudy()
349 if not med_obj:
350     raise RuntimeError, "Med object is not found in the study"
351 print "OK"
352
353 print
354 print "--- Get field from study ..."
355 field = visu_gui.visu.getFieldObjectFromStudy(3,1)
356 if not field:
357     raise RuntimeError, "Field object is not found in the study"
358 print "OK"
359
360 print
361 print "--- Import field to the VISU ..."
362 aMeshName = "maa1"
363 anEntity = VISU.NODE
364 aTimeStampId = -1
365 result1 = visu.ImportMedField(field)
366 if not result1:
367     raise RuntimeError, "Can't import field"
368 print "OK"
369
370 print
371 print "--- Create mesh presentation [1] ..."
372 mesh1 = visu.MeshOnEntity(result1, aMeshName, anEntity);
373 if not mesh1:
374     raise RuntimeError, "Can't create mesh presentation"
375 print "OK"
376            
377 print
378 print "--- Create scalar map [1] ..."
379 scalarMap1 = visu.ScalarMapOnField(result1, aMeshName, anEntity, field.getName(), aTimeStampId)
380 if not scalarMap1:
381     raise RuntimeError, "Can't create scalar map"
382 print "OK"
383            
384 print
385 print "--- Import med file %s to the VISU ..." % medFile
386 result2 = visu.ImportFile(medFile);
387 if not result2:
388     raise RuntimeError, "Can't import file"
389 print "OK"
390
391 print
392 print "--- Create mesh presentation [2] ..."
393 mesh2 = visu.MeshOnEntity(result2, aMeshName, anEntity);
394 if not mesh2:
395     raise RuntimeError, "Can't create mesh presentation"
396 print "OK"
397            
398 print
399 print "--- Create scalar map [2] ..."
400 scalarMap2 = visu.ScalarMapOnField(result2, aMeshName, anEntity, field.getName(), 3)
401 if not scalarMap2:
402     raise RuntimeError, "Can't create scalar map"
403 print "OK"
404
405 salome.sg.updateObjBrowser(0)