From 7a5ee2daa4c654c69531598959f75a18b339ff3b Mon Sep 17 00:00:00 2001 From: vsr Date: Mon, 17 Mar 2014 12:52:50 +0400 Subject: [PATCH] Fix single study problem in Python API - add methods to finalize current study - finalize study from GUI when it is closed or unloaded --- src/KERNEL_PY/__init__.py | 11 ++++++++++- src/KERNEL_PY/salome_iapp.py | 7 +++++++ src/KERNEL_PY/salome_kernel.py | 5 +++++ src/KERNEL_PY/salome_study.py | 30 +++++++++++++----------------- 4 files changed, 35 insertions(+), 18 deletions(-) mode change 100644 => 100755 src/KERNEL_PY/__init__.py mode change 100644 => 100755 src/KERNEL_PY/salome_iapp.py mode change 100644 => 100755 src/KERNEL_PY/salome_kernel.py mode change 100644 => 100755 src/KERNEL_PY/salome_study.py diff --git a/src/KERNEL_PY/__init__.py b/src/KERNEL_PY/__init__.py old mode 100644 new mode 100755 index de2c86de3..da81c5ad9 --- a/src/KERNEL_PY/__init__.py +++ b/src/KERNEL_PY/__init__.py @@ -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() diff --git a/src/KERNEL_PY/salome_iapp.py b/src/KERNEL_PY/salome_iapp.py old mode 100644 new mode 100755 index 2faa4fab9..dcea86988 --- a/src/KERNEL_PY/salome_iapp.py +++ b/src/KERNEL_PY/salome_iapp.py @@ -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 + + diff --git a/src/KERNEL_PY/salome_kernel.py b/src/KERNEL_PY/salome_kernel.py old mode 100644 new mode 100755 index 9ab94c9f9..65602bca4 --- a/src/KERNEL_PY/salome_kernel.py +++ b/src/KERNEL_PY/salome_kernel.py @@ -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 diff --git a/src/KERNEL_PY/salome_study.py b/src/KERNEL_PY/salome_study.py old mode 100644 new mode 100755 index 49398828d..24a676314 --- a/src/KERNEL_PY/salome_study.py +++ b/src/KERNEL_PY/salome_study.py @@ -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 -- 2.39.2