1 ####################################################################################################
3 # Test the Med Component: mounting in Memory a .med file and trying to get information through
6 ####################################################################################################
13 from libSALOME_Swig import *
26 def changeBlankToUnderScore(stringWithBlank):
29 decompString = string.split(stringWithBlank,blank)
30 length = len(decompString)
31 stringWithUnderScore = decompString[0]
32 for i in range(1,length):
33 stringWithUnderScore += underscore
34 stringWithUnderScore += decompString[i]
35 return stringWithUnderScore
37 def getMedObjectFromStudy(file):
38 objNameInStudy = "MED_OBJECT_FROM_FILE_"+file
39 compNameInStudy= "MED"
40 listOfSO = salome.myStudy.FindObjectByName(objNameInStudy,compNameInStudy)
41 listLength = len(listOfSO)
42 if (listLength == 0) :
43 print "PROBLEME ",objNameInStudy," cannot be found in the Study under the component ",compNameInStudy
45 elif (listLength > 1) :
46 print "PROBLEME there are more than one instance of ",objNameInStudy," in the Study under the component ",compNameInStudy
50 print "PROBLEM ",objNameInStudy," cannot be found in the Study"
53 anAttr = mySO.FindAttribute("AttributeIOR")[1]
54 obj = salome.orb.string_to_object(anAttr.Value())
55 myObj = obj._narrow(SALOME_MED.MED)
57 print "PROBLEM ",objNameInStudy," has been found in the Study but with the wrong type"
60 def getMeshObjectFromStudy(meshName):
61 objNameInStudy = "/Med/MEDMESH/"+meshName
62 mySO = salome.myStudy.FindObjectByPath(objNameInStudy)
64 print "PROBLEM ",objNameInStudy," cannot be found in the Study"
67 anAttr = mySO.FindAttribute("AttributeIOR")[1]
68 obj = salome.orb.string_to_object(anAttr.Value())
69 myObj = obj._narrow(SALOME_MED.MESH)
71 print "PROBLEM ",objNameInStudy," has been found in the Study but with the wrong type"
74 def getSupportObjectFromStudy(meshName,supportName):
75 meshNameStudy = changeBlankToUnderScore(meshName)
76 objNameInStudy = "/Med/MEDMESH/MEDSUPPORTS_OF_"+meshNameStudy+"/"+supportName
77 mySO = salome.myStudy.FindObjectByPath(objNameInStudy)
79 print "PROBLEM ",objNameInStudy," cannot be found in the Study"
82 anAttr = mySO.FindAttribute("AttributeIOR")[1]
83 obj = salome.orb.string_to_object(anAttr.Value())
84 myObj = obj._narrow(SALOME_MED.SUPPORT)
86 print "PROBLEM ",objNameInStudy," has been found in the Study but with the wrong type"
89 def getFieldObjectFromStudy(dt,it,fieldName,supportName,meshName):
90 meshNameStudy = changeBlankToUnderScore(meshName)
91 objNameInStudy = "/Med/MEDFIELD/"+fieldName+"/("+str(dt)+","+str(it)+")_ON_"+supportName+"_OF_"+meshNameStudy
92 mySO = salome.myStudy.FindObjectByPath(objNameInStudy)
94 print "PROBLEM ",objNameInStudy," cannot be found in the Study"
97 anAttr = mySO.FindAttribute("AttributeIOR")[1]
98 obj = salome.orb.string_to_object(anAttr.Value())
99 myObj = obj._narrow(SALOME_MED.FIELDINT)
101 myObj = obj._narrow(SALOME_MED.FIELDDOUBLE)
103 print "PROBLEM ",objNameInStudy," has been found in the Study but with the wrong type"
106 fileName = "cube_hexa8_quad4.med"
108 #fileName = "carre_en_quad4_seg2.med"
110 medComp=salome.lcc.FindOrLoadComponent("FactoryServer", "MED")
114 filePath=os.environ["MED_ROOT_DIR"]
115 filePath=filePath+"/share/salome/resources/"
117 filePathName = filePath + fileName
119 print "Reading the .med file ",filePathName," and pushing corba objects in the SALOME study"
120 medComp.readStructFileWithFieldType(filePathName,salome.myStudyName)
121 sg.updateObjBrowser(1)
123 print "getting the MED object from the study"
124 medObj = getMedObjectFromStudy(fileName)
126 nbOfMeshes = medObj.getNumberOfMeshes()
127 meshNames = medObj.getMeshNames()
129 print "in this med file there is(are) ",nbOfMeshes," mesh(es):"
130 for i in range(nbOfMeshes):
131 meshName = meshNames[i]
132 print " - the ",print_ord(i)," mesh is named ",meshName
133 print " getting the MESH object using the API of the corba object MED"
134 meshObj = medObj.getMeshByName(meshName)
135 print " getting mesh information (including corba object) using the API of the corba object MESH"
136 for entity in [SALOME_MED.MED_NODE,SALOME_MED.MED_CELL,
137 SALOME_MED.MED_FACE,SALOME_MED.MED_EDGE]:
138 nbFam = meshObj.getNumberOfFamilies(entity)
139 nbGrp = meshObj.getNumberOfGroups(entity)
140 if (entity == SALOME_MED.MED_NODE):
141 print " this mesh has ",nbFam," Node Family(ies) and ",nbGrp," Node Group(s)"
142 elif (entity == SALOME_MED.MED_CELL):
143 print " ",nbFam," Cell Family(ies) and ",nbGrp," Cell Group(s)"
144 elif (entity == SALOME_MED.MED_FACE):
145 print " ",nbFam," Face Family(ies) and ",nbGrp," Face Group(s)"
146 elif (entity == SALOME_MED.MED_EDGE):
147 print " ",nbFam," Edge Family(ies) and ",nbGrp," Cell Group(s)"
150 for j in range(nbFam):
151 familyObj = meshObj.getFamily(entity,j+1)
155 for j in range(nbGrp):
156 groupObj = meshObj.getGroup(entity,j+1)
160 print " getting the MESH object from the Study"
161 meshObj = getMeshObjectFromStudy(meshName)
163 print " getting mesh information using the API of the corba object MESH but corba objects are obtained from the Study"
164 for entity in [SALOME_MED.MED_NODE,SALOME_MED.MED_CELL,
165 SALOME_MED.MED_FACE,SALOME_MED.MED_EDGE]:
166 nbFam = meshObj.getNumberOfFamilies(entity)
167 nbGrp = meshObj.getNumberOfGroups(entity)
168 if (entity == SALOME_MED.MED_NODE):
169 print " this mesh has ",nbFam," Node Family(ies) and ",nbGrp," Node Group(s)"
170 elif (entity == SALOME_MED.MED_CELL):
171 print " ",nbFam," Cell Family(ies) and ",nbGrp," Cell Group(s)"
172 elif (entity == SALOME_MED.MED_FACE):
173 print " ",nbFam," Face Family(ies) and ",nbGrp," Face Group(s)"
174 elif (entity == SALOME_MED.MED_EDGE):
175 print " ",nbFam," Edge Family(ies) and ",nbGrp," Cell Group(s)"
178 for j in range(nbFam):
179 familyName = (meshObj.getFamily(entity,j+1)).getName()
180 familyObj = getSupportObjectFromStudy(meshName,familyName)
184 for j in range(nbGrp):
185 groupName = (meshObj.getGroup(entity,j+1)).getName()
186 groupObj = getSupportObjectFromStudy(meshName,groupName)
189 print "let's get other SUPPORT object from the Study"
190 for entity in [SALOME_MED.MED_NODE,SALOME_MED.MED_CELL,
191 SALOME_MED.MED_FACE,SALOME_MED.MED_EDGE]:
193 if entity == SALOME_MED.MED_NODE :
194 entitySupport = "MED_NOEUD"
195 elif entity == SALOME_MED.MED_CELL :
196 entitySupport = "MED_MAILLE"
197 elif entity == SALOME_MED.MED_FACE :
198 entitySuppor = "MED_FACE"
199 elif entity == SALOME_MED.MED_EDGE :
200 entitySupport = "MED_ARETE"
202 supportName = "SupportOnAll_"+entitySupport
203 supportObj = getSupportObjectFromStudy(meshName,supportName)
205 nbOfFields = medObj.getNumberOfFields()
206 print "in the considered .med file there is(are) ",nbOfFields," field(s):"
207 fieldNames = medObj.getFieldNames()
208 for i in range(nbOfFields):
209 fieldName = fieldNames[i]
210 nbOfIt = medObj.getFieldNumberOfIteration(fieldName)
211 print " - the ",print_ord(i)," field is name ",fieldName," and has ",nbOfIt," iteration(s)"
212 for j in range(nbOfIt):
213 dtitfield = medObj.getFieldIteration(fieldName,j)
216 print " * Iteration:",dt,"Order number:",it
217 for k in range(nbOfMeshes):
218 meshName = meshNames[k]
219 for entity in [SALOME_MED.MED_NODE,SALOME_MED.MED_CELL,
220 SALOME_MED.MED_FACE,SALOME_MED.MED_EDGE]:
221 if entity == SALOME_MED.MED_NODE :
222 entitySupport = "MED_NOEUD"
223 elif entity == SALOME_MED.MED_CELL :
224 entitySupport = "MED_MAILLE"
225 elif entity == SALOME_MED.MED_FACE :
226 entitySuppor = "MED_FACE"
227 elif entity == SALOME_MED.MED_EDGE :
228 entitySupport = "MED_ARETE"
229 supportName = "SupportOnAll_"+entitySupport
230 print "getting a corba object Field from the study iteration ",dt," order number ",it," on the support ",supportName," from the mesh ",meshName
231 fieldObj = getFieldObjectFromStudy(dt,it,fieldName,supportName,meshName)
235 print "END of the Pyhton script ..... Ctrl D to exit"