1 ####################################################################################################
3 # Test the Med Component: mounting in Memory a .med file and trying to get information through
6 ####################################################################################################
11 from libSALOME_Swig import *
24 def getMedObjectFromStudy(file):
25 objNameInStudy = "MED_OBJECT_FROM_FILE_"+file
26 compNameInStudy= "MED"
27 listOfSO = salome.myStudy.FindObjectByName(objNameInStudy,compNameInStudy)
28 listLength = len(listOfSO)
29 if (listLength == 0) :
30 print "PROBLEME ",objNameInStudy," cannot be found in the Study under the component ",compNameInStudy
32 elif (listLength > 1) :
33 print "PROBLEME there are more than one instance of ",objNameInStudy," in the Study under the component ",compNameInStudy
37 print "PROBLEM ",objNameInStudy," cannot be found in the Study"
40 anAttr = mySO.FindAttribute("AttributeIOR")[1]
41 obj = salome.orb.string_to_object(anAttr.Value())
42 myObj = obj._narrow(SALOME_MED.MED)
44 print "PROBLEM ",objNameInStudy," has been found in the Study but with the wrong type"
47 def getMeshObjectFromStudy(meshName):
48 objNameInStudy = "/Med/MEDMESH/"+meshName
49 mySO = salome.myStudy.FindObjectByPath(objNameInStudy)
51 print "PROBLEM ",objNameInStudy," cannot be found in the Study"
54 anAttr = mySO.FindAttribute("AttributeIOR")[1]
55 obj = salome.orb.string_to_object(anAttr.Value())
56 myObj = obj._narrow(SALOME_MED.MESH)
58 print "PROBLEM ",objNameInStudy," has been found in the Study but with the wrong type"
61 def getSupportObjectFromStudy(meshName,supportName):
62 objNameInStudy = "/Med/MEDMESH/MEDSUPPORTS_OF_"+meshName+"/"+supportName
63 mySO = salome.myStudy.FindObjectByPath(objNameInStudy)
65 print "PROBLEM ",objNameInStudy," cannot be found in the Study"
68 anAttr = mySO.FindAttribute("AttributeIOR")[1]
69 obj = salome.orb.string_to_object(anAttr.Value())
70 myObj = obj._narrow(SALOME_MED.SUPPORT)
72 print "PROBLEM ",objNameInStudy," has been found in the Study but with the wrong type"
75 def getFieldObjectFromStudy(dt,it,fieldName,supportName,meshName):
76 objNameInStudy = "/Med/MEDFIELD/"+fieldName+"/("+str(dt)+","+str(it)+")_ON_"+supportName+"_OF_"+meshName
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.FIELDINT)
86 myObj = obj._narrow(SALOME_MED.FIELDDOUBLE)
88 print "PROBLEM ",objNameInStudy," has been found in the Study but with the wrong type"
91 fileName = "cube_hexa8_quad4.med"
93 #fileName = "carre_en_quad4_seg2.med"
95 medComp=salome.lcc.FindOrLoadComponent("FactoryServer", "MED")
99 filePath=os.environ["MED_ROOT_DIR"]
100 filePath=filePath+"/share/salome/resources/"
102 filePathName = filePath + fileName
104 print "Reading the .med file ",filePathName," and pushing corba objects in the SALOME study"
105 medComp.readStructFileWithFieldType(filePathName,salome.myStudyName)
106 sg.updateObjBrowser(1)
108 print "getting the MED object from the study"
109 medObj = getMedObjectFromStudy(fileName)
111 nbOfMeshes = medObj.getNumberOfMeshes()
112 meshNames = medObj.getMeshNames()
114 print "in this med file there is(are) ",nbOfMeshes," mesh(es):"
115 for i in range(nbOfMeshes):
116 meshName = meshNames[i]
117 print " - the ",print_ord(i)," mesh is named ",meshName
118 print " getting the MESH object using the API of the corba object MED"
119 meshObj = medObj.getMeshByName(meshName)
120 print " getting mesh information (including corba object) using the API of the corba object MESH"
121 for entity in [SALOME_MED.MED_NODE,SALOME_MED.MED_CELL,
122 SALOME_MED.MED_FACE,SALOME_MED.MED_EDGE]:
123 nbFam = meshObj.getNumberOfFamilies(entity)
124 nbGrp = meshObj.getNumberOfGroups(entity)
125 if (entity == SALOME_MED.MED_NODE):
126 print " this mesh has ",nbFam," Node Family(ies) and ",nbGrp," Node Group(s)"
127 elif (entity == SALOME_MED.MED_CELL):
128 print " ",nbFam," Cell Family(ies) and ",nbGrp," Cell Group(s)"
129 elif (entity == SALOME_MED.MED_FACE):
130 print " ",nbFam," Face Family(ies) and ",nbGrp," Face Group(s)"
131 elif (entity == SALOME_MED.MED_EDGE):
132 print " ",nbFam," Edge Family(ies) and ",nbGrp," Cell Group(s)"
135 for j in range(nbFam):
136 familyObj = meshObj.getFamily(entity,j+1)
140 for j in range(nbGrp):
141 groupObj = meshObj.getGroup(entity,j+1)
145 print " getting the MESH object from the Study"
146 meshObj = getMeshObjectFromStudy(meshName)
148 print " getting mesh information using the API of the corba object MESH but corba objects are obtained from the Study"
149 for entity in [SALOME_MED.MED_NODE,SALOME_MED.MED_CELL,
150 SALOME_MED.MED_FACE,SALOME_MED.MED_EDGE]:
151 nbFam = meshObj.getNumberOfFamilies(entity)
152 nbGrp = meshObj.getNumberOfGroups(entity)
153 if (entity == SALOME_MED.MED_NODE):
154 print " this mesh has ",nbFam," Node Family(ies) and ",nbGrp," Node Group(s)"
155 elif (entity == SALOME_MED.MED_CELL):
156 print " ",nbFam," Cell Family(ies) and ",nbGrp," Cell Group(s)"
157 elif (entity == SALOME_MED.MED_FACE):
158 print " ",nbFam," Face Family(ies) and ",nbGrp," Face Group(s)"
159 elif (entity == SALOME_MED.MED_EDGE):
160 print " ",nbFam," Edge Family(ies) and ",nbGrp," Cell Group(s)"
163 for j in range(nbFam):
164 familyName = (meshObj.getFamily(entity,j+1)).getName()
165 familyObj = getSupportObjectFromStudy(meshName,familyName)
169 for j in range(nbGrp):
170 groupName = (meshObj.getGroup(entity,j+1)).getName()
171 groupObj = getSupportObjectFromStudy(meshName,groupName)
174 print "let's get other SUPPORT object from the Study"
175 for entity in [SALOME_MED.MED_NODE,SALOME_MED.MED_CELL,
176 SALOME_MED.MED_FACE,SALOME_MED.MED_EDGE]:
178 if entity == SALOME_MED.MED_NODE :
179 entitySupport = "MED_NOEUD"
180 elif entity == SALOME_MED.MED_CELL :
181 entitySupport = "MED_MAILLE"
182 elif entity == SALOME_MED.MED_FACE :
183 entitySuppor = "MED_FACE"
184 elif entity == SALOME_MED.MED_EDGE :
185 entitySupport = "MED_ARETE"
187 supportName = "SupportOnAll_"+entitySupport
188 supportObj = getSupportObjectFromStudy(meshName,supportName)
190 nbOfFields = medObj.getNumberOfFields()
191 print "in the considered .med file there is(are) ",nbOfFields," field(s):"
192 fieldNames = medObj.getFieldNames()
193 for i in range(nbOfFields):
194 fieldName = fieldNames[i]
195 nbOfIt = medObj.getFieldNumberOfIteration(fieldName)
196 print " - the ",print_ord(i)," field is name ",fieldName," and has ",nbOfIt," iteration(s)"
197 for j in range(nbOfIt):
198 dtitfield = medObj.getFieldIteration(fieldName,j)
201 print " * Iteration:",dt,"Order number:",it
202 for k in range(nbOfMeshes):
203 meshName = meshNames[k]
204 for entity in [SALOME_MED.MED_NODE,SALOME_MED.MED_CELL,
205 SALOME_MED.MED_FACE,SALOME_MED.MED_EDGE]:
206 if entity == SALOME_MED.MED_NODE :
207 entitySupport = "MED_NOEUD"
208 elif entity == SALOME_MED.MED_CELL :
209 entitySupport = "MED_MAILLE"
210 elif entity == SALOME_MED.MED_FACE :
211 entitySuppor = "MED_FACE"
212 elif entity == SALOME_MED.MED_EDGE :
213 entitySupport = "MED_ARETE"
214 supportName = "SupportOnAll_"+entitySupport
215 print "getting a corba object Field from the study iteration ",dt," order number ",it," on the support ",supportName," from the mesh ",meshName
216 fieldObj = getFieldObjectFromStudy(dt,it,fieldName,supportName,meshName)
220 print "END of the Pyhton script ..... Ctrl D to exit"