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',
54 UI_ELT_IDS.NEW_DATASSIMCASE_ID:"newDatassimCase",
57 class DatassimGuiUiComponentBuilder:
59 The initialisation of this class creates the graphic components involved
60 in the GUI (menu, menu item, toolbar). A ui component builder should be
61 created for each opened study and associated to its context (see usage in OMAGUI.py).
64 self.initUiComponents()
66 def initUiComponents(self):
70 # create top-level menu
71 mid = sgPyQt.createMenu( "DATASSIM", -1, UI_ELT_IDS.DATASSIM_MENU_ID, sgPyQt.defaultMenuGroup() )
73 tid = sgPyQt.createTool( "DATASSIM" )
75 a = sgPyQt.createAction( UI_ELT_IDS.NEW_DATASSIMCASE_ID, "New case", "New case", "Create a new datassim case", "" )
76 sgPyQt.createMenu(a, mid)
77 sgPyQt.createTool(a, tid)
79 class DatassimGuiActionImpl(EficasObserver):
81 This class implements the ui actions concerning the management of oma study
84 __dlgEficasWrapper = None
88 # This dialog is created once so that it can be recycled for each call
90 #self.__dlgNewStudyCase = DlgNewStudyCase()
91 self.__dlgEficasWrapper = DatassimEficasWrapper(parent=SalomePyQt.SalomePyQt().getDesktop())
92 self.__dlgEficasWrapper.addObserver(self)
94 # ==========================================================================
95 # Processing of ui actions
97 def processAction(self,actionId):
99 Main switch function for ui actions processing
101 if ACTIONS_MAP.has_key(actionId):
103 functionName = ACTIONS_MAP[actionId]
104 getattr(self,functionName)()
106 traceback.print_exc()
108 msg = "The requested action is not implemented: " + str(actionId)
111 def newDatassimCase(self):
112 self.__dlgEficasWrapper.displayNew()
114 # ==========================================================================
115 # Processing notifications from eficas
118 EficasEvent.EVENT_TYPES.CLOSE : "_processEficasCloseEvent",
119 EficasEvent.EVENT_TYPES.SAVE : "_processEficasSaveEvent",
120 EficasEvent.EVENT_TYPES.NEW : "_processEficasNewEvent",
121 EficasEvent.EVENT_TYPES.DESTROY : "_processEficasDestroyEvent"
123 def processEficasEvent(self, eficasWrapper, eficasEvent):
125 Implementation of the interface EficasObserver. The implementation is a
126 switch on the possible types of events defined in EficasEvent.EVENT_TYPES.
129 functionName = self.__processOptions.get(eficasEvent.eventType, lambda : "_processEficasUnknownEvent")
130 return getattr(self,functionName)(eficasWrapper, eficasEvent)
132 def _processEficasCloseEvent(self, eficasWrapper, eficasEvent):
133 print "This is the process of EficasCloseEvent"
134 print "Remove datassim case in study if empty..."
137 def _processEficasNewEvent(self, eficasWrapper, eficasEvent):
139 new_case = DatassimCase()
140 salomeStudyId = datassimGuiHelper.getActiveStudyId()
141 salomeStudyItem = datassimStudyEditor.addInStudy(salomeStudyId, new_case)
142 case_key = (salomeStudyId, salomeStudyItem)
143 __cases__[case_key] = new_case
144 datassimGuiHelper.refreshObjectBrowser()
145 callbackId = [salomeStudyId, salomeStudyItem]
146 self.__dlgEficasWrapper.setCallbackId(callbackId)
148 def _processEficasSaveEvent(self, eficasWrapper, eficasEvent):
149 callbackId = eficasEvent.callbackId
150 if callbackId is None:
151 raise DevelException("the callback data should not be None. Can't guess what are the study and case")
152 [targetSalomeStudyId,targetSalomeStudyItem] = callbackId
153 if ( targetSalomeStudyId is None ) or ( targetSalomeStudyItem is None ):
154 raise DevelException("the parameters targetSalomeStudyId and targetSalomeStudyItem should not be None")
156 # Get Editor All infos we need !
157 file_name = eficasWrapper.getCaseName()
159 case_key = (targetSalomeStudyId, targetSalomeStudyItem)
160 case =__cases__[case_key]
161 case.set_name(file_name)
162 datassimStudyEditor.updateItem(targetSalomeStudyId, targetSalomeStudyItem, case)
163 datassimGuiHelper.refreshObjectBrowser()
165 def _processEficasDestroyEvent(self, eficasWrapper, eficasEvent):
166 callbackId = eficasEvent.callbackId
167 if callbackId is None:
168 raise DevelException("the callback data should not be None. Can't guess what are the study and case")
169 [targetSalomeStudyId,targetSalomeStudyItem] = callbackId
170 if ( targetSalomeStudyId is None ) or ( targetSalomeStudyItem is None ):
171 raise DevelException("the parameters targetSalomeStudyId and targetSalomeStudyItem should not be None")
173 case_key = (targetSalomeStudyId, targetSalomeStudyItem)
174 __cases__.pop(case_key)
175 datassimStudyEditor.removeItem(targetSalomeStudyId, targetSalomeStudyItem)
176 datassimGuiHelper.refreshObjectBrowser()
178 def _processEficasUnknownEvent(self, eficasWrapper, eficasEvent):
179 print "Unknown Eficas Event"