1 # -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
4 # Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
5 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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, or (at your option) any later version.
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.
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
21 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
25 print "Perform quick test of the application by loading of the GEOM, SMESH, MED, PARAVIS"
26 print "components and doing some operation within the components."
34 import SALOME_ModuleCatalog
38 print "======================================================================"
39 print " %d. Initialize study " % step; step+=1
40 print "======================================================================"
45 builder = salome.myStudy.NewBuilder()
50 print "======================================================================"
51 print " %d. Retrieve module catalog " % step; step+=1
52 print "======================================================================"
54 obj = salome.naming_service.Resolve('Kernel/ModulCatalog')
55 catalog = obj._narrow(SALOME_ModuleCatalog.ModuleCatalog)
57 raise RuntimeError, "Can't accesss module catalog"
62 print "======================================================================"
63 print " %d. Check modules availability in the module catalog " % step; step+=1
64 print "======================================================================"
66 for module in [ "GEOM", "SMESH", "MEDFactory", "PVSERVER"]:
68 print "--- Check %s ..." % module
69 comp = catalog.GetComponent(module)
71 raise RuntimeError, "Component %s is not found in Module Catalog." % module
77 print "======================================================================"
78 print " %d. Test Data Server " % step; step+=1
79 print "======================================================================"
82 print "--- Create new component ..."
83 comp = builder.NewComponent("TEST")
85 raise RuntimeError, "Can't create new component"
89 print "--- Create AttributeName ..."
90 A = builder.FindOrCreateAttribute(comp, "AttributeName")
92 raise RuntimeError, "Can't create AttributeName attribute"
94 if A.Value() != "TEST":
95 raise RuntimeError, "Error : wrong value of AttributeName"
99 print "--- Create AttributeReal ..."
100 A = builder.FindOrCreateAttribute(comp, "AttributeReal")
102 raise RuntimeError, "Can't create AttributeReal attribute"
104 if A.Value() != 0.0001:
105 raise RuntimeError, "Error : wrong value of AttributeReal"
110 print "======================================================================"
111 print " %d. Test Geometry " % step; step+=1
112 print "======================================================================"
114 from salome.geom import geomBuilder
115 geompy = geomBuilder.New(salome.myStudy)
117 ShapeTypeCompSolid = 1
126 print "--- Create a box ..."
127 box = geompy.MakeBox(0., 0., 0., 100., 200., 300.)
128 idbox = geompy.addToStudy(box, "box")
129 box_obj = salome.myStudy.FindObjectByPath("/Geometry/box")
131 raise RuntimeError, "Error : wrong value of AttributeReal"
134 # ---- add shell from box in study
136 print "--- Extract shell ..."
137 subShellList = geompy.SubShapeAll(box, ShapeTypeShell)
138 shell = subShellList[0]
139 name = geompy.SubShapeName(shell, box)
140 idshell = geompy.addToStudyInFather(box, shell, name)
144 # ---- add first face of box in study
146 print "--- Extract face ..."
147 subShapeList = geompy.SubShapeAll(box, ShapeTypeFace)
148 face = subShapeList[0]
149 name = geompy.SubShapeName(face, box)
150 idface = geompy.addToStudyInFather(box, face, name)
154 # ---- add first edge of face in study
156 print "--- Extract edge ..."
157 edgeList = geompy.SubShapeAll(face, ShapeTypeEdge)
159 name = geompy.SubShapeName(edge, face)
160 idedge = geompy.addToStudyInFather(face, edge, name)
164 # ---- update object browser
165 if salome.hasDesktop():
166 salome.sg.updateObjBrowser(1);
170 print "======================================================================"
171 print " %d. Test Mesh " % step; step+=1
172 print "======================================================================"
174 from salome.StdMeshers import StdMeshersBuilder
176 from salome.smesh import smeshBuilder
178 smesh = salome.lcc.FindOrLoadComponent("FactoryServer", "SMESH")
179 if salome.hasDesktop():
180 smeshgui = salome.ImportComponentGUI("SMESH")
181 smeshgui.Init(salome.myStudyId);
183 smesh = smeshBuilder.New(salome.myStudy)
185 # ---- create hypotheses
187 if sys.platform == "win32":
188 stdMeshersEngine = "StdMeshersEngine"
190 stdMeshersEngine = "libStdMeshersEngine.so"
193 print "--- Create hypotheses ..."
196 print "------ LocalLength ..."
197 hypLen1 = smesh.CreateHypothesis( "LocalLength", stdMeshersEngine )
198 hypLen1.SetLength(100)
199 print hypLen1.GetName()
200 print hypLen1.GetId()
201 print hypLen1.GetLength()
202 if salome.hasDesktop():
203 smeshgui.SetName(salome.ObjectToID(hypLen1), "Local_Length_100")
207 print "------ NumberOfSegments ..."
208 hypNbSeg1= smesh.CreateHypothesis( "NumberOfSegments", stdMeshersEngine )
209 hypNbSeg1.SetNumberOfSegments(7)
210 print hypNbSeg1.GetName()
211 print hypNbSeg1.GetId()
212 print hypNbSeg1.GetNumberOfSegments()
213 if salome.hasDesktop():
214 smeshgui.SetName(salome.ObjectToID(hypNbSeg1), "NumberOfSegments_7")
218 print "------ MaxElementArea [1] ..."
219 hypArea1 = smesh.CreateHypothesis( "MaxElementArea", stdMeshersEngine )
220 hypArea1.SetMaxElementArea(2500)
221 print hypArea1.GetName()
222 print hypArea1.GetId()
223 print hypArea1.GetMaxElementArea()
224 if salome.hasDesktop():
225 smeshgui.SetName(salome.ObjectToID(hypArea1), "MaxElementArea_2500")
229 print "------ MaxElementArea [2] ..."
230 hypArea2 = smesh.CreateHypothesis( "MaxElementArea", stdMeshersEngine )
231 hypArea2.SetMaxElementArea(500)
232 print hypArea2.GetName()
233 print hypArea2.GetId()
234 print hypArea2.GetMaxElementArea()
235 if salome.hasDesktop():
236 smeshgui.SetName(salome.ObjectToID(hypArea2), "MaxElementArea_500")
239 # ---- create algorithms
242 print "--- Create algorithms ..."
245 print "------ Regular_1D ..."
246 algoReg = smesh.CreateHypothesis( "Regular_1D", stdMeshersEngine )
247 listHyp = algoReg.GetCompatibleHypothesis()
250 print algoReg.GetName()
251 print algoReg.GetId()
252 if salome.hasDesktop():
253 smeshgui.SetName(salome.ObjectToID(algoReg), "Regular_1D" )
257 print "------ MEFISTO_2D ..."
258 algoMef = smesh.CreateHypothesis( "MEFISTO_2D", stdMeshersEngine )
259 listHyp=algoMef.GetCompatibleHypothesis()
262 print algoMef.GetName()
263 print algoMef.GetId()
264 if salome.hasDesktop():
265 smeshgui.SetName(salome.ObjectToID(algoMef), "MEFISTO_2D" )
268 # ---- create mesh on the box, apply hypotheses / algorithms
271 print "--- Create mesh on the box ..."
272 mesh = smesh.CreateMesh(box)
273 if salome.hasDesktop():
274 smeshgui.SetName( salome.ObjectToID(mesh), "MeshBox" );
275 ret = mesh.AddHypothesis(box, algoReg)
276 ret = mesh.AddHypothesis(box, algoMef)
277 ret = mesh.AddHypothesis(box, hypNbSeg1)
278 ret = mesh.AddHypothesis(box, hypArea1)
281 # ---- create submesh on the edge, add hypothesis
284 print "--- Add 1D sub-mesh on the edge ..."
285 submesh = mesh.GetSubMesh(edge, "SubMeshEdge")
286 ret = mesh.AddHypothesis(edge, algoReg)
287 ret = mesh.AddHypothesis(edge, hypLen1)
290 # ---- create submesh on the edge, add hypothesis
293 print "--- Add 2D sub-mesh on the face ..."
294 submesh = mesh.GetSubMesh(face, "SubMeshFace")
295 ret = mesh.AddHypothesis(face, hypArea2)
300 print "--- Compute mesh ..."
301 smesh.Compute(mesh, box)
304 # ---- update object browser
305 if salome.hasDesktop():
306 salome.sg.updateObjBrowser(1);
310 print "======================================================================"
311 print " %d. Test Med " % step; step+=1
312 print "======================================================================"
315 #from medcalc import properties
316 from medcalc.fieldproxy import FieldProxy
318 medcalc.medconsole.setConsoleGlobals(globals())
320 med_root=os.environ["MED_ROOT_DIR"]
322 raise RuntimeError("MED_ROOT_DIR should be defined to load the test data")
324 filepath = os.path.join(med_root,"share","salome","resources","med","medcalc_testfiles","smallmesh_varfield.med")
325 medcalc.medio.LoadDataSource(filepath)
326 fieldHandlerList = medcalc.medevents.dataManager.getFieldHandlerList()
328 fieldHandler0 = fieldHandlerList[0]
329 print "---Field Handler 0:\n%s" % fieldHandler0
330 fieldHandler1 = fieldHandlerList[1]
331 print "---Field Handler 1:\n%s" % fieldHandler1
333 print "--- The addition of two fields can be done using field handler directly."
334 addFieldHandler = medcalc.fieldproxy.calculator.add(fieldHandler0,fieldHandler1)
335 print "--- Result handler:\n%s" % addFieldHandler
337 print "--- Or with a field proxy that easy the writing of operations."
338 fieldProxy0 = FieldProxy(fieldHandler0)
339 fieldProxy1 = FieldProxy(fieldHandler1)
341 resHandler = fieldProxy0 + fieldProxy1
342 if resHandler is None:
343 print "Error: result handler is None!"
345 print "--- Result handler:\n%s" % resHandler
351 print "======================================================================"
352 print " %d. Test Paravis " % step; step+=1
353 print "======================================================================"
355 if salome.hasDesktop(): # in gui mode
357 print "**** Importing pvserver... It can take some time."
358 from presentations import *
362 my_paravis = pvserver.myPVServerService
364 #====================Stage1: Importing MED file====================
366 print "**** Stage1: Importing MED file"
368 print 'Import "ResOK_0000.med"...............',
369 medFileName = "ResOK_0000.med"
370 medFile = os.path.join(os.getenv('DATA_DIR'), 'MedFiles', medFileName)
371 pvsimple.MEDReader( FileName=medFile )
372 med_reader = pvsimple.GetActiveSource()
374 if med_reader is None:
379 cell_entity = EntityType.CELL
380 node_entity = EntityType.NODE
382 #====================Stage2: Displaying vector field===============
384 print "**** Stage3: Displaying vector field"
386 print 'Get view...................',
387 view = pvsimple.GetRenderView()
394 print "Creating Scalar Map.......",
395 scalarmap = ScalarMapOnField(med_reader, node_entity, 'vitesse', 2)
396 if scalarmap is None:
400 bar.Orientation = 'Horizontal'
401 bar.Position = [0.1, 0.1]
402 bar.Position2 = [0.1, 0.25]
405 display_only(scalarmap, view)
410 print "Creating Vectors..........",
411 vectors = VectorsOnField(med_reader, node_entity, 'vitesse', 2)
415 display_only(vectors, view)
418 print "Creating Iso Surfaces.....",
419 isosurfaces = IsoSurfacesOnField(med_reader, node_entity, 'vitesse', 2)
420 if isosurfaces is None:
423 display_only(isosurfaces, view)
426 print "Creating Cut Planes.......",
427 cutplanes = CutPlanesOnField(med_reader, node_entity, 'vitesse', 2,
428 nb_planes=30, orientation=Orientation.YZ)
429 if cutplanes is None:
432 display_only(cutplanes, view)
435 print "Creating Scalar Map On Deformed Shape.......",
436 scalarmapondefshape = DeformedShapeAndScalarMapOnField(med_reader,
442 if scalarmapondefshape is None:
445 display_only(scalarmapondefshape, view)
448 else: # not in gui mode, Paravis can not be tested
451 print "PARAVIS module requires SALOME to be running in GUI mode."
453 print "Skipping test for PARAVIS..."
456 # ---- update object browser
457 if salome.hasDesktop():
458 salome.sg.updateObjBrowser(1);