]> SALOME platform Git repositories - modules/adao.git/blob - src/daSalome/daGUI/daGuiImpl/datassimGuiManager.py
Salome HOME
- On gére bien le GUI EFICAS
[modules/adao.git] / src / daSalome / daGUI / daGuiImpl / datassimGuiManager.py
1 # -*- coding: iso-8859-1 -*-
2 #  Copyright (C) 2010 EDF R&D
3 #
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.
8 #
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.
13 #
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
17 #
18 #  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #
20
21 """
22 This file centralizes the definitions and implementations of ui components used
23 in the GUI part of the module.
24 """
25
26 __author__ = "aribes/gboulant"
27
28 import traceback
29 from PyQt4.QtCore import QObject
30 import SalomePyQt
31 sgPyQt = SalomePyQt.SalomePyQt()
32
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
40
41 __cases__ = {}
42
43 #
44 # ==============================================================================
45 # Classes to manage the building of UI components
46 # ==============================================================================
47 #
48 UI_ELT_IDS = Enumerate([
49         'DATASSIM_MENU_ID',
50         'NEW_DATASSIMCASE_ID',
51         ],offset=950)
52
53 ACTIONS_MAP={
54     UI_ELT_IDS.NEW_DATASSIMCASE_ID:"newDatassimCase",
55 }
56
57 class DatassimGuiUiComponentBuilder:
58     """
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).
62     """
63     def __init__(self):
64         self.initUiComponents()
65
66     def initUiComponents(self):
67         
68         objectTR = QObject()
69
70         # create top-level menu
71         mid = sgPyQt.createMenu( "DATASSIM", -1, UI_ELT_IDS.DATASSIM_MENU_ID, sgPyQt.defaultMenuGroup() )
72         # create toolbar
73         tid = sgPyQt.createTool( "DATASSIM" )
74
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)
78
79 class DatassimGuiActionImpl(EficasObserver):
80     """
81     This class implements the ui actions concerning the management of oma study
82     cases.
83     """
84     __dlgEficasWrapper = None
85
86     def __init__(self):
87         pass
88         # This dialog is created once so that it can be recycled for each call
89         # to newOmaCase().
90         #self.__dlgNewStudyCase = DlgNewStudyCase()
91         self.__dlgEficasWrapper = DatassimEficasWrapper(parent=SalomePyQt.SalomePyQt().getDesktop())
92         self.__dlgEficasWrapper.addObserver(self)
93
94     # ==========================================================================
95     # Processing of ui actions
96     #
97     def processAction(self,actionId):
98         """
99         Main switch function for ui actions processing
100         """
101         if ACTIONS_MAP.has_key(actionId):
102             try:
103                 functionName = ACTIONS_MAP[actionId]
104                 getattr(self,functionName)()
105             except:
106                 traceback.print_exc()
107         else:
108             msg = "The requested action is not implemented: " + str(actionId)
109             print msg
110
111     def newDatassimCase(self):
112       self.__dlgEficasWrapper.displayNew()
113
114     # ==========================================================================
115     # Processing notifications from eficas
116     #
117     __processOptions={
118         EficasEvent.EVENT_TYPES.CLOSE : "_processEficasCloseEvent",
119         EficasEvent.EVENT_TYPES.SAVE  : "_processEficasSaveEvent",
120         EficasEvent.EVENT_TYPES.NEW  : "_processEficasNewEvent",
121         EficasEvent.EVENT_TYPES.DESTROY  : "_processEficasDestroyEvent"
122         }
123     def processEficasEvent(self, eficasWrapper, eficasEvent):
124         """
125         Implementation of the interface EficasObserver. The implementation is a
126         switch on the possible types of events defined in EficasEvent.EVENT_TYPES.
127         @overload
128         """
129         functionName = self.__processOptions.get(eficasEvent.eventType, lambda : "_processEficasUnknownEvent")
130         return getattr(self,functionName)(eficasWrapper, eficasEvent)
131
132     def _processEficasCloseEvent(self, eficasWrapper, eficasEvent):
133         print "This is the process of EficasCloseEvent"
134         print "Remove datassim case in study if empty..."
135         pass
136
137     def _processEficasNewEvent(self, eficasWrapper, eficasEvent):
138       global __cases__
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)
147
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")
155
156         # Get Editor All infos we need !
157         file_name = eficasWrapper.getCaseName()
158         if file_name != "" :
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()
164
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")
172
173         case_key = (targetSalomeStudyId, targetSalomeStudyItem)
174         __cases__.pop(case_key)
175         datassimStudyEditor.removeItem(targetSalomeStudyId, targetSalomeStudyItem)
176         datassimGuiHelper.refreshObjectBrowser()
177
178     def _processEficasUnknownEvent(self, eficasWrapper, eficasEvent):
179       print "Unknown Eficas Event"