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 PyQt4.QtGui import *
33 from PyQt4.QtCore import *
35 #from :sat:{PYCMP}_utils import *
38 from Controller import Controller
39 from TreeWidget import TreeWidget
40 from :sat:{PYCMP}Desktop import :sat:{PYCMP}Desktop
42 # Get SALOME PyQt interface
46 ########################################################
48 ########################################################
50 sgPyQt = SalomePyQt.SalomePyQt()
51 sg = libSALOME_Swig.SALOMEGUI_Swig()
52 sgDesktop = sgPyQt.getDesktop()
53 widgetDialogBox = None
55 objectsManager = Controller( None )
60 ADVANCED_MENU_ID = 1001
65 ########################################################
67 ########################################################
70 """This method returns the active study ID"""
71 return sgPyQt.getStudyId()
74 """This method returns the active study"""
76 studyId = _getStudyId()
77 study = getStudyManager().GetStudyByID( studyId )
81 """This method returns the current :sat:{PYCMP} desktop"""
86 def setDesktop( studyID ):
87 """This method sets and returns :sat:{PYCMP} desktop"""
89 global moduleDesktop, currentDesktop, objectsManager
91 if not moduleDesktop.has_key( studyID ):
92 moduleDesktop[studyID] = :sat:{PYCMP}Desktop( sgPyQt, sg )
93 objectsManager = Controller( moduleDesktop[studyID] )
94 moduleDesktop[studyID].setController( objectsManager )
96 currentDesktop = moduleDesktop[studyID]
99 def incObjToMap( m, id ):
100 """This method incrementes the object counter in the map"""
102 if id not in m: m[id] = 0
107 """This method analyses selection"""
109 selcount = sg.SelectedCount()
111 for i in range( selcount ):
112 incObjToMap( seltypes, getObjectID( getStudy(), sg.getSelected( i ) ) )
114 return selcount, seltypes
116 ################################################
118 ################################################
121 """This method is called when module is initialized. It performs initialization actions"""
123 setDesktop( getStudyId() )
127 """This method is called when module is initialized. It returns a map of popup windows to be used by the module"""
130 wm[SalomePyQt.WT_ObjectBrowser] = Qt.LeftDockWidgetArea
131 wm[SalomePyQt.WT_PyConsole] = Qt.BottomDockWidgetArea
135 """This method is called when module is initialized. It returns a list of 2D/3D views to be used by the module"""
138 def createPreferences():
139 """This method is called when module is initialized. It exports module preferences"""
143 """This method is called when module is initialized. It returns True if activating is successfull, False otherwise"""
145 global moduleDesktop, sgPyQt, widgetDialogBox
147 widgetDialogBox = QDockWidget( sgDesktop )
148 moduleDesktop[getStudyId()].createActions()
149 moduleDesktop[getStudyId()].createMenus()
150 moduleDesktop[getStudyId()].createToolBars()
151 moduleDesktop[getStudyId()].createPopups()
152 moduleDesktop[getStudyId()].getDockGlobalTree().show()
153 moduleDesktop[getStudyId()].getGlobalGraphicsView().show()
154 sgPyQt.activateView( moduleDesktop[getStudyId()].getGlobalGraphicsViewID() )
157 def viewTryClose( wid ):
158 sgPyQt.setViewClosable(wid, True)
162 """This method is called when module is deactivated"""
164 global moduleDesktop, widgetDialogBox
166 widgetDialogBox.close()
167 moduleDesktop[getStudyId()].getDockGlobalTree().hide()
168 moduleDesktop[getStudyId()].updateGlobalGraphicsView( None )
169 moduleDesktop[getStudyId()].getGlobalGraphicsView().hide()
172 def activeStudyChanged( studyID ):
173 """This method is called when active study is changed"""
175 setDesktop( getStudyId() )
178 def createPopupMenu( popup, context ):
179 """This method is called when popup menu is invocked"""
182 def OnGUIEvent( commandID ):
183 """This method is called when a GUI action is activated"""
185 if dict_command.has_key( commandID ):
186 dict_command[commandID]()
190 def preferenceChanged( section, setting ):
191 """This method is called when module's preferences are changed"""
194 def activeViewChanged( viewID ):
195 """This method is called when active view is changed"""
198 def viewCloned( viewID ):
199 """This method is called when active view is cloned"""
202 def viewClosed( viewID ):
203 """This method is called when active view viewClosed"""
207 """This method is called when study is opened. It returns engine IOR"""
208 return getEngineIOR()
211 ################################################
212 # GUI actions implementation
213 ################################################
215 def showCreatePolylineDialog() :
216 from CreatePolylineDialog import CreatePolylineDialog
218 global widgetDialogBox
219 widgetDialogBox = QDockWidget( sgDesktop )
220 myDialog = CreatePolylineDialog( "www.cea.fr", objectsManager, widgetDialogBox )
221 widgetDialogBox.setWidget( myDialog )
222 widgetDialogBox.setWindowTitle( "Polyline definition" )
223 sgDesktop.addDockWidget(Qt.LeftDockWidgetArea, widgetDialogBox)
226 def showCreateCircleDialog() :
227 from CreateCircleDialog import CreateCircleDialog
229 global widgetDialogBox
230 widgetDialogBox = QDockWidget( sgDesktop )
231 myDialog = CreateCircleDialog( "www.cea.fr", objectsManager, widgetDialogBox )
232 widgetDialogBox.setWidget( myDialog )
233 widgetDialogBox.setWindowTitle( "Circle definition" )
234 sgDesktop.addDockWidget(Qt.LeftDockWidgetArea, widgetDialogBox)
238 models = moduleDesktop[getStudyId()].getController().getModels()
239 if len( models ) == 0 : return
240 answer = QMessageBox.question( moduleDesktop[getStudyId()], 'Confirmation', 'Do you really want to delete all the existing objects ?' , QMessageBox.Yes | QMessageBox.No )
241 if answer == QMessageBox.Yes :
242 for model in models :
243 moduleDesktop[getStudyId()].getController().removeModel( model )
248 ########################################################
249 # Commands dictionary
250 ########################################################
252 dict_command = { POLYLINE_ID : showCreatePolylineDialog,
253 CIRCLE_ID : showCreateCircleDialog,
254 DEL_ALL_ID : deleteAll
257 ########################################################