]> SALOME platform Git repositories - modules/adao.git/blob - src/daSalome/daGUI/daEficasWrapper/adaoEficasWrapper.py
Salome HOME
Gestion de la sélection dans l'arbre d'étude
[modules/adao.git] / src / daSalome / daGUI / daEficasWrapper / adaoEficasWrapper.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 import sys
22 import os
23
24 import eficasSalome               # Import from EFICAS_SRC
25 from InterfaceQT4 import qtEficas # Import from Eficas
26 from PyQt4.QtGui  import *        # Import from PyQT
27 from PyQt4.QtCore import *        # Import from PyQT
28 from PyQt4.QtAssistant import *   # Import from PyQT
29
30 from daUtils.adaoEficasEvent import *
31 from daGuiImpl.adaoLogger import *
32
33 #
34 # ============================================
35 # Specialization of the EficasWrapper for ADAO
36 # ============================================
37 #
38 class AdaoEficasWrapper(eficasSalome.MyEficas):
39
40     def __init__(self, parent):
41         # Configuration de l'installation
42         # Permet à EFICAS de faire ses import correctement
43         my_path = os.path.dirname(os.path.abspath(__file__))
44         ADAO_INSTALL_DIR = my_path + "/../daEficas"
45         sys.path[:0]=[ADAO_INSTALL_DIR]
46
47         self.__myCallbackId = {}
48         self.__close_editor = None
49         self.__file_open_name = ""
50         self.__parent = parent
51
52     def init_gui(self):
53
54       eficasSalome.MyEficas.__init__(self, self.__parent, code="ADAO", module="ADAO")
55       self.connect(self.viewmanager.myQtab, SIGNAL('currentChanged(int)'), self.tabChanged)
56
57
58       # On réouvre tous les fichiers comm
59       # On fait une copie pour ne pas tomber dans une boucle infinie
60       # Deprecated
61       # Normalement on ne ferme plus le GUI donc on ne passe plus par là
62       save_CallbackId =  self.__myCallbackId.copy()
63       for editor, myCallbackId in save_CallbackId.iteritems():
64         self.notifyObserver(EficasEvent.EVENT_TYPES.REOPEN, callbackId=myCallbackId)
65
66     def tabChanged(self, index):
67       debug("tabChanged " + str(index))
68       # This signal is also emit when a new case is created/added
69       # On regarde que le dictionnaire contient l'index
70       if index in self.viewmanager.dict_editors.keys():
71         self.notifyObserver(EficasEvent.EVENT_TYPES.TABCHANGED, callbackId=self.viewmanager.dict_editors[index])
72
73     def addJdcInSalome(  self, jdcPath ):
74       # On gere nous meme l'etude
75       pass
76
77     def adaofileNew(self, adao_case):
78
79         qtEficas.Appli.fileNew(self)
80         index = self.viewmanager.myQtab.currentIndex()
81         adao_case.name          = str(self.viewmanager.myQtab.tabText(index)) # Utilisation de str() pour passer d'un Qstring à un string
82         adao_case.eficas_editor = self.viewmanager.dict_editors[index]
83         self.notifyObserver(EficasEvent.EVENT_TYPES.NEW, callbackId=adao_case)
84
85     def openEmptyCase(self, callbackId):
86         qtEficas.Appli.fileNew(self)
87         self.removeCallbackId(callbackId)
88         self.setCallbackId(callbackId)
89
90     def adaoFileSave(self, adao_case):
91
92         ok = qtEficas.Appli.fileSave(self)
93         if ok:
94           index = self.viewmanager.myQtab.currentIndex()
95           adao_case.name          = str(self.viewmanager.myQtab.tabText(index)) # Utilisation de str() pour passer d'un Qstring à un string
96           adao_case.eficas_editor = self.viewmanager.dict_editors[index]
97           adao_case.filename      = str(self.viewmanager.dict_editors[index].fichier)
98           self.notifyObserver(EficasEvent.EVENT_TYPES.SAVE, callbackId=adao_case)
99
100     def fileSaveAs(self):
101         """
102         @overload
103         """
104         qtEficas.Appli.fileSaveAs(self)
105         self.notifyObserver(EficasEvent.EVENT_TYPES.SAVE)
106
107     def getCaseName(self):
108       if self.__close_editor is None:
109         index = self.viewmanager.myQtab.currentIndex()
110         CaseName = self.viewmanager.myQtab.tabText(index)
111         return CaseName
112       else:
113         CaseName = str(self.__close_editor.fichier.split('/')[-1])
114         return CaseName
115
116     def getFileCaseName(self):
117       if self.__close_editor is None:
118         index = self.viewmanager.myQtab.currentIndex()
119         editor = self.viewmanager.dict_editors[index]
120         return editor.fichier
121       else:
122         return self.__close_editor.fichier
123
124     def Openfile(self, filename):
125       self.viewmanager.handleOpen(fichier=filename)
126
127     def handleOpenRecent(self):
128       """
129       @overload
130       """
131       idx = self.sender()
132       fichier = self.ficRecents[idx]
133       self.__file_open_name = fichier
134       self.notifyObserver(EficasEvent.EVENT_TYPES.OPEN)
135       self.__file_open_name = ""
136
137     def fileOpen(self):
138         """
139         @overload
140         """
141         fichier = QFileDialog.getOpenFileName(self,
142                                               self.trUtf8('Ouvrir Fichier'),
143                                               self.CONFIGURATION.savedir,
144                                               self.trUtf8('JDC Files (*.comm);;''All Files (*)'))
145         if fichier.isNull(): return
146         self.__file_open_name = fichier
147         self.notifyObserver(EficasEvent.EVENT_TYPES.OPEN)
148         self.__file_open_name = ""
149
150     def getOpenFileName(self):
151       return str(self.__file_open_name)
152
153     def selectCase(self, editor):
154       rtn = False
155       for indexEditor in self.viewmanager.dict_editors.keys():
156         if editor is self.viewmanager.dict_editors[indexEditor]:
157           self.viewmanager.myQtab.setCurrentIndex(indexEditor)
158           rtn = True
159           break
160       return rtn
161
162     def fileClose(self):
163         """
164         @overload
165         """
166         index = self.viewmanager.myQtab.currentIndex()
167         self.__close_editor = self.viewmanager.dict_editors[index]
168         res = self.viewmanager.handleClose(self)
169         if res != 2: # l utilsateur a annule
170           if self.__close_editor.fichier is None:
171             # We have to destroy the case
172             self.notifyObserver(EficasEvent.EVENT_TYPES.DESTROY)
173             self.__myCallbackId.pop(self.__close_editor)
174           else:
175             # Il faudrait en faire plus -> Voir Edit dans SALOME !
176             self.notifyObserver(EficasEvent.EVENT_TYPES.SAVE)
177             self.__myCallbackId.pop(self.__close_editor)
178         self.__close_editor = None
179         return res
180
181     def fileCloseAll(self):
182       """
183       @overload
184       """
185       while len(self.viewmanager.dict_editors) > 0:
186         self.viewmanager.myQtab.setCurrentIndex(0)
187         if self.viewmanager.myQtab.currentIndex() == 0:
188           res = self.fileClose()
189           if res==2 : return res   # l utilsateur a annule
190         else:
191           return 0
192
193     # ==========================================================================
194     # Function for the notification interface between an EficasWrapper an an
195     # EficasObserver.
196
197     # Association de l'objet editor avec le callbackId
198     def setCallbackId(self, callbackId):
199       index = self.viewmanager.myQtab.currentIndex()
200       self.__myCallbackId[self.viewmanager.dict_editors[index]] = callbackId
201
202     def removeCallbackId(self, callbackId):
203       key_to_remove = None
204       print callbackId
205       for k, v in self.__myCallbackId.iteritems():
206         print k, v
207         if v[0] == callbackId[0] and v[1].GetID() == callbackId[1].GetID():
208           key_to_remove = k
209       if key_to_remove is not None:
210         del self.__myCallbackId[key_to_remove]
211       else:
212         print "Oups - cannot find callbackId"
213
214     def getCallbackId(self):
215       if self.__close_editor is None:
216         index = self.viewmanager.myQtab.currentIndex()
217         return self.__myCallbackId[self.viewmanager.dict_editors[index]]
218       else:
219         return self.__myCallbackId[self.__close_editor]
220
221     def addObserver(self, observer):
222         """
223         In fact, only one observer may be defined for the moment.
224         """
225         try:
226             observer.processEficasEvent
227         except:
228             raise DevelException("the argument should implement the function processEficasEvent")
229         self.__observer = observer
230
231     def notifyObserver(self, eventType, callbackId=None):
232       if eventType != EficasEvent.EVENT_TYPES.OPEN:
233         if callbackId is None :
234           eficasEvent = EficasEvent(eventType, self.getCallbackId())
235         else:
236           eficasEvent = EficasEvent(eventType, callbackId)
237       else:
238         eficasEvent = EficasEvent(eventType)
239       self.__observer.processEficasEvent(self, eficasEvent)
240