From: caremoli Date: Wed, 19 Jan 2011 15:51:49 +0000 (+0000) Subject: CCAR: add two function to salome package to change current study in external X-Git-Tag: Start_BR_19998_21191~98 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=7128e10c7e4db47fe4c90517b7fc9c58e3896128;p=modules%2Fkernel.git CCAR: add two function to salome package to change current study in external python interpreter (setCurrentStudyId(theId=0) and setCurrentStudy(theStudy)) --- diff --git a/src/KERNEL_PY/__init__.py b/src/KERNEL_PY/__init__.py index 2c8755ecd..ada702d71 100644 --- a/src/KERNEL_PY/__init__.py +++ b/src/KERNEL_PY/__init__.py @@ -124,6 +124,7 @@ extend_path(ROOT_PYTHONPACKAGE_NAME) from salome_kernel import * from salome_study import * from salome_iapp import * +import salome_study # # The next block is workaround for the problem of shared symbols loading for the extension modules (e.g. SWIG-generated) @@ -164,6 +165,27 @@ if flags: orb, lcc, naming_service, cm,sg=None,None,None,None,None myStudyManager, myStudyId, myStudy, myStudyName=None,None,None,None +def setCurrentStudy(theStudy): + """ + Change current study : an existing one given by a study object. + + :param theStudy: the study CORBA object to set as current study + """ + global myStudyId, myStudy, myStudyName + myStudyId, myStudy, myStudyName =salome_study.setCurrentStudy(theStudy) + +def setCurrentStudyId(theStudyId=0): + """ + Change current study : an existing or new one given by Id. + + :param theStudyId: the study Id (optional argument) + 0 : create a new study (default). + n (>0) : try connection to study with Id = n, or create a new one + if study not found. + """ + global myStudyId, myStudy, myStudyName + myStudyId, myStudy, myStudyName =salome_study.setCurrentStudyId(theStudyId) + salome_initial=1 def salome_init(theStudyId=0,embedded=0): """ diff --git a/src/KERNEL_PY/salome_study.py b/src/KERNEL_PY/salome_study.py index 9cd9e8a44..00676ffbc 100644 --- a/src/KERNEL_PY/salome_study.py +++ b/src/KERNEL_PY/salome_study.py @@ -250,7 +250,7 @@ salome_study_ID = -1 def getActiveStudy(theStudyId=0): global salome_study_ID - + if verbose(): print "getActiveStudy" if salome_study_ID == -1: if salome_iapp.hasDesktop(): @@ -267,7 +267,42 @@ def getActiveStudy(theStudyId=0): salome_study_ID = createNewStudy() if verbose(): print"--- Study Id ", salome_study_ID return salome_study_ID - + + #-------------------------------------------------------------------------- + +def setCurrentStudy(theStudy): + """ + Change current study : an existing one given by a study object. + + :param theStudy: the study CORBA object to set as current study + """ + global myStudyId, myStudy, myStudyName + global salome_study_ID + myStudy=theStudy + myStudyId=theStudy._get_StudyId() + myStudyName=theStudy._get_Name() + return myStudyId, myStudy, myStudyName + + #-------------------------------------------------------------------------- + +def setCurrentStudyId(theStudyId=0): + """ + Change current study : an existing or new one. + optional argument : theStudyId + 0 : create a new study (default). + n (>0) : try connection to study with Id = n, or create a new one + if study not found. + """ + global myStudyId, myStudy, myStudyName + global salome_study_ID + salome_study_ID = -1 + myStudyId = getActiveStudy(theStudyId) + if verbose(): print "myStudyId",myStudyId + myStudy = myStudyManager.GetStudyByID(myStudyId) + myStudyName = myStudy._get_Name() + + return myStudyId, myStudy, myStudyName + #-------------------------------------------------------------------------- def createNewStudy(): @@ -303,16 +338,16 @@ def salome_study_init(theStudyId=0): n (>0) : try connection to study with Id = n, or create a new one if study not found. """ - + global salome_study_initial global myStudyManager, myStudyId, myStudy, myStudyName global orb, lcc, naming_service, cm - + if salome_study_initial: salome_study_initial = 0 - + orb, lcc, naming_service, cm = salome_kernel.salome_kernel_init() - + # get Study Manager reference if verbose(): print "looking for studyManager ..." obj = naming_service.Resolve('myStudyManager')