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 # MED MedCorba_Swig : binding of MED CORBA objects woth Python
23 # File : batchmode_medcorba_test.py
26 import batchmode_salome
30 from libMedCorba_Swig import *
36 filePath = os.environ["MED_ROOT_DIR"]
37 filePath = os.path.join( filePath, "share", "salome", "resources", "med" )
39 #==============================================================================
41 def AnalyzeField(field):
42 name = field.getName()
43 desc = field.getDescription()
44 nbComp = field.getNumberOfComponents()
45 itNum = field.getIterationNumber()
46 ordNum = field.getOrderNumber()
48 print "Analysis of the field ",name," with the description ",desc
49 print "iteration number ",itNum," order Number ",ordNum
50 print "It has ",nbComp," component(s)"
52 fieldValue = field.getValue(SALOME_MED.MED_FULL_INTERLACE)
53 fieldSupport = field.getSupport()
54 fieldMesh = fieldSupport.getMesh()
55 fieldEntity = fieldSupport.getEntity()
56 bool = fieldSupport.isOnAllElements()
59 print "The support of this field is on all entities ",fieldEntity," of the mesh ",fieldMesh.getName()
60 if fieldEntity == SALOME_MED.MED_NODE:
61 nbValByComp = fieldMesh.getNumberOfNodes()
63 nbValByComp = fieldMesh.getNumberOfElements(fieldEntity,SALOME_MED.MED_ALL_ELEMENTS)
64 print "and its dimension (number of values by component of the field) is ",nbValByComp
66 print "The support of this field is partially on entities ",fieldEntity," of the mesh ",fieldMesh.getName()
67 nbValByComp = fieldSupport.getNumberOfElements(SALOME_MED.MED_ALL_ELEMENTS)
68 print "and its dimension (number of values by component of the field) is ",nbValByComp
70 for i in range(nbComp):
71 compName = field.getComponentName(i+1)
72 compUnit = field.getComponentUnit(i+1)
73 print "The ",(i+1),"-th component ",compName," with the unit ",compUnit
75 for i in range(nbValByComp):
76 print " * ",fieldValue[i*nbComp:(i+1)*nbComp]
78 #==============================================================================
80 def getMeshObjectFromStudy(number):
81 mySO = batchmode_salome.myStudy.FindObject("MEDMESH")
82 mysub = mySO.FindSubObject(number)[1]
84 Builder = batchmode_salome.myStudy.NewBuilder()
85 anAttr = Builder.FindOrCreateAttribute(mysub, "AttributeIOR")
86 obj = batchmode_salome.orb.string_to_object(anAttr.Value())
87 myObj = obj._narrow(SALOME_MED.MESH)
90 print "ERROR: No Mesh Object stored in this Study"
94 #==============================================================================
96 def getFieldDoubleObjectFromStudy(number,subnumber):
97 mySO = batchmode_salome.myStudy.FindObject("MEDFIELD")
98 mysub = mySO.FindSubObject(number)[1]
100 mysubsub = mysub.FindSubObject(subnumber)[1]
102 Builder = batchmode_salome.myStudy.NewBuilder()
103 anAttr = Builder.FindOrCreateAttribute(mysubsub, "AttributeIOR")
104 obj = batchmode_salome.orb.string_to_object(anAttr.Value())
105 anAttr = Builder.FindOrCreateAttribute(mysubsub, "AttributeName")
106 myObj = obj._narrow(SALOME_MED.FIELDDOUBLE)
109 print "ERROR: No FieldDouble Object stored in this Study"
112 print "ERROR: No FieldDouble Object stored in this Study"
116 #==============================================================================
118 def getFieldIntObjectFromStudy(number,subnumber):
119 mySO = batchmode_salome.myStudy.FindObject("MEDFIELD")
120 mysub = mySO.FindSubObject(number)[1]
122 mysubsub = mysub.FindSubObject(subnumber)[1]
124 Builder = batchmode_salome.myStudy.NewBuilder()
125 anAttr = Builder.FindOrCreateAttribute(mysubsub, "AttributeIOR")
126 obj = batchmode_salome.orb.string_to_object(anAttr.Value())
127 myObj = obj._narrow(SALOME_MED.FIELDINT)
130 print "ERROR: No FieldInt Object stored in this Study"
133 print "ERROR: No FieldInt Object stored in this Study"
136 #==============================================================================
138 def getMedObjectFromStudy(fileName=None):
139 myObj=None; Builder = batchmode_salome.myStudy.NewBuilder()
140 if fileName is not None:
141 objNameInStudy = "MED_OBJECT_FROM_FILE_"+fileName
142 mySO = batchmode_salome.myStudy.FindObject(objNameInStudy)
144 anAttr = Builder.FindOrCreateAttribute(mySO, "AttributeIOR")
145 obj = batchmode_salome.orb.string_to_object(anAttr.Value())
147 myObj = obj._narrow(SALOME_MED.MED)
149 print "ERROR: ",myObj," has been found in the Study, but with the type different of SALOME_MED.MED!!!"
151 print "ERROR: ",objNameInStudy," hasn't been found in the Study!!!"
153 SObj_root = batchmode_salome.myStudy.FindObjectByPath("/Med/")
154 if SObj_root is not None:
155 iter = batchmode_salome.myStudy.NewChildIterator(SObj_root)
161 Ok, anAttr = Builder.FindAttribute(Obj, "AttributeIOR")
163 if len(anAttr.Value()) > 0:
164 obj = batchmode_salome.orb.string_to_object(anAttr.Value())
166 myObj = obj._narrow(SALOME_MED.MED)
167 if myObj is not None:
172 else: print "Root object Med hasn't been found in the study!!!"
175 studyCurrent = batchmode_salome.myStudyName
176 studyCurrentId = batchmode_salome.myStudyId
178 med_comp = batchmode_salome.lcc.FindOrLoadComponent("FactoryServer", "MED")