]> SALOME platform Git repositories - modules/kernel.git/blob - src/KERNEL_PY/salome_test.py
Salome HOME
9b799e5a48e9b26c521c7a121019b5b26bc5144f
[modules/kernel.git] / src / KERNEL_PY / salome_test.py
1 #  -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2013  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 SALOME
31 import SALOMEDS
32 import os
33 import sys
34 import SALOME_ModuleCatalog
35
36 step = 1
37
38 print "======================================================================"
39 print "           %d. Initialize study " % step; step+=1
40 print "======================================================================"
41
42 # initialize study
43 salome.salome_init()
44 # get study builder
45 builder = salome.myStudy.NewBuilder()
46 print "OK"
47
48 print 
49
50 print "======================================================================"
51 print "           %d. Retrieve module catalog " % step; step+=1
52 print "======================================================================"
53
54 obj = salome.naming_service.Resolve('Kernel/ModulCatalog')
55 catalog = obj._narrow(SALOME_ModuleCatalog.ModuleCatalog)
56 if not catalog:
57     raise RuntimeError, "Can't accesss module catalog"
58 print "OK"
59
60 print
61
62 print "======================================================================"
63 print "           %d. Check modules availability in the module catalog " % step; step+=1
64 print "======================================================================"
65
66 print
67 print "--- Check GEOM ..."
68 comp = catalog.GetComponent("GEOM")
69 if not comp:
70     raise RuntimeError, "Component GEOM is not found in Module Catalog."
71 print "OK"
72
73 print
74 print "--- Check SMESH ..."
75 comp = catalog.GetComponent("SMESH")
76 if not comp:
77     raise RuntimeError, "Component SMESH is not found in Module Catalog."
78 print "OK"
79
80 print
81 print "--- Check MED ..."
82 comp = catalog.GetComponent("MEDOPFactory")
83 if not comp:
84     raise RuntimeError, "Component MED is not found in Module Catalog."
85 print "OK"
86
87 print
88 print "--- Check PARAVIS ..."
89 comp = catalog.GetComponent("PARAVIS")
90 if not comp:
91     raise RuntimeError, "Component PARAVIS is not found in Module Catalog."
92 print "OK"
93
94 print
95
96 print "======================================================================"
97 print "           %d. Test Data Server " % step; step+=1
98 print "======================================================================"
99
100 print
101 print "--- Create new component ..."
102 comp = builder.NewComponent("TEST")
103 if not comp:
104     raise RuntimeError, "Can't create new component"
105 print "OK"
106
107 print
108 print "--- Create AttributeName ..."
109 A = builder.FindOrCreateAttribute(comp, "AttributeName")
110 if not A:
111     raise RuntimeError, "Can't create AttributeName attribute"
112 A.SetValue("TEST")
113 if A.Value() != "TEST":
114     raise RuntimeError, "Error : wrong value of  AttributeName"
115 print "OK"
116
117 print
118 print "--- Create AttributeReal ..."
119 A = builder.FindOrCreateAttribute(comp, "AttributeReal")
120 if not A:
121     raise RuntimeError, "Can't create AttributeReal attribute"
122 A.SetValue(0.0001)
123 if A.Value() != 0.0001:
124     raise RuntimeError, "Error : wrong value of  AttributeReal"
125 print "OK"
126
127 print
128
129 print "======================================================================"
130 print "           %d. Test Geometry " % step; step+=1
131 print "======================================================================"
132
133 import geompy
134
135 ShapeTypeCompSolid = 1
136 ShapeTypeSolid = 2
137 ShapeTypeShell = 3
138 ShapeTypeFace = 4
139 ShapeTypeWire = 5
140 ShapeTypeEdge = 6
141 ShapeTypeVertex = 7
142
143 print
144 print "--- Create a box ..."
145 box = geompy.MakeBox(0., 0., 0., 100., 200., 300.)
146 idbox = geompy.addToStudy(box, "box")
147 box_obj = salome.myStudy.FindObjectByPath("/Geometry/box")
148 if not box_obj:
149     raise RuntimeError, "Error : wrong value of  AttributeReal"
150 print "OK"
151
152 # ---- add shell from box in study
153 print 
154 print "--- Extract shell ..."
155 subShellList = geompy.SubShapeAll(box, ShapeTypeShell)
156 shell = subShellList[0]
157 name = geompy.SubShapeName(shell, box)
158 idshell = geompy.addToStudyInFather(box, shell, name)
159 print name
160 print "OK"
161
162 # ---- add first face of box in study
163 print 
164 print "--- Extract face ..."
165 subShapeList = geompy.SubShapeAll(box, ShapeTypeFace)
166 face = subShapeList[0]
167 name = geompy.SubShapeName(face, box)
168 idface = geompy.addToStudyInFather(box, face, name)
169 print name
170 print "OK"
171
172 # ---- add first edge of face in study
173 print 
174 print "--- Extract edge ..."
175 edgeList = geompy.SubShapeAll(face, ShapeTypeEdge)
176 edge = edgeList[0];
177 name = geompy.SubShapeName(edge, face)
178 idedge = geompy.addToStudyInFather(face, edge, name)
179 print name
180 print "OK"
181
182 # ---- update object browser
183 if salome.hasDesktop():
184     salome.sg.updateObjBrowser(1);
185
186 print
187
188 print "======================================================================"
189 print "           %d. Test Mesh " % step; step+=1
190 print "======================================================================"
191
192 import StdMeshers
193 import SMESH
194
195 smesh = salome.lcc.FindOrLoadComponent("FactoryServer", "SMESH")
196 if salome.hasDesktop():
197     smeshgui = salome.ImportComponentGUI("SMESH")
198     smeshgui.Init(salome.myStudyId);
199 else:
200     smesh.SetCurrentStudy(salome.myStudy)
201
202 # ---- create hypotheses 
203
204 if sys.platform == "win32":
205   stdMeshersEngine = "StdMeshersEngine"
206 else:
207   stdMeshersEngine = "libStdMeshersEngine.so"
208
209 print
210 print "--- Create hypotheses ..."
211
212 print
213 print "------ LocalLength ..."
214 hypLen1 = smesh.CreateHypothesis( "LocalLength", stdMeshersEngine )
215 hypLen1.SetLength(100)
216 print hypLen1.GetName()
217 print hypLen1.GetId()
218 print hypLen1.GetLength()
219 if salome.hasDesktop():
220     smeshgui.SetName(salome.ObjectToID(hypLen1), "Local_Length_100")
221 print "OK"
222
223 print
224 print "------ NumberOfSegments ..."
225 hypNbSeg1= smesh.CreateHypothesis( "NumberOfSegments", stdMeshersEngine )
226 hypNbSeg1.SetNumberOfSegments(7)
227 print hypNbSeg1.GetName()
228 print hypNbSeg1.GetId()
229 print hypNbSeg1.GetNumberOfSegments()
230 if salome.hasDesktop():
231     smeshgui.SetName(salome.ObjectToID(hypNbSeg1), "NumberOfSegments_7")
232 print "OK"
233
234 print
235 print "------ MaxElementArea [1] ..."
236 hypArea1 = smesh.CreateHypothesis( "MaxElementArea", stdMeshersEngine )
237 hypArea1.SetMaxElementArea(2500)
238 print hypArea1.GetName()
239 print hypArea1.GetId()
240 print hypArea1.GetMaxElementArea()
241 if salome.hasDesktop():
242     smeshgui.SetName(salome.ObjectToID(hypArea1), "MaxElementArea_2500")
243 print "OK"
244
245 print
246 print "------ MaxElementArea [2] ..."
247 hypArea2 = smesh.CreateHypothesis( "MaxElementArea", stdMeshersEngine )
248 hypArea2.SetMaxElementArea(500)
249 print hypArea2.GetName()
250 print hypArea2.GetId()
251 print hypArea2.GetMaxElementArea()
252 if salome.hasDesktop():
253     smeshgui.SetName(salome.ObjectToID(hypArea2), "MaxElementArea_500")
254 print "OK"
255
256 # ---- create algorithms
257
258 print
259 print "--- Create algorithms ..."
260
261 print
262 print "------ Regular_1D ..."
263 algoReg = smesh.CreateHypothesis( "Regular_1D", stdMeshersEngine )
264 listHyp = algoReg.GetCompatibleHypothesis()
265 for hyp in listHyp:
266     print hyp
267 print algoReg.GetName()
268 print algoReg.GetId()
269 if salome.hasDesktop():
270     smeshgui.SetName(salome.ObjectToID(algoReg), "Regular_1D" )
271 print "OK"
272
273 print
274 print "------ MEFISTO_2D ..."
275 algoMef = smesh.CreateHypothesis( "MEFISTO_2D", stdMeshersEngine )
276 listHyp=algoMef.GetCompatibleHypothesis()
277 for hyp in listHyp:
278     print hyp
279 print algoMef.GetName()
280 print algoMef.GetId()
281 if salome.hasDesktop():
282     smeshgui.SetName(salome.ObjectToID(algoMef), "MEFISTO_2D" )
283 print "OK"
284
285 # ---- create mesh on the box, apply hypotheses / algorithms
286
287 print
288 print "--- Create mesh on the box ..."
289 mesh = smesh.CreateMesh(box)
290 if salome.hasDesktop():
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 print "OK"
320
321 # ---- update object browser
322 if salome.hasDesktop():
323     salome.sg.updateObjBrowser(1);
324
325 print
326
327 print "======================================================================"
328 print "           %d. Test Med " % step; step+=1
329 print "======================================================================"
330
331 import xmed
332 from xmed import properties
333 from xmed.fieldproxy import FieldProxy
334
335 xmed.setConsoleGlobals(globals())
336
337 # Load some test data in the MedDataManager
338 filepath  = properties.testFilePath
339 xmed.dataManager.addDatasource(filepath)
340 fieldHandlerList = xmed.dataManager.getFieldHandlerList()
341
342 fieldHandler0 = fieldHandlerList[0]
343 print "---Field Handler 0:\n%s" % fieldHandler0
344 fieldHandler1 = fieldHandlerList[1]
345 print "---Field Handler 1:\n%s" % fieldHandler1
346
347 print "--- The addition of two fields can be done using field handler directly."
348 addFieldHandler = xmed.calculator.add(fieldHandler0, fieldHandler1)
349 print "--- Result handler:\n%s" % addFieldHandler
350
351 print "--- Or with a field proxy that easy the writing of operations."
352 fieldProxy0 = FieldProxy(fieldHandler0)
353 fieldProxy1 = FieldProxy(fieldHandler1)
354
355 resHandler = fieldProxy0 + fieldProxy1
356 if resHandler is None:
357     print "Error: result handler is None!"
358 else:
359     print "--- Result handler:\n%s" % resHandler
360     print "OK"
361
362 print
363
364
365 print "======================================================================"
366 print "           %d. Test Paravis " % step; step+=1
367 print "======================================================================"
368
369 if salome.hasDesktop(): # in gui mode
370
371     print "**** Importing paravis... It can take some time."
372     from presentations import *
373     import paravis
374     import pvsimple
375     
376     my_paravis = paravis.myParavis
377     
378     #====================Stage1: Importing MED file====================
379     
380     print "**** Stage1: Importing MED file"
381     
382     print 'Import "ResOK_0000.med"...............',
383     medFileName = "ResOK_0000.med"
384     medFile = os.path.join(os.getenv('DATA_DIR'), 'MedFiles', medFileName)
385     my_paravis.ImportFile(medFile)
386     med_reader = pvsimple.GetActiveSource()
387     
388     if med_reader is None:
389         print "FAILED"
390     else:
391         print "OK"
392     
393     cell_entity = EntityType.CELL
394     node_entity = EntityType.NODE
395     
396     #====================Stage2: Displaying vector field===============
397     
398     print "**** Stage3: Displaying vector field"
399     
400     print 'Get view...................',
401     view = pvsimple.GetRenderView()
402     if view is None:
403         print "FAILED"
404     else:
405         reset_view(view)
406         print "OK"
407     
408     print "Creating Scalar Map.......",
409     scalarmap = ScalarMapOnField(med_reader, node_entity, 'vitesse', 1)
410     if scalarmap is None:
411         print "FAILED"
412     else:
413         bar = get_bar()
414         bar.Orientation = 'Horizontal'
415         bar.Position = [0.1, 0.1]
416         bar.Position2 = [0.1, 0.25]
417         bar.AspectRatio = 3
418         
419         display_only(scalarmap, view)
420         print "OK"
421     
422     view.ResetCamera()
423     
424     print "Creating Vectors..........",
425     vectors = VectorsOnField(med_reader, node_entity, 'vitesse', 1)
426     if vectors is None:
427         print "FAILED"
428     else:
429         display_only(vectors, view)
430         print "OK"
431     
432     print "Creating Iso Surfaces.....",
433     isosurfaces = IsoSurfacesOnField(med_reader, node_entity, 'vitesse', 1)
434     if isosurfaces is None:
435         print "FAILED"
436     else:
437         display_only(isosurfaces, view)
438         print "OK"
439     
440     print "Creating Cut Planes.......",
441     cutplanes = CutPlanesOnField(med_reader, node_entity, 'vitesse', 1,
442                                  nb_planes=30, orientation=Orientation.YZ)
443     if cutplanes is None:
444         print "FAILED"
445     else:
446         display_only(cutplanes, view)
447         print "OK"
448     
449     print "Creating Scalar Map On Deformed Shape.......",
450     scalarmapondefshape = DeformedShapeAndScalarMapOnField(med_reader,
451                                                            node_entity,
452                                                            'vitesse', 1,
453                                                            None,
454                                                            cell_entity,
455                                                            'pression')
456     if scalarmapondefshape is None:
457         print "FAILED"
458     else:
459         display_only(scalarmapondefshape, view)
460         print "OK"
461
462 else: # not in gui mode, Paravis can not be tested
463     
464     print
465     print "PARAVIS module requires SALOME to be running in GUI mode."
466     print
467     print "Skipping test for PARAVIS..."
468     pass
469
470 # ---- update object browser
471 if salome.hasDesktop():
472     salome.sg.updateObjBrowser(1);