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
24 ####################################################################################################
25 # Test the Med Component: mounting in Memory a .med file and trying to get information through
27 ####################################################################################################
35 from libSALOME_Swig import *
48 def changeBlankToUnderScore(stringWithBlank):
51 decompString = string.split(stringWithBlank,blank)
52 length = len(decompString)
53 stringWithUnderScore = decompString[0]
54 for i in range(1,length):
55 stringWithUnderScore += underscore
56 stringWithUnderScore += decompString[i]
57 return stringWithUnderScore
59 def getMedObjectFromStudy(file):
60 objNameInStudy = "MED_OBJECT_FROM_FILE_"+file
61 compNameInStudy= "MED"
62 listOfSO = salome.myStudy.FindObjectByName(objNameInStudy,compNameInStudy)
63 listLength = len(listOfSO)
64 if (listLength == 0) :
65 print objNameInStudy," cannot be found in the Study under the component ",compNameInStudy
67 elif (listLength > 1) :
68 print "there are more than one instance of ",objNameInStudy," in the Study under the component ",compNameInStudy
72 print objNameInStudy," cannot be found in the Study"
75 anAttr = mySO.FindAttribute("AttributeIOR")[1]
76 obj = salome.orb.string_to_object(anAttr.Value())
77 myObj = obj._narrow(SALOME_MED.MED)
79 print objNameInStudy," has been found in the Study but with the wrong type"
82 def getMeshObjectFromStudy(meshName):
83 objNameInStudy = "/Med/MEDMESH/"+meshName
84 mySO = salome.myStudy.FindObjectByPath(objNameInStudy)
86 print objNameInStudy," cannot be found in the Study"
89 anAttr = mySO.FindAttribute("AttributeIOR")[1]
90 obj = salome.orb.string_to_object(anAttr.Value())
91 myObj = obj._narrow(SALOME_MED.MESH)
93 print objNameInStudy," has been found in the Study but with the wrong type"
96 def getSupportObjectFromStudy(meshName,supportName):
97 meshNameStudy = changeBlankToUnderScore(meshName)
98 objNameInStudy = "/Med/MEDMESH/MEDSUPPORTS_OF_"+meshNameStudy+"/"+supportName
99 mySO = salome.myStudy.FindObjectByPath(objNameInStudy)
101 print objNameInStudy," cannot be found in the Study"
104 anAttr = mySO.FindAttribute("AttributeIOR")[1]
105 obj = salome.orb.string_to_object(anAttr.Value())
106 myObj = obj._narrow(SALOME_MED.SUPPORT)
108 print objNameInStudy," has been found in the Study but with the wrong type"
111 def getFieldObjectFromStudy(dt,it,fieldName,supportName,meshName):
112 meshNameStudy = changeBlankToUnderScore(meshName)
113 objNameInStudy = "/Med/MEDFIELD/"+fieldName+"/("+str(dt)+","+str(it)+")_ON_"+supportName+"_OF_"+meshNameStudy
114 mySO = salome.myStudy.FindObjectByPath(objNameInStudy)
116 print objNameInStudy," cannot be found in the Study"
119 anAttr = mySO.FindAttribute("AttributeIOR")[1]
120 obj = salome.orb.string_to_object(anAttr.Value())
121 myObj = obj._narrow(SALOME_MED.FIELDINT)
123 myObj = obj._narrow(SALOME_MED.FIELDDOUBLE)
125 print objNameInStudy," has been found in the Study but with the wrong type"
128 fileName = "cube_hexa8_quad4.med"
130 #fileName = "carre_en_quad4_seg2.med"
132 medComp=salome.lcc.FindOrLoadComponent("FactoryServer", "MED")
136 filePath=os.environ["MED_ROOT_DIR"]
137 filePath=os.path.join(filePath, "share", "salome", "resources", "med")
139 filePathName = os.path.join(filePath, fileName)
141 print "Reading the .med file ",filePathName," and pushing corba objects in the SALOME study"
142 medComp.readStructFileWithFieldType(filePathName,salome.myStudyName)
143 sg.updateObjBrowser(1)
145 print "getting the MED object from the study"
146 medObj = getMedObjectFromStudy(fileName)
148 nbOfMeshes = medObj.getNumberOfMeshes()
149 meshNames = medObj.getMeshNames()
151 print "in this med file there is(are) ",nbOfMeshes," mesh(es):"
152 for i in range(nbOfMeshes):
153 meshName = meshNames[i]
154 print " - the ",print_ord(i)," mesh is named ",meshName
155 print " getting the MESH object using the API of the corba object MED"
156 meshObj = medObj.getMeshByName(meshName)
157 print " getting mesh information (including corba object) using the API of the corba object MESH"
158 for entity in [SALOME_MED.MED_NODE,SALOME_MED.MED_CELL,
159 SALOME_MED.MED_FACE,SALOME_MED.MED_EDGE]:
160 nbFam = meshObj.getNumberOfFamilies(entity)
161 nbGrp = meshObj.getNumberOfGroups(entity)
162 if (entity == SALOME_MED.MED_NODE):
163 print " this mesh has ",nbFam," Node Family(ies) and ",nbGrp," Node Group(s)"
164 elif (entity == SALOME_MED.MED_CELL):
165 print " ",nbFam," Cell Family(ies) and ",nbGrp," Cell Group(s)"
166 elif (entity == SALOME_MED.MED_FACE):
167 print " ",nbFam," Face Family(ies) and ",nbGrp," Face Group(s)"
168 elif (entity == SALOME_MED.MED_EDGE):
169 print " ",nbFam," Edge Family(ies) and ",nbGrp," Cell Group(s)"
172 for j in range(nbFam):
173 familyObj = meshObj.getFamily(entity,j+1)
177 for j in range(nbGrp):
178 groupObj = meshObj.getGroup(entity,j+1)
182 print " getting the MESH object from the Study"
183 meshObj = getMeshObjectFromStudy(meshName)
185 print " getting mesh information using the API of the corba object MESH but corba objects are obtained from the Study"
186 for entity in [SALOME_MED.MED_NODE,SALOME_MED.MED_CELL,
187 SALOME_MED.MED_FACE,SALOME_MED.MED_EDGE]:
188 nbFam = meshObj.getNumberOfFamilies(entity)
189 nbGrp = meshObj.getNumberOfGroups(entity)
190 if (entity == SALOME_MED.MED_NODE):
191 print " this mesh has ",nbFam," Node Family(ies) and ",nbGrp," Node Group(s)"
192 elif (entity == SALOME_MED.MED_CELL):
193 print " ",nbFam," Cell Family(ies) and ",nbGrp," Cell Group(s)"
194 elif (entity == SALOME_MED.MED_FACE):
195 print " ",nbFam," Face Family(ies) and ",nbGrp," Face Group(s)"
196 elif (entity == SALOME_MED.MED_EDGE):
197 print " ",nbFam," Edge Family(ies) and ",nbGrp," Cell Group(s)"
200 for j in range(nbFam):
201 familyName = (meshObj.getFamily(entity,j+1)).getName()
202 familyObj = getSupportObjectFromStudy(meshName,familyName)
206 for j in range(nbGrp):
207 groupName = (meshObj.getGroup(entity,j+1)).getName()
208 groupObj = getSupportObjectFromStudy(meshName,groupName)
211 print "let's get other SUPPORT object from the Study"
212 for entity in [SALOME_MED.MED_NODE,SALOME_MED.MED_CELL,
213 SALOME_MED.MED_FACE,SALOME_MED.MED_EDGE]:
215 if entity == SALOME_MED.MED_NODE :
216 entitySupport = "MED_NOEUD"
217 elif entity == SALOME_MED.MED_CELL :
218 entitySupport = "MED_MAILLE"
219 elif entity == SALOME_MED.MED_FACE :
220 entitySuppor = "MED_FACE"
221 elif entity == SALOME_MED.MED_EDGE :
222 entitySupport = "MED_ARETE"
224 supportName = "SupportOnAll_"+entitySupport
225 supportObj = getSupportObjectFromStudy(meshName,supportName)
227 nbOfFields = medObj.getNumberOfFields()
228 print "in the considered .med file there is(are) ",nbOfFields," field(s):"
229 fieldNames = medObj.getFieldNames()
230 for i in range(nbOfFields):
231 fieldName = fieldNames[i]
232 nbOfIt = medObj.getFieldNumberOfIteration(fieldName)
233 print " - the ",print_ord(i)," field is name ",fieldName," and has ",nbOfIt," iteration(s)"
234 for j in range(nbOfIt):
235 dtitfield = medObj.getFieldIteration(fieldName,j)
238 print " * Iteration:",dt,"Order number:",it
239 for k in range(nbOfMeshes):
240 meshName = meshNames[k]
241 for entity in [SALOME_MED.MED_NODE,SALOME_MED.MED_CELL,
242 SALOME_MED.MED_FACE,SALOME_MED.MED_EDGE]:
243 if entity == SALOME_MED.MED_NODE :
244 entitySupport = "MED_NOEUD"
245 elif entity == SALOME_MED.MED_CELL :
246 entitySupport = "MED_MAILLE"
247 elif entity == SALOME_MED.MED_FACE :
248 entitySuppor = "MED_FACE"
249 elif entity == SALOME_MED.MED_EDGE :
250 entitySupport = "MED_ARETE"
251 supportName = "SupportOnAll_"+entitySupport
252 print "getting a corba object Field from the study iteration ",dt," order number ",it," on the support ",supportName," from the mesh ",meshName
253 fieldObj = getFieldObjectFromStudy(dt,it,fieldName,supportName,meshName)
257 print "END of the Pyhton script ..... Ctrl D to exit"