1 # -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2010 EDF R&D
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License.
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # Lesser General Public License for more details.
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 This file centralizes the definitions and implementations of ui components used
23 in the GUI part of the module.
26 __author__ = "aribes/gboulant"
29 from PyQt4.QtCore import QObject
31 sgPyQt = SalomePyQt.SalomePyQt()
33 from daGuiImpl.enumerate import Enumerate
34 from daGuiImpl.datassimCase import DatassimCase
35 from daEficasWrapper.datassimEficasWrapper import DatassimEficasWrapper
36 from daEficasWrapper.eficasWrapper import EficasObserver
37 from daEficasWrapper.eficasWrapper import EficasEvent
38 import datassimGuiHelper
39 import datassimStudyEditor
44 # ==============================================================================
45 # Classes to manage the building of UI components
46 # ==============================================================================
48 UI_ELT_IDS = Enumerate([
50 'NEW_DATASSIMCASE_ID',
51 'EDIT_DATASSIMCASE_POP_ID',
52 'DELETE_DATASSIMCASE_POP_ID',
57 UI_ELT_IDS.NEW_DATASSIMCASE_ID:"newDatassimCase",
58 UI_ELT_IDS.EDIT_DATASSIMCASE_POP_ID:"editDatassimCase",
61 class DatassimGuiUiComponentBuilder:
63 The initialisation of this class creates the graphic components involved
64 in the GUI (menu, menu item, toolbar). A ui component builder should be
65 created for each opened study and associated to its context (see usage in OMAGUI.py).
68 self.initUiComponents()
70 def initUiComponents(self):
74 # create top-level menu
75 mid = sgPyQt.createMenu( "DATASSIM", -1, UI_ELT_IDS.DATASSIM_MENU_ID, sgPyQt.defaultMenuGroup() )
77 tid = sgPyQt.createTool( "DATASSIM" )
79 a = sgPyQt.createAction( UI_ELT_IDS.NEW_DATASSIMCASE_ID, "New case", "New case", "Create a new datassim case", "" )
80 sgPyQt.createMenu(a, mid)
81 sgPyQt.createTool(a, tid)
83 # the following action are used in context popup
84 a = sgPyQt.createAction( UI_ELT_IDS.EDIT_DATASSIMCASE_POP_ID, "Edit case", "Edit case", "Edit the selected study case", "" )
85 a = sgPyQt.createAction( UI_ELT_IDS.DELETE_DATASSIMCASE_POP_ID, "Delete case", "Delete case", "Delete the selected study case", "" )
86 a = sgPyQt.createAction( UI_ELT_IDS.YACS_EXPORT_POP_ID, "Export to YACS", "Export to YACS", "Generate a YACS graph executing this case", "" )
88 def createPopupMenuOnItem(self,popup,salomeSudyId, item):
89 if datassimStudyEditor.isValidDatassimCaseItem(salomeSudyId, item):
90 popup.addAction( sgPyQt.action( UI_ELT_IDS.EDIT_DATASSIMCASE_POP_ID ) )
91 popup.addAction( sgPyQt.action( UI_ELT_IDS.DELETE_DATASSIMCASE_POP_ID ) )
92 popup.addAction( sgPyQt.action( UI_ELT_IDS.YACS_EXPORT_POP_ID ) )
96 class DatassimGuiActionImpl(EficasObserver):
98 This class implements the ui actions concerning the management of oma study
101 __dlgEficasWrapper = None
105 # This dialog is created once so that it can be recycled for each call
107 #self.__dlgNewStudyCase = DlgNewStudyCase()
108 self.__dlgEficasWrapper = DatassimEficasWrapper(parent=SalomePyQt.SalomePyQt().getDesktop())
109 self.__dlgEficasWrapper.addObserver(self)
111 # ==========================================================================
112 # Processing of ui actions
114 def processAction(self,actionId):
116 Main switch function for ui actions processing
118 if ACTIONS_MAP.has_key(actionId):
120 functionName = ACTIONS_MAP[actionId]
121 getattr(self,functionName)()
123 traceback.print_exc()
125 msg = "The requested action is not implemented: " + str(actionId)
128 def newDatassimCase(self):
129 self.__dlgEficasWrapper.displayNew()
131 def editDatassimCase(self):
133 salomeStudyId = datassimGuiHelper.getActiveStudyId()
134 salomeStudyItem = datassimGuiHelper.getSelectedItem(salomeStudyId)
135 case_key = (salomeStudyId, salomeStudyItem.GetName())
137 case = __cases__[case_key]
138 self.__dlgEficasWrapper.Openfile(case.get_name())
139 callbackId = [salomeStudyId, salomeStudyItem]
140 self.__dlgEficasWrapper.setCallbackId(callbackId)
141 self.__dlgEficasWrapper.show()
143 print "Oups - cannot edit case !"
144 traceback.print_exc()
147 # ==========================================================================
148 # Processing notifications from eficas
151 EficasEvent.EVENT_TYPES.CLOSE : "_processEficasCloseEvent",
152 EficasEvent.EVENT_TYPES.SAVE : "_processEficasSaveEvent",
153 EficasEvent.EVENT_TYPES.NEW : "_processEficasNewEvent",
154 EficasEvent.EVENT_TYPES.DESTROY : "_processEficasDestroyEvent"
156 def processEficasEvent(self, eficasWrapper, eficasEvent):
158 Implementation of the interface EficasObserver. The implementation is a
159 switch on the possible types of events defined in EficasEvent.EVENT_TYPES.
162 functionName = self.__processOptions.get(eficasEvent.eventType, lambda : "_processEficasUnknownEvent")
163 return getattr(self,functionName)(eficasWrapper, eficasEvent)
165 def _processEficasCloseEvent(self, eficasWrapper, eficasEvent):
166 print "This is the process of EficasCloseEvent"
167 print "Remove datassim case in study if empty..."
170 def _processEficasNewEvent(self, eficasWrapper, eficasEvent):
172 new_case = DatassimCase()
173 salomeStudyId = datassimGuiHelper.getActiveStudyId()
174 salomeStudyItem = datassimStudyEditor.addInStudy(salomeStudyId, new_case)
175 case_key = (salomeStudyId, salomeStudyItem.GetName())
176 __cases__[case_key] = new_case
177 datassimGuiHelper.refreshObjectBrowser()
178 callbackId = [salomeStudyId, salomeStudyItem]
179 self.__dlgEficasWrapper.setCallbackId(callbackId)
181 def _processEficasSaveEvent(self, eficasWrapper, eficasEvent):
183 callbackId = eficasEvent.callbackId
184 if callbackId is None:
185 raise DevelException("the callback data should not be None. Can't guess what are the study and case")
186 [targetSalomeStudyId,targetSalomeStudyItem] = callbackId
187 if ( targetSalomeStudyId is None ) or ( targetSalomeStudyItem is None ):
188 raise DevelException("the parameters targetSalomeStudyId and targetSalomeStudyItem should not be None")
190 # Get Editor All infos we need !
191 file_name = eficasWrapper.getCaseName()
194 old_case_key = (targetSalomeStudyId, targetSalomeStudyItem.GetName())
195 case =__cases__[old_case_key]
197 # Set new informations
198 case.set_name(file_name)
199 datassimStudyEditor.updateItem(targetSalomeStudyId, targetSalomeStudyItem, case)
202 new_case_key = (targetSalomeStudyId, targetSalomeStudyItem.GetName())
203 # A ne pas inverser !!!
204 __cases__.pop(old_case_key)
205 __cases__[new_case_key] = case
207 datassimGuiHelper.refreshObjectBrowser()
209 def _processEficasDestroyEvent(self, eficasWrapper, eficasEvent):
211 callbackId = eficasEvent.callbackId
212 if callbackId is None:
213 raise DevelException("the callback data should not be None. Can't guess what are the study and case")
214 [targetSalomeStudyId,targetSalomeStudyItem] = callbackId
215 if ( targetSalomeStudyId is None ) or ( targetSalomeStudyItem is None ):
216 raise DevelException("the parameters targetSalomeStudyId and targetSalomeStudyItem should not be None")
218 case_key = (targetSalomeStudyId, targetSalomeStudyItem.GetName())
219 __cases__.pop(case_key)
220 datassimStudyEditor.removeItem(targetSalomeStudyId, targetSalomeStudyItem)
221 datassimGuiHelper.refreshObjectBrowser()
223 def _processEficasUnknownEvent(self, eficasWrapper, eficasEvent):
224 print "Unknown Eficas Event"