1 # Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
3 # Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 # File : :sat:{PYCMP}GUI.py
25 # Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
32 from qtsalome import *
34 #from :sat:{PYCMP}_utils import *
37 from Controller import Controller
38 from TreeWidget import TreeWidget
39 from :sat:{PYCMP}Desktop import :sat:{PYCMP}Desktop
41 # Get SALOME PyQt interface
45 ########################################################
47 ########################################################
49 sgPyQt = SalomePyQt.SalomePyQt()
50 sg = libSALOME_Swig.SALOMEGUI_Swig()
51 sgDesktop = sgPyQt.getDesktop()
52 widgetDialogBox = None
54 objectsManager = Controller( None )
58 ADVANCED_MENU_ID = 1001
63 ########################################################
65 ########################################################
68 """This method returns the current :sat:{PYCMP} desktop"""
74 """This method sets and returns :sat:{PYCMP} desktop"""
76 global moduleDesktop, objectsManager
78 if moduleDesktop is None:
79 moduleDesktop = :sat:{PYCMP}Desktop( sgPyQt, sg )
80 objectsManager = Controller( moduleDesktop )
81 moduleDesktop.setController( objectsManager )
85 def incObjToMap( m, id ):
86 """This method incrementes the object counter in the map"""
88 if id not in m: m[id] = 0
93 """This method analyses selection"""
95 selcount = sg.SelectedCount()
97 for i in range( selcount ):
98 incObjToMap( seltypes, getObjectID( sg.getSelected( i ) ) )
100 return selcount, seltypes
102 ################################################
104 ################################################
107 """This method is called when module is initialized. It performs initialization actions"""
112 """This method is called when module is initialized. It returns a map of popup windows to be used by the module"""
115 wm[SalomePyQt.WT_ObjectBrowser] = Qt.LeftDockWidgetArea
116 wm[SalomePyQt.WT_PyConsole] = Qt.BottomDockWidgetArea
120 """This method is called when module is initialized. It returns a list of 2D/3D views to be used by the module"""
123 def createPreferences():
124 """This method is called when module is initialized. It exports module preferences"""
128 """This method is called when module is initialized. It returns True if activating is successfull, False otherwise"""
130 global moduleDesktop, sgPyQt, widgetDialogBox
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() )
142 def viewTryClose( wid ):
143 sgPyQt.setViewClosable(wid, True)
147 """This method is called when module is deactivated"""
149 global moduleDesktop, widgetDialogBox
151 widgetDialogBox.close()
152 moduleDesktop.getDockGlobalTree().hide()
153 moduleDesktop.updateGlobalGraphicsView( None )
154 moduleDesktop.getGlobalGraphicsView().hide()
157 def activeStudyChanged():
158 """This method is called when active study is changed"""
163 def createPopupMenu( popup, context ):
164 """This method is called when popup menu is invocked"""
167 def OnGUIEvent( commandID ):
168 """This method is called when a GUI action is activated"""
170 if commandID in dict_command:
171 dict_command[commandID]()
175 def preferenceChanged( section, setting ):
176 """This method is called when module's preferences are changed"""
179 def activeViewChanged( viewID ):
180 """This method is called when active view is changed"""
183 def viewCloned( viewID ):
184 """This method is called when active view is cloned"""
187 def viewClosed( viewID ):
188 """This method is called when active view viewClosed"""
192 """This method is called when study is opened. It returns engine IOR"""
193 return getEngineIOR()
196 ################################################
197 # GUI actions implementation
198 ################################################
200 def showCreatePolylineDialog() :
201 from CreatePolylineDialog import CreatePolylineDialog
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)
211 def showCreateCircleDialog() :
212 from CreateCircleDialog import CreateCircleDialog
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)
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 )
233 ########################################################
234 # Commands dictionary
235 ########################################################
237 dict_command = { POLYLINE_ID : showCreatePolylineDialog,
238 CIRCLE_ID : showCreateCircleDialog,
239 DEL_ALL_ID : deleteAll
242 ########################################################