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
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)
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
# 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
salome_study_ID = -1
-def getActiveStudy():
+def getActiveStudy(theStudyId=0):
global salome_study_ID
print "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
#--------------------------------------------------------------------------
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
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()