Salome HOME
Fix for Bug IPAL8945
[modules/visu.git] / src / VISU_SWIG / visu.py
index 037cc764ce9a2f0fa13ae14bb073e3ef8e34e7c7..daadf7aa4f935a60d91c2587847a18132f5e3518 100644 (file)
@@ -184,7 +184,7 @@ def SObjectToObject(theSObject) :
        print "SObjectToObject - IOR = ''"
     return anObj;
  
-def CreatePrsForMed(theVisu, theFileName, thePrsTypeList, thePictureDir, thePictureExt) :
+def CreatePrsForMed(theVisu, theFileName, thePrsTypeList, thePictureDir, thePictureExt, theIsAutoDelete = 0) :
 #    try:
         global myLifeCycleCORBA
         print "lcc.FindOrLoadComponent...",
@@ -204,8 +204,12 @@ def CreatePrsForMed(theVisu, theFileName, thePrsTypeList, thePictureDir, thePict
         aResult = theVisu.ImportMed(aMedSObj)
         if aResult is None : raise RuntimeError, "Error"
         else : print "OK"
-        aVISUObjList.append(aResult)
-        aVISUObjList.extend(CreatePrsForResult(theVisu, aResult, myView, thePrsTypeList, thePictureDir, thePictureExt))
+
+        aVISUObjList.extend(CreatePrsForResult(theVisu, aResult, myView, thePrsTypeList, thePictureDir, thePictureExt, theIsAutoDelete))
+        if theIsAutoDelete :
+            aResult.RemoveFromStudy()
+        else :
+            aVISUObjList.append(aResult)
         
         aFolderIter = myLocalStudy.NewChildIterator(aMedSObj.GetFather());
         while aFolderIter.More() :
@@ -249,8 +253,12 @@ def CreatePrsForMed(theVisu, theFileName, thePrsTypeList, thePictureDir, thePict
                     aResult = theVisu.ImportMed(aFieldSObj)
                     if aResult is None : raise RuntimeError, "Error"
                     else : print "OK"
-                    aVISUObjList.append(aResult)
-                    aVISUObjList.extend(CreatePrsForResult(theVisu, aResult, myView, thePrsTypeList, thePictureDir, thePictureExt))
+
+                    aVISUObjList.extend(CreatePrsForResult(theVisu, aResult, myView, thePrsTypeList, thePictureDir, thePictureExt, theIsAutoDelete))
+                    if theIsAutoDelete :
+                        aResult.RemoveFromStudy()
+                    else :
+                        aVISUObjList.append(aResult)
 
                     aTimeStampIter = myLocalStudy.NewChildIterator(aFieldSObj);
                     if aTimeStampIter.More() :
@@ -268,15 +276,19 @@ def CreatePrsForMed(theVisu, theFileName, thePrsTypeList, thePictureDir, thePict
                             aResult = theVisu.ImportMedField(aMedField)
                             if aResult is None : raise RuntimeError, "Error"
                             else : print "OK"
-                            aVISUObjList.append(aResult)
-                            aVISUObjList.extend(CreatePrsForResult(theVisu, aResult, myView, thePrsTypeList, thePictureDir, thePictureExt))
+
+                            aVISUObjList.extend(CreatePrsForResult(theVisu, aResult, myView, thePrsTypeList, thePictureDir, thePictureExt, theIsAutoDelete))
+                            if theIsAutoDelete :
+                                aResult.RemoveFromStudy()
+                            else :
+                                aVISUObjList.append(aResult)
                     
         return aVISUObjList
     
 #    except Exception, e:
 #        print str(e)
         
-def CreatePrsForFile(theVisu, theFileName, thePrsTypeList, thePictureDir, thePictureExt) :
+def CreatePrsForFile(theVisu, theFileName, thePrsTypeList, thePictureDir, thePictureExt, theIsAutoDelete = 0) :
  #   try:
         aVISUObjList = [myLocalStudy, myViewManager, myView] = CreateStudyForMed(theVisu, theFileName)
 
@@ -285,17 +297,27 @@ def CreatePrsForFile(theVisu, theFileName, thePrsTypeList, thePictureDir, thePic
         if aResult is None : raise RuntimeError, "Error"
         else : print "OK"
         
-        aVISUObjList.extend(CreatePrsForResult(theVisu, aResult, myView, thePrsTypeList, thePictureDir, thePictureExt))
-        
+        aVISUObjList.extend(CreatePrsForResult(theVisu, aResult, myView, thePrsTypeList, thePictureDir, thePictureExt, theIsAutoDelete))
+
+        if theIsAutoDelete :
+            aResult.RemoveFromStudy()
+        else :
+            aVISUObjList.append(aResult)
+
         return aVISUObjList
     
 #    except Exception, e:
 #        print str(e)
                 
-def CreatePrsForResult(theVisu, theResult, theView, thePrsTypeList, thePictureDir, thePictureExt) :
-    aVISUObjList = []
+def CreatePrsForResult(theVisu, theResult, theView, thePrsTypeList, thePictureDir, thePictureExt, theIsAutoDelete = 0) :
+    aVISUObjList = None
+    if theIsAutoDelete is not None :
+       aVISUObjList = []
+       pass
+       
     print "CreatePrsForResult - myLocalStudy.FindObjectIOR...",
     myLocalStudy = theVisu.GetCurrentStudy()
+
     aSObj = myLocalStudy.FindObjectIOR(theResult.GetID())
     if aSObj is None : raise RuntimeError, "Error"
     else : print "OK"
@@ -356,7 +378,10 @@ def CreatePrsForResult(theVisu, theResult, theView, thePrsTypeList, thePictureDi
                             aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "." + thePictureExt
                             aPictureName = re.sub("\s+","_", aPictureName);
                             theView.SavePicture(aPictureName)
-                            aVISUObjList.append(aMesh)
+                            if theIsAutoDelete :
+                                aMesh.RemoveFromStudy()
+                            else :
+                                aVISUObjList.append(aMesh)
                         
                         anFamilyIter = myLocalStudy.NewChildIterator(anEntitySObj);
                         while anFamilyIter.More() :
@@ -376,7 +401,10 @@ def CreatePrsForResult(theVisu, theResult, theView, thePrsTypeList, thePictureDi
                                     aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + anFamilyName + "." + thePictureExt
                                     aPictureName = re.sub("\s+","_", aPictureName);
                                     theView.SavePicture(aPictureName)
-                                    aVISUObjList.append(aMesh)
+                                    if theIsAutoDelete :
+                                        aMesh.RemoveFromStudy()
+                                    else :
+                                        aVISUObjList.append(aMesh)
                                 
             if aFolderName == 'Groups' :
                 aGroupIter = myLocalStudy.NewChildIterator(aFolderSObj);
@@ -397,7 +425,10 @@ def CreatePrsForResult(theVisu, theResult, theView, thePrsTypeList, thePictureDi
                             aPictureName = thePictureDir + aMeshNamePic + "_" + aGroupName + "." + thePictureExt
                             aPictureName = re.sub("\s+","_", aPictureName);
                             theView.SavePicture(aPictureName)
-                            aVISUObjList.append(aMesh)
+                            if theIsAutoDelete :
+                                aMesh.RemoveFromStudy()
+                            else :
+                                aVISUObjList.append(aMesh)
                         
             if aFolderName == 'Fields' :
                 aFieldIter = myLocalStudy.NewChildIterator(aFolderSObj);
@@ -446,8 +477,11 @@ def CreatePrsForResult(theVisu, theResult, theView, thePrsTypeList, thePictureDi
                                     aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TSCALARMAP." + thePictureExt
                                     aPictureName = re.sub("\s+","_", aPictureName);
                                     theView.SavePicture(aPictureName)
-                                    aVISUObjList.append(aPrsObj)
-                                
+                                    if theIsAutoDelete :
+                                       aPrsObj.RemoveFromStudy()
+                                    else :
+                                        aVISUObjList.append(aPrsObj)
+
                             if HasValue(thePrsTypeList,VISU.TISOSURFACE) :
                                 print "          Creating IsoSurfacesOnField",
                                 aPrsObj = theVisu.IsoSurfacesOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
@@ -459,7 +493,10 @@ def CreatePrsForResult(theVisu, theResult, theView, thePrsTypeList, thePictureDi
                                     aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TISOSURFACE." + thePictureExt
                                     aPictureName = re.sub("\s+","_", aPictureName);
                                     theView.SavePicture(aPictureName)
-                                    aVISUObjList.append(aPrsObj)
+                                    if theIsAutoDelete :
+                                       aPrsObj.RemoveFromStudy()
+                                    else :
+                                        aVISUObjList.append(aPrsObj)
                                 
                             if HasValue(thePrsTypeList,VISU.TCUTPLANES) :
                                 print "          Creating CutPlanesOnField",
@@ -473,7 +510,10 @@ def CreatePrsForResult(theVisu, theResult, theView, thePrsTypeList, thePictureDi
                                     aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TCUTPLANES." + thePictureExt
                                     aPictureName = re.sub("\s+","_", aPictureName)
                                     theView.SavePicture(aPictureName)
-                                    aVISUObjList.append(aPrsObj)
+                                    if theIsAutoDelete :
+                                       aPrsObj.RemoveFromStudy()
+                                    else :
+                                        aVISUObjList.append(aPrsObj)
                                 
                             if HasValue(thePrsTypeList,VISU.TCUTLINES) :
                                 print "          Creating CutLinesOnField",
@@ -488,7 +528,10 @@ def CreatePrsForResult(theVisu, theResult, theView, thePrsTypeList, thePictureDi
                                     aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TCUTLINES." + thePictureExt
                                     aPictureName = re.sub("\s+","_", aPictureName)
                                     theView.SavePicture(aPictureName)
-                                    aVISUObjList.append(aPrsObj)
+                                    if theIsAutoDelete :
+                                       aPrsObj.RemoveFromStudy()
+                                    else :
+                                        aVISUObjList.append(aPrsObj)
                                 
                             if HasValue(thePrsTypeList,VISU.TPLOT3D) :
                                 print "          Creating Plot3DOnField",
@@ -505,7 +548,10 @@ def CreatePrsForResult(theVisu, theResult, theView, thePrsTypeList, thePictureDi
                                     aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TPLOT3D." + thePictureExt
                                     aPictureName = re.sub("\s+","_", aPictureName)
                                     theView.SavePicture(aPictureName)
-                                    aVISUObjList.append(aPrsObj)
+                                    if theIsAutoDelete :
+                                       aPrsObj.RemoveFromStudy()
+                                    else :
+                                        aVISUObjList.append(aPrsObj)
                                 
                             aNumComponent = atoi(aMap["myNumComponent"])
                             if aNumComponent > 1 :
@@ -520,7 +566,10 @@ def CreatePrsForResult(theVisu, theResult, theView, thePrsTypeList, thePictureDi
                                         aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TDEFORMEDSHAPE." + thePictureExt
                                         aPictureName = re.sub("\s+","_", aPictureName)
                                         theView.SavePicture(aPictureName)
-                                        aVISUObjList.append(aPrsObj)
+                                        if theIsAutoDelete :
+                                            aPrsObj.RemoveFromStudy()
+                                        else :
+                                            aVISUObjList.append(aPrsObj)
 
                                 if HasValue(thePrsTypeList,VISU.TVECTORS) :
                                     print "          Creating VectorsOnField",
@@ -533,7 +582,10 @@ def CreatePrsForResult(theVisu, theResult, theView, thePrsTypeList, thePictureDi
                                         aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TVECTORS." + thePictureExt
                                         aPictureName = re.sub("\s+","_", aPictureName)
                                         theView.SavePicture(aPictureName)
-                                        aVISUObjList.append(aPrsObj)
+                                        if theIsAutoDelete :
+                                            aPrsObj.RemoveFromStudy()
+                                        else :
+                                            aVISUObjList.append(aPrsObj)
                                     
                                 if HasValue(thePrsTypeList,VISU.TSTREAMLINES) :
                                     print "          Creating StreamLinesOnField",
@@ -546,8 +598,10 @@ def CreatePrsForResult(theVisu, theResult, theView, thePrsTypeList, thePictureDi
                                         aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TSTREAMLINES." + thePictureExt
                                         aPictureName = re.sub("\s+","_", aPictureName)
                                         theView.SavePicture(aPictureName)
-                                        aVISUObjList.append(aPrsObj)
-                    
+                                        if theIsAutoDelete :
+                                            aPrsObj.RemoveFromStudy()
+                                        else :
+                                            aVISUObjList.append(aPrsObj)
     return aVISUObjList
 
 
@@ -688,7 +742,7 @@ def dump_deformedshape_parameters(theObject):
 # ----------------------
 def try_cutplanes_parameters(thePattern) :
 
-    if thePattern  is None : return aList 
+    if thePattern  is None : return None 
     import copy
     import random