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, FIELDS, 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)
58 raise RuntimeError("Can't access module catalog")
63 print("======================================================================")
64 print(" %d. Check modules availability in the module catalog " % step); step+=1
65 print("======================================================================")
67 for module in [ "GEOM", "SMESH", "MEDFactory", "PVSERVER"]:
69 print("--- Check %s ..." % module)
70 comp = catalog.GetComponent(module)
72 raise RuntimeError("Component %s is not found in Module Catalog." % module)
78 print("======================================================================")
79 print(" %d. Test Data Server " % step); step+=1
80 print("======================================================================")
83 print("--- Create new component ...")
84 comp = builder.NewComponent("TEST")
86 raise RuntimeError("Can't create new component")
90 print("--- Create AttributeName ...")
91 A = builder.FindOrCreateAttribute(comp, "AttributeName")
93 raise RuntimeError("Can't create AttributeName attribute")
95 if A.Value() != "TEST":
96 raise RuntimeError("Error : wrong value of AttributeName")
100 print("--- Create AttributeReal ...")
101 A = builder.FindOrCreateAttribute(comp, "AttributeReal")
103 raise RuntimeError("Can't create AttributeReal attribute")
105 if A.Value() != 0.0001:
106 raise RuntimeError("Error : wrong value of AttributeReal")
111 print("======================================================================")
112 print(" %d. Test Geometry " % step); step+=1
113 print("======================================================================")
115 from salome.geom import geomBuilder
116 geompy = geomBuilder.New()
118 ShapeTypeCompSolid = 1
127 print("--- Create a box ...")
128 box = geompy.MakeBox(0., 0., 0., 100., 200., 300.)
129 idbox = geompy.addToStudy(box, "box")
130 box_obj = salome.myStudy.FindObjectByPath("/Geometry/box")
132 raise RuntimeError("Error : wrong value of AttributeReal")
135 # ---- add shell from box in study
137 print("--- Extract shell ...")
138 subShellList = geompy.SubShapeAll(box, ShapeTypeShell)
139 shell = subShellList[0]
140 name = geompy.SubShapeName(shell, box)
141 idshell = geompy.addToStudyInFather(box, shell, name)
145 # ---- add first face of box in study
147 print("--- Extract face ...")
148 subShapeList = geompy.SubShapeAll(box, ShapeTypeFace)
149 face = subShapeList[0]
150 name = geompy.SubShapeName(face, box)
151 idface = geompy.addToStudyInFather(box, face, name)
155 # ---- add first edge of face in study
157 print("--- Extract edge ...")
158 edgeList = geompy.SubShapeAll(face, ShapeTypeEdge)
160 name = geompy.SubShapeName(edge, face)
161 idedge = geompy.addToStudyInFather(face, edge, name)
165 # ---- update object browser
166 if salome.hasDesktop():
167 salome.sg.updateObjBrowser();
171 print("======================================================================")
172 print(" %d. Test Mesh " % step); step+=1
173 print("======================================================================")
175 from salome.StdMeshers import StdMeshersBuilder
177 from salome.smesh import smeshBuilder
179 smesh = salome.lcc.FindOrLoadComponent("FactoryServer", "SMESH")
180 if salome.hasDesktop():
181 smeshgui = salome.ImportComponentGUI("SMESH")
184 smesh = smeshBuilder.New()
186 # ---- create hypotheses
188 stdMeshersEngine = "StdMeshersEngine"
191 print("--- Create hypotheses ...")
194 print("------ LocalLength ...")
195 hypLen1 = smesh.CreateHypothesis( "LocalLength", stdMeshersEngine )
196 hypLen1.SetLength(100)
197 print(hypLen1.GetName())
198 print(hypLen1.GetId())
199 print(hypLen1.GetLength())
200 if salome.hasDesktop():
201 smeshgui.SetName(salome.ObjectToID(hypLen1), "Local_Length_100")
205 print("------ NumberOfSegments ...")
206 hypNbSeg1= smesh.CreateHypothesis( "NumberOfSegments", stdMeshersEngine )
207 hypNbSeg1.SetNumberOfSegments(7)
208 print(hypNbSeg1.GetName())
209 print(hypNbSeg1.GetId())
210 print(hypNbSeg1.GetNumberOfSegments())
211 if salome.hasDesktop():
212 smeshgui.SetName(salome.ObjectToID(hypNbSeg1), "NumberOfSegments_7")
216 print("------ MaxElementArea [1] ...")
217 hypArea1 = smesh.CreateHypothesis( "MaxElementArea", stdMeshersEngine )
218 hypArea1.SetMaxElementArea(2500)
219 print(hypArea1.GetName())
220 print(hypArea1.GetId())
221 print(hypArea1.GetMaxElementArea())
222 if salome.hasDesktop():
223 smeshgui.SetName(salome.ObjectToID(hypArea1), "MaxElementArea_2500")
227 print("------ MaxElementArea [2] ...")
228 hypArea2 = smesh.CreateHypothesis( "MaxElementArea", stdMeshersEngine )
229 hypArea2.SetMaxElementArea(500)
230 print(hypArea2.GetName())
231 print(hypArea2.GetId())
232 print(hypArea2.GetMaxElementArea())
233 if salome.hasDesktop():
234 smeshgui.SetName(salome.ObjectToID(hypArea2), "MaxElementArea_500")
237 # ---- create algorithms
240 print("--- Create algorithms ...")
243 print("------ Regular_1D ...")
244 algoReg = smesh.CreateHypothesis( "Regular_1D", stdMeshersEngine )
245 listHyp = algoReg.GetCompatibleHypothesis()
248 print(algoReg.GetName())
249 print(algoReg.GetId())
250 if salome.hasDesktop():
251 smeshgui.SetName(salome.ObjectToID(algoReg), "Regular_1D" )
255 print("------ MEFISTO_2D ...")
256 algoMef = smesh.CreateHypothesis( "MEFISTO_2D", stdMeshersEngine )
257 listHyp=algoMef.GetCompatibleHypothesis()
260 print(algoMef.GetName())
261 print(algoMef.GetId())
262 if salome.hasDesktop():
263 smeshgui.SetName(salome.ObjectToID(algoMef), "MEFISTO_2D" )
266 # ---- create mesh on the box, apply hypotheses / algorithms
269 print("--- Create mesh on the box ...")
270 mesh = smesh.CreateMesh(box)
271 if salome.hasDesktop():
272 smeshgui.SetName( salome.ObjectToID(mesh), "MeshBox" );
273 ret = mesh.AddHypothesis(box, algoReg)
274 ret = mesh.AddHypothesis(box, algoMef)
275 ret = mesh.AddHypothesis(box, hypNbSeg1)
276 ret = mesh.AddHypothesis(box, hypArea1)
279 # ---- create submesh on the edge, add hypothesis
282 print("--- Add 1D sub-mesh on the edge ...")
283 submesh = mesh.GetSubMesh(edge, "SubMeshEdge")
284 ret = mesh.AddHypothesis(edge, algoReg)
285 ret = mesh.AddHypothesis(edge, hypLen1)
288 # ---- create submesh on the edge, add hypothesis
291 print("--- Add 2D sub-mesh on the face ...")
292 submesh = mesh.GetSubMesh(face, "SubMeshFace")
293 ret = mesh.AddHypothesis(face, hypArea2)
298 print("--- Compute mesh ...")
299 smesh.Compute(mesh, box)
302 # ---- update object browser
303 if salome.hasDesktop():
304 salome.sg.updateObjBrowser();
308 print("======================================================================")
309 print(" %d. Test Fields " % step); step+=1
310 print("======================================================================")
313 #from medcalc import properties
314 from medcalc.fieldproxy import FieldProxy
316 medcalc.medconsole.setConsoleGlobals(globals())
318 med_root=os.environ["FIELDS_ROOT_DIR"]
319 except KeyError as e:
320 raise RuntimeError("FIELDS_ROOT_DIR should be defined to load the test data")
322 filepath = os.path.join(med_root,"share","salome","resources","fields","medcalc_testfiles","smallmesh_varfield.med")
323 medcalc.medio.LoadDataSource(filepath)
324 fieldHandlerList = medcalc.medevents.dataManager.getFieldHandlerList()
326 fieldHandler0 = fieldHandlerList[0]
327 print("---Field Handler 0:\n%s" % fieldHandler0)
328 fieldHandler1 = fieldHandlerList[1]
329 print("---Field Handler 1:\n%s" % fieldHandler1)
331 print("--- The addition of two fields can be done using field handler directly.")
332 addFieldHandler = medcalc.fieldproxy.calculator.add(fieldHandler0,fieldHandler1)
333 print("--- Result handler:\n%s" % addFieldHandler)
335 print("--- Or with a field proxy that easy the writing of operations.")
336 fieldProxy0 = FieldProxy(fieldHandler0)
337 fieldProxy1 = FieldProxy(fieldHandler1)
339 resHandler = fieldProxy0 + fieldProxy1
340 if resHandler is None:
341 print("Error: result handler is None!")
343 print("--- Result handler:\n%s" % resHandler)
349 print("======================================================================")
350 print(" %d. Test Paravis " % step); step+=1
351 print("======================================================================")
353 if salome.hasDesktop(): # in gui mode
355 print("**** Importing pvserver... It can take some time.")
359 #====================Stage1: Importing MED file====================
361 print("**** Stage1: Importing MED file")
363 print('Import "ResOK_0000.med"...............', end=' ')
364 medFileName = "ResOK_0000.med"
365 medFile = os.path.join(os.getenv('DATA_DIR'), 'MedFiles', medFileName)
366 pvsimple.MEDReader( FileName=medFile )
367 med_reader = pvsimple.GetActiveSource()
369 if med_reader is None:
374 #====================Stage2: Displaying presentation===============
376 print("**** Stage2: Displaying presentation")
378 print('Get view...................', end=' ')
379 view = pvsimple.GetRenderView()
385 print("Creating presentation.......",end='')
386 prs = pvsimple.GetRepresentation(med_reader)
390 rep_list = view.Representations
392 if hasattr(rep, 'Visibility'):
393 rep.Visibility = (rep == prs)
394 pvsimple.Render(view=view)
396 # ---- surface representation
397 prs.SetRepresentationType('Surface')
402 else: # not in gui mode, Paravis can not be tested
405 print("PARAVIS module requires SALOME to be running in GUI mode.")
407 print("Skipping test for PARAVIS...")
410 # ---- update object browser
411 if salome.hasDesktop():
412 salome.sg.updateObjBrowser();