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 )
59 ADVANCED_MENU_ID = 1001
64 ########################################################
66 ########################################################
69 """This method returns the active study ID"""
70 return sgPyQt.getStudyId()
73 """This method returns the active study"""
75 studyId = _getStudyId()
76 study = getStudyManager().GetStudyByID( studyId )
80 """This method returns the current :sat:{PYCMP} desktop"""
85 def setDesktop( studyID ):
86 """This method sets and returns :sat:{PYCMP} desktop"""
88 global moduleDesktop, currentDesktop, objectsManager
90 if not moduleDesktop.has_key( studyID ):
91 moduleDesktop[studyID] = :sat:{PYCMP}Desktop( sgPyQt, sg )
92 objectsManager = Controller( moduleDesktop[studyID] )
93 moduleDesktop[studyID].setController( objectsManager )
95 currentDesktop = moduleDesktop[studyID]
98 def incObjToMap( m, id ):
99 """This method incrementes the object counter in the map"""
101 if id not in m: m[id] = 0
106 """This method analyses selection"""
108 selcount = sg.SelectedCount()
110 for i in range( selcount ):
111 incObjToMap( seltypes, getObjectID( getStudy(), sg.getSelected( i ) ) )
113 return selcount, seltypes
115 ################################################
117 ################################################
120 """This method is called when module is initialized. It performs initialization actions"""
122 setDesktop( getStudyId() )
126 """This method is called when module is initialized. It returns a map of popup windows to be used by the module"""
129 wm[SalomePyQt.WT_ObjectBrowser] = Qt.LeftDockWidgetArea
130 wm[SalomePyQt.WT_PyConsole] = Qt.BottomDockWidgetArea
134 """This method is called when module is initialized. It returns a list of 2D/3D views to be used by the module"""
137 def createPreferences():
138 """This method is called when module is initialized. It exports module preferences"""
142 """This method is called when module is initialized. It returns True if activating is successfull, False otherwise"""
144 global moduleDesktop, sgPyQt, widgetDialogBox
146 widgetDialogBox = QDockWidget( sgDesktop )
147 moduleDesktop[getStudyId()].createActions()
148 moduleDesktop[getStudyId()].createMenus()
149 moduleDesktop[getStudyId()].createToolBars()
150 moduleDesktop[getStudyId()].createPopups()
151 moduleDesktop[getStudyId()].getDockGlobalTree().show()
152 moduleDesktop[getStudyId()].getGlobalGraphicsView().show()
153 sgPyQt.activateView( moduleDesktop[getStudyId()].getGlobalGraphicsViewID() )
156 def viewTryClose( wid ):
157 sgPyQt.setViewClosable(wid, True)
161 """This method is called when module is deactivated"""
163 global moduleDesktop, widgetDialogBox
165 widgetDialogBox.close()
166 moduleDesktop[getStudyId()].getDockGlobalTree().hide()
167 moduleDesktop[getStudyId()].updateGlobalGraphicsView( None )
168 moduleDesktop[getStudyId()].getGlobalGraphicsView().hide()
171 def activeStudyChanged( studyID ):
172 """This method is called when active study is changed"""
174 setDesktop( getStudyId() )
177 def createPopupMenu( popup, context ):
178 """This method is called when popup menu is invocked"""
181 def OnGUIEvent( commandID ):
182 """This method is called when a GUI action is activated"""
184 if dict_command.has_key( commandID ):
185 dict_command[commandID]()
189 def preferenceChanged( section, setting ):
190 """This method is called when module's preferences are changed"""
193 def activeViewChanged( viewID ):
194 """This method is called when active view is changed"""
197 def viewCloned( viewID ):
198 """This method is called when active view is cloned"""
201 def viewClosed( viewID ):
202 """This method is called when active view viewClosed"""
206 """This method is called when study is opened. It returns engine IOR"""
207 return getEngineIOR()
210 ################################################
211 # GUI actions implementation
212 ################################################
214 def showCreatePolylineDialog() :
215 from CreatePolylineDialog import CreatePolylineDialog
217 global widgetDialogBox
218 widgetDialogBox = QDockWidget( sgDesktop )
219 myDialog = CreatePolylineDialog( "www.cea.fr", objectsManager, widgetDialogBox )
220 widgetDialogBox.setWidget( myDialog )
221 widgetDialogBox.setWindowTitle( "Polyline definition" )
222 sgDesktop.addDockWidget(Qt.LeftDockWidgetArea, widgetDialogBox)
225 def showCreateCircleDialog() :
226 from CreateCircleDialog import CreateCircleDialog
228 global widgetDialogBox
229 widgetDialogBox = QDockWidget( sgDesktop )
230 myDialog = CreateCircleDialog( "www.cea.fr", objectsManager, widgetDialogBox )
231 widgetDialogBox.setWidget( myDialog )
232 widgetDialogBox.setWindowTitle( "Circle definition" )
233 sgDesktop.addDockWidget(Qt.LeftDockWidgetArea, widgetDialogBox)
237 models = moduleDesktop[getStudyId()].getController().getModels()
238 if len( models ) == 0 : return
239 answer = QMessageBox.question( moduleDesktop[getStudyId()], 'Confirmation', 'Do you really want to delete all the existing objects ?' , QMessageBox.Yes | QMessageBox.No )
240 if answer == QMessageBox.Yes :
241 for model in models :
242 moduleDesktop[getStudyId()].getController().removeModel( model )
247 ########################################################
248 # Commands dictionary
249 ########################################################
251 dict_command = { POLYLINE_ID : showCreatePolylineDialog,
252 CIRCLE_ID : showCreateCircleDialog,
253 DEL_ALL_ID : deleteAll
256 ########################################################