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