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 self.notifyObserver(EficasEvent.EVENT_TYPES.TABCHANGED, callbackId=self.viewmanager.dict_editors[index])
70 def addJdcInSalome( self, jdcPath ):
71 # On gere nous meme l'etude
74 def adaofileNew(self, adao_case):
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)
82 def openEmptyCase(self, callbackId):
83 qtEficas.Appli.fileNew(self)
84 self.removeCallbackId(callbackId)
85 self.setCallbackId(callbackId)
87 def adaoFileSave(self, adao_case):
89 ok = qtEficas.Appli.fileSave(self)
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)
101 qtEficas.Appli.fileSaveAs(self)
102 self.notifyObserver(EficasEvent.EVENT_TYPES.SAVE)
104 def getCaseName(self):
105 if self.__close_editor is None:
106 index = self.viewmanager.myQtab.currentIndex()
107 CaseName = self.viewmanager.myQtab.tabText(index)
110 CaseName = str(self.__close_editor.fichier.split('/')[-1])
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
119 return self.__close_editor.fichier
121 def Openfile(self, filename):
122 self.viewmanager.handleOpen(fichier=filename)
124 def handleOpenRecent(self):
129 fichier = self.ficRecents[idx]
130 self.__file_open_name = fichier
131 self.notifyObserver(EficasEvent.EVENT_TYPES.OPEN)
132 self.__file_open_name = ""
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 = ""
147 def getOpenFileName(self):
148 return str(self.__file_open_name)
150 def selectCase(self, callbackId):
152 for editor, myCallbackId in self.__myCallbackId.iteritems():
153 if myCallbackId[0] == callbackId[0]:
154 if myCallbackId[1].GetID() == callbackId[1].GetID():
156 for indexEditor in self.viewmanager.dict_editors.keys():
157 if editor is self.viewmanager.dict_editors[indexEditor]:
158 self.viewmanager.myQtab.setCurrentIndex(indexEditor)
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)
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
183 def fileCloseAll(self):
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
195 # ==========================================================================
196 # Function for the notification interface between an EficasWrapper an an
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
204 def removeCallbackId(self, callbackId):
207 for k, v in self.__myCallbackId.iteritems():
209 if v[0] == callbackId[0] and v[1].GetID() == callbackId[1].GetID():
211 if key_to_remove is not None:
212 del self.__myCallbackId[key_to_remove]
214 print "Oups - cannot find callbackId"
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]]
221 return self.__myCallbackId[self.__close_editor]
223 def addObserver(self, observer):
225 In fact, only one observer may be defined for the moment.
228 observer.processEficasEvent
230 raise DevelException("the argument should implement the function processEficasEvent")
231 self.__observer = observer
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())
238 eficasEvent = EficasEvent(eventType, callbackId)
240 eficasEvent = EficasEvent(eventType)
241 self.__observer.processEficasEvent(self, eficasEvent)