Salome HOME
Removed references to OCC
[modules/kernel.git] / src / KERNEL_PY / salome.py
1 #  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 #  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
3
4 #  This library is free software; you can redistribute it and/or 
5 #  modify it under the terms of the GNU Lesser General Public 
6 #  License as published by the Free Software Foundation; either 
7 #  version 2.1 of the License. 
8
9 #  This library is distributed in the hope that it will be useful, 
10 #  but WITHOUT ANY WARRANTY; without even the implied warranty of 
11 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
12 #  Lesser General Public License for more details. 
13
14 #  You should have received a copy of the GNU Lesser General Public 
15 #  License along with this library; if not, write to the Free Software 
16 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
17
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #
20 #
21 #
22 #  File   : salome.py
23 #  Author : Paul RASCLE, EDF
24 #  Module : SALOME
25 #  $Header$
26 """
27 Module salome gives access to Salome ressources.
28
29 variables:
30
31   salome.orb             : CORBA
32   salome.naming_service  : instance of naming Service class
33       methods:
34           Resolve(name)  : find a CORBA object (ior) by its pathname
35           Register(name) : register a CORBA object under a pathname
36   salome.lcc             : instance of lifeCycleCORBA class
37       methods:
38           FindOrLoadComponent(server,name) :
39                            obtain an Engine (CORBA object)
40                            or launch the Engine if not found,
41                            with a Server name and an Engine name
42   salome.sg
43       methods:
44          updateObjBrowser(bool):
45          getActiveStudyId():
46          getActiveStudyName():
47
48          SelectedCount():      returns number of selected objects
49          getSelected(i):       returns entry of selected object number i
50          getAllSelected():     returns list of entry of selected objects
51          AddIObject(Entry):    select an existing Interactive object
52          RemoveIObject(Entry): remove object from selection
53          ClearIObjects():      clear selection
54
55          Display(*Entry):
56          DisplayOnly(Entry):
57          Erase(Entry):
58          DisplayAll():
59          EraseAll():
60
61          IDToObject(Entry):    returns CORBA reference from entry
62
63   salome.myStudyName     : active Study Name
64   salome.myStudyId       : active Study Id
65   salome.myStudy         : the active Study itself (CORBA ior)
66                            methods : defined in SALOMEDS.idl
67
68 """
69
70 from salome_kernel import *
71 from salome_study import *
72 from salome_iapp import *
73
74 orb, lcc, naming_service, cm,sg=None,None,None,None,None
75 myStudyManager, myStudyId, myStudy, myStudyName=None,None,None,None
76
77 salome_initial=1
78 def salome_init(theStudyId=0,embedded=0):
79     """
80     Performs only once SALOME general purpose intialisation for scripts.
81     optional argument : theStudyId
82       When in embedded interpreter inside IAPP, theStudyId is not used
83       When used without GUI (external interpreter)
84         0      : create a new study (default).
85         n (>0) : try connection to study with Id = n, or create a new one
86                  if study not found.
87                  If study creation, its Id may be different from theStudyId !
88     Provides:
89     orb             reference to CORBA
90     lcc             a LifeCycleCorba instance
91     naming_service  a naming service instance
92     cm              reference to the container manager
93     sg              access to SALOME GUI (when linked with IAPP GUI)
94     myStudyManager  the study manager
95     myStudyId       active study identifier
96     myStudy         active study itself (CORBA reference)
97     myStudyName     active study name
98     """
99     global salome_initial
100     global orb, lcc, naming_service, cm
101     global sg
102     global myStudyManager, myStudyId, myStudy, myStudyName
103
104     try:
105         if salome_initial:
106             salome_initial=0
107             sg = salome_iapp_init(embedded)
108             orb, lcc, naming_service, cm = salome_kernel_init()
109             myStudyManager, myStudyId, myStudy, myStudyName =salome_study_init(theStudyId)
110             pass
111         pass
112     except RuntimeError, inst:
113         # wait a little to avoid trace mix
114         import time
115         time.sleep(0.2)
116         x = inst
117         print "salome.salome_init():", x
118         print """
119         ============================================
120         May be there is no running SALOME session
121         salome.salome_init() is intented to be used
122         within an already running session
123         ============================================
124         """
125         raise
126
127 #to expose all objects to pydoc
128 __all__=dir()