From: Paul RASCLE Date: Fri, 7 Mar 2014 13:40:24 +0000 (+0100) Subject: avoid creating several studies from Python X-Git-Tag: V7_3_1rc2^0 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=0ba5d6883e3f014a15d108a07fa24da37af3a887;p=modules%2Fkernel.git avoid creating several studies from Python --- diff --git a/src/KERNEL_PY/__init__.py b/src/KERNEL_PY/__init__.py index 166446a04..de2c86de3 100644 --- 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(theStudyId) + myStudyManager, myStudyId, myStudy, myStudyName =salome_study_init() pass pass except RuntimeError, inst: diff --git a/src/KERNEL_PY/salome_study.py b/src/KERNEL_PY/salome_study.py index 02dc26a43..49398828d 100644 --- 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(theStudyId=0): +def getActiveStudy(): global salome_study_ID if verbose(): print "getActiveStudy" @@ -279,13 +279,20 @@ def getActiveStudy(theStudyId=0): 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 @@ -332,6 +339,8 @@ 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 @@ -349,7 +358,7 @@ def createNewStudy(): salome_study_initial = 1 -def salome_study_init(theStudyId=0): +def salome_study_init(): """ Performs only once study creation or connection. optional argument : theStudyId @@ -376,7 +385,7 @@ def salome_study_init(theStudyId=0): if verbose(): print "studyManager found" # get active study Id, ref and name - myStudyId = getActiveStudy(theStudyId) + myStudyId = getActiveStudy() if verbose(): print "myStudyId",myStudyId myStudy = myStudyManager.GetStudyByID(myStudyId) myStudyName = myStudy._get_Name()