1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2010 EDF R&D
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.
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.
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
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
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
30 from daUtils.adaoEficasEvent import *
31 from daGuiImpl.adaoLogger import *
34 # ============================================
35 # Specialization of the EficasWrapper for ADAO
36 # ============================================
38 class AdaoEficasWrapper(eficasSalome.MyEficas):
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]
47 self.__myCallbackId = {}
48 self.__close_editor = None
49 self.__file_open_name = ""
50 self.__parent = parent
54 eficasSalome.MyEficas.__init__(self, self.__parent, code="ADAO", module="ADAO")
55 self.connect(self.viewmanager.myQtab, SIGNAL('currentChanged(int)'), self.tabChanged)
58 # On réouvre tous les fichiers comm
59 # On fait une copie pour ne pas tomber dans une boucle infinie
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)
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])
73 def addJdcInSalome( self, jdcPath ):
74 # On gere nous meme l'etude
77 def adaofileNew(self, adao_case):
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)
85 def openEmptyCase(self, callbackId):
86 qtEficas.Appli.fileNew(self)
87 self.removeCallbackId(callbackId)
88 self.setCallbackId(callbackId)
90 def adaoFileSave(self, adao_case):
92 ok = qtEficas.Appli.fileSave(self)
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)
100 def fileSaveAs(self):
104 qtEficas.Appli.fileSaveAs(self)
105 self.notifyObserver(EficasEvent.EVENT_TYPES.SAVE)
107 def getCaseName(self):
108 if self.__close_editor is None:
109 index = self.viewmanager.myQtab.currentIndex()
110 CaseName = self.viewmanager.myQtab.tabText(index)
113 CaseName = str(self.__close_editor.fichier.split('/')[-1])
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
122 return self.__close_editor.fichier
124 def Openfile(self, filename):
125 self.viewmanager.handleOpen(fichier=filename)
127 def handleOpenRecent(self):
132 fichier = self.ficRecents[idx]
133 self.__file_open_name = fichier
134 self.notifyObserver(EficasEvent.EVENT_TYPES.OPEN)
135 self.__file_open_name = ""
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 = ""
150 def getOpenFileName(self):
151 return str(self.__file_open_name)
153 def selectCase(self, editor):
155 for indexEditor in self.viewmanager.dict_editors.keys():
156 if editor is self.viewmanager.dict_editors[indexEditor]:
157 self.viewmanager.myQtab.setCurrentIndex(indexEditor)
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)
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
181 def fileCloseAll(self):
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
193 # ==========================================================================
194 # Function for the notification interface between an EficasWrapper an an
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
202 def removeCallbackId(self, callbackId):
205 for k, v in self.__myCallbackId.iteritems():
207 if v[0] == callbackId[0] and v[1].GetID() == callbackId[1].GetID():
209 if key_to_remove is not None:
210 del self.__myCallbackId[key_to_remove]
212 print "Oups - cannot find callbackId"
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]]
219 return self.__myCallbackId[self.__close_editor]
221 def addObserver(self, observer):
223 In fact, only one observer may be defined for the moment.
226 observer.processEficasEvent
228 raise DevelException("the argument should implement the function processEficasEvent")
229 self.__observer = observer
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())
236 eficasEvent = EficasEvent(eventType, callbackId)
238 eficasEvent = EficasEvent(eventType)
239 self.__observer.processEficasEvent(self, eficasEvent)