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