]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
Fix single study problem in Python API
authorvsr <vsr@opencascade.com>
Mon, 17 Mar 2014 08:52:50 +0000 (12:52 +0400)
committervsr <vsr@opencascade.com>
Mon, 17 Mar 2014 08:52:50 +0000 (12:52 +0400)
- add methods to finalize current study
- finalize study from GUI when it is closed or unloaded

src/KERNEL_PY/__init__.py [changed mode: 0644->0755]
src/KERNEL_PY/salome_iapp.py [changed mode: 0644->0755]
src/KERNEL_PY/salome_kernel.py [changed mode: 0644->0755]
src/KERNEL_PY/salome_study.py [changed mode: 0644->0755]

old mode 100644 (file)
new mode 100755 (executable)
index de2c86d..da81c5a
@@ -221,7 +221,7 @@ def salome_init(theStudyId=0,embedded=0):
             salome_initial=0
             sg = salome_iapp_init(embedded)
             orb, lcc, naming_service, cm = salome_kernel_init()
-            myStudyManager, myStudyId, myStudy, myStudyName =salome_study_init()
+            myStudyManager, myStudyId, myStudy, myStudyName =salome_study_init(theStudyId)
             pass
         pass
     except RuntimeError, inst:
@@ -239,5 +239,14 @@ def salome_init(theStudyId=0,embedded=0):
         """
         raise
 
+def salome_close():
+    global salome_initial
+    salome_initial=1
+    salome_iapp_close()
+    salome_kernel_close()
+    salome_study_close()
+    pass
+
+
 #to expose all objects to pydoc
 __all__=dir()
old mode 100644 (file)
new mode 100755 (executable)
index 2faa4fa..dcea869
@@ -180,3 +180,10 @@ def salome_iapp_init(embedded):
             sg=SalomeOutsideGUI()
             IN_SALOME_GUI=0
     return sg
+
+def salome_iapp_close():
+    global salome_iapp_initial
+    salome_iapp_initial=1
+    pass
+
+
old mode 100644 (file)
new mode 100755 (executable)
index 9ab94c9..65602bc
@@ -55,3 +55,8 @@ def salome_kernel_init():
         cm = obj._narrow(Engines.ContainerManager)
 
     return orb, lcc, naming_service, cm
+
+def salome_kernel_close():
+    global salome_kernel_initial
+    salome_kernel_initial=1
+    pass
old mode 100644 (file)
new mode 100755 (executable)
index 4939882..24a6763
@@ -269,7 +269,7 @@ def FindFileInDataDir(filename):
 
 salome_study_ID = -1
 
-def getActiveStudy():
+def getActiveStudy(theStudyId=0):
     global salome_study_ID
 
     if verbose(): print "getActiveStudy"
@@ -279,20 +279,13 @@ def getActiveStudy():
             salome_study_ID = salome_iapp.sg.getActiveStudyId()
         else:
             if verbose(): print "---outside gui"
+            if theStudyId:
+                aStudy=myStudyManager.GetStudyByID(theStudyId)
+                if aStudy:
+                    if verbose(): print "connection to existing study ", theStudyId
+                    salome_study_ID = theStudyId
             if salome_study_ID == -1:
-              listOpenStudies = myStudyManager.GetOpenStudies()
-              if len(listOpenStudies) == 0:
                 salome_study_ID = createNewStudy()
-              else:
-                s = myStudyManager.GetStudyByName(listOpenStudies[0])
-                salome_study_ID = s._get_StudyId()
-            else:
-              pass
-            #if theStudyId:
-                #aStudy=myStudyManager.GetStudyByID(theStudyId)
-                #if aStudy:
-                    #if verbose(): print "connection to existing study ", theStudyId
-                    #salome_study_ID = theStudyId
             if verbose(): print"--- Study Id ", salome_study_ID
     return salome_study_ID
 
@@ -339,8 +332,6 @@ def createNewStudy():
     aStudyName = "noName"
     nameAlreadyInUse = 1
     listOfOpenStudies = myStudyManager.GetOpenStudies()
-    if len(listOfOpenStudies) != 0:
-      raise ValueError("There is already an opened study: %s" % listOfOpenStudies[0])
     print listOfOpenStudies
     while nameAlreadyInUse:
         aStudyName = "extStudy_%d"%i
@@ -358,7 +349,7 @@ def createNewStudy():
 
 salome_study_initial = 1
 
-def salome_study_init():
+def salome_study_init(theStudyId=0):
     """
     Performs only once study creation or connection.
     optional argument : theStudyId
@@ -385,10 +376,15 @@ def salome_study_init():
         if verbose(): print "studyManager found"
 
         # get active study Id, ref and name
-        myStudyId = getActiveStudy()
+        myStudyId = getActiveStudy(theStudyId)
         if verbose(): print "myStudyId",myStudyId
         myStudy = myStudyManager.GetStudyByID(myStudyId)
         myStudyName = myStudy._get_Name()
 
     return myStudyManager, myStudyId, myStudy, myStudyName
 
+def salome_study_close():
+    global salome_study_initial, salome_study_ID
+    salome_study_initial=1
+    salome_study_ID=-1
+    pass