]> SALOME platform Git repositories - modules/adao.git/blob - src/daSalome/daGUI/daGuiImpl/datassimGuiManager.py
Salome HOME
9d53d56a4dc5cc58a6663d5b56d48d010357cadf
[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 daEficasWrapper.datassimEficasWrapper import DatassimEficasWrapper
35 from daEficasWrapper.eficasWrapper import EficasObserver
36 from daEficasWrapper.eficasWrapper import EficasEvent
37 import datassimGuiHelper
38 import datassimStudyEditor
39
40 #
41 # ==============================================================================
42 # Classes to manage the building of UI components
43 # ==============================================================================
44 #
45 UI_ELT_IDS = Enumerate([
46         'DATASSIM_MENU_ID',
47         'NEW_DATASSIMCASE_ID',
48         ],offset=950)
49
50 ACTIONS_MAP={
51     UI_ELT_IDS.NEW_DATASSIMCASE_ID:"newDatassimCase",
52 }
53
54 class DatassimGuiUiComponentBuilder:
55     """
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).
59     """
60     def __init__(self):
61         self.initUiComponents()
62
63     def initUiComponents(self):
64         
65         objectTR = QObject()
66
67         # create top-level menu
68         mid = sgPyQt.createMenu( "DATASSIM", -1, UI_ELT_IDS.DATASSIM_MENU_ID, sgPyQt.defaultMenuGroup() )
69         # create toolbar
70         tid = sgPyQt.createTool( "DATASSIM" )
71
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)
75
76 class DatassimGuiActionImpl(EficasObserver):
77     """
78     This class implements the ui actions concerning the management of oma study
79     cases.
80     """
81     __dlgEficasWrapper = None
82
83     def __init__(self):
84         pass
85         # This dialog is created once so that it can be recycled for each call
86         # to newOmaCase().
87         #self.__dlgNewStudyCase = DlgNewStudyCase()
88         self.__dlgEficasWrapper = DatassimEficasWrapper(parent=SalomePyQt.SalomePyQt().getDesktop())
89         self.__dlgEficasWrapper.addObserver(self)
90
91     # ==========================================================================
92     # Processing of ui actions
93     #
94     def processAction(self,actionId):
95         """
96         Main switch function for ui actions processing
97         """
98         if ACTIONS_MAP.has_key(actionId):
99             try:
100                 functionName = ACTIONS_MAP[actionId]
101                 getattr(self,functionName)()
102             except:
103                 traceback.print_exc()
104         else:
105             msg = "The requested action is not implemented: " + str(actionId)
106             print msg
107
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()
116
117     # ==========================================================================
118     # Processing notifications from eficas
119     #
120     __processOptions={
121         EficasEvent.EVENT_TYPES.CLOSE : "_processEficasCloseEvent",
122         EficasEvent.EVENT_TYPES.SAVE  : "_processEficasSaveEvent"
123         }
124     def processEficasEvent(self, eficasWrapper, eficasEvent):
125         """
126         Implementation of the interface EficasObserver. The implementation is a
127         switch on the possible types of events defined in EficasEvent.EVENT_TYPES.
128         @overload
129         """
130         functionName = self.__processOptions.get(eficasEvent.eventType, lambda : "_processEficasUnknownEvent")
131         return getattr(self,functionName)(eficasWrapper, eficasEvent)
132
133     def _processEficasCloseEvent(self, eficasWrapper, eficasEvent):
134         print "This is the process of EficasCloseEvent"
135         print "Remove datassim case in study if empty..."
136         pass
137
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")
145
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()))
151
152     def _processEficasUnknownEvent(self, eficasWrapper, eficasEvent):
153       print "Unknown Eficas Event"