]> SALOME platform Git repositories - modules/adao.git/blob - src/daSalome/daGUI/daEficasWrapper/adaoEficasWrapper.py
Salome HOME
Bouton Close ok
[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.__parent = parent
48
49     def init_gui(self):
50
51       eficasSalome.MyEficas.__init__(self, self.__parent, code="ADAO", module="ADAO")
52       self.connect(self.viewmanager.myQtab, SIGNAL('currentChanged(int)'), self.tabChanged)
53
54     def addJdcInSalome(self, jdcPath):
55       debug("addJdcInSalome is called " + str(jdcPath))
56       # On gere nous meme l'etude
57       pass
58
59 #######
60 #
61 # Gestion des évènements provenant des widgets QT d'Eficas
62 #
63 #######
64
65     def tabChanged(self, index):
66       debug("tabChanged " + str(index))
67       # This signal is also emit when a new case is created/added
68       # On regarde que le dictionnaire contient l'index
69       if index in self.viewmanager.dict_editors.keys():
70         self.notifyObserver(EficasEvent.EVENT_TYPES.TABCHANGED, callbackId=self.viewmanager.dict_editors[index])
71
72 #######
73 #
74 # Méthodes gérant les boutons dans SALOME
75 #
76 #######
77
78 # Rq: Utilisation de la méthode str() pour passer d'un Qstring à un string
79
80     def adaofileNew(self, adao_case):
81
82       qtEficas.Appli.fileNew(self)
83       index = self.viewmanager.myQtab.currentIndex()
84       adao_case.name          = str(self.viewmanager.myQtab.tabText(index))
85       adao_case.eficas_editor = self.viewmanager.dict_editors[index]
86       self.notifyObserver(EficasEvent.EVENT_TYPES.NEW, callbackId=adao_case)
87
88     def adaoFileSave(self, adao_case):
89
90       ok = qtEficas.Appli.fileSave(self)
91       if ok:
92         index = self.viewmanager.myQtab.currentIndex()
93         adao_case.name          = str(self.viewmanager.myQtab.tabText(index))
94         adao_case.filename      = str(self.viewmanager.dict_editors[index].fichier)
95         adao_case.eficas_editor = self.viewmanager.dict_editors[index]
96         self.notifyObserver(EficasEvent.EVENT_TYPES.SAVE, callbackId=adao_case)
97
98     def adaoFileSaveAs(self, adao_case):
99
100       ok = qtEficas.Appli.fileSaveAs(self)
101       if ok:
102         index = self.viewmanager.myQtab.currentIndex()
103         adao_case.name          = str(self.viewmanager.myQtab.tabText(index))
104         adao_case.filename      = str(self.viewmanager.dict_editors[index].fichier)
105         adao_case.eficas_editor = self.viewmanager.dict_editors[index]
106         self.notifyObserver(EficasEvent.EVENT_TYPES.SAVE, callbackId=adao_case)
107
108     def adaoFileOpen(self, adao_case):
109
110       tab_number = self.viewmanager.myQtab.count()
111       ok = self.viewmanager.handleOpen()
112       if ok:
113         # On regarde si c'est un nouveau editeur
114         if self.viewmanager.myQtab.count() > tab_number:
115           index = self.viewmanager.myQtab.currentIndex()
116           adao_case.name          = str(self.viewmanager.myQtab.tabText(index))
117           adao_case.filename      = str(self.viewmanager.dict_editors[index].fichier)
118           adao_case.eficas_editor = self.viewmanager.dict_editors[index]
119           self.notifyObserver(EficasEvent.EVENT_TYPES.OPEN, callbackId=adao_case)
120
121     def adaoFileClose(self, adao_case):
122
123         index = self.viewmanager.myQtab.currentIndex()
124         close_editor = self.viewmanager.dict_editors[index]
125         res = self.viewmanager.handleClose(self)
126         if res != 2: # l utilsateur a annule
127           if close_editor.fichier is None:
128             # Cas fichier vide
129             print "cas fichier vide"
130             self.notifyObserver(EficasEvent.EVENT_TYPES.CLOSE, callbackId=close_editor)
131           else:
132             # Cas fichier existant
133             print "cas fichier existant"
134             self.notifyObserver(EficasEvent.EVENT_TYPES.CLOSE, callbackId=close_editor)
135
136 #######
137 #
138 # Méthodes auxiliares de gestion du GUI Eficas pour synchronisation
139 # avec la partie GUI de SALOME
140 #
141 #######
142
143     def selectCase(self, editor):
144       rtn = False
145       for indexEditor in self.viewmanager.dict_editors.keys():
146         if editor is self.viewmanager.dict_editors[indexEditor]:
147           self.viewmanager.myQtab.setCurrentIndex(indexEditor)
148           rtn = True
149           break
150       return rtn
151
152
153
154
155 #######
156 #
157 # Méthodes secondaires permettant de gérer les observeurs du
158 # GUI d'Eficas
159 #
160 #######
161
162     def addObserver(self, observer):
163         """
164         In fact, only one observer may be defined for the moment.
165         """
166         try:
167             observer.processEficasEvent
168         except:
169             raise DevelException("the argument should implement the function processEficasEvent")
170         self.__observer = observer
171
172     def notifyObserver(self, eventType, callbackId=None):
173       eficasEvent = EficasEvent(eventType, callbackId)
174       self.__observer.processEficasEvent(self, eficasEvent)
175
176
177 #######
178 #
179 # Deprecated code
180 #
181 #######
182
183     def openEmptyCase(self, callbackId):
184         qtEficas.Appli.fileNew(self)
185         self.removeCallbackId(callbackId)
186         self.setCallbackId(callbackId)
187
188     def getCaseName(self):
189       if self.__close_editor is None:
190         index = self.viewmanager.myQtab.currentIndex()
191         CaseName = self.viewmanager.myQtab.tabText(index)
192         return CaseName
193       else:
194         CaseName = str(self.__close_editor.fichier.split('/')[-1])
195         return CaseName
196
197     def getFileCaseName(self):
198       if self.__close_editor is None:
199         index = self.viewmanager.myQtab.currentIndex()
200         editor = self.viewmanager.dict_editors[index]
201         return editor.fichier
202       else:
203         return self.__close_editor.fichier
204
205     def Openfile(self, filename):
206       self.viewmanager.handleOpen(fichier=filename)
207
208     def handleOpenRecent(self):
209       """
210       @overload
211       """
212       idx = self.sender()
213       fichier = self.ficRecents[idx]
214       self.__file_open_name = fichier
215       self.notifyObserver(EficasEvent.EVENT_TYPES.OPEN)
216       self.__file_open_name = ""
217
218
219     def getOpenFileName(self):
220       return str(self.__file_open_name)
221
222
223     def fileClose(self):
224         """
225         @overload
226         """
227         index = self.viewmanager.myQtab.currentIndex()
228         self.__close_editor = self.viewmanager.dict_editors[index]
229         res = self.viewmanager.handleClose(self)
230         if res != 2: # l utilsateur a annule
231           if self.__close_editor.fichier is None:
232             # We have to destroy the case
233             self.notifyObserver(EficasEvent.EVENT_TYPES.DESTROY)
234             self.__myCallbackId.pop(self.__close_editor)
235           else:
236             # Il faudrait en faire plus -> Voir Edit dans SALOME !
237             self.notifyObserver(EficasEvent.EVENT_TYPES.SAVE)
238             self.__myCallbackId.pop(self.__close_editor)
239         self.__close_editor = None
240         return res
241
242     def fileCloseAll(self):
243       """
244       @overload
245       """
246       while len(self.viewmanager.dict_editors) > 0:
247         self.viewmanager.myQtab.setCurrentIndex(0)
248         if self.viewmanager.myQtab.currentIndex() == 0:
249           res = self.fileClose()
250           if res==2 : return res   # l utilsateur a annule
251         else:
252           return 0
253