Salome HOME
Update copyright information
[modules/visu.git] / src / VISU_SWIG / visu.py
index 9306e262e5593bb7e68cde47265709c33b1ebc87..92086f150492e4fdde702ef8a5424b6a9598c989 100644 (file)
@@ -1,12 +1,30 @@
-#  VISU VISU_SWIG : binding of C++ implementation and Python
+#  -*- coding: iso-8859-1 -*-
+# Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
+#
+# Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License.
 #
-#  Copyright (C) 2003  CEA/DEN, EDF R&D
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
 #
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 #
+# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 #
+
+#  VISU VISU_SWIG : binding of C++ implementation and Python
 #  File   : visu.py
 #  Module : VISU
-
+#
 import os
 import re
 from time import sleep
@@ -16,9 +34,11 @@ import SALOME
 import SALOME_Session_idl
 import SALOMEDS
 import SALOME_MED
+import SALOME_ModuleCatalog
 from omniORB import CORBA
 from string import *
 from time import sleep
+from salome import ObjectToID
 
 myORB = None
 myNamingService = None
@@ -29,18 +49,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
@@ -49,7 +58,8 @@ def Initialize(theORB, theNamingService, theLifeCycleCORBA, theStudyManager, the
     myNamingService = theNamingService
     myLifeCycleCORBA = theLifeCycleCORBA
     myLocalStudyManager = theStudyManager
-    mySession = myNamingService.Resolve("/Kernel/Session")
+    while mySession == None:
+       mySession = myNamingService.Resolve("/Kernel/Session")
     mySession = mySession._narrow(SALOME.Session)
     mySession.GetInterface()
     myDelay = theDelay
@@ -58,7 +68,47 @@ def Initialize(theORB, theNamingService, theLifeCycleCORBA, theStudyManager, the
     myLocalStudy = theStudy
     myLocalVisu.SetCurrentStudy(myLocalStudy)
     return myLocalVisu
+
+def PublishComponent(theStudyDocument):
+    aComponentDataType = myLocalVisu.ComponentDataType()
+    aSComponent = theStudyDocument.FindComponent(aComponentDataType)
+    if aSComponent == None:
+        aStudyBuilder = theStudyDocument.NewBuilder()
+        aStudyBuilder.NewCommand()
+        aLocked = theStudyDocument.GetProperties().IsLocked()
+        if aLocked:
+            theStudyDocument.GetProperties().SetLocked(0)
+            pass
+
+        aSComponent = aStudyBuilder.NewComponent(aComponentDataType);
+        aName = aStudyBuilder.FindOrCreateAttribute(aSComponent,"AttributeName")
+        aModuleCatalogObj = myNamingService.Resolve("/Kernel/ModulCatalog");
+        aModuleCatalog = aModuleCatalogObj._narrow(SALOME_ModuleCatalog.ModuleCatalog)
+        aComponent = aModuleCatalog.GetComponent(aComponentDataType);
+        if aComponent != None:
+            aComponentUserName = aComponent._get_componentusername()
+            aName.SetValue(aComponentUserName)
+            pass
+        
+        aPixMap = aStudyBuilder.FindOrCreateAttribute(aSComponent,"AttributePixMap")
+        aPixMap.SetPixMap("ICON_OBJBROWSER_Visu")
+        
+        aStudyBuilder.DefineComponentInstance(aSComponent,myLocalVisu);
+        if aLocked:
+            theStudyDocument.GetProperties().SetLocked(1);
+            pass
+        
+        aStudyBuilder.CommitCommand();
+        pass
     
+    return aSComponent;
+
+def SetName(theObj, theName):
+    anIOR  = myORB.object_to_string(theObj)
+    aSObj  = myLocalStudy.FindObjectIOR(anIOR)
+    anAttr = aSObj.FindAttribute("AttributeName")[1]
+    anAttr.SetValue(theName)
+        
 def StrToMap(theString) :
     aPairList = split(theString,";")
     aMap = {}
@@ -78,6 +128,17 @@ def IntToEntity(theInt) :
         return VISU.FACE;
     else :
         return VISU.CELL;
+
+def getObjectID(obj):
+   ID = ""
+   entry = ObjectToID(obj)
+   if entry is not None:
+       lst = entry.split(":")
+       if len(entry) > 6:
+               ID = entry[6:]            
+               return "VISU_" + ID
+       return ID
+
         
 def HasValue(theList, theValue) :
     try :
@@ -108,106 +169,53 @@ def CreateStudyForMed(theVisu, theFileName) :
             print "OK"
 
             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"
+    raise RuntimeError, "Error: There is no such file."
 
+def getMedSObject(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]
-    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"
-
+    aSO = theStudy.FindObject("Med")
+    anIsPresetn, aSObject = aSO.FindSubObject(1)
+    return aSObject
+
+def getMedObjectFromStudy(theStudy = myLocalStudy):
+    aSObject = getMedSObject(theStudy)
+    if aSObject:
+        anAttr = aSObject.FindAttribute("AttributeIOR")[1]
+        anObj = myORB.string_to_object(anAttr.Value())
+        return  anObj._narrow(SALOME_MED.MED)
+    return None
+
+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
+    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
-    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 getSObjectByFatherPathAndName(theStudy, thePath, theName):
+    father = theStudy.FindObjectByPath(thePath)
+    itr = theStudy.NewChildIterator(father)
+    while itr.More():
+        so = itr.Value()
+        if so.GetName()==theName: return so
+        itr.Next()
+        pass
+    return None
 
 def SObjectToObject(theSObject) :
      #    global myORB
@@ -224,7 +232,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...",
@@ -236,14 +244,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"
         
@@ -251,9 +252,13 @@ 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() :
             aFolderSObj = aFolderIter.Value()
@@ -296,8 +301,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() :
@@ -315,15 +324,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)
 
@@ -332,17 +345,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"
@@ -364,7 +387,9 @@ def CreatePrsForResult(theVisu, theResult, theView, thePrsTypeList, thePictureDi
         while aFolderIter.More() :
             aFolderSObj = aFolderIter.Value()
             aFolderIter.Next()
-            anAttr = aFolderSObj.FindAttribute("AttributeName")[1]
+            anIsFound, anAttr = aFolderSObj.FindAttribute("AttributeName")
+            if not anIsFound :
+                continue
             anAttr = anAttr._narrow(SALOMEDS.AttributeName);
             aFolderName = anAttr.Value()
             print "    ", aFolderName
@@ -396,13 +421,17 @@ def CreatePrsForResult(theVisu, theResult, theView, thePrsTypeList, thePictureDi
                         print "      ", anEntityName, aMeshName,
                         aMesh = theVisu.MeshOnEntity(theResult,aMeshName,anEntity)
                         if aMesh is None : print "Error"
-                        else : print ",OK"
-                        theView.DisplayOnly(aMesh)
-                        theView.FitAll()
-                        aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "." + thePictureExt
-                        aPictureName = re.sub("\s+","_", aPictureName);
-                        theView.SavePicture(aPictureName)
-                        aVISUObjList.append(aMesh)
+                        else :
+                            print ",OK"
+                            theView.DisplayOnly(aMesh)
+                            theView.FitAll()
+                            aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "." + thePictureExt
+                            aPictureName = re.sub("\s+","_", aPictureName);
+                            theView.SavePicture(aPictureName)
+                            if theIsAutoDelete :
+                                aMesh.RemoveFromStudy()
+                            else :
+                                aVISUObjList.append(aMesh)
                         
                         anFamilyIter = myLocalStudy.NewChildIterator(anEntitySObj);
                         while anFamilyIter.More() :
@@ -415,13 +444,17 @@ def CreatePrsForResult(theVisu, theResult, theView, thePrsTypeList, thePictureDi
                                 print "        ", anFamilyName,
                                 aMesh = theVisu.FamilyMeshOnEntity(theResult,aMeshName,anEntity,anFamilyName)
                                 if aMesh is None : print "Error"
-                                else : print ",OK"
-                                theView.DisplayOnly(aMesh)
-                                theView.FitAll()
-                                aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + anFamilyName + "." + thePictureExt
-                                aPictureName = re.sub("\s+","_", aPictureName);
-                                theView.SavePicture(aPictureName)
-                                aVISUObjList.append(aMesh)
+                                else :
+                                    print ",OK"
+                                    theView.DisplayOnly(aMesh)
+                                    theView.FitAll()
+                                    aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + anFamilyName + "." + thePictureExt
+                                    aPictureName = re.sub("\s+","_", aPictureName);
+                                    theView.SavePicture(aPictureName)
+                                    if theIsAutoDelete :
+                                        aMesh.RemoveFromStudy()
+                                    else :
+                                        aVISUObjList.append(aMesh)
                                 
             if aFolderName == 'Groups' :
                 aGroupIter = myLocalStudy.NewChildIterator(aFolderSObj);
@@ -435,13 +468,17 @@ def CreatePrsForResult(theVisu, theResult, theView, thePrsTypeList, thePictureDi
                         print "      ", aGroupName,
                         aMesh = theVisu.GroupMesh(theResult,aMeshName,aGroupName)
                         if aMesh is None : print "Error"
-                        else : print ",OK"
-                        theView.DisplayOnly(aMesh)
-                        theView.FitAll()
-                        aPictureName = thePictureDir + aMeshNamePic + "_" + aGroupName + "." + thePictureExt
-                        aPictureName = re.sub("\s+","_", aPictureName);
-                        theView.SavePicture(aPictureName)
-                        aVISUObjList.append(aMesh)
+                        else :
+                            print ",OK"
+                            theView.DisplayOnly(aMesh)
+                            theView.FitAll()
+                            aPictureName = thePictureDir + aMeshNamePic + "_" + aGroupName + "." + thePictureExt
+                            aPictureName = re.sub("\s+","_", aPictureName);
+                            theView.SavePicture(aPictureName)
+                            if theIsAutoDelete :
+                                aMesh.RemoveFromStudy()
+                            else :
+                                aVISUObjList.append(aMesh)
                         
             if aFolderName == 'Fields' :
                 aFieldIter = myLocalStudy.NewChildIterator(aFolderSObj);
@@ -453,8 +490,8 @@ def CreatePrsForResult(theVisu, theResult, theView, thePrsTypeList, thePictureDi
                     aFieldName = anAttr.Value()
                     print "      ", aFieldName
                     
-                    anAttr = aFieldSObj.FindAttribute("AttributeComment")[1]
-                    anAttr = anAttr._narrow(SALOMEDS.AttributeComment);
+                    anAttr = aFieldSObj.FindAttribute("AttributeString")[1]
+                    anAttr = anAttr._narrow(SALOMEDS.AttributeString);
                     aFieldComment = anAttr.Value()
                     aMap = StrToMap(aFieldComment)
                     
@@ -469,8 +506,8 @@ def CreatePrsForResult(theVisu, theResult, theView, thePrsTypeList, thePictureDi
                             aTimeStampName = anAttr.Value()
                             print "        ", aTimeStampName
                             
-                            anAttr = aTimeStampSObj.FindAttribute("AttributeComment")[1]
-                            anAttr = anAttr._narrow(SALOMEDS.AttributeComment);
+                            anAttr = aTimeStampSObj.FindAttribute("AttributeString")[1]
+                            anAttr = anAttr._narrow(SALOMEDS.AttributeString);
                             aTimeStampComment = anAttr.Value()
                             aMap = StrToMap(aTimeStampComment)
                             aMeshName = aMap["myMeshName"]
@@ -483,52 +520,104 @@ def CreatePrsForResult(theVisu, theResult, theView, thePrsTypeList, thePictureDi
                                 print "          Creating ScalarMapOnField",
                                 aPrsObj = theVisu.ScalarMapOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
                                 if aPrsObj is None : print "Error"
-                                else : print ",OK"
-                                theView.DisplayOnly(aPrsObj)
-                                theView.FitAll()
-                                aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TSCALARMAP." + thePictureExt
-                                aPictureName = re.sub("\s+","_", aPictureName);
-                                theView.SavePicture(aPictureName)
-                                aVISUObjList.append(aPrsObj)
-                                
-                            if HasValue(thePrsTypeList,VISU.TISOSURFACE) :
+                                else :
+                                    print ",OK"
+                                    theView.DisplayOnly(aPrsObj)
+                                    theView.FitAll()
+                                    aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TSCALARMAP." + thePictureExt
+                                    aPictureName = re.sub("\s+","_", aPictureName);
+                                    theView.SavePicture(aPictureName)
+                                    if theIsAutoDelete :
+                                       aPrsObj.RemoveFromStudy()
+                                    else :
+                                        aVISUObjList.append(aPrsObj)
+
+                            if HasValue(thePrsTypeList,VISU.TISOSURFACES) :
                                 print "          Creating IsoSurfacesOnField",
                                 aPrsObj = theVisu.IsoSurfacesOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
                                 if aPrsObj is None : print "Error"
-                                else : print ",OK"
-                                theView.DisplayOnly(aPrsObj)
-                                theView.FitAll()
-                                aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TISOSURFACE." + thePictureExt
-                                aPictureName = re.sub("\s+","_", aPictureName);
-                                theView.SavePicture(aPictureName)
-                                aVISUObjList.append(aPrsObj)
+                                else :
+                                    print ",OK"
+                                    theView.DisplayOnly(aPrsObj)
+                                    theView.FitAll()
+                                    aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TISOSURFACES." + thePictureExt
+                                    aPictureName = re.sub("\s+","_", aPictureName);
+                                    theView.SavePicture(aPictureName)
+                                    if theIsAutoDelete :
+                                       aPrsObj.RemoveFromStudy()
+                                    else :
+                                        aVISUObjList.append(aPrsObj)
                                 
                             if HasValue(thePrsTypeList,VISU.TCUTPLANES) :
                                 print "          Creating CutPlanesOnField",
                                 aPrsObj = theVisu.CutPlanesOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
                                 if aPrsObj is None : print "Error"
-                                else : print ",OK"
-                                aPrsObj.SetOrientation(VISU.CutPlanes.ZX,aPrsObj.GetRotateX(),aPrsObj.GetRotateY())
-                                theView.DisplayOnly(aPrsObj)
-                                theView.FitAll()
-                                aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TCUTPLANES." + thePictureExt
-                                aPictureName = re.sub("\s+","_", aPictureName)
-                                theView.SavePicture(aPictureName)
-                                aVISUObjList.append(aPrsObj)
+                                else :
+                                    print ",OK"
+                                    aPrsObj.SetOrientation(VISU.CutPlanes.ZX,aPrsObj.GetRotateX(),aPrsObj.GetRotateY())
+                                    theView.DisplayOnly(aPrsObj)
+                                    theView.FitAll()
+                                    aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TCUTPLANES." + thePictureExt
+                                    aPictureName = re.sub("\s+","_", aPictureName)
+                                    theView.SavePicture(aPictureName)
+                                    if theIsAutoDelete :
+                                       aPrsObj.RemoveFromStudy()
+                                    else :
+                                        aVISUObjList.append(aPrsObj)
                                 
                             if HasValue(thePrsTypeList,VISU.TCUTLINES) :
                                 print "          Creating CutLinesOnField",
                                 aPrsObj = theVisu.CutLinesOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
                                 if aPrsObj is None : print "Error"
-                                else : print ",OK"
-                                aPrsObj.SetOrientation(VISU.CutPlanes.XY,aPrsObj.GetRotateX(),aPrsObj.GetRotateY())
-                                aPrsObj.SetOrientation2(VISU.CutPlanes.ZX,aPrsObj.GetRotateX2(),aPrsObj.GetRotateY2())
-                                theView.DisplayOnly(aPrsObj)
-                                theView.FitAll()
-                                aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TCUTLINES." + thePictureExt
-                                aPictureName = re.sub("\s+","_", aPictureName)
-                                theView.SavePicture(aPictureName)
-                                aVISUObjList.append(aPrsObj)
+                                else :
+                                    print ",OK"
+                                    aPrsObj.SetOrientation(VISU.CutPlanes.XY,aPrsObj.GetRotateX(),aPrsObj.GetRotateY())
+                                    aPrsObj.SetOrientation2(VISU.CutPlanes.ZX,aPrsObj.GetRotateX2(),aPrsObj.GetRotateY2())
+                                    theView.DisplayOnly(aPrsObj)
+                                    theView.FitAll()
+                                    aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TCUTLINES." + thePictureExt
+                                    aPictureName = re.sub("\s+","_", aPictureName)
+                                    theView.SavePicture(aPictureName)
+                                    if theIsAutoDelete :
+                                       aPrsObj.RemoveFromStudy()
+                                    else :
+                                        aVISUObjList.append(aPrsObj)
+                                
+                            if HasValue(thePrsTypeList,VISU.TCUTSEGMENT) :
+                                print "          Creating CutSegmentOnField",
+                                aPrsObj = theVisu.CutSegmentOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
+                                if aPrsObj is None : print "Error"
+                                else :
+                                    print ",OK"
+                                    theView.DisplayOnly(aPrsObj)
+                                    theView.FitAll()
+                                    aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TCUTSEGMENT." + thePictureExt
+                                    aPictureName = re.sub("\s+","_", aPictureName)
+                                    theView.SavePicture(aPictureName)
+                                    if theIsAutoDelete :
+                                       aPrsObj.RemoveFromStudy()
+                                    else :
+                                        aVISUObjList.append(aPrsObj)
+                                
+                            if HasValue(thePrsTypeList,VISU.TPLOT3D) :
+                                print "          Creating Plot3DOnField",
+                                aPrsObj = theVisu.Plot3DOnField(theResult,aMeshName,anEntity,
+                                                                aFieldName,aTimeStampId)
+                                if aPrsObj is None : print "Error"
+                                else :
+                                    print ",OK"
+                                #aPrsObj.SetOrientation(VISU.CutPlanes.ZX,
+                                #                       aPrsObj.GetRotateX(),
+                                #                       aPrsObj.GetRotateY())
+                                    theView.DisplayOnly(aPrsObj)
+                                    theView.FitAll()
+                                    aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TPLOT3D." + thePictureExt
+                                    aPictureName = re.sub("\s+","_", aPictureName)
+                                    theView.SavePicture(aPictureName)
+                                    if theIsAutoDelete :
+                                       aPrsObj.RemoveFromStudy()
+                                    else :
+                                        aVISUObjList.append(aPrsObj)
                                 
                             aNumComponent = atoi(aMap["myNumComponent"])
                             if aNumComponent > 1 :
@@ -536,44 +625,92 @@ def CreatePrsForResult(theVisu, theResult, theView, thePrsTypeList, thePictureDi
                                     print "          Creating DeformedShapeOnField",
                                     aPrsObj = theVisu.DeformedShapeOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
                                     if aPrsObj is None : print "Error"
-                                    else : print ",OK"
-                                    theView.DisplayOnly(aPrsObj)
-                                    theView.FitAll()
-                                    aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TDEFORMEDSHAPE." + thePictureExt
-                                    aPictureName = re.sub("\s+","_", aPictureName)
-                                    theView.SavePicture(aPictureName)
-                                    aVISUObjList.append(aPrsObj)
+                                    else :
+                                        print ",OK"
+                                        theView.DisplayOnly(aPrsObj)
+                                        theView.FitAll()
+                                        aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TDEFORMEDSHAPE." + thePictureExt
+                                        aPictureName = re.sub("\s+","_", aPictureName)
+                                        theView.SavePicture(aPictureName)
+                                        if theIsAutoDelete :
+                                            aPrsObj.RemoveFromStudy()
+                                        else :
+                                            aVISUObjList.append(aPrsObj)
 
                                 if HasValue(thePrsTypeList,VISU.TVECTORS) :
                                     print "          Creating VectorsOnField",
                                     aPrsObj = theVisu.VectorsOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
                                     if aPrsObj is None : print "Error"
-                                    else : print ",OK"
-                                    theView.DisplayOnly(aPrsObj)
-                                    theView.FitAll()
-                                    aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TVECTORS." + thePictureExt
-                                    aPictureName = re.sub("\s+","_", aPictureName)
-                                    theView.SavePicture(aPictureName)
-                                    aVISUObjList.append(aPrsObj)
+                                    else :
+                                        print ",OK"
+                                        theView.DisplayOnly(aPrsObj)
+                                        theView.FitAll()
+                                        aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TVECTORS." + thePictureExt
+                                        aPictureName = re.sub("\s+","_", aPictureName)
+                                        theView.SavePicture(aPictureName)
+                                        if theIsAutoDelete :
+                                            aPrsObj.RemoveFromStudy()
+                                        else :
+                                            aVISUObjList.append(aPrsObj)
                                     
                                 if HasValue(thePrsTypeList,VISU.TSTREAMLINES) :
                                     print "          Creating StreamLinesOnField",
                                     aPrsObj = theVisu.StreamLinesOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
                                     if aPrsObj is None : print "Error"
-                                    else : print ",OK"
-                                    theView.DisplayOnly(aPrsObj)
-                                    theView.FitAll()
-                                    aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TSTREAMLINES." + thePictureExt
-                                    aPictureName = re.sub("\s+","_", aPictureName)
-                                    theView.SavePicture(aPictureName)
-                                    aVISUObjList.append(aPrsObj)
-                    
+                                    else :
+                                        print ",OK"
+                                        theView.DisplayOnly(aPrsObj)
+                                        theView.FitAll()
+                                        aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TSTREAMLINES." + thePictureExt
+                                        aPictureName = re.sub("\s+","_", aPictureName)
+                                        theView.SavePicture(aPictureName)
+                                        if theIsAutoDelete :
+                                            aPrsObj.RemoveFromStudy()
+                                        else :
+                                            aVISUObjList.append(aPrsObj)
+
+                                if HasValue(thePrsTypeList,VISU.TSCALARMAPONDEFORMEDSHAPE) or HasValue(thePrsTypeList,VISU.TDEFORMEDSHAPEANDSCALARMAP) :
+                                    print "          Creating DeformedShapeAndScalarMapOnField",
+                                    aPrsObj = theVisu.DeformedShapeAndScalarMapOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
+                                    if aPrsObj is None : print "Error"
+                                    else :
+                                        print ",OK"
+                                        theView.DisplayOnly(aPrsObj)
+                                        theView.FitAll()
+                                        aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TDEFORMEDSHAPEANDSCALARMAP." + thePictureExt
+                                        aPictureName = re.sub("\s+","_", aPictureName)
+                                        theView.SavePicture(aPictureName)
+                                        if theIsAutoDelete :
+                                            aPrsObj.RemoveFromStudy()
+                                        else :
+                                            aVISUObjList.append(aPrsObj)
+
+                                if HasValue(thePrsTypeList,VISU.TGAUSSPOINTS) :
+                                    print "          Creating GaussPointsOnField",
+                                    aPrsObj = theVisu.GaussPointsOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
+                                    if aPrsObj is None : print "Error"
+                                    else :
+                                        print ",OK"
+                                        theView.DisplayOnly(aPrsObj)
+                                        theView.FitAll()
+                                        aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TGAUSSPOINTS." + thePictureExt
+                                        aPictureName = re.sub("\s+","_", aPictureName)
+                                        theView.SavePicture(aPictureName)
+                                        if theIsAutoDelete :
+                                            aPrsObj.RemoveFromStudy()
+                                            pass
+                                        else :
+                                            aVISUObjList.append(aPrsObj)
+                                            pass
+                                        pass
+                                    pass
+                                
     return aVISUObjList
 
 
 def generateName(prefix = None):
-    import whrandom;
-    int = whrandom.randint(1,1000);
+    import random;
+    int = random.randint(1,1000);
     if prefix is None:
         return "Study" + str(int)
     else :
@@ -708,7 +845,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
 
@@ -803,6 +940,36 @@ def dump_cutlines_parameters(theObject):
     print "GetRotateY() = ", str(theObject.GetRotateY())
     print "GetRotateY2() = ", str(theObject.GetRotateY2())
 
+# ----------------------
+# CUT SEGMENT
+# ----------------------
+def try_cutsegment_parameters(thePattern):
+
+    if thePattern  is None : return None 
+    import copy
+    import random
+
+    anObj = try_scalarmap_parameters(thePattern)
+
+    anObj.SetPoint1(random.randint(-100,100)*random.random(),
+                    random.randint(-100,100)*random.random(),
+                    random.randint(-100,100)*random.random())
+    anObj.SetPoint2(random.randint(-100,100)*random.random(),
+                    random.randint(-100,100)*random.random(),
+                    random.randint(-100,100)*random.random())
+
+    return anObj
+
+def dump_cutsegment_parameters(theObject):
+    dump_scalarmap_parameters(theObject)
+
+    x1 = y1 = z1 = 0
+    x2 = y2 = z2 = 0
+    theObject.GetPoint1(x1, y1, z1)
+    theObject.GetPoint1(x2, y2, z2)
+    print "GetPoint1() = " + str(x1) + ", " + str(y1) + ", " + str(z1)
+    print "GetPoint2() = " + str(x2) + ", " + str(y2) + ", " + str(z2)
+
 # ----------------------
 # STREAM LINES
 # ----------------------
@@ -877,7 +1044,7 @@ def try_vectors_parameters(thePattern, theNum):
     
     return anObj
 
-def dump_vetctors_parameters(theObject):
+def dump_vectors_parameters(theObject):
     
     dump_deformedshape_parameters(theObject)
     
@@ -909,3 +1076,153 @@ def dump_isosurfaces_parameters(theObject):
     
     dump_scalarmap_parameters(theObject)
     print "GetNbSurfaces() = "+ str(theObject.GetNbSurfaces())
+
+# ----------------------------
+# SCALAR MAP ON DEFORMED SHAPE
+# ----------------------------
+def dump_scalarmapondeformedshape_parameters(theObject):
+    dump_scalarmap_parameters(theObject)
+    print "GetScale()          =", theObject.GetScale()
+    print "GetScalarCMeshName ()=|",theObject.GetScalarCMeshName(),"|"
+    print "GetScalarCFieldName()=|",theObject.GetScalarCFieldName(),"|"
+    print "GetScalarEEntity()   =",theObject.GetScalarEEntity()
+    print "GetScalarLIteration()=",theObject.GetScalarLIteration()
+    pass
+
+def try_scalarmapondeformedshape_parameters(thePattern):
+
+    if thePattern  is None : return None 
+    import copy
+    import random
+
+    anObj = try_scalarmap_parameters(thePattern)
+
+    # --- SCALING ---
+    print 
+    anObj.SetScale( anObj.GetScale()/random.random()*random.randint(1,10))
+
+    # --- Scalar Field ---
+    # not implemented yet.
+    
+    return anObj
+# ----------------------
+# PLOT 3D 
+# ----------------------
+def dump_plot3d_parameters(theObject):
+    dump_scalarmap_parameters(theObject)
+    print "GetOrientationType()=",str(theObject.GetOrientationType())
+    print "GetRotateX()=",theObject.GetRotateX()
+    print "GetRotateY()=",theObject.GetRotateY()
+    print "GetPlanePosition()=",theObject.GetPlanePosition()
+    print "IsPositionRelative()=",theObject.IsPositionRelative()
+    print "GetScaleFactor()=",theObject.GetScaleFactor()
+    print "GetIsContourPrs()=",theObject.GetIsContourPrs()
+    print "GetNbOfContours()=",theObject.GetNbOfContours()
+    pass
+
+def try_plot3d_parameters(thePattern):
+    if thePattern is None : return None
+    import random
+    
+    anObj = try_scalarmap_parameters(thePattern)
+
+    ORIENT = [VISU.Plot3D.XY, VISU.Plot3D.YZ, VISU.Plot3D.ZX]
+
+    theXAngle = random.random()*random.randint(-180,180)
+    theYAngle = random.random()*random.randint(-180,180)
+
+    # ORIENTATION and ANGLES
+    anObj.SetOrientation(ORIENT[random.randint(0,2)],theXAngle,theYAngle)
+
+    # Plane position (revative)
+    anObj.SetPlanePosition(random.random(),1)
+
+    # SCALE FACTOR
+    anObj.SetScaleFactor(random.random()*random.randint(-10000,10000))
+
+    # CONTOUR PRS
+    anObj.SetContourPrs(random.randint(0,1))
+    if anObj.GetIsContourPrs():
+        anObj.SetNbOfContours(random.randint(1,999))
+        pass
+    
+    pass
+
+# ----------------------
+# Gauss points
+# ----------------------
+def dump_gausspoints_parameters(theObject):
+    
+    print "\tGetScalarMode() = " + str(anObj.GetScalarMode())
+    print "\tGetMin() = " + str(anObj.GetMin()) + "  GetMax() = " + str (anObj.GetMax())
+    print "\tGetPosX() = ", str(anObj.GetPosX()) + "  GetPosY() = ", str(anObj.GetPosY())
+    print "\tGetWidth() = ", str ( anObj.GetWidth()) + "  GetHeight() = " + str(anObj.GetHeight())
+    print "\tGetNbColors() = " + str(anObj.GetNbColors())
+    print "\tGetLabels() = " + str(anObj.GetLabels())
+    print "\tGetTitle() = " + str(anObj.GetTitle())
+    pass
+
+def try_plot3d_parameters(thePattern):
+    if thePattern is None : return None
+    import random
+    
+    pass
+
+# ----------------------
+# TABLES AND CURVES
+# ----------------------
+
+def FillTable( theTable, theValues, theRows, theColumns, theRowTitles, theRowUnits, theColumnTitles ):
+    if theTable is None: return
+    if len(theRows) != len(theColumns): return
+    if len(theRows) != len(theValues): return
+    i = 0
+    for value in theValues:
+        theTable.PutValue( value, theRows[ i ], theColumns[ i ])
+        i = i + 1
+        pass
+    i = 1
+    for title in theRowTitles:
+        theTable.SetRowTitle( i, title )
+        theTable.SetRowUnit( i, theRowUnits[ i - 1 ])
+        i = i + 1
+        pass
+    i = 1
+    for title in theColumnTitles:
+        theTable.SetColumnTitle( i, title )
+        i = i + 1
+        pass
+    pass
+
+def CreateCurve( theTable, theHRow, theVRow, theTitle, theColor, theMarker, theLineType, theLineWidth ):
+    if theTitle is None: return
+    curve = myLocalVisu.CreateCurve( theTable, theHRow, theVRow );
+    if curve:
+        curve.SetTitle( theTitle )
+        curve.SetColor( theColor )
+        curve.SetMarker( theMarker )
+        curve.SetLine( theLineType, theLineWidth )
+        pass
+    return curve
+
+def CreateCurveWithZ( theTable, theHRow, theVRow, theZRow, theTitle, theColor, theMarker, theLineType, theLineWidth ):
+    if theTitle is None: return
+    curve = myLocalVisu.CreateCurveWithZ( theTable, theHRow, theVRow, theZRow );
+    if curve:
+        curve.SetTitle( theTitle )
+        curve.SetColor( theColor )
+        curve.SetMarker( theMarker )
+        curve.SetLine( theLineType, theLineWidth )
+        pass
+    return curve
+
+def CreateCurveWithZExt( theTable, theHRow, theVRow, theZRow, theIsV2, theTitle, theColor, theMarker, theLineType, theLineWidth ):
+    if theTitle is None: return
+    curve = myLocalVisu.CreateCurveWithZExt( theTable, theHRow, theVRow, theZRow, theIsV2 );
+    if curve:
+        curve.SetTitle( theTitle )
+        curve.SetColor( theColor )
+        curve.SetMarker( theMarker )
+        curve.SetLine( theLineType, theLineWidth )
+        pass
+    return curve