1 # Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 # Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 # This library is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU Lesser General Public
8 # License as published by the Free Software Foundation; either
9 # version 2.1 of the License.
11 # This library is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # Lesser General Public License for more details.
16 # You should have received a copy of the GNU Lesser General Public
17 # License along with this library; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 ####################################################################################################
23 # Test the Med Component: mounting in Memory a .med file and trying to get information through
25 ####################################################################################################
33 from libSALOME_Swig import *
46 def changeBlankToUnderScore(stringWithBlank):
49 decompString = string.split(stringWithBlank,blank)
50 length = len(decompString)
51 stringWithUnderScore = decompString[0]
52 for i in range(1,length):
53 stringWithUnderScore += underscore
54 stringWithUnderScore += decompString[i]
55 return stringWithUnderScore
57 def getMedObjectFromStudy(file):
58 objNameInStudy = "MED_OBJECT_FROM_FILE_"+file
59 compNameInStudy= "MED"
60 listOfSO = salome.myStudy.FindObjectByName(objNameInStudy,compNameInStudy)
61 listLength = len(listOfSO)
62 if (listLength == 0) :
63 print objNameInStudy," cannot be found in the Study under the component ",compNameInStudy
65 elif (listLength > 1) :
66 print "there are more than one instance of ",objNameInStudy," in the Study under the component ",compNameInStudy
70 print objNameInStudy," cannot be found in the Study"
73 anAttr = mySO.FindAttribute("AttributeIOR")[1]
74 obj = salome.orb.string_to_object(anAttr.Value())
75 myObj = obj._narrow(SALOME_MED.MED)
77 print objNameInStudy," has been found in the Study but with the wrong type"
80 def getMeshObjectFromStudy(meshName):
81 objNameInStudy = "/Med/MEDMESH/"+meshName
82 mySO = salome.myStudy.FindObjectByPath(objNameInStudy)
84 print objNameInStudy," cannot be found in the Study"
87 anAttr = mySO.FindAttribute("AttributeIOR")[1]
88 obj = salome.orb.string_to_object(anAttr.Value())
89 myObj = obj._narrow(SALOME_MED.MESH)
91 print objNameInStudy," has been found in the Study but with the wrong type"
94 def getSupportObjectFromStudy(meshName,supportName):
95 meshNameStudy = changeBlankToUnderScore(meshName)
96 objNameInStudy = "/Med/MEDMESH/MEDSUPPORTS_OF_"+meshNameStudy+"/"+supportName
97 mySO = salome.myStudy.FindObjectByPath(objNameInStudy)
99 print objNameInStudy," cannot be found in the Study"
102 anAttr = mySO.FindAttribute("AttributeIOR")[1]
103 obj = salome.orb.string_to_object(anAttr.Value())
104 myObj = obj._narrow(SALOME_MED.SUPPORT)
106 print objNameInStudy," has been found in the Study but with the wrong type"
109 def getFieldObjectFromStudy(dt,it,fieldName,supportName,meshName):
110 meshNameStudy = changeBlankToUnderScore(meshName)
111 objNameInStudy = "/Med/MEDFIELD/"+fieldName+"/("+str(dt)+","+str(it)+")_ON_"+supportName+"_OF_"+meshNameStudy
112 mySO = salome.myStudy.FindObjectByPath(objNameInStudy)
114 print objNameInStudy," cannot be found in the Study"
117 anAttr = mySO.FindAttribute("AttributeIOR")[1]
118 obj = salome.orb.string_to_object(anAttr.Value())
119 myObj = obj._narrow(SALOME_MED.FIELDINT)
121 myObj = obj._narrow(SALOME_MED.FIELDDOUBLE)
123 print objNameInStudy," has been found in the Study but with the wrong type"
126 fileName = "cube_hexa8_quad4.med"
128 #fileName = "carre_en_quad4_seg2.med"
130 medComp=salome.lcc.FindOrLoadComponent("FactoryServer", "MED")
134 filePath=os.environ["MED_ROOT_DIR"]
135 filePath=os.path.join(filePath, "share", "salome", "resources", "med")
137 filePathName = os.path.join(filePath, fileName)
139 print "Reading the .med file ",filePathName," and pushing corba objects in the SALOME study"
140 medComp.readStructFileWithFieldType(filePathName,salome.myStudyName)
141 sg.updateObjBrowser(1)
143 print "getting the MED object from the study"
144 medObj = getMedObjectFromStudy(fileName)
146 nbOfMeshes = medObj.getNumberOfMeshes()
147 meshNames = medObj.getMeshNames()
149 print "in this med file there is(are) ",nbOfMeshes," mesh(es):"
150 for i in range(nbOfMeshes):
151 meshName = meshNames[i]
152 print " - the ",print_ord(i)," mesh is named ",meshName
153 print " getting the MESH object using the API of the corba object MED"
154 meshObj = medObj.getMeshByName(meshName)
155 print " getting mesh information (including corba object) using the API of the corba object MESH"
156 for entity in [SALOME_MED.MED_NODE,SALOME_MED.MED_CELL,
157 SALOME_MED.MED_FACE,SALOME_MED.MED_EDGE]:
158 nbFam = meshObj.getNumberOfFamilies(entity)
159 nbGrp = meshObj.getNumberOfGroups(entity)
160 if (entity == SALOME_MED.MED_NODE):
161 print " this mesh has ",nbFam," Node Family(ies) and ",nbGrp," Node Group(s)"
162 elif (entity == SALOME_MED.MED_CELL):
163 print " ",nbFam," Cell Family(ies) and ",nbGrp," Cell Group(s)"
164 elif (entity == SALOME_MED.MED_FACE):
165 print " ",nbFam," Face Family(ies) and ",nbGrp," Face Group(s)"
166 elif (entity == SALOME_MED.MED_EDGE):
167 print " ",nbFam," Edge Family(ies) and ",nbGrp," Cell Group(s)"
170 for j in range(nbFam):
171 familyObj = meshObj.getFamily(entity,j+1)
175 for j in range(nbGrp):
176 groupObj = meshObj.getGroup(entity,j+1)
180 print " getting the MESH object from the Study"
181 meshObj = getMeshObjectFromStudy(meshName)
183 print " getting mesh information using the API of the corba object MESH but corba objects are obtained from the Study"
184 for entity in [SALOME_MED.MED_NODE,SALOME_MED.MED_CELL,
185 SALOME_MED.MED_FACE,SALOME_MED.MED_EDGE]:
186 nbFam = meshObj.getNumberOfFamilies(entity)
187 nbGrp = meshObj.getNumberOfGroups(entity)
188 if (entity == SALOME_MED.MED_NODE):
189 print " this mesh has ",nbFam," Node Family(ies) and ",nbGrp," Node Group(s)"
190 elif (entity == SALOME_MED.MED_CELL):
191 print " ",nbFam," Cell Family(ies) and ",nbGrp," Cell Group(s)"
192 elif (entity == SALOME_MED.MED_FACE):
193 print " ",nbFam," Face Family(ies) and ",nbGrp," Face Group(s)"
194 elif (entity == SALOME_MED.MED_EDGE):
195 print " ",nbFam," Edge Family(ies) and ",nbGrp," Cell Group(s)"
198 for j in range(nbFam):
199 familyName = (meshObj.getFamily(entity,j+1)).getName()
200 familyObj = getSupportObjectFromStudy(meshName,familyName)
204 for j in range(nbGrp):
205 groupName = (meshObj.getGroup(entity,j+1)).getName()
206 groupObj = getSupportObjectFromStudy(meshName,groupName)
209 print "let's get other SUPPORT object from the Study"
210 for entity in [SALOME_MED.MED_NODE,SALOME_MED.MED_CELL,
211 SALOME_MED.MED_FACE,SALOME_MED.MED_EDGE]:
213 if entity == SALOME_MED.MED_NODE :
214 entitySupport = "MED_NOEUD"
215 elif entity == SALOME_MED.MED_CELL :
216 entitySupport = "MED_MAILLE"
217 elif entity == SALOME_MED.MED_FACE :
218 entitySuppor = "MED_FACE"
219 elif entity == SALOME_MED.MED_EDGE :
220 entitySupport = "MED_ARETE"
222 supportName = "SupportOnAll_"+entitySupport
223 supportObj = getSupportObjectFromStudy(meshName,supportName)
225 nbOfFields = medObj.getNumberOfFields()
226 print "in the considered .med file there is(are) ",nbOfFields," field(s):"
227 fieldNames = medObj.getFieldNames()
228 for i in range(nbOfFields):
229 fieldName = fieldNames[i]
230 nbOfIt = medObj.getFieldNumberOfIteration(fieldName)
231 print " - the ",print_ord(i)," field is name ",fieldName," and has ",nbOfIt," iteration(s)"
232 for j in range(nbOfIt):
233 dtitfield = medObj.getFieldIteration(fieldName,j)
236 print " * Iteration:",dt,"Order number:",it
237 for k in range(nbOfMeshes):
238 meshName = meshNames[k]
239 for entity in [SALOME_MED.MED_NODE,SALOME_MED.MED_CELL,
240 SALOME_MED.MED_FACE,SALOME_MED.MED_EDGE]:
241 if entity == SALOME_MED.MED_NODE :
242 entitySupport = "MED_NOEUD"
243 elif entity == SALOME_MED.MED_CELL :
244 entitySupport = "MED_MAILLE"
245 elif entity == SALOME_MED.MED_FACE :
246 entitySuppor = "MED_FACE"
247 elif entity == SALOME_MED.MED_EDGE :
248 entitySupport = "MED_ARETE"
249 supportName = "SupportOnAll_"+entitySupport
250 print "getting a corba object Field from the study iteration ",dt," order number ",it," on the support ",supportName," from the mesh ",meshName
251 fieldObj = getFieldObjectFromStudy(dt,it,fieldName,supportName,meshName)
255 print "END of the Pyhton script ..... Ctrl D to exit"