]> SALOME platform Git repositories - tools/sat.git/blob - data/templates/PythonComponent/src/PYCMPGUI/PYCMPGUI.py
Salome HOME
Revert "spns #43062: add new git_commands key"
[tools/sat.git] / data / templates / PythonComponent / src / PYCMPGUI / PYCMPGUI.py
1 #  Copyright (C) 2007-2010  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
23 # ---
24 # File   : :sat:{PYCMP}GUI.py
25 # Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
26 # ---
27 #
28 import traceback
29 import string
30 import os
31 import sys
32 from qtsalome import *
33
34 #from :sat:{PYCMP}_utils import *
35
36 import salome
37 from Controller import Controller
38 from TreeWidget import TreeWidget
39 from :sat:{PYCMP}Desktop import :sat:{PYCMP}Desktop
40
41 # Get SALOME PyQt interface
42 import SalomePyQt
43 import libSALOME_Swig
44
45 ########################################################
46 # Global variables
47 ########################################################
48
49 sgPyQt = SalomePyQt.SalomePyQt()
50 sg = libSALOME_Swig.SALOMEGUI_Swig()
51 sgDesktop = sgPyQt.getDesktop()
52 widgetDialogBox = None
53
54 objectsManager = Controller( None )
55 moduleDesktop  = None
56
57 CURVE_MENU_ID = 1000
58 ADVANCED_MENU_ID = 1001
59 POLYLINE_ID = 1002
60 CIRCLE_ID = 1003
61 DEL_ALL_ID = 1004
62
63 ########################################################
64 # Internal methods
65 ########################################################
66
67 def getDesktop():
68     """This method returns the current :sat:{PYCMP} desktop"""
69
70     global moduleDesktop
71     return moduleDesktop
72
73 def setDesktop( ):
74     """This method sets and returns :sat:{PYCMP} desktop"""
75
76     global moduleDesktop, objectsManager
77
78     if moduleDesktop is None:
79         moduleDesktop = :sat:{PYCMP}Desktop( sgPyQt, sg )
80         objectsManager = Controller( moduleDesktop )
81         moduleDesktop.setController( objectsManager )
82         pass
83     return moduleDesktop
84
85 def incObjToMap( m, id ):
86     """This method incrementes the object counter in the map"""
87
88     if id not in m: m[id] = 0
89     m[id] += 1
90     pass
91
92 def getSelection():
93     """This method analyses selection"""
94
95     selcount = sg.SelectedCount()
96     seltypes = {}
97     for i in range( selcount ):
98         incObjToMap( seltypes, getObjectID( sg.getSelected( i ) ) )
99         pass
100     return selcount, seltypes
101
102 ################################################
103 # Callback functions
104 ################################################
105
106 def initialize():
107     """This method is called when module is initialized. It performs initialization actions"""
108     setDesktop()
109     pass
110
111 def windows():
112     """This method is called when module is initialized. It returns a map of popup windows to be used by the module"""
113
114     wm = {}
115     wm[SalomePyQt.WT_ObjectBrowser] = Qt.LeftDockWidgetArea
116     wm[SalomePyQt.WT_PyConsole]     = Qt.BottomDockWidgetArea
117     return wm
118
119 def views():
120     """This method is called when module is initialized. It returns a list of 2D/3D views to be used by the module"""
121     return []
122
123 def createPreferences():
124     """This method is called when module is initialized. It exports module preferences"""
125     pass
126
127 def activate():
128     """This method is called when module is initialized. It returns True if activating is successfull, False otherwise"""
129
130     global moduleDesktop, sgPyQt, widgetDialogBox
131
132     widgetDialogBox = QDockWidget( sgDesktop )
133     moduleDesktop.createActions()
134     moduleDesktop.createMenus()
135     moduleDesktop.createToolBars()
136     moduleDesktop.createPopups()
137     moduleDesktop.getDockGlobalTree().show()
138     moduleDesktop.getGlobalGraphicsView().show()
139     sgPyQt.activateView( moduleDesktop.getGlobalGraphicsViewID() )
140     return True
141
142 def viewTryClose( wid ):
143     sgPyQt.setViewClosable(wid, True)
144     pass
145
146 def deactivate():
147     """This method is called when module is deactivated"""
148
149     global moduleDesktop, widgetDialogBox
150
151     widgetDialogBox.close()
152     moduleDesktop.getDockGlobalTree().hide()
153     moduleDesktop.updateGlobalGraphicsView( None )
154     moduleDesktop.getGlobalGraphicsView().hide()
155     pass
156
157 def activeStudyChanged():
158     """This method is called when active study is changed"""
159
160     setDesktop()
161     pass
162
163 def createPopupMenu( popup, context ):
164     """This method is called when popup menu is invocked"""
165     pass
166
167 def OnGUIEvent( commandID ):
168     """This method is called when a GUI action is activated"""
169
170     if commandID in dict_command:
171        dict_command[commandID]()
172        pass
173     pass
174
175 def preferenceChanged( section, setting ):
176     """This method is called when module's preferences are changed"""
177     pass
178
179 def activeViewChanged( viewID ):
180     """This method is called when active view is changed"""
181     pass
182
183 def viewCloned( viewID ):
184     """This method is called when active view is cloned"""
185     pass
186
187 def viewClosed( viewID ):
188     """This method is called when active view viewClosed"""
189     pass
190
191 def engineIOR():
192     """This method is called when study is opened. It returns engine IOR"""
193     return getEngineIOR()
194
195
196 ################################################
197 # GUI actions implementation
198 ################################################
199
200 def showCreatePolylineDialog() :
201     from CreatePolylineDialog import CreatePolylineDialog
202
203     global widgetDialogBox
204     widgetDialogBox = QDockWidget( sgDesktop )
205     myDialog = CreatePolylineDialog( "www.cea.fr", objectsManager, widgetDialogBox )
206     widgetDialogBox.setWidget( myDialog )
207     widgetDialogBox.setWindowTitle( "Polyline definition" )
208     sgDesktop.addDockWidget(Qt.LeftDockWidgetArea, widgetDialogBox)
209     pass
210
211 def showCreateCircleDialog() :
212     from CreateCircleDialog import CreateCircleDialog
213
214     global widgetDialogBox
215     widgetDialogBox = QDockWidget( sgDesktop )
216     myDialog = CreateCircleDialog( "www.cea.fr", objectsManager, widgetDialogBox )
217     widgetDialogBox.setWidget( myDialog )
218     widgetDialogBox.setWindowTitle( "Circle definition" )
219     sgDesktop.addDockWidget(Qt.LeftDockWidgetArea, widgetDialogBox)
220     pass
221
222 def deleteAll() :
223     models = moduleDesktop.getController().getModels()
224     if len( models ) == 0 : return
225     answer = QMessageBox.question( moduleDesktop, 'Confirmation', 'Do you really want to delete all the existing objects ?' , QMessageBox.Yes | QMessageBox.No )
226     if answer == QMessageBox.Yes :
227        for model in models :
228           moduleDesktop.getController().removeModel( model )
229           pass
230        pass
231     pass
232
233 ########################################################
234 # Commands dictionary
235 ########################################################
236
237 dict_command = { POLYLINE_ID : showCreatePolylineDialog,
238                  CIRCLE_ID   : showCreateCircleDialog,
239                  DEL_ALL_ID : deleteAll
240                 }
241
242 ########################################################