]> SALOME platform Git repositories - modules/adao.git/blob - src/daSalome/daGUI/daEficasWrapper/adaoEficasWrapper.py
Salome HOME
Nouvelle version de Save
[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       self.notifyObserver(EficasEvent.EVENT_TYPES.TABCHANGED, callbackId=self.viewmanager.dict_editors[index])
69
70     def addJdcInSalome(  self, jdcPath ):
71       # On gere nous meme l'etude
72       pass
73
74     def adaofileNew(self, adao_case):
75
76         qtEficas.Appli.fileNew(self)
77         index = self.viewmanager.myQtab.currentIndex()
78         adao_case.name          = str(self.viewmanager.myQtab.tabText(index)) # Utilisation de str() pour passer d'un Qstring à un string
79         adao_case.eficas_editor = self.viewmanager.dict_editors[index]
80         self.notifyObserver(EficasEvent.EVENT_TYPES.NEW, callbackId=adao_case)
81
82     def openEmptyCase(self, callbackId):
83         qtEficas.Appli.fileNew(self)
84         self.removeCallbackId(callbackId)
85         self.setCallbackId(callbackId)
86
87     def adaoFileSave(self, adao_case):
88
89         ok = qtEficas.Appli.fileSave(self)
90         if ok:
91           index = self.viewmanager.myQtab.currentIndex()
92           adao_case.name          = str(self.viewmanager.myQtab.tabText(index)) # Utilisation de str() pour passer d'un Qstring à un string
93           adao_case.eficas_editor = self.viewmanager.dict_editors[index]
94           adao_case.filename      = str(self.viewmanager.dict_editors[index].fichier)
95           self.notifyObserver(EficasEvent.EVENT_TYPES.SAVE, callbackId=adao_case)
96
97     def fileSaveAs(self):
98         """
99         @overload
100         """
101         qtEficas.Appli.fileSaveAs(self)
102         self.notifyObserver(EficasEvent.EVENT_TYPES.SAVE)
103
104     def getCaseName(self):
105       if self.__close_editor is None:
106         index = self.viewmanager.myQtab.currentIndex()
107         CaseName = self.viewmanager.myQtab.tabText(index)
108         return CaseName
109       else:
110         CaseName = str(self.__close_editor.fichier.split('/')[-1])
111         return CaseName
112
113     def getFileCaseName(self):
114       if self.__close_editor is None:
115         index = self.viewmanager.myQtab.currentIndex()
116         editor = self.viewmanager.dict_editors[index]
117         return editor.fichier
118       else:
119         return self.__close_editor.fichier
120
121     def Openfile(self, filename):
122       self.viewmanager.handleOpen(fichier=filename)
123
124     def handleOpenRecent(self):
125       """
126       @overload
127       """
128       idx = self.sender()
129       fichier = self.ficRecents[idx]
130       self.__file_open_name = fichier
131       self.notifyObserver(EficasEvent.EVENT_TYPES.OPEN)
132       self.__file_open_name = ""
133
134     def fileOpen(self):
135         """
136         @overload
137         """
138         fichier = QFileDialog.getOpenFileName(self,
139                                               self.trUtf8('Ouvrir Fichier'),
140                                               self.CONFIGURATION.savedir,
141                                               self.trUtf8('JDC Files (*.comm);;''All Files (*)'))
142         if fichier.isNull(): return
143         self.__file_open_name = fichier
144         self.notifyObserver(EficasEvent.EVENT_TYPES.OPEN)
145         self.__file_open_name = ""
146
147     def getOpenFileName(self):
148       return str(self.__file_open_name)
149
150     def selectCase(self, callbackId):
151       rtn = False
152       for editor, myCallbackId in self.__myCallbackId.iteritems():
153         if myCallbackId[0] == callbackId[0]:
154           if myCallbackId[1].GetID() == callbackId[1].GetID():
155             try:
156               for indexEditor in self.viewmanager.dict_editors.keys():
157                 if editor is self.viewmanager.dict_editors[indexEditor]:
158                   self.viewmanager.myQtab.setCurrentIndex(indexEditor)
159                   rtn = True
160             except:
161               pass
162       return rtn
163
164     def fileClose(self):
165         """
166         @overload
167         """
168         index = self.viewmanager.myQtab.currentIndex()
169         self.__close_editor = self.viewmanager.dict_editors[index]
170         res = self.viewmanager.handleClose(self)
171         if res != 2: # l utilsateur a annule
172           if self.__close_editor.fichier is None:
173             # We have to destroy the case
174             self.notifyObserver(EficasEvent.EVENT_TYPES.DESTROY)
175             self.__myCallbackId.pop(self.__close_editor)
176           else:
177             # Il faudrait en faire plus -> Voir Edit dans SALOME !
178             self.notifyObserver(EficasEvent.EVENT_TYPES.SAVE)
179             self.__myCallbackId.pop(self.__close_editor)
180         self.__close_editor = None
181         return res
182
183     def fileCloseAll(self):
184       """
185       @overload
186       """
187       while len(self.viewmanager.dict_editors) > 0:
188         self.viewmanager.myQtab.setCurrentIndex(0)
189         if self.viewmanager.myQtab.currentIndex() == 0:
190           res = self.fileClose()
191           if res==2 : return res   # l utilsateur a annule
192         else:
193           return 0
194
195     # ==========================================================================
196     # Function for the notification interface between an EficasWrapper an an
197     # EficasObserver.
198
199     # Association de l'objet editor avec le callbackId
200     def setCallbackId(self, callbackId):
201       index = self.viewmanager.myQtab.currentIndex()
202       self.__myCallbackId[self.viewmanager.dict_editors[index]] = callbackId
203
204     def removeCallbackId(self, callbackId):
205       key_to_remove = None
206       print callbackId
207       for k, v in self.__myCallbackId.iteritems():
208         print k, v
209         if v[0] == callbackId[0] and v[1].GetID() == callbackId[1].GetID():
210           key_to_remove = k
211       if key_to_remove is not None:
212         del self.__myCallbackId[key_to_remove]
213       else:
214         print "Oups - cannot find callbackId"
215
216     def getCallbackId(self):
217       if self.__close_editor is None:
218         index = self.viewmanager.myQtab.currentIndex()
219         return self.__myCallbackId[self.viewmanager.dict_editors[index]]
220       else:
221         return self.__myCallbackId[self.__close_editor]
222
223     def addObserver(self, observer):
224         """
225         In fact, only one observer may be defined for the moment.
226         """
227         try:
228             observer.processEficasEvent
229         except:
230             raise DevelException("the argument should implement the function processEficasEvent")
231         self.__observer = observer
232
233     def notifyObserver(self, eventType, callbackId=None):
234       if eventType != EficasEvent.EVENT_TYPES.OPEN:
235         if callbackId is None :
236           eficasEvent = EficasEvent(eventType, self.getCallbackId())
237         else:
238           eficasEvent = EficasEvent(eventType, callbackId)
239       else:
240         eficasEvent = EficasEvent(eventType)
241       self.__observer.processEficasEvent(self, eficasEvent)
242