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 daEficasWrapper.datassimEficasWrapper import DatassimEficasWrapper
35 from daEficasWrapper.eficasWrapper import EficasObserver
36 from daEficasWrapper.eficasWrapper import EficasEvent
37 import datassimGuiHelper
38 import datassimStudyEditor
41 # ==============================================================================
42 # Classes to manage the building of UI components
43 # ==============================================================================
45 UI_ELT_IDS = Enumerate([
47 'NEW_DATASSIMCASE_ID',
51 UI_ELT_IDS.NEW_DATASSIMCASE_ID:"newDatassimCase",
54 class DatassimGuiUiComponentBuilder:
56 The initialisation of this class creates the graphic components involved
57 in the GUI (menu, menu item, toolbar). A ui component builder should be
58 created for each opened study and associated to its context (see usage in OMAGUI.py).
61 self.initUiComponents()
63 def initUiComponents(self):
67 # create top-level menu
68 mid = sgPyQt.createMenu( "DATASSIM", -1, UI_ELT_IDS.DATASSIM_MENU_ID, sgPyQt.defaultMenuGroup() )
70 tid = sgPyQt.createTool( "DATASSIM" )
72 a = sgPyQt.createAction( UI_ELT_IDS.NEW_DATASSIMCASE_ID, "New case", "New case", "Create a new datassim case", "" )
73 sgPyQt.createMenu(a, mid)
74 sgPyQt.createTool(a, tid)
76 class DatassimGuiActionImpl(EficasObserver):
78 This class implements the ui actions concerning the management of oma study
81 __dlgEficasWrapper = None
85 # This dialog is created once so that it can be recycled for each call
87 #self.__dlgNewStudyCase = DlgNewStudyCase()
88 self.__dlgEficasWrapper = DatassimEficasWrapper(parent=SalomePyQt.SalomePyQt().getDesktop())
89 self.__dlgEficasWrapper.addObserver(self)
91 # ==========================================================================
92 # Processing of ui actions
94 def processAction(self,actionId):
96 Main switch function for ui actions processing
98 if ACTIONS_MAP.has_key(actionId):
100 functionName = ACTIONS_MAP[actionId]
101 getattr(self,functionName)()
103 traceback.print_exc()
105 msg = "The requested action is not implemented: " + str(actionId)
108 def newDatassimCase(self):
109 print "newDatassimCase"
110 salomeStudyId = datassimGuiHelper.getActiveStudyId()
111 salomeStudyItem = datassimStudyEditor.addInStudy(salomeStudyId, "newDatassimCase")
112 datassimGuiHelper.refreshObjectBrowser()
113 callbackId = [salomeStudyId, salomeStudyItem]
114 self.__dlgEficasWrapper.setCallbackId(callbackId)
115 self.__dlgEficasWrapper.displayNew()
117 # ==========================================================================
118 # Processing notifications from eficas
121 EficasEvent.EVENT_TYPES.CLOSE : "_processEficasCloseEvent",
122 EficasEvent.EVENT_TYPES.SAVE : "_processEficasSaveEvent"
124 def processEficasEvent(self, eficasWrapper, eficasEvent):
126 Implementation of the interface EficasObserver. The implementation is a
127 switch on the possible types of events defined in EficasEvent.EVENT_TYPES.
130 functionName = self.__processOptions.get(eficasEvent.eventType, lambda : "_processEficasUnknownEvent")
131 return getattr(self,functionName)(eficasWrapper, eficasEvent)
133 def _processEficasCloseEvent(self, eficasWrapper, eficasEvent):
134 print "This is the process of EficasCloseEvent"
135 print "Remove datassim case in study if empty..."
138 def _processEficasSaveEvent(self, eficasWrapper, eficasEvent):
139 callbackId = eficasEvent.callbackId
140 if callbackId is None:
141 raise DevelException("the callback data should not be None. Can't guess what are the study and case")
142 [targetSalomeStudyId,targetSalomeStudyItem] = callbackId
143 if ( targetSalomeStudyId is None ) or ( targetSalomeStudyItem is None ):
144 raise DevelException("the parameters targetSalomeStudyId and targetSalomeStudyItem should not be None")
146 file_name = eficasWrapper.getCurrentFileName()
147 datassimStudyEditor.updateItem(targetSalomeStudyId, targetSalomeStudyItem, file_name)
148 #studyCase = omaStudyEditor.getOmaCaseFromItem(targetSalomeStudyId, targetSalomeStudyItem)
149 #studyCase = eficasWrapper.getData(studyCase)
150 #logger.debug("jdc="+str(studyCase.userdata.getJdc()))
152 def _processEficasUnknownEvent(self, eficasWrapper, eficasEvent):
153 print "Unknown Eficas Event"