1 # Copyright (C) 2005 OPEN CASCADE, CEA, EDF R&D, LEG
2 # PRINCIPIA R&D, EADS CCR, Lip6, BV, CEDRAT
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License.
8 # This library is distributed in the hope that it will be useful
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 # Lesser General Public License for more details.
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 ####################################################################################################
21 # Test the Med Component: mounting in Memory a .med file and trying to get information through
24 ####################################################################################################
31 from libSALOME_Swig import *
44 def changeBlankToUnderScore(stringWithBlank):
47 decompString = string.split(stringWithBlank,blank)
48 length = len(decompString)
49 stringWithUnderScore = decompString[0]
50 for i in range(1,length):
51 stringWithUnderScore += underscore
52 stringWithUnderScore += decompString[i]
53 return stringWithUnderScore
55 def getMedObjectFromStudy(file):
56 objNameInStudy = "MED_OBJECT_FROM_FILE_"+file
57 compNameInStudy= "MED"
58 listOfSO = salome.myStudy.FindObjectByName(objNameInStudy,compNameInStudy)
59 listLength = len(listOfSO)
60 if (listLength == 0) :
61 print objNameInStudy," cannot be found in the Study under the component ",compNameInStudy
63 elif (listLength > 1) :
64 print "there are more than one instance of ",objNameInStudy," in the Study under the component ",compNameInStudy
68 print objNameInStudy," cannot be found in the Study"
71 anAttr = mySO.FindAttribute("AttributeIOR")[1]
72 obj = salome.orb.string_to_object(anAttr.Value())
73 myObj = obj._narrow(SALOME_MED.MED)
75 print objNameInStudy," has been found in the Study but with the wrong type"
78 def getMeshObjectFromStudy(meshName):
79 objNameInStudy = "/Med/MEDMESH/"+meshName
80 mySO = salome.myStudy.FindObjectByPath(objNameInStudy)
82 print objNameInStudy," cannot be found in the Study"
85 anAttr = mySO.FindAttribute("AttributeIOR")[1]
86 obj = salome.orb.string_to_object(anAttr.Value())
87 myObj = obj._narrow(SALOME_MED.MESH)
89 print objNameInStudy," has been found in the Study but with the wrong type"
92 def getSupportObjectFromStudy(meshName,supportName):
93 meshNameStudy = changeBlankToUnderScore(meshName)
94 objNameInStudy = "/Med/MEDMESH/MEDSUPPORTS_OF_"+meshNameStudy+"/"+supportName
95 mySO = salome.myStudy.FindObjectByPath(objNameInStudy)
97 print objNameInStudy," cannot be found in the Study"
100 anAttr = mySO.FindAttribute("AttributeIOR")[1]
101 obj = salome.orb.string_to_object(anAttr.Value())
102 myObj = obj._narrow(SALOME_MED.SUPPORT)
104 print objNameInStudy," has been found in the Study but with the wrong type"
107 def getFieldObjectFromStudy(dt,it,fieldName,supportName,meshName):
108 meshNameStudy = changeBlankToUnderScore(meshName)
109 objNameInStudy = "/Med/MEDFIELD/"+fieldName+"/("+str(dt)+","+str(it)+")_ON_"+supportName+"_OF_"+meshNameStudy
110 mySO = salome.myStudy.FindObjectByPath(objNameInStudy)
112 print objNameInStudy," cannot be found in the Study"
115 anAttr = mySO.FindAttribute("AttributeIOR")[1]
116 obj = salome.orb.string_to_object(anAttr.Value())
117 myObj = obj._narrow(SALOME_MED.FIELDINT)
119 myObj = obj._narrow(SALOME_MED.FIELDDOUBLE)
121 print objNameInStudy," has been found in the Study but with the wrong type"
124 fileName = "cube_hexa8_quad4.med"
126 #fileName = "carre_en_quad4_seg2.med"
128 medComp=salome.lcc.FindOrLoadComponent("FactoryServer", "MED")
132 filePath=os.environ["MED_ROOT_DIR"]
133 filePath=filePath+"/share/salome/resources/med/"
135 filePathName = filePath + fileName
137 print "Reading the .med file ",filePathName," and pushing corba objects in the SALOME study"
138 medComp.readStructFileWithFieldType(filePathName,salome.myStudyName)
139 sg.updateObjBrowser(1)
141 print "getting the MED object from the study"
142 medObj = getMedObjectFromStudy(fileName)
144 nbOfMeshes = medObj.getNumberOfMeshes()
145 meshNames = medObj.getMeshNames()
147 print "in this med file there is(are) ",nbOfMeshes," mesh(es):"
148 for i in range(nbOfMeshes):
149 meshName = meshNames[i]
150 print " - the ",print_ord(i)," mesh is named ",meshName
151 print " getting the MESH object using the API of the corba object MED"
152 meshObj = medObj.getMeshByName(meshName)
153 print " getting mesh information (including corba object) using the API of the corba object MESH"
154 for entity in [SALOME_MED.MED_NODE,SALOME_MED.MED_CELL,
155 SALOME_MED.MED_FACE,SALOME_MED.MED_EDGE]:
156 nbFam = meshObj.getNumberOfFamilies(entity)
157 nbGrp = meshObj.getNumberOfGroups(entity)
158 if (entity == SALOME_MED.MED_NODE):
159 print " this mesh has ",nbFam," Node Family(ies) and ",nbGrp," Node Group(s)"
160 elif (entity == SALOME_MED.MED_CELL):
161 print " ",nbFam," Cell Family(ies) and ",nbGrp," Cell Group(s)"
162 elif (entity == SALOME_MED.MED_FACE):
163 print " ",nbFam," Face Family(ies) and ",nbGrp," Face Group(s)"
164 elif (entity == SALOME_MED.MED_EDGE):
165 print " ",nbFam," Edge Family(ies) and ",nbGrp," Cell Group(s)"
168 for j in range(nbFam):
169 familyObj = meshObj.getFamily(entity,j+1)
173 for j in range(nbGrp):
174 groupObj = meshObj.getGroup(entity,j+1)
178 print " getting the MESH object from the Study"
179 meshObj = getMeshObjectFromStudy(meshName)
181 print " getting mesh information using the API of the corba object MESH but corba objects are obtained from the Study"
182 for entity in [SALOME_MED.MED_NODE,SALOME_MED.MED_CELL,
183 SALOME_MED.MED_FACE,SALOME_MED.MED_EDGE]:
184 nbFam = meshObj.getNumberOfFamilies(entity)
185 nbGrp = meshObj.getNumberOfGroups(entity)
186 if (entity == SALOME_MED.MED_NODE):
187 print " this mesh has ",nbFam," Node Family(ies) and ",nbGrp," Node Group(s)"
188 elif (entity == SALOME_MED.MED_CELL):
189 print " ",nbFam," Cell Family(ies) and ",nbGrp," Cell Group(s)"
190 elif (entity == SALOME_MED.MED_FACE):
191 print " ",nbFam," Face Family(ies) and ",nbGrp," Face Group(s)"
192 elif (entity == SALOME_MED.MED_EDGE):
193 print " ",nbFam," Edge Family(ies) and ",nbGrp," Cell Group(s)"
196 for j in range(nbFam):
197 familyName = (meshObj.getFamily(entity,j+1)).getName()
198 familyObj = getSupportObjectFromStudy(meshName,familyName)
202 for j in range(nbGrp):
203 groupName = (meshObj.getGroup(entity,j+1)).getName()
204 groupObj = getSupportObjectFromStudy(meshName,groupName)
207 print "let's get other SUPPORT object from the Study"
208 for entity in [SALOME_MED.MED_NODE,SALOME_MED.MED_CELL,
209 SALOME_MED.MED_FACE,SALOME_MED.MED_EDGE]:
211 if entity == SALOME_MED.MED_NODE :
212 entitySupport = "MED_NOEUD"
213 elif entity == SALOME_MED.MED_CELL :
214 entitySupport = "MED_MAILLE"
215 elif entity == SALOME_MED.MED_FACE :
216 entitySuppor = "MED_FACE"
217 elif entity == SALOME_MED.MED_EDGE :
218 entitySupport = "MED_ARETE"
220 supportName = "SupportOnAll_"+entitySupport
221 supportObj = getSupportObjectFromStudy(meshName,supportName)
223 nbOfFields = medObj.getNumberOfFields()
224 print "in the considered .med file there is(are) ",nbOfFields," field(s):"
225 fieldNames = medObj.getFieldNames()
226 for i in range(nbOfFields):
227 fieldName = fieldNames[i]
228 nbOfIt = medObj.getFieldNumberOfIteration(fieldName)
229 print " - the ",print_ord(i)," field is name ",fieldName," and has ",nbOfIt," iteration(s)"
230 for j in range(nbOfIt):
231 dtitfield = medObj.getFieldIteration(fieldName,j)
234 print " * Iteration:",dt,"Order number:",it
235 for k in range(nbOfMeshes):
236 meshName = meshNames[k]
237 for entity in [SALOME_MED.MED_NODE,SALOME_MED.MED_CELL,
238 SALOME_MED.MED_FACE,SALOME_MED.MED_EDGE]:
239 if entity == SALOME_MED.MED_NODE :
240 entitySupport = "MED_NOEUD"
241 elif entity == SALOME_MED.MED_CELL :
242 entitySupport = "MED_MAILLE"
243 elif entity == SALOME_MED.MED_FACE :
244 entitySuppor = "MED_FACE"
245 elif entity == SALOME_MED.MED_EDGE :
246 entitySupport = "MED_ARETE"
247 supportName = "SupportOnAll_"+entitySupport
248 print "getting a corba object Field from the study iteration ",dt," order number ",it," on the support ",supportName," from the mesh ",meshName
249 fieldObj = getFieldObjectFromStudy(dt,it,fieldName,supportName,meshName)
253 print "END of the Pyhton script ..... Ctrl D to exit"