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