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