From 0cbfa02741884c6a8fb6321919825318744df207 Mon Sep 17 00:00:00 2001 From: yfr Date: Mon, 19 Jul 2004 15:04:23 +0000 Subject: [PATCH] DCQ: prepare V2.0.0 --- resources/config | 1 - src/VISU_SWIG/visu.py | 140 ++++++------------------------ src/VISU_SWIG/visu_prs_example.py | 69 +++++---------- 3 files changed, 51 insertions(+), 159 deletions(-) delete mode 100644 resources/config diff --git a/resources/config b/resources/config deleted file mode 100644 index 69253976..00000000 --- a/resources/config +++ /dev/null @@ -1 +0,0 @@ -language=en \ No newline at end of file diff --git a/src/VISU_SWIG/visu.py b/src/VISU_SWIG/visu.py index 9306e262..86d8adc8 100644 --- a/src/VISU_SWIG/visu.py +++ b/src/VISU_SWIG/visu.py @@ -29,18 +29,7 @@ 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 @@ -110,104 +99,38 @@ def CreateStudyForMed(theVisu, theFileName) : return [aStudy, myViewManager, myView] raise RuntimeError, "Error: There is no shuch file." -##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" - +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 - 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 getMedSObject(theStudy = myLocalStudy ): + return theStudy.FindObject("Objet MED") +def getFieldObjectFromStudy(number, subnumber, theStudy = myLocalStudy): if theStudy is None: theStudy = myLocalStudy - - 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 + 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: - 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 + print "ERROR: No Field Object stored in this Study" + return None def SObjectToObject(theSObject) : # global myORB @@ -236,14 +159,7 @@ def CreatePrsForMed(theVisu, theFileName, thePrsTypeList, thePictureDir, thePict print "aMedComp.readStructFileWithFieldType...", aMedComp.readStructFileWithFieldType(theFileName,myLocalStudy._get_Name()) - 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) + aMedSObj = getMedSObject(myLocalStudy) if aMedSObj is None : raise RuntimeError, "Error" else : print "OK" @@ -253,7 +169,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 b23aacb3..84d65be4 100644 --- a/src/VISU_SWIG/visu_prs_example.py +++ b/src/VISU_SWIG/visu_prs_example.py @@ -22,7 +22,6 @@ import visu_gui myVisu = visu_gui.myVisu medFile = "pointe.med" -absMedFile = medFile medFile = os.getenv('KERNEL_ROOT_DIR') + '/examples/' + medFile print medFile @@ -33,56 +32,34 @@ med_comp = salome.lcc.FindOrLoadComponent("FactoryServer", "MED") try: if os.access(medFile, os.R_OK) : - 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 + 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 - 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) + sg.updateObjBrowser(0) + else : print "We have no permission to rewrite medFile, so readStructFileWithFieldType can't open this file"; 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