]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
PR: behavior improvment outside GUI, some comments added
authorprascle <prascle>
Wed, 26 Jan 2005 12:17:41 +0000 (12:17 +0000)
committerprascle <prascle>
Wed, 26 Jan 2005 12:17:41 +0000 (12:17 +0000)
src/SALOME_SWIG_WITHOUTIHM/salome.py
src/SALOME_SWIG_WITHOUTIHM/salome_iapp.py
src/SALOME_SWIG_WITHOUTIHM/salome_kernel.py
src/SALOME_SWIG_WITHOUTIHM/salome_study.py

index 5591226dd2535a6740e51a8ca244504608f9eb4f..e8d5d5bacaae82df26cc3eed8493f570df448af4 100755 (executable)
@@ -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)
 
index 519714a086ecbb4223e55df486cdd11f4e3a7887..befa0d075dca54e31a45a7ba1710cfc360cd3d6a 100644 (file)
@@ -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
index 93be05fb16ea23a76c916b304a117ca4e4379370..40fe9e124efb750f9fc58cbac163c5b270cc8c8c 100644 (file)
@@ -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
index 3fa7fb12bfe16f74e5b7904627c932307db0214d..cf5b304b98b02aabac2d57fcf7c0743c5f2694d5 100644 (file)
@@ -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()