1 # Copyright (C) 2007-2015 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, or (at your option) any later version.
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
29 #CCRTfrom libSALOME_Swig import *
30 #CCRTsg = SALOMEGUI_Swig()
36 host = os.getenv( 'HOST' )
37 orb, lcc, naming_service, contmgr = salome.salome_kernel.salome_kernel_init()
38 obj = naming_service.Resolve('myStudyManager')
39 myStudyManager = obj._narrow(SALOMEDS.StudyManager)
40 print "studyManager found"
41 myStudy = myStudyManager.NewStudy('medClient_withoutIHM_test')
42 studynameId = myStudy._get_StudyId()
43 studyname = myStudy._get_Name()
44 print "We are working in the study ",studyname," with the ID ",studynameId
57 def changeBlankToUnderScore(stringWithBlank):
60 decompString = string.split(stringWithBlank,blank)
61 length = len(decompString)
62 stringWithUnderScore = decompString[0]
63 for i in range(1,length):
64 stringWithUnderScore += underscore
65 stringWithUnderScore += decompString[i]
66 return stringWithUnderScore
68 def getMedObjectFromStudy(file):
69 objNameInStudy = "MED_OBJECT_FROM_FILE_"+file
70 compNameInStudy= "MED"
71 #CCRTlistOfSO = salome.myStudy.FindObjectByName(objNameInStudy,compNameInStudy)
72 listOfSO = myStudy.FindObjectByName(objNameInStudy,compNameInStudy)
73 listLength = len(listOfSO)
74 if (listLength == 0) :
75 print "getMedObjectFromStudy",objNameInStudy," cannot be found in the Study under the component ",compNameInStudy
77 elif (listLength > 1) :
78 print "there are more than one instance of ",objNameInStudy," in the Study under the component ",compNameInStudy
82 print "getMedObjectFromStudy",objNameInStudy," cannot be found in the Study"
85 anAttr = mySO.FindAttribute("AttributeIOR")[1]
86 #CCRTobj = salome.orb.string_to_object(anAttr.Value())
87 obj = orb.string_to_object(anAttr.Value())
88 myObj = obj._narrow(SALOME_MED.MED)
90 print objNameInStudy," has been found in the Study but with the wrong type"
93 def getMeshObjectFromStudy(meshName):
94 objNameInStudy = "/Med/MEDMESH/"+meshName
95 #CCRTmySO = salome.myStudy.FindObjectByPath(objNameInStudy)
96 mySO = myStudy.FindObjectByPath(objNameInStudy)
98 print "getMeshObjectFromStudy",objNameInStudy," cannot be found in the Study"
101 anAttr = mySO.FindAttribute("AttributeIOR")[1]
102 #CCRTobj = salome.orb.string_to_object(anAttr.Value())
103 obj = orb.string_to_object(anAttr.Value())
104 myObj = obj._narrow(SALOME_MED.MESH)
106 print objNameInStudy," has been found in the Study but with the wrong type"
109 def getSupportObjectFromStudy(meshName,supportName):
110 meshNameStudy = changeBlankToUnderScore(meshName)
111 objNameInStudy = "/Med/MEDMESH/MEDSUPPORTS_OF_"+meshNameStudy+"/"+supportName
112 #CCRTmySO = salome.myStudy.FindObjectByPath(objNameInStudy)
113 mySO = myStudy.FindObjectByPath(objNameInStudy)
115 print "getSupportObjectFromStudy",objNameInStudy," cannot be found in the Study"
116 print "/Med/MEDMESH/MEDSUPPORTS_OF_"+meshNameStudy,":",myStudy.GetObjectNames("/Med/MEDMESH/MEDSUPPORTS_OF_"+meshNameStudy)
119 anAttr = mySO.FindAttribute("AttributeIOR")[1]
120 #CCRTobj = salome.orb.string_to_object(anAttr.Value())
121 obj = orb.string_to_object(anAttr.Value())
122 myObj = obj._narrow(SALOME_MED.SUPPORT)
124 print objNameInStudy," has been found in the Study but with the wrong type"
127 def getFieldObjectFromStudy(dt,it,fieldName,supportName,meshName):
129 meshNameStudy = changeBlankToUnderScore(meshName)
130 objNameInStudy = "/Med/MEDFIELD/"+fieldName+"/("+str(dt)+","+str(it)+")_ON_"+supportName+"_OF_"+meshNameStudy
131 #CCRTmySO = salome.myStudy.FindObjectByPath(objNameInStudy)
132 mySO = myStudy.FindObjectByPath(objNameInStudy)
134 print "getFieldObjectFromStudy",objNameInStudy," cannot be found in the Study"
135 print "/Med/MEDFIELD/"+fieldName,":",myStudy.GetObjectNames("/Med/MEDFIELD/"+fieldName)
138 anAttr = mySO.FindAttribute("AttributeIOR")[1]
139 #CCRTobj = salome.orb.string_to_object(anAttr.Value())
140 obj = orb.string_to_object(anAttr.Value())
141 myObj = obj._narrow(SALOME_MED.FIELDINT)
144 myObj = obj._narrow(SALOME_MED.FIELDDOUBLE)
147 print objNameInStudy," has been found in the Study but with the wrong type"
151 fileName = "pointe.med"
153 from MEDCoupling import *
154 from MEDLoader import *
155 from MEDCouplingCorba import *
156 from MEDCouplingClient import *
157 import MEDCouplingCorbaServant_idl
159 #CCRTmedComp=salome.lcc.FindOrLoadComponent("FactoryServer", "MED")
160 medComp=lcc.FindOrLoadComponent("FactoryServer", "MED")
164 filePath=os.environ["MED_ROOT_DIR"]
165 filePath=filePath+"/share/salome/resources/med/"
167 filePathName = filePath + fileName
169 print "Reading the .med file ",filePathName," and pushing corba objects in the SALOME study"
170 #CCRTmedComp.readStructFileWithFieldType(filePathName,salome.myStudyName)
171 ##medComp.readStructFileWithFieldType(filePathName,studyname)
172 #CCRTsg.updateObjBrowser(1)
174 ##print "getting the MED object from the study"
175 ##medObj = getMedObjectFromStudy(fileName)
177 meshNames = MEDLoader.GetMeshNames(filePathName)
178 nbOfMeshes = len(meshNames)#medObj.getNumberOfMeshes()
180 print "in this med file there is(are) ",nbOfMeshes," mesh(es):"
182 meshName = meshNames[0]
184 #meshObj = medObj.getMeshByName(meshName)
185 meshObj3D = MEDLoader.ReadUMeshFromFile(filePathName,meshName,0)
187 fieldName = "fieldcelldoublevector"
188 fieldTypedObj = MEDLoader.ReadFieldCell(filePathName,meshName,0,fieldName,-1,-1)
189 fieldTypedObjCORBA=MEDCouplingFieldDoubleServant._this(fieldTypedObj)
191 ############## Load Calculator Component ###################
192 # Calculator Component must be in the Container of MED
194 print "Load Calculator Component "
195 # we need to import CALCULATOR_ORB to get a typed object (to perform narrowing)
196 import CALCULATOR_ORB
197 #CCRTcalculator = salome.lcc.FindOrLoadComponent("FactoryServer", "CALCULATOR")
198 calculator = lcc.FindOrLoadComponent("FactoryServer", "CALCULATOR")
201 #calculator.printField(fieldTypedObj)
205 ############## Test Calculator Component ###################
208 print "Appel cloneField : fieldTypedObj -> f1,f2,f3,f4"
209 #fieldTypedObj.Register()
210 (f1,f2,f3,f4)=calculator.cloneField(fieldTypedObjCORBA) # fieldTypedObj is consumed
213 ##calculator.printField(f1)
214 print "Add fields f2+f3"
215 f_add=calculator.add(f2, f3)
217 ##calculator.printField( f_add ) # f_add is consumed
220 print "Apply linear function"
221 f_lin=calculator.applyLin(f4,2.0,1.0)
223 ##calculator.printField( f_lin ) # f_lin is consumed
225 print "Appel Norme Max "
227 norme=calculator.normMax(f_lin) # f_lin is consumed
228 print " -> norme = ",norme
233 ############ Creation of a MED file with fields created by Caculator #################
236 f_addLocal=MEDCouplingFieldDoubleClient.New(f_add)
238 f_addLocal.setName(fieldName+"add")
239 f_linLocal=MEDCouplingFieldDoubleClient.New(f_lin)
241 f_linLocal.setName(fieldName+"lin")
243 meshLocal = f_addLocal.getMesh()
245 print " getting information from the local copy of the distant mesh"
246 name = meshLocal.getName()
247 spaceDimension = meshLocal.getSpaceDimension()
248 meshDimension = meshLocal.getMeshDimension()
249 numberOfNodes = meshLocal.getNumberOfNodes()
250 print " Name = ", name, " space Dim = ", spaceDimension, " mesh Dim = ", meshDimension, " Nb of Nodes = ", numberOfNodes
253 #Warning : OutputMedFiles are removed here after =================================
254 #Outmed21File="OutCalculatorpointe21_V3.2.0b1.med"
255 #os.system( 'rm -fr ' + Outmed21File )
256 Outmed22File="OutCalculatorpointe22_V3.2.0b1.med"
257 os.system( 'rm -fr ' + Outmed22File )
259 MEDLoader.WriteUMesh(Outmed22File,meshLocal,True)
260 MEDLoader.WriteFieldUsingAlreadyWrittenMesh(Outmed22File,f_addLocal)
261 MEDLoader.WriteFieldUsingAlreadyWrittenMesh(Outmed22File,f_linLocal)
264 print "END of the Pyhton script ..... Ctrl D to exit"