From 53758e972d01fc912801c4085ea39339e391c352 Mon Sep 17 00:00:00 2001 From: prascle Date: Wed, 26 Jan 2005 12:17:41 +0000 Subject: [PATCH] PR: behavior improvment outside GUI, some comments added --- src/SALOME_SWIG_WITHOUTIHM/salome.py | 27 +++++++++++++++++---- src/SALOME_SWIG_WITHOUTIHM/salome_iapp.py | 2 +- src/SALOME_SWIG_WITHOUTIHM/salome_kernel.py | 4 +-- src/SALOME_SWIG_WITHOUTIHM/salome_study.py | 26 ++++++++++++++++---- 4 files changed, 46 insertions(+), 13 deletions(-) diff --git a/src/SALOME_SWIG_WITHOUTIHM/salome.py b/src/SALOME_SWIG_WITHOUTIHM/salome.py index 5591226dd..e8d5d5bac 100755 --- a/src/SALOME_SWIG_WITHOUTIHM/salome.py +++ b/src/SALOME_SWIG_WITHOUTIHM/salome.py @@ -29,7 +29,27 @@ from salome_study import * from salome_iapp import * salome_initial=1 -def salome_init(): +def salome_init(theStudyId=0): + """ + Performs only once SALOME general purpose intialisation for scripts. + optional argument : theStudyId + When in embedded interpreter inside IAPP, theStudyId is not used + When used without GUI (external interpreter) + 0 : create a new study (default). + n (>0) : try connection to study with Id = n, or create a new one + if study not found. + If study creation, its Id may be different from theStudyId ! + Provides: + orb reference to CORBA + lcc a LifeCycleCorba instance + naming_service a naming service instance + cm reference to the container manager + sg access to SALOME GUI (when linked with IAPP GUI) + myStudyManager the study manager + myStudyId active study identifier + myStudy active study itself (CORBA reference) + myStudyName active study name + """ global salome_initial global orb, lcc, naming_service, cm global sg @@ -38,9 +58,6 @@ def salome_init(): if salome_initial: salome_initial=0 sg = salome_iapp_init() - if not sg.hasDesktop(): - print "import salome_shared_modules once" - import salome_shared_modules orb, lcc, naming_service, cm = salome_kernel_init() - myStudyManager, myStudyId, myStudy, myStudyName =salome_study_init() + myStudyManager, myStudyId, myStudy, myStudyName =salome_study_init(theStudyId) diff --git a/src/SALOME_SWIG_WITHOUTIHM/salome_iapp.py b/src/SALOME_SWIG_WITHOUTIHM/salome_iapp.py index 519714a08..befa0d075 100644 --- a/src/SALOME_SWIG_WITHOUTIHM/salome_iapp.py +++ b/src/SALOME_SWIG_WITHOUTIHM/salome_iapp.py @@ -68,7 +68,7 @@ def salome_iapp_init(): if salome_iapp_initial: salome_iapp_initial=0 - # create an SALOMEGUI_Swig instance + # create a SALOMEGUI_Swig instance sg = SalomeGUI() IN_SALOME_GUI=sg.hasDesktop() return sg diff --git a/src/SALOME_SWIG_WITHOUTIHM/salome_kernel.py b/src/SALOME_SWIG_WITHOUTIHM/salome_kernel.py index 93be05fb1..40fe9e124 100644 --- a/src/SALOME_SWIG_WITHOUTIHM/salome_kernel.py +++ b/src/SALOME_SWIG_WITHOUTIHM/salome_kernel.py @@ -42,10 +42,10 @@ def salome_kernel_init(): # initialise the ORB orb = CORBA.ORB_init([''], CORBA.ORB_ID) - # create an LifeCycleCORBA instance + # create a LifeCycleCORBA instance lcc = LifeCycleCORBA(orb) - #create an naming service instance + #create a naming service instance naming_service = SALOME_NamingServicePy_i(orb) # get Container Manager diff --git a/src/SALOME_SWIG_WITHOUTIHM/salome_study.py b/src/SALOME_SWIG_WITHOUTIHM/salome_study.py index 3fa7fb12b..cf5b304b9 100644 --- a/src/SALOME_SWIG_WITHOUTIHM/salome_study.py +++ b/src/SALOME_SWIG_WITHOUTIHM/salome_study.py @@ -104,7 +104,7 @@ def IDToSObject(id): salome_study_ID = -1 -def getActiveStudy(): +def getActiveStudy(theStudyId=0): global salome_study_ID print "getActiveStudy" @@ -115,8 +115,14 @@ def getActiveStudy(): salome_study_ID = sg.getActiveStudyId() else: print "---outside gui" - salome_study_ID = createNewStudy() - print"---", salome_study_ID + if theStudyId: + aStudy=myStudyManager.GetStudyByID(theStudyId) + if aStudy: + print "connection to existing study ", theStudyId + salome_study_ID = theStudyId + if salome_study_ID == -1: + salome_study_ID = createNewStudy() + print"--- Study Id ", salome_study_ID return salome_study_ID #-------------------------------------------------------------------------- @@ -144,7 +150,17 @@ 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 + When in embedded interpreter inside IAPP, theStudyId is not used + When used without GUI (external interpreter) + 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 salome_study_initial global myStudyManager, myStudyId, myStudy, myStudyName global orb, lcc, naming_service, cm @@ -161,7 +177,7 @@ def salome_study_init(): print "studyManager found" # get active study Id, ref and name - myStudyId = getActiveStudy() + myStudyId = getActiveStudy(theStudyId) print "myStudyId",myStudyId myStudy = myStudyManager.GetStudyByID(myStudyId) myStudyName = myStudy._get_Name() -- 2.39.2