1 # -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2013 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.
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, VISU, MED"
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 "======================================================================"
67 print "--- Check GEOM ..."
68 comp = catalog.GetComponent("GEOM")
70 raise RuntimeError, "Component GEOM is not found in Module Catalog."
74 print "--- Check SMESH ..."
75 comp = catalog.GetComponent("SMESH")
77 raise RuntimeError, "Component SMESH is not found in Module Catalog."
81 print "--- Check MED ..."
82 comp = catalog.GetComponent("MED")
84 raise RuntimeError, "Component MED is not found in Module Catalog."
88 print "--- Check VISU ..."
89 comp = catalog.GetComponent("VISU")
91 raise RuntimeError, "Component VISU is not found in Module Catalog."
96 print "======================================================================"
97 print " %d. Test Data Server " % step; step+=1
98 print "======================================================================"
101 print "--- Create new component ..."
102 comp = builder.NewComponent("TEST")
104 raise RuntimeError, "Can't create new component"
108 print "--- Create AttributeName ..."
109 A = builder.FindOrCreateAttribute(comp, "AttributeName")
111 raise RuntimeError, "Can't create AttributeName attribute"
113 if A.Value() != "TEST":
114 raise RuntimeError, "Error : wrong value of AttributeName"
118 print "--- Create AttributeReal ..."
119 A = builder.FindOrCreateAttribute(comp, "AttributeReal")
121 raise RuntimeError, "Can't create AttributeReal attribute"
123 if A.Value() != 0.0001:
124 raise RuntimeError, "Error : wrong value of AttributeReal"
129 print "======================================================================"
130 print " %d. Test Geometry " % step; step+=1
131 print "======================================================================"
135 ShapeTypeCompSolid = 1
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")
149 raise RuntimeError, "Error : wrong value of AttributeReal"
152 # ---- add shell from box in study
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)
162 # ---- add first face of box in study
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)
172 # ---- add first edge of face in study
174 print "--- Extract edge ..."
175 edgeList = geompy.SubShapeAll(face, ShapeTypeEdge)
177 name = geompy.SubShapeName(edge, face)
178 idedge = geompy.addToStudyInFather(face, edge, name)
182 # ---- update object browser
183 if salome.hasDesktop():
184 salome.sg.updateObjBrowser(1);
188 print "======================================================================"
189 print " %d. Test Mesh " % step; step+=1
190 print "======================================================================"
195 smesh = salome.lcc.FindOrLoadComponent("FactoryServer", "SMESH")
196 if salome.hasDesktop():
197 smeshgui = salome.ImportComponentGUI("SMESH")
198 smeshgui.Init(salome.myStudyId);
200 smesh.SetCurrentStudy(salome.myStudy)
202 # ---- create hypotheses
204 if sys.platform == "win32":
205 stdMeshersEngine = "StdMeshersEngine"
207 stdMeshersEngine = "libStdMeshersEngine.so"
210 print "--- Create hypotheses ..."
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")
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")
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")
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")
256 # ---- create algorithms
259 print "--- Create algorithms ..."
262 print "------ Regular_1D ..."
263 algoReg = smesh.CreateHypothesis( "Regular_1D", stdMeshersEngine )
264 listHyp = algoReg.GetCompatibleHypothesis()
267 print algoReg.GetName()
268 print algoReg.GetId()
269 if salome.hasDesktop():
270 smeshgui.SetName(salome.ObjectToID(algoReg), "Regular_1D" )
274 print "------ MEFISTO_2D ..."
275 algoMef = smesh.CreateHypothesis( "MEFISTO_2D", stdMeshersEngine )
276 listHyp=algoMef.GetCompatibleHypothesis()
279 print algoMef.GetName()
280 print algoMef.GetId()
281 if salome.hasDesktop():
282 smeshgui.SetName(salome.ObjectToID(algoMef), "MEFISTO_2D" )
285 # ---- create mesh on the box, apply hypotheses / algorithms
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)
298 # ---- create submesh on the edge, add hypothesis
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)
307 # ---- create submesh on the edge, add hypothesis
310 print "--- Add 2D sub-mesh on the face ..."
311 submesh = mesh.GetSubMesh(face, "SubMeshFace")
312 ret = mesh.AddHypothesis(face, hypArea2)
317 print "--- Compute mesh ..."
318 smesh.Compute(mesh, box)
321 # ---- update object browser
322 if salome.hasDesktop():
323 salome.sg.updateObjBrowser(1);
327 print "======================================================================"
328 print " %d. Test Med " % step; step+=1
329 print "======================================================================"
332 from xmed import properties
333 from xmed.fieldproxy import FieldProxy
335 xmed.setConsoleGlobals(globals())
337 # Load some test data in the MedDataManager
338 filepath = properties.testFilePath
339 xmed.dataManager.addDatasource(filepath)
340 fieldHandlerList = xmed.dataManager.getFieldHandlerList()
342 fieldHandler0 = fieldHandlerList[0]
343 print "---Field Handler 0:\n%s" % fieldHandler0
344 fieldHandler1 = fieldHandlerList[1]
345 print "---Field Handler 1:\n%s" % fieldHandler1
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
351 print "--- Or with a field proxy that easy the writing of operations."
352 fieldProxy0 = FieldProxy(fieldHandler0)
353 fieldProxy1 = FieldProxy(fieldHandler1)
355 resHandler = fieldProxy0 + fieldProxy1
356 if resHandler is None:
357 print "Error: result handler is None!"
359 print "--- Result handler:\n%s" % resHandler
364 print "======================================================================"
365 print " %d. Test Post-Pro " % step; step+=1
366 print "======================================================================"
370 medFileName = "pointe.med"
371 medFile = os.path.join(os.getenv('DATA_DIR'), 'MedFiles', medFileName)
375 field_name = "fieldnodedouble"
377 if salome.hasDesktop(): # in gui mode
380 visu = salome.lcc.FindOrLoadComponent("FactoryServer", "VISU")
383 print "--- Import med file %s to the VISU ..." % medFile
384 result2 = visu.ImportFile(medFile);
386 raise RuntimeError, "Can't import file"
390 print "--- Create mesh presentation ..."
391 mesh2 = visu.MeshOnEntity(result2, aMeshName, anEntity);
393 raise RuntimeError, "Can't create mesh presentation"
397 print "--- Create scalar map ..."
398 scalarMap2 = visu.ScalarMapOnField(result2, aMeshName, anEntity, field_name, 3)
400 raise RuntimeError, "Can't create scalar map"
404 else: # not in gui mode, visu can not be tested
407 print "VISU module requires SALOME to be running in GUI mode."
409 print "Skipping test for VISU..."
412 print "======================================================================"
413 print " %d. Test Paravis " % step; step+=1
414 print "======================================================================"
416 if salome.hasDesktop(): # in gui mode
418 print "**** Importing paravis... It can take some time."
419 from presentations import *
423 my_paravis = paravis.myParavis
425 #====================Stage1: Importing MED file====================
427 print "**** Stage1: Importing MED file"
429 print 'Import "ResOK_0000.med"...............',
430 medFileName = "ResOK_0000.med"
431 medFile = os.path.join(os.getenv('DATA_DIR'), 'MedFiles', medFileName)
432 my_paravis.ImportFile(medFile)
433 med_reader = pvsimple.GetActiveSource()
435 if med_reader is None:
440 cell_entity = EntityType.CELL
441 node_entity = EntityType.NODE
443 #====================Stage2: Displaying vector field===============
445 print "**** Stage3: Displaying vector field"
447 print 'Get view...................',
448 view = pvsimple.GetRenderView()
455 print "Creating Scalar Map.......",
456 scalarmap = ScalarMapOnField(med_reader, node_entity, 'vitesse', 1)
457 if scalarmap is None:
461 bar.Orientation = 'Horizontal'
462 bar.Position = [0.1, 0.1]
463 bar.Position2 = [0.1, 0.25]
466 display_only(scalarmap, view)
471 print "Creating Vectors..........",
472 vectors = VectorsOnField(med_reader, node_entity, 'vitesse', 1)
476 display_only(vectors, view)
479 print "Creating Iso Surfaces.....",
480 isosurfaces = IsoSurfacesOnField(med_reader, node_entity, 'vitesse', 1)
481 if isosurfaces is None:
484 display_only(isosurfaces, view)
487 print "Creating Cut Planes.......",
488 cutplanes = CutPlanesOnField(med_reader, node_entity, 'vitesse', 1,
489 nb_planes=30, orientation=Orientation.YZ)
490 if cutplanes is None:
493 display_only(cutplanes, view)
496 print "Creating Scalar Map On Deformed Shape.......",
497 scalarmapondefshape = DeformedShapeAndScalarMapOnField(med_reader,
503 if scalarmapondefshape is None:
506 display_only(scalarmapondefshape, view)
509 else: # not in gui mode, Paravis can not be tested
512 print "PARAVIS module requires SALOME to be running in GUI mode."
514 print "Skipping test for PARAVIS..."
517 # ---- update object browser
518 if salome.hasDesktop():
519 salome.sg.updateObjBrowser(1);