From: nadir Date: Wed, 14 Apr 2004 07:40:14 +0000 (+0000) Subject: correction due to changes in the organisation of the Med Component which is X-Git-Tag: PreV2_0_0~1 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=1faa67e034be5799062813cb3804ed94c9833b17;p=modules%2Fmed.git correction due to changes in the organisation of the Med Component which is now more suitable in the mounting of several .med files in memory and all groups and families in each mesh stored in the .med file are now clearly seen in the Med Component Study. --- diff --git a/src/MedCorba_Swig/batchmode_medcorba_test.py b/src/MedCorba_Swig/batchmode_medcorba_test.py index cbd5273e1..a3784cfe1 100755 --- a/src/MedCorba_Swig/batchmode_medcorba_test.py +++ b/src/MedCorba_Swig/batchmode_medcorba_test.py @@ -61,28 +61,45 @@ def AnalyzeField(field): #============================================================================== -def getMeshObjectFromStudy(number): - mySO = batchmode_salome.myStudy.FindObject("MEDMESH") - mysub = mySO.FindSubObject(number)[1] - if mysub: - Builder = batchmode_salome.myStudy.NewBuilder() - anAttr = Builder.FindOrCreateAttribute(mysub, "AttributeIOR") +def getMeshObjectFromStudy(meshName): + objNameInStudy = "/Med/MEDMESH/"+meshName + mySO = batchmode_salome.myStudy.FindObjectByPath(objNameInStudy) + if (mySO == None) : + print "ERROR: ",objNameInStudy," cannot be found in the Study" + return mySO + else: + anAttr = mySO.FindAttribute("AttributeIOR")[1] obj = batchmode_salome.orb.string_to_object(anAttr.Value()) myObj = obj._narrow(SALOME_MED.MESH) + if (myObj == None) : + print "ERROR: ",objNameInStudy," has been found in the Study but with the wrong type" return myObj - else: - print "ERROR: No Mesh Object stored in this Study" - return None #============================================================================== -def getMedObjectFromStudy(): - mySO = batchmode_salome.myStudy.FindObject("Objet MED") - Builder = batchmode_salome.myStudy.NewBuilder() - anAttr = Builder.FindOrCreateAttribute(mySO, "AttributeIOR") - obj = batchmode_salome.orb.string_to_object(anAttr.Value()) - myObj = obj._narrow(SALOME_MED.MED) - return myObj +def getMedObjectFromStudy(file): + objNameInStudy = "MED_OBJECT_FROM_FILE_"+file + compNameInStudy= "MED" + listOfSO = batchmode_salome.myStudy.FindObjectByName(objNameInStudy, + compNameInStudy) + listLength = len(listOfSO) + if (listLength == 0) : + print "ERROR: ",objNameInStudy," cannot be found in the Study under the component ",compNameInStudy + return None + elif (listLength > 1) : + print "ERROR: there are more than one instance of ",objNameInStudy," in the Study under the component ",compNameInStudy + return None + mySO = listOfSO[0] + if (mySO == None) : + print "ERROR: ",objNameInStudy," cannot be found in the Study" + return mySO + else: + anAttr = mySO.FindAttribute("AttributeIOR")[1] + obj = batchmode_salome.orb.string_to_object(anAttr.Value()) + myObj = obj._narrow(SALOME_MED.MED) + if (myObj == None) : + print "ERROR: ",objNameInStudy," has been found in the Study but with the wrong type" + return myObj #============================================================================== # @@ -105,8 +122,9 @@ studyCurrentId = batchmode_salome.myStudyId print "We are working in the study ",studyCurrent," with the ID ",studyCurrentId print "" +fileName = "cube_hexa8_quad4.med" #medFile = "carre_en_quad4_seg2.med" -medFile = filePath + "cube_hexa8_quad4.med" +medFile = filePath + fileName print "Loading of the Med Component" print "" @@ -115,25 +133,27 @@ med_comp = batchmode_salome.lcc.FindOrLoadComponent("FactoryServer", "MED") med_comp.readStructFile(medFile,studyCurrent) -med_obj = getMedObjectFromStudy() +med_obj = getMedObjectFromStudy(fileName) nbMeshes = med_obj.getNumberOfMeshes() nbFields = med_obj.getNumberOfFields() +meshNames = med_obj.getMeshNames() + print "" print "The med file ",medFile," has ",nbMeshes," Meshe(s) and ",nbFields," Field(s)" print "" -meshcorba = getMeshObjectFromStudy(1) +meshName = meshNames[0] -name = meshcorba.getName() +meshcorba = getMeshObjectFromStudy(meshName) nbNodes = meshcorba.getNumberOfNodes() spaceDim = meshcorba.getSpaceDimension() -print "The mesh from the Study is ",name,".It is a ",spaceDim,"-D mesh and it has ",nbNodes," Nodes" +print "The mesh from the Study is ",meshName,".It is a ",spaceDim,"-D mesh and it has ",nbNodes," Nodes" print "" for entity in [SALOME_MED.MED_NODE,SALOME_MED.MED_CELL,SALOME_MED.MED_FACE,SALOME_MED.MED_EDGE]: diff --git a/src/MedCorba_Swig/medcorba_test.py b/src/MedCorba_Swig/medcorba_test.py index 8bae396ea..dedb4b212 100644 --- a/src/MedCorba_Swig/medcorba_test.py +++ b/src/MedCorba_Swig/medcorba_test.py @@ -28,6 +28,9 @@ import salome import SALOME_MED +from libSALOME_Swig import * +sg = SALOMEGUI_Swig() + from libMedCorba_Swig import * from random import * @@ -78,28 +81,44 @@ def AnalyzeField(field): #============================================================================== -def getMeshObjectFromStudy(number): - mySO = salome.myStudy.FindObject("MEDMESH") - mysub = mySO.FindSubObject(number)[1] - if mysub: - Builder = salome.myStudy.NewBuilder() - anAttr = Builder.FindOrCreateAttribute(mysub, "AttributeIOR") +def getMeshObjectFromStudy(meshName): + objNameInStudy = "/Med/MEDMESH/"+meshName + mySO = salome.myStudy.FindObjectByPath(objNameInStudy) + if (mySO == None) : + print "ERROR: ",objNameInStudy," cannot be found in the Study" + return mySO + else: + anAttr = mySO.FindAttribute("AttributeIOR")[1] obj = salome.orb.string_to_object(anAttr.Value()) myObj = obj._narrow(SALOME_MED.MESH) + if (myObj == None) : + print "ERROR: ",objNameInStudy," has been found in the Study but with the wrong type" return myObj - else: - print "ERROR: No Mesh Object stored in this Study" - return None #============================================================================== -def getMedObjectFromStudy(): - mySO = salome.myStudy.FindObject("Objet MED") - Builder = salome.myStudy.NewBuilder() - anAttr = Builder.FindOrCreateAttribute(mySO, "AttributeIOR") - obj = salome.orb.string_to_object(anAttr.Value()) - myObj = obj._narrow(SALOME_MED.MED) - return myObj +def getMedObjectFromStudy(file): + objNameInStudy = "MED_OBJECT_FROM_FILE_"+file + compNameInStudy= "MED" + listOfSO = salome.myStudy.FindObjectByName(objNameInStudy,compNameInStudy) + listLength = len(listOfSO) + if (listLength == 0) : + print "ERROR: ",objNameInStudy," cannot be found in the Study under the component ",compNameInStudy + return None + elif (listLength > 1) : + print "ERROR: there are more than one instance of ",objNameInStudy," in the Study under the component ",compNameInStudy + return None + mySO = listOfSO[0] + if (mySO == None) : + print "ERROR: ",objNameInStudy," cannot be found in the Study" + return mySO + else: + anAttr = mySO.FindAttribute("AttributeIOR")[1] + obj = salome.orb.string_to_object(anAttr.Value()) + myObj = obj._narrow(SALOME_MED.MED) + if (myObj == None) : + print "ERROR: ",objNameInStudy," has been found in the Study but with the wrong type" + return myObj #============================================================================== @@ -109,8 +128,9 @@ studyCurrentId = salome.myStudyId print "We are working in the study ",studyCurrent," with the ID ",studyCurrentId print "" +fileName = "cube_hexa8_quad4.med" #medFile = "carre_en_quad4_seg2.med" -medFile = filePath + "cube_hexa8_quad4.med" +medFile = filePath + fileName print "Loading of the Med Component" print "" @@ -118,26 +138,29 @@ print "" med_comp = salome.lcc.FindOrLoadComponent("FactoryServer", "MED") med_comp.readStructFile(medFile,studyCurrent) +sg.updateObjBrowser(1) -med_obj = getMedObjectFromStudy() +med_obj = getMedObjectFromStudy(fileName) nbMeshes = med_obj.getNumberOfMeshes() nbFields = med_obj.getNumberOfFields() +meshNames = med_obj.getMeshNames() + print "" print "The med file ",medFile," has ",nbMeshes," Meshe(s) and ",nbFields," Field(s)" print "" -meshcorba = getMeshObjectFromStudy(1) +meshName = meshNames[0] -name = meshcorba.getName() +meshcorba = getMeshObjectFromStudy(meshName) nbNodes = meshcorba.getNumberOfNodes() spaceDim = meshcorba.getSpaceDimension() -print "The mesh from the Study is ",name,".It is a ",spaceDim,"-D mesh and it has ",nbNodes," Nodes" +print "The mesh from the Study is ",meshName,".It is a ",spaceDim,"-D mesh and it has ",nbNodes," Nodes" print "" for entity in [SALOME_MED.MED_NODE,SALOME_MED.MED_CELL,SALOME_MED.MED_FACE,SALOME_MED.MED_EDGE]: