Salome HOME
Merge branch 'V8_5_BR'
[modules/kernel.git] / src / KERNEL_PY / salome_iapp.py
1 #  -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
3 #
4 # Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
5 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 #
7 # This library is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU Lesser General Public
9 # License as published by the Free Software Foundation; either
10 # version 2.1 of the License, or (at your option) any later version.
11 #
12 # This library is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 # Lesser General Public License for more details.
16 #
17 # You should have received a copy of the GNU Lesser General Public
18 # License along with this library; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
20 #
21 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 #
23
24 #  File   : salome_iapp.py
25 #  Author : Paul RASCLE, EDF
26 #  Module : SALOME
27 #  $Header$
28 ## @package salome_iapp
29 # Module salome gives access to Salome GUI resources (if GUI has been launched).
30 #
31 import salome_ComponentGUI
32
33     #--------------------------------------------------------------------------
34
35 IN_SALOME_GUI=None
36
37 def ImportComponentGUI(ComponentName):
38     if IN_SALOME_GUI:
39         libName = "lib" + ComponentName + "_Swig"
40         command = "from " + libName + " import *"
41         exec ( command )
42         constructor = ComponentName + "_Swig()"
43         command = "gui = " + constructor
44         exec ( command )
45         return gui
46     else:
47         print "Warning: ImportComponentGUI(",ComponentName,") outside GUI !"
48         print "calls to GUI methods may crash..."
49         return salome_ComponentGUI
50
51     #--------------------------------------------------------------------------
52
53 def SalomeGUIgetAllSelected(self):
54     selNumber = self.SelectedCount()
55     listSelected = []
56     for i in range(selNumber):
57         listSelected.append(self.getSelected(i))
58     return listSelected
59
60     #--------------------------------------------------------------------------
61
62 def hasDesktop():
63     return IN_SALOME_GUI
64
65     #--------------------------------------------------------------------------
66
67 salome_iapp_initial = 1
68
69 class SalomeOutsideGUI(object):
70     """
71     Provides a replacement for class SalomeGUI outside GUI process.
72     Do almost nothing
73     """
74     global myStudyId, myStudyName
75     
76     def hasDesktop(self):
77         """Indicate if GUI is running"""
78         return False
79     
80     def updateObjBrowser(self, bid):
81         """update the GUI object browser"""
82         print "SalomeOutsideGUI: no objectBrowser update outside GUI"
83         pass
84     
85     def getActiveStudyId(self):
86         """Get the active study id"""
87         print "SalomeOutsideGUI.getActiveStudyId: avoid use outside GUI"
88         return myStudyId
89     
90     def getActiveStudyName(self):
91         """Get the active study name"""
92         print "SalomeOutsideGUI.getActiveStudyName: avoid use outside GUI"
93         return myStudyName
94     
95     def SelectedCount(self):
96         """Get the number of active selections"""
97         print "SalomeOutsideGUI: no selection mechanism available outside GUI"
98         return 0
99     
100     def getSelected(self, i):
101         """Get the selection number i """
102         print "SalomeOutsideGUI: no selection mechanism available outside GUI"
103         return none
104     
105     def AddIObject(self, Entry):
106         """Add an entry"""
107         print "SalomeOutsideGUI.AddIOObject: not available outside GUI"
108         pass
109     
110     def RemoveIObject(self, Entry):
111         """Remove an entry"""
112         print "SalomeOutsideGUI.REmoveIOObject: not available outside GUI"
113         pass
114     
115     def ClearIObjects(self):
116         """Clear entries"""
117         print "SalomeOutsideGUI.ClearIOObject: not available outside GUI"
118         pass
119     
120     def Display(self, Entry):
121         """Display an entry"""
122         print "SalomeOutsideGUI.Display: not available outside GUI"
123         pass
124     
125     def DisplayOnly(self, Entry):
126         """Display only an entry"""
127         print "SalomeOutsideGUI.DisplayOnly: not available outside GUI"
128         pass
129     
130     def Erase(self, Entry):
131         """Erase en entry"""
132         print "SalomeOutsideGUI.Erase: not available outside GUI"
133         pass
134     
135     def DisplayAll(self):
136         """Display all"""
137         print "SalomeOutsideGUI.Erase: not available outside GUI"
138         pass
139     
140     def EraseAll(self):
141         """Erase all"""
142         print "SalomeOutsideGUI.EraseAll: not available outside GUI"
143         pass
144
145     def IsInCurrentView(self, Entry):
146         """Indicate if an entry is in current view"""
147         print "SalomeOutsideGUI.IsIncurrentView: not available outside GUI"
148         return False
149         
150     def getComponentName(self, ComponentUserName ):
151         """Get component name from component user name"""
152         print "SalomeOutsideGUI.getComponentName: not available outside GUI"
153         return ""
154    
155     def getComponentUserName( self, ComponentName ):
156         """Get component user name from component name"""
157         print "SalomeOutsideGUI.getComponentUserName: not available outside GUI"
158         return ""
159         
160     #--------------------------------------------------------------------------
161
162     
163 def salome_iapp_init(embedded):
164     global salome_iapp_initial
165     global sg,IN_SALOME_GUI
166
167     if salome_iapp_initial:
168         salome_iapp_initial=0
169         if embedded:
170             import libSALOME_Swig
171         
172             class SalomeGUI(libSALOME_Swig.SALOMEGUI_Swig):
173                 getAllSelected = SalomeGUIgetAllSelected
174
175             # create a SALOMEGUI_Swig instance
176             sg = SalomeGUI()
177             inSalomeGUI = sg.hasDesktop()
178         else:
179             # Not embedded in GUI
180             sg=SalomeOutsideGUI()
181             inSalomeGUI=0
182         if IN_SALOME_GUI is None:
183           IN_SALOME_GUI = inSalomeGUI
184     return sg
185
186 def salome_iapp_close():
187     global salome_iapp_initial
188     salome_iapp_initial=1
189     pass
190
191