]> SALOME platform Git repositories - modules/adao.git/blob - src/daSalome/daGUI/daGuiImpl/adaoGuiManager.py
Salome HOME
Ajout des icones etats dans l'arbre d'étude (+ gestion activation)
[modules/adao.git] / src / daSalome / daGUI / daGuiImpl / adaoGuiManager.py
1 # -*- coding: utf-8 -*-
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 from PyQt4.QtCore import *        # Import from PyQT
31 from PyQt4 import QtGui,QtCore
32 import SalomePyQt
33 sgPyQt = SalomePyQt.SalomePyQt()
34
35 from daGuiImpl.enumerate import Enumerate
36 from daGuiImpl.adaoCase import AdaoCase
37 from daEficasWrapper.adaoEficasWrapper import AdaoEficasWrapper
38
39 from daUtils.adaoEficasEvent import *
40 import adaoGuiHelper
41 import adaoStudyEditor
42 import adaoLogger
43
44 __cases__ = {}
45
46 #
47 # ==============================================================================
48 # Classes to manage the building of UI components
49 # ==============================================================================
50 #
51 UI_ELT_IDS = Enumerate([
52         'ADAO_MENU_ID',
53         'NEW_ADAOCASE_ID',
54         'OPEN_ADAOCASE_ID',
55         'SAVE_ADAOCASE_ID',
56         'SAVE_AS_ADAOCASE_ID',
57         'CLOSE_ADAOCASE_ID',
58
59         'EDIT_ADAOCASE_POP_ID',
60         'YACS_EXPORT_POP_ID',
61         ],offset=6950)
62
63 ACTIONS_MAP={
64     UI_ELT_IDS.NEW_ADAOCASE_ID:"newAdaoCase",
65     UI_ELT_IDS.OPEN_ADAOCASE_ID:"openAdaoCase",
66     UI_ELT_IDS.SAVE_ADAOCASE_ID:"saveAdaoCase",
67     UI_ELT_IDS.SAVE_AS_ADAOCASE_ID:"saveasAdaoCase",
68     UI_ELT_IDS.CLOSE_ADAOCASE_ID:"closeAdaoCase",
69
70     UI_ELT_IDS.EDIT_ADAOCASE_POP_ID:"editAdaoCase",
71     UI_ELT_IDS.YACS_EXPORT_POP_ID:"exportCaseToYACS",
72 }
73
74
75 class AdaoCaseManager(EficasObserver):
76   """
77   Cette classe gére les cas ADAO et coordonne les GUI de SALOME (l'étude)
78   et le GUI de l'objet Eficas (héritage du module Eficas)
79   """
80
81   def __init__(self):
82
83     # Création d'un dictionnaire de cas
84     # Key   == ref objet editor eficas (on est sur qu'elle est unique, cas duplication)
85     # Value == objet AdaoCase()
86     self.cases = {}
87
88     # Création des deux managers
89     self.salome_manager = AdaoGuiUiComponentBuilder()
90     self.eficas_manager = AdaoEficasWrapper(parent=SalomePyQt.SalomePyQt().getDesktop())
91
92     # On s'enregistre comme observer pour les évènements venant d'Eficas
93     # Les évènements du salome_manager viennent par le biais de la méthode
94     # processGUIEvent
95     self.eficas_manager.addObserver(self)
96
97     # Création du GUI Eficas
98     self.eficas_manager.init_gui()
99
100     # Création du viewer QT
101     # Scroll Widget (pour les petites résolutions)
102     area = QtGui.QScrollArea(SalomePyQt.SalomePyQt().getDesktop());
103     area.setWidget(self.eficas_manager)
104     area.setWidgetResizable(1)
105     wmType = "ADAO View"
106     self.eficas_viewId = sgPyQt.createView(wmType, area)
107
108     # On interdit que la vue soit fermée
109     # Cela simplifier grandement le code
110     sgPyQt.setViewClosable(self.eficas_viewId, False)
111
112     # On s'abonne au gestionnaire de selection
113     self.selection_manager = sgPyQt.getSelection()
114     QtCore.QObject.connect(self.selection_manager, QtCore.SIGNAL('currentSelectionChanged()'), self.currentSelectionChanged)
115
116 ######
117 #
118 # Gestion de l'activation/désactivation du module
119 #
120 ######
121
122   def activate(self):
123     self.eficas_manager.setEnabled(True)
124     sgPyQt.activateView(self.eficas_viewId)
125     self.harmonizeSelectionFromEficas()
126
127   def deactivate(self):
128     self.eficas_manager.setEnabled(False)
129
130 #######
131 #
132 # Gestion de la sélection entre le GUI d'Eficas
133 # et l'arbre d'étude de SALOME
134 #
135 #######
136
137   # Depuis l'étude SALOME
138   def currentSelectionChanged(self):
139     """
140     Cette méthode permet de changer le tab vu dans eficas
141     selon la sélection de l'utilisateur dans l'étude SALOME
142     """
143     adaoLogger.debug("currentSelectionChanged")
144     salomeStudyItem = adaoGuiHelper.getSelectedItem()
145     for case_editor, adao_case in self.cases.iteritems():
146       if adao_case.salome_study_item.GetID() == salomeStudyItem.GetID():
147         self.eficas_manager.selectCase(adao_case.eficas_editor)
148         break
149
150   # Depuis Eficas
151   def _processEficasTabChanged(self, eficasWrapper, eficasEvent):
152     """
153     Gestion de la synchonisation entre le tab courant d'Eficas
154     et la selection dans l'étude SALOME
155     """
156     editor = eficasEvent.callbackId
157     for case_editor, adao_case in self.cases.iteritems():
158       if case_editor is editor:
159         adaoGuiHelper.selectItem(adao_case.salome_study_item.GetID())
160         break
161
162   # On remet la sélection dans SALOME grâce au tab dans Eficas
163   def harmonizeSelectionFromEficas(self):
164     """
165     Cette méthode permet d'harmoniser la sélection dans l'étude
166     grâce au tab courant d'Eficas
167     """
168     adaoLogger.error("harmonizeSelectionFromEficas NOT YET IMPLEMENTED")
169     if self.cases:
170       pass
171       # 1: Get current tab index in Eficas
172       # 2: sync with SALOME GUI is a tab is opened
173
174 #######
175 #
176 # Gestion de la création d'un nouveau cas
177 # 1: la fonction newAdaoCase est appelée par le GUI SALOME
178 # 2: la fonction _processEficasNewEvent est appelée par le manager EFICAS
179 #
180 #######
181
182   def newAdaoCase(self):
183     adaoLogger.debug("Création d'un nouveau cas adao")
184     self.eficas_manager.adaofileNew(AdaoCase())
185
186   def _processEficasNewEvent(self, eficasWrapper, eficasEvent):
187     adao_case = eficasEvent.callbackId
188     # Ajout dand l'étude
189     salomeStudyId   = adaoGuiHelper.getActiveStudyId()
190     salomeStudyItem = adaoStudyEditor.addInStudy(salomeStudyId, adao_case)
191     # Affichage correct dans l'étude
192     adaoGuiHelper.refreshObjectBrowser()
193     adaoGuiHelper.selectItem(salomeStudyItem.GetID())
194     # Finalisation des données du cas
195     adao_case.salome_study_id   = salomeStudyId
196     adao_case.salome_study_item = salomeStudyItem
197     # Ajout du cas
198     self.cases[adao_case.eficas_editor] = adao_case
199
200 #######
201 #
202 # Gestion de l'ouverture d'un cas
203 # 1: la fonction openAdaoCase est appelée par le GUI SALOME
204 # 2: la fonction _processEficasOpenEvent est appelée par le manager EFICAS
205 #
206 #######
207
208 # Rq: l'ouverture d'un cas adao est un cas particulier de la création d'un cas adao
209
210   def openAdaoCase(self):
211     adaoLogger.debug("Ouverture d'un cas adao")
212     self.eficas_manager.adaoFileOpen(AdaoCase())
213
214   def _processEficasOpenEvent(self, eficasWrapper, eficasEvent):
215     self._processEficasNewEvent(eficasWrapper, eficasEvent)
216
217 #######
218 #
219 # Gestion de la sauvegarde d'un cas
220 # 1: la fonction saveAdaoCase est appelée par le GUI SALOME
221 # 1 bis: la fonction saveasAdaoCase est appelée par le GUI SALOME
222 # 2: la fonction _processEficasSaveEvent est appelée par le manager EFICAS
223 #
224 #######
225
226   def saveAdaoCase(self):
227     adaoLogger.debug("Sauvegarde du cas s'il y a modification")
228     # A priori, l'utilisateur s'attend à sauvegarder le cas qui est ouvert
229     # dans le GUI d'Eficas
230     self.harmonizeSelectionFromEficas()
231     salomeStudyItem = adaoGuiHelper.getSelectedItem()
232     for case_name, adao_case in self.cases.iteritems():
233       if adao_case.salome_study_item.GetID() == salomeStudyItem.GetID():
234         self.eficas_manager.adaoFileSave(adao_case)
235         break
236
237   def saveasAdaoCase(self):
238     adaoLogger.debug("Sauvegarde du cas s'il y a modification (version save as)")
239     # A priori, l'utilisateur s'attend à sauvegarder le cas qui est ouvert
240     # dans le GUI d'Eficas
241     self.harmonizeSelectionFromEficas()
242     salomeStudyItem = adaoGuiHelper.getSelectedItem()
243     for case_name, adao_case in self.cases.iteritems():
244       if adao_case.salome_study_item.GetID() == salomeStudyItem.GetID():
245         self.eficas_manager.adaoFileSaveAs(adao_case)
246         break
247
248   def _processEficasSaveEvent(self, eficasWrapper, eficasEvent):
249     adao_case = eficasEvent.callbackId
250     # On met à jour l'étude
251     adaoStudyEditor.updateItem(adao_case.salome_study_id, adao_case.salome_study_item, adao_case)
252     # Affichage correct dans l'étude
253     adaoGuiHelper.refreshObjectBrowser()
254     adaoGuiHelper.selectItem(adao_case.salome_study_item.GetID())
255     # Ajout du cas
256     self.cases[adao_case.name] = adao_case
257
258 #######
259 #
260 # Gestion de la fermeture d'un cas
261 # 1: la fonction closeAdaoCase est appelée par le GUI SALOME
262 # 2: la fonction _processEficasCloseEvent est appelée par le manager EFICAS
263 #
264 #######
265
266   def closeAdaoCase(self):
267     adaoLogger.debug("Fermeture d'un cas")
268     # A priori, l'utilisateur s'attend à sauvegarder le cas qui est ouvert
269     # dans le GUI d'Eficas
270     self.harmonizeSelectionFromEficas()
271     salomeStudyItem = adaoGuiHelper.getSelectedItem()
272     for case_name, adao_case in self.cases.iteritems():
273       if adao_case.salome_study_item.GetID() == salomeStudyItem.GetID():
274         self.eficas_manager.adaoFileClose(adao_case)
275         break
276
277   def _processEficasCloseEvent(self, eficasWrapper, eficasEvent):
278     editor = eficasEvent.callbackId
279     # Recuperation du cas
280     adao_case = self.cases[editor]
281     # Suppression de l'objet dans l'étude
282     adaoStudyEditor.removeItem(adao_case.salome_study_id, adao_case.salome_study_item)
283     adaoGuiHelper.refreshObjectBrowser()
284     # Suppression du cas
285     del self.cases[editor]
286
287 #######
288 #
289 # Méthodes secondaires permettant de rediriger les évènements
290 # de SALOME et d'Eficas vers les bonnes méthodes de la classe
291 #
292 #######
293
294   # Gestion des évènements venant du manager Eficas
295   __processOptions={
296       EficasEvent.EVENT_TYPES.CLOSE      : "_processEficasCloseEvent",
297       EficasEvent.EVENT_TYPES.SAVE       : "_processEficasSaveEvent",
298       EficasEvent.EVENT_TYPES.NEW        : "_processEficasNewEvent",
299       EficasEvent.EVENT_TYPES.CLOSE      : "_processEficasCloseEvent",
300       EficasEvent.EVENT_TYPES.OPEN       : "_processEficasOpenEvent",
301       EficasEvent.EVENT_TYPES.TABCHANGED : "_processEficasTabChanged",
302       EficasEvent.EVENT_TYPES.REOPEN     : "_processEficasReOpenEvent"
303       }
304
305   def processEficasEvent(self, eficasWrapper, eficasEvent):
306       """
307       Implementation of the interface EficasObserver. The implementation is a
308       switch on the possible types of events defined in EficasEvent.EVENT_TYPES.
309       @overload
310       """
311       functionName = self.__processOptions.get(eficasEvent.eventType, lambda : "_processEficasUnknownEvent")
312       return getattr(self,functionName)(eficasWrapper, eficasEvent)
313
314   def _processEficasUnknownEvent(self, eficasWrapper, eficasEvent):
315     adaoLogger.error("Unknown Eficas Event")
316
317   # Gestion des évènements venant du GUI de SALOME
318   def processGUIEvent(self, actionId):
319     """
320     Main switch function for ui actions processing
321     """
322     if ACTIONS_MAP.has_key(actionId):
323       try:
324           functionName = ACTIONS_MAP[actionId]
325           getattr(self,functionName)()
326       except:
327           traceback.print_exc()
328     else:
329       adaoLogger.warning("The requested action is not implemented: " + str(actionId))
330
331 class AdaoGuiUiComponentBuilder:
332     """
333     The initialisation of this class creates the graphic components involved
334     in the GUI (menu, menu item, toolbar). A ui component builder should be
335     created for each opened study and associated to its context.
336     """
337     def __init__(self):
338         self.initUiComponents()
339
340     def initUiComponents(self):
341
342         objectTR = QObject()
343
344         # create top-level menu
345         mid = sgPyQt.createMenu( "ADAO", -1, UI_ELT_IDS.ADAO_MENU_ID, sgPyQt.defaultMenuGroup() )
346         # create toolbar
347         tid = sgPyQt.createTool( "ADAO" )
348
349         a = sgPyQt.createAction( UI_ELT_IDS.NEW_ADAOCASE_ID, "New case", "New case", "Create a new adao case", "" )
350         sgPyQt.createMenu(a, mid)
351         sgPyQt.createTool(a, tid)
352         a = sgPyQt.createAction( UI_ELT_IDS.OPEN_ADAOCASE_ID, "Open case", "Open case", "Open an adao case", "" )
353         sgPyQt.createMenu(a, mid)
354         sgPyQt.createTool(a, tid)
355         a = sgPyQt.createAction( UI_ELT_IDS.SAVE_ADAOCASE_ID, "Save case", "Save case", "Save an adao case", "" )
356         sgPyQt.createMenu(a, mid)
357         sgPyQt.createTool(a, tid)
358         a = sgPyQt.createAction( UI_ELT_IDS.SAVE_AS_ADAOCASE_ID, "Save as case", "Save as case", "Save an adao case as", "" )
359         sgPyQt.createMenu(a, mid)
360         sgPyQt.createTool(a, tid)
361         a = sgPyQt.createAction( UI_ELT_IDS.CLOSE_ADAOCASE_ID, "Close case", "Close case", "Close an adao case", "" )
362         sgPyQt.createMenu(a, mid)
363         sgPyQt.createTool(a, tid)
364
365         # the following action are used in context popup
366         a = sgPyQt.createAction( UI_ELT_IDS.CLOSE_ADAOCASE_ID, "Close case", "Close case", "Close the selected case", "" )
367
368         a = sgPyQt.createAction( UI_ELT_IDS.EDIT_ADAOCASE_POP_ID, "Edit case", "Edit case", "Edit the selected study case", "" )
369         a = sgPyQt.createAction( UI_ELT_IDS.YACS_EXPORT_POP_ID, "Export to YACS", "Export to YACS", "Generate a YACS graph executing this case", "" )
370
371     def createPopupMenuOnItem(self,popup,salomeSudyId, item):
372         if adaoStudyEditor.isValidAdaoCaseItem(salomeSudyId, item):
373           popup.addAction( sgPyQt.action( UI_ELT_IDS.CLOSE_ADAOCASE_ID ) )
374
375           popup.addAction( sgPyQt.action( UI_ELT_IDS.EDIT_ADAOCASE_POP_ID ) )
376           popup.addAction( sgPyQt.action( UI_ELT_IDS.YACS_EXPORT_POP_ID ) )
377
378         return popup
379
380 class AdaoGuiActionImpl(EficasObserver):
381     """
382     This class implements the ui actions concerning the management of oma study
383     cases.
384     """
385
386     def __init__(self):
387         pass
388         # This dialog is created once so that it can be recycled for each call
389         # to newOmaCase().
390         #self.__dlgNewStudyCase = DlgNewStudyCase()
391         self.__parent = SalomePyQt.SalomePyQt().getDesktop()
392         self.__dlgEficasWrapper = AdaoEficasWrapper(parent=SalomePyQt.SalomePyQt().getDesktop())
393         self.__dlgEficasWrapper.addObserver(self)
394         self.__Eficas_viewId = -1
395
396     # ==========================================================================
397     # Processing of ui actions
398     #
399     def processAction(self,actionId):
400         """
401         Main switch function for ui actions processing
402         """
403         if ACTIONS_MAP.has_key(actionId):
404             try:
405                 functionName = ACTIONS_MAP[actionId]
406                 getattr(self,functionName)()
407             except:
408                 traceback.print_exc()
409         else:
410             msg = "The requested action is not implemented: " + str(actionId)
411             print msg
412
413     def showEficas(self):
414       if self.__Eficas_viewId == -1:
415         self.__dlgEficasWrapper.init_gui()
416
417
418         # Scroll Widget
419         area = QtGui.QScrollArea(SalomePyQt.SalomePyQt().getDesktop());
420         area.setWidget( self.__dlgEficasWrapper)
421         area.setWidgetResizable(1)
422
423         wmType = "ADAO View"
424         self.__Eficas_viewId = sgPyQt.createView(wmType, area)
425         sgPyQt.setViewClosable(self.__Eficas_viewId, False)
426       else:
427         if SalomePyQt.SalomePyQt().getActiveView() != self.__Eficas_viewId :
428           result_activate = SalomePyQt.SalomePyQt().activateView(self.__Eficas_viewId)
429           if result_activate == False:
430             self.__dlgEficasWrapper.init_gui()
431
432             # Scroll Widget
433             area = QtGui.QScrollArea(SalomePyQt.SalomePyQt().getDesktop());
434             area.setWidget( self.__dlgEficasWrapper)
435             area.setWidgetResizable(1)
436
437             wmType = "ADAO View"
438             self.__Eficas_viewId = sgPyQt.createView(wmType, area)
439             sgPyQt.setViewClosable(self.__Eficas_viewId, False)
440         self.__dlgEficasWrapper.setEnabled(True)
441
442     def activate(self):
443       self.showEficas()
444
445     def deactivate(self):
446       self.showEficas()
447       if self.__Eficas_viewId != -1:
448         self.__dlgEficasWrapper.setEnabled(False)
449
450     # Actions from SALOME GUI
451
452     def newAdaoCase(self):
453
454       adaoLogger.debug("newAdaoCase")
455       self.showEficas()
456       self.__dlgEficasWrapper.fileNew()
457
458     def openAdaoCase(self):
459
460       adaoLogger.debug("openAdaoCase")
461       self.showEficas()
462       global __cases__
463       fichier = QtGui.QFileDialog.getOpenFileName(SalomePyQt.SalomePyQt().getDesktop(),
464                                                   self.__dlgEficasWrapper.trUtf8('Ouvrir Fichier'),
465                                                   self.__dlgEficasWrapper.CONFIGURATION.savedir,
466                                                   self.__dlgEficasWrapper.trUtf8('JDC Files (*.comm);;''All Files (*)'))
467       if fichier.isNull(): return
468       new_case = AdaoCase()
469       new_case.set_filename(str(fichier))
470       new_case.set_name(str(fichier.split('/')[-1]))
471       salomeStudyId   = adaoGuiHelper.getActiveStudyId()
472       salomeStudyItem = adaoStudyEditor.addInStudy(salomeStudyId, new_case)
473       case_key = (salomeStudyId, salomeStudyItem.GetID())
474       __cases__[case_key] = new_case
475
476       # Open file in Eficas
477       self.__dlgEficasWrapper.Openfile(new_case.get_filename())
478       callbackId = [salomeStudyId, salomeStudyItem]
479       self.__dlgEficasWrapper.setCallbackId(callbackId)
480       self.showEficas()
481       adaoGuiHelper.refreshObjectBrowser()
482
483     def editAdaoCase(self):
484
485       adaoLogger.debug("editAdaoCase")
486       global __cases__
487
488       # Take study item
489       salomeStudyId   = adaoGuiHelper.getActiveStudyId()
490       salomeStudyItem = adaoGuiHelper.getSelectedItem(salomeStudyId)
491       case_key = (salomeStudyId, salomeStudyItem.GetID())
492
493       # ShowEficas, If case is an empty case - case is destroyed by reopen
494       self.showEficas()
495       try:
496         case = __cases__[case_key]
497         # Search if case is in Eficas !
498         callbackId = [salomeStudyId, salomeStudyItem]
499         case_open_in_eficas = self.__dlgEficasWrapper.selectCase(callbackId)
500
501         # If case is not in eficas Open It !
502         if case_open_in_eficas == False:
503           if case.get_filename() != "":
504             self.__dlgEficasWrapper.Openfile(case.get_filename())
505             callbackId = [salomeStudyId, salomeStudyItem]
506             self.__dlgEficasWrapper.setCallbackId(callbackId)
507       except:
508         # Case has been destroyed - create a new one
509         self.__dlgEficasWrapper.fileNew()
510
511     def closeAdaoCase(self):
512
513       adaoLogger.debug("closeAdaoCase")
514       global __cases__
515
516       # First step: get selected case
517       salomeStudyId   = adaoGuiHelper.getActiveStudyId()
518       salomeStudyItem = adaoGuiHelper.getSelectedItem(salomeStudyId)
519
520       # Check if there is a selected case
521       if salomeStudyItem is None:
522         print "[Close case] Please select a case"
523         return
524
525       callbackId = [salomeStudyId, salomeStudyItem]
526       case_open_in_eficas = self.__dlgEficasWrapper.selectCase(callbackId)
527
528       # If case is in eficas close it !
529       if case_open_in_eficas:
530         # fileClose: remove the CallbackId
531         # fileClose: sends a destroy event
532         self.__dlgEficasWrapper.fileClose()
533       else:
534         # Test if case exists
535         case_key = (salomeStudyId, salomeStudyItem.GetID())
536         if __cases__.has_key(case_key):
537           __cases__.pop(case_key)
538           adaoStudyEditor.removeItem(salomeStudyId, salomeStudyItem)
539           adaoGuiHelper.refreshObjectBrowser()
540
541     def saveAdaoCase(self):
542
543       adaoLogger.debug("saveAdaoCase")
544       global __cases__
545
546     def saveasAdaoCase(self):
547
548       adaoLogger.debug("saveasAdaoCase")
549       global __cases__
550
551     def exportCaseToYACS(self):
552
553       adaoLogger.debug("exportCaseToYACS")
554       global __cases__
555
556       # Get case from study
557       salomeStudyId   = adaoGuiHelper.getActiveStudyId()
558       salomeStudyItem = adaoGuiHelper.getSelectedItem(salomeStudyId)
559       case_key = (salomeStudyId, salomeStudyItem.GetID())
560       case = __cases__[case_key]
561
562       # Generates YACS schema and export it
563       msg = case.exportCaseToYACS()
564
565       # If msg is not empty -> error found
566       if msg != "":
567         adaoGuiHelper.gui_warning(self.__parent, msg)
568
569     # ==========================================================================
570     # Processing notifications from adaoEficasWrapper
571     #
572     __processOptions={
573         EficasEvent.EVENT_TYPES.CLOSE   : "_processEficasCloseEvent",
574         EficasEvent.EVENT_TYPES.SAVE    : "_processEficasSaveEvent",
575         EficasEvent.EVENT_TYPES.NEW     : "_processEficasNewEvent",
576         EficasEvent.EVENT_TYPES.OPEN    : "_processEficasOpenEvent",
577         EficasEvent.EVENT_TYPES.REOPEN  : "_processEficasReOpenEvent"
578         }
579     def processEficasEvent(self, eficasWrapper, eficasEvent):
580         """
581         Implementation of the interface EficasObserver. The implementation is a
582         switch on the possible types of events defined in EficasEvent.EVENT_TYPES.
583         @overload
584         """
585         functionName = self.__processOptions.get(eficasEvent.eventType, lambda : "_processEficasUnknownEvent")
586         return getattr(self,functionName)(eficasWrapper, eficasEvent)
587
588     def _processEficasCloseEvent(self, eficasWrapper, eficasEvent):
589         pass
590
591     def _processEficasNewEvent(self, eficasWrapper, eficasEvent):
592       global __cases__
593
594       new_case = AdaoCase()
595       case_name = eficasWrapper.getCaseName()
596       new_case.set_name(case_name)
597       salomeStudyId   = adaoGuiHelper.getActiveStudyId()
598       salomeStudyItem = adaoStudyEditor.addInStudy(salomeStudyId, new_case)
599       case_key = (salomeStudyId, salomeStudyItem.GetID())
600       __cases__[case_key] = new_case
601       adaoGuiHelper.refreshObjectBrowser()
602       callbackId = [salomeStudyId, salomeStudyItem]
603       self.__dlgEficasWrapper.setCallbackId(callbackId)
604
605       # We need to select the case
606       adaoGuiHelper.selectItem(salomeStudyItem.GetID())
607
608
609     def _processEficasOpenEvent(self, eficasWrapper, eficasEvent):
610       global __cases__
611
612       # Ouverture du fichier
613       self.__dlgEficasWrapper.Openfile(self.__dlgEficasWrapper.getOpenFileName())
614
615       # Creation d'un nouveau cas
616       new_case = AdaoCase()
617       salomeStudyId   = adaoGuiHelper.getActiveStudyId()
618       salomeStudyItem = adaoStudyEditor.addInStudy(salomeStudyId, new_case)
619       case_key = (salomeStudyId, salomeStudyItem.GetID())
620       __cases__[case_key] = new_case
621
622       # Connexion du nouveau cas
623       callbackId = [salomeStudyId, salomeStudyItem]
624       self.__dlgEficasWrapper.setCallbackId(callbackId)
625
626       # On sauvegarde le cas
627       self._processEficasSaveEvent(self.__dlgEficasWrapper, None, callbackId)
628
629     def _processEficasSaveEvent(self, eficasWrapper, eficasEvent, callbackId=None):
630         global __cases__
631         if callbackId is None:
632           callbackId = eficasEvent.callbackId
633           if callbackId is None:
634             raise DevelException("the callback data should not be None. Can't guess what are the study and case")
635           [targetSalomeStudyId,targetSalomeStudyItem] = callbackId
636           if ( targetSalomeStudyId is None ) or ( targetSalomeStudyItem is None ):
637             raise DevelException("the parameters targetSalomeStudyId and targetSalomeStudyItem should not be None")
638         else:
639           [targetSalomeStudyId,targetSalomeStudyItem] = callbackId
640
641         # Get Editor All infos we need !
642         case_name = eficasWrapper.getCaseName()
643         file_case_name = eficasWrapper.getFileCaseName()
644         if case_name != "" :
645           # Get case
646           old_case_key = (targetSalomeStudyId, targetSalomeStudyItem.GetID())
647           case =__cases__[old_case_key]
648
649           # Set new informations
650           case.set_name(case_name)
651           if str(case_name).startswith("Untitled"):
652             pass
653           else:
654             case.set_filename(file_case_name)
655           adaoStudyEditor.updateItem(targetSalomeStudyId, targetSalomeStudyItem, case)
656
657           # Case key changed !
658           #new_case_key = (targetSalomeStudyId, targetSalomeStudyItem.GetID())
659           # A ne pas inverser !!!
660           #__cases__.pop(old_case_key)
661           #__cases__[new_case_key] = case
662
663           adaoGuiHelper.refreshObjectBrowser()
664
665     def _processEficasDestroyEvent(self, eficasWrapper, eficasEvent):
666         global __cases__
667         callbackId = eficasEvent.callbackId
668         if callbackId is None:
669             raise DevelException("the callback data should not be None. Can't guess what are the study and case")
670         [targetSalomeStudyId,targetSalomeStudyItem] = callbackId
671         if ( targetSalomeStudyId is None ) or ( targetSalomeStudyItem is None ):
672             raise DevelException("the parameters targetSalomeStudyId and targetSalomeStudyItem should not be None")
673
674         case_key = (targetSalomeStudyId, targetSalomeStudyItem.GetID())
675         __cases__.pop(case_key)
676         adaoStudyEditor.removeItem(targetSalomeStudyId, targetSalomeStudyItem)
677         adaoGuiHelper.refreshObjectBrowser()
678
679     # Deprecated
680     # Normalement on ne ferme plus le GUI donc on ne passe plus par là
681     def _processEficasReOpenEvent(self, eficasWrapper, eficasEvent):
682
683       adaoLogger.warning("_processEficasReOpenEvent")
684       global __cases__
685
686       try:
687         callbackId = eficasEvent.callbackId
688         [salomeStudyId, salomeStudyItem] = callbackId
689         case_key = (salomeStudyId, salomeStudyItem.GetID())
690         case = __cases__[case_key]
691         # Search if case is in Eficas !
692         callbackId = [salomeStudyId, salomeStudyItem]
693         case_open_in_eficas = self.__dlgEficasWrapper.selectCase(callbackId)
694         # If case is not in eficas Open It !
695         if case_open_in_eficas == False:
696           if case.get_filename() != "":
697             self.__dlgEficasWrapper.Openfile(case.get_filename())
698             callbackId = [salomeStudyId, salomeStudyItem]
699             self.__dlgEficasWrapper.setCallbackId(callbackId)
700           else:
701             # Since I am an empty case I destroy myself before reloading
702             adaoStudyEditor.removeItem(salomeStudyId, salomeStudyItem)
703             adaoGuiHelper.refreshObjectBrowser()
704             __cases__.pop(case_key)
705             callbackId = [salomeStudyId, salomeStudyItem]
706             self.__dlgEficasWrapper.removeCallbackId(callbackId)
707       except:
708         print "Oups - cannot reopen case !"
709         traceback.print_exc()
710
711     def _processEficasUnknownEvent(self, eficasWrapper, eficasEvent):
712       print "Unknown Eficas Event"