From 3c2c25c9dea3f77ca5d9274d0e74ff989746a495 Mon Sep 17 00:00:00 2001 From: nadir Date: Thu, 24 Jun 2004 13:20:08 +0000 Subject: [PATCH] updating those python scripts due to the new organisation of the MED component study. --- src/VISU_SWIG/visu.py | 140 ++++++++++++++++++++++++------ src/VISU_SWIG/visu_prs_example.py | 69 ++++++++++----- 2 files changed, 158 insertions(+), 51 deletions(-) diff --git a/src/VISU_SWIG/visu.py b/src/VISU_SWIG/visu.py index 86d8adc8..9306e262 100644 --- a/src/VISU_SWIG/visu.py +++ b/src/VISU_SWIG/visu.py @@ -29,7 +29,18 @@ myLocalStudy = None myLocalVisu = None myDelay = None mySession = None - + +def changeBlankToUnderScore(stringWithBlank): + blank = ' ' + underscore = '_' + decompString = split(stringWithBlank,blank) + length = len(decompString) + stringWithUnderScore = decompString[0] + for i in range(1,length): + stringWithUnderScore += underscore + stringWithUnderScore += decompString[i] + return stringWithUnderScore + def Initialize(theORB, theNamingService, theLifeCycleCORBA, theStudyManager, theStudy, theDelay) : global myORB, myNamingService, myLifeCycleCORBA, myLocalStudyManager, myLocalStudy global mySession, myLocalVisu, myDelay @@ -99,38 +110,104 @@ def CreateStudyForMed(theVisu, theFileName) : return [aStudy, myViewManager, myView] raise RuntimeError, "Error: There is no shuch file." -def getMedObjectFromStudy(theStudy = myLocalStudy): +##def getMedObjectFromStudy(theStudy = myLocalStudy): +## if theStudy is None: +## theStudy = myLocalStudy +## mySO = theStudy.FindObject("Objet MED") +## anAttr = mySO.FindAttribute("AttributeIOR")[1] +## obj = myORB.string_to_object(anAttr.Value()) +## myObj = obj._narrow(SALOME_MED.MED) +## return myObj + +def getMedObjectFromStudy(file, theStudy = myLocalStudy): + objNameInStudy = "MED_OBJECT_FROM_FILE_"+file + compNameInStudy= "MED" + if theStudy is None: theStudy = myLocalStudy - mySO = theStudy.FindObject("Objet MED") - anAttr = mySO.FindAttribute("AttributeIOR")[1] - obj = myORB.string_to_object(anAttr.Value()) - myObj = obj._narrow(SALOME_MED.MED) - return myObj -def getMedSObject(theStudy = myLocalStudy ): - return theStudy.FindObject("Objet MED") + listOfSO = theStudy.FindObjectByName(objNameInStudy,compNameInStudy) + listLength = len(listOfSO) + if (listLength == 0) : + print "PROBLEME ",objNameInStudy," cannot be found in the Study under the component ",compNameInStudy + return None + elif (listLength > 1) : + print "PROBLEME there are more than one instance of ",objNameInStudy," in the Study under the component ",compNameInStudy + return None + mySO = listOfSO[0] + if (mySO == None) : + print "PROBLEM ",objNameInStudy," cannot be found in the Study" + return mySO + else: + anAttr = mySO.FindAttribute("AttributeIOR")[1] + obj = myORB.string_to_object(anAttr.Value()) + myObj = obj._narrow(SALOME_MED.MED) + if (myObj == None) : + print "PROBLEM ",objNameInStudy," has been found in the Study but with the wrong type" + return myObj + +##def getMedSObject(theStudy = myLocalStudy ): +## return theStudy.FindObject("Objet MED") + +def getMedSObject(file, theStudy = myLocalStudy ): + objNameInStudy = "MED_OBJECT_FROM_FILE_"+file + compNameInStudy= "MED" -def getFieldObjectFromStudy(number, subnumber, theStudy = myLocalStudy): if theStudy is None: theStudy = myLocalStudy - mySO = theStudy.FindObject("MEDFIELD") - if mySO is None: - raise Runtime, "getFieldObjectFromStudy mySO is None" - mysub = mySO.FindSubObject(number)[1] - if mysub: - mysubsub = mysub.FindSubObject(subnumber)[1] - if mysubsub: - Builder = theStudy.NewBuilder() - anAttr = Builder.FindOrCreateAttribute(mysubsub, "AttributeIOR") - obj = myORB.string_to_object(anAttr.Value()) - myObj = obj._narrow(SALOME_MED.FIELDINT) - if (myObj == None): - myObj = obj._narrow(SALOME_MED.FIELDDOUBLE) - return myObj - else: - print "ERROR: No Field Object stored in this Study" + + listOfSO = theStudy.FindObjectByName(objNameInStudy,compNameInStudy) + listLength = len(listOfSO) + if (listLength == 0) : + print "PROBLEME ",objNameInStudy," cannot be found in the Study under the component ",compNameInStudy + return None + elif (listLength > 1) : + print "PROBLEME there are more than one instance of ",objNameInStudy," in the Study under the component ",compNameInStudy return None + mySO = listOfSO[0] + return mySO + +##def getFieldObjectFromStudy(number, subnumber, theStudy = myLocalStudy): +## if theStudy is None: +## theStudy = myLocalStudy +## mySO = theStudy.FindObject("MEDFIELD") +## if mySO is None: +## raise Runtime, "getFieldObjectFromStudy mySO is None" +## mysub = mySO.FindSubObject(number)[1] +## if mysub: +## mysubsub = mysub.FindSubObject(subnumber)[1] +## if mysubsub: +## Builder = theStudy.NewBuilder() +## anAttr = Builder.FindOrCreateAttribute(mysubsub, "AttributeIOR") +## obj = myORB.string_to_object(anAttr.Value()) +## myObj = obj._narrow(SALOME_MED.FIELDINT) +## if (myObj == None): +## myObj = obj._narrow(SALOME_MED.FIELDDOUBLE) +## return myObj +## else: +## print "ERROR: No Field Object stored in this Study" +## return None + +def getFieldObjectFromStudy(dt, it, fieldName, supportName, meshName, + theStudy = myLocalStudy): + meshNameStudy = changeBlankToUnderScore(meshName) + if theStudy is None: + theStudy = myLocalStudy + + objNameInStudy = "/Med/MEDFIELD/"+fieldName+"/("+str(dt)+","+str(it)+")_ON_"+supportName+"_OF_"+meshNameStudy + mySO = theStudy.FindObjectByPath(objNameInStudy) + if (mySO == None) : + print "PROBLEM ",objNameInStudy," cannot be found in the Study" + return mySO + else: + anAttr = mySO.FindAttribute("AttributeIOR")[1] + obj = myORB.string_to_object(anAttr.Value()) + myObj = obj._narrow(SALOME_MED.FIELDINT) + if (myObj == None): + myObj = obj._narrow(SALOME_MED.FIELDDOUBLE) + if (myObj == None) : + print "PROBLEM ",objNameInStudy," has been found in the Study but with the wrong type" + return myObj def SObjectToObject(theSObject) : # global myORB @@ -159,7 +236,14 @@ def CreatePrsForMed(theVisu, theFileName, thePrsTypeList, thePictureDir, thePict print "aMedComp.readStructFileWithFieldType...", aMedComp.readStructFileWithFieldType(theFileName,myLocalStudy._get_Name()) - aMedSObj = getMedSObject(myLocalStudy) + print "reading the med file is OK ..." + + # taking the absolute name of theFileName (without the path to it) + decompFileName = split(theFileName,"/") + lenDecomp = len(decompFileName) + absFileName = decompFileName[lenDecomp-1] + + aMedSObj = getMedSObject(absFileName,myLocalStudy) if aMedSObj is None : raise RuntimeError, "Error" else : print "OK" @@ -169,7 +253,7 @@ def CreatePrsForMed(theVisu, theFileName, thePrsTypeList, thePictureDir, thePict else : print "OK" aVISUObjList.append(aResult) aVISUObjList.extend(CreatePrsForResult(theVisu, aResult, myView, thePrsTypeList, thePictureDir, thePictureExt)) - + aFolderIter = myLocalStudy.NewChildIterator(aMedSObj.GetFather()); while aFolderIter.More() : aFolderSObj = aFolderIter.Value() diff --git a/src/VISU_SWIG/visu_prs_example.py b/src/VISU_SWIG/visu_prs_example.py index 84d65be4..b23aacb3 100644 --- a/src/VISU_SWIG/visu_prs_example.py +++ b/src/VISU_SWIG/visu_prs_example.py @@ -22,6 +22,7 @@ import visu_gui myVisu = visu_gui.myVisu medFile = "pointe.med" +absMedFile = medFile medFile = os.getenv('KERNEL_ROOT_DIR') + '/examples/' + medFile print medFile @@ -32,34 +33,56 @@ med_comp = salome.lcc.FindOrLoadComponent("FactoryServer", "MED") try: if os.access(medFile, os.R_OK) : - if os.access(medFile, os.W_OK) : - med_comp.readStructFileWithFieldType(medFile,studyCurrent) - med_obj = visu_gui.visu.getMedObjectFromStudy() - print "med_obj - ", med_obj - - myField = visu_gui.visu.getFieldObjectFromStudy(2,1) - aMeshName = "FILED_DOUBLE_MESH" - anEntity = VISU.NODE - aTimeStampId = 0 + print "Reading the .med file ",medFile," and pushing corba objects in the SALOME study" + med_comp.readStructFileWithFieldType(medFile,studyCurrent) + med_obj = visu_gui.visu.getMedObjectFromStudy(absMedFile) + print "med_obj - ", med_obj + + + nbOfMeshes = med_obj.getNumberOfMeshes() + print "in this med file there is(are) ",nbOfMeshes," mesh(es)," + meshNames = med_obj.getMeshNames() + meshName = meshNames[0] + + supportName = "SupportOnAll_MED_NOEUD" + + nbOfFields = med_obj.getNumberOfFields() + print "and ",nbOfFields," field(s)." + fieldNames = med_obj.getFieldNames() + fieldName = fieldNames[1] + nbOfIt = med_obj.getFieldNumberOfIteration(fieldName) + print "the field ",fieldName," has ",nbOfIt," iteration(s)" + dtitsfield = med_obj.getFieldIterations(fieldName) + dtitfield = dtitsfield[0:2] + dt = dtitfield[0] + it = dtitfield[1] + +## myField = visu_gui.visu.getFieldObjectFromStudy(2,1) + # the first iteration of the second field + myField = visu_gui.visu.getFieldObjectFromStudy(dt, it, fieldName, + supportName, + meshName) + aMeshName = "FILED_DOUBLE_MESH" + anEntity = VISU.NODE + aTimeStampId = 0 - myResult1 = myVisu.ImportMedField(myField) - aMesh1 = myVisu.MeshOnEntity(myResult1, aMeshName, anEntity); + myResult1 = myVisu.ImportMedField(myField) + aMesh1 = myVisu.MeshOnEntity(myResult1, aMeshName, anEntity); - aScalarMap1= myVisu.ScalarMapOnField(myResult1, aMeshName, anEntity, myField.getName(), aTimeStampId) - if(myField.getNumberOfComponents() > 1) : - aVectors = myVisu.VectorsOnField(myResult1, aMeshName, anEntity, myField.getName(), aTimeStampId) + aScalarMap1= myVisu.ScalarMapOnField(myResult1, aMeshName, anEntity, myField.getName(), aTimeStampId) + if(myField.getNumberOfComponents() > 1) : + aVectors = myVisu.VectorsOnField(myResult1, aMeshName, anEntity, myField.getName(), aTimeStampId) - myResult2 = myVisu.ImportFile(medFile) - aMeshName = "maa1" - anEntity = VISU.NODE - aMesh2 = myVisu.MeshOnEntity(myResult2, aMeshName, anEntity) + myResult2 = myVisu.ImportFile(medFile) + aMeshName = "maa1" + anEntity = VISU.NODE + aMesh2 = myVisu.MeshOnEntity(myResult2, aMeshName, anEntity) - aScalarMap2 = myVisu.ScalarMapOnField(myResult2, aMeshName, anEntity, myField.getName(), aTimeStampId) - if(myField.getNumberOfComponents() > 1) : - aCutPlanes = myVisu.CutPlanesOnField(myResult2, aMeshName, anEntity, myField.getName(), aTimeStampId) + aScalarMap2 = myVisu.ScalarMapOnField(myResult2, aMeshName, anEntity, myField.getName(), aTimeStampId) + if(myField.getNumberOfComponents() > 1) : + aCutPlanes = myVisu.CutPlanesOnField(myResult2, aMeshName, anEntity, myField.getName(), aTimeStampId) - sg.updateObjBrowser(0) - else : print "We have no permission to rewrite medFile, so readStructFileWithFieldType can't open this file"; + sg.updateObjBrowser(0) else : print "We have no permission to read medFile, it will not be opened"; except: if sys.exc_type == SALOME.SALOME_Exception : -- 2.39.2