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)
91 qtEficas.Appli.fileSave(self)
92 index = self.viewmanager.myQtab.currentIndex()
94 self.notifyObserver(EficasEvent.EVENT_TYPES.SAVE)
100 qtEficas.Appli.fileSaveAs(self)
101 self.notifyObserver(EficasEvent.EVENT_TYPES.SAVE)
103 def getCaseName(self):
104 if self.__close_editor is None:
105 index = self.viewmanager.myQtab.currentIndex()
106 CaseName = self.viewmanager.myQtab.tabText(index)
109 CaseName = str(self.__close_editor.fichier.split('/')[-1])
112 def getFileCaseName(self):
113 if self.__close_editor is None:
114 index = self.viewmanager.myQtab.currentIndex()
115 editor = self.viewmanager.dict_editors[index]
116 return editor.fichier
118 return self.__close_editor.fichier
120 def Openfile(self, filename):
121 self.viewmanager.handleOpen(fichier=filename)
123 def handleOpenRecent(self):
128 fichier = self.ficRecents[idx]
129 self.__file_open_name = fichier
130 self.notifyObserver(EficasEvent.EVENT_TYPES.OPEN)
131 self.__file_open_name = ""
137 fichier = QFileDialog.getOpenFileName(self,
138 self.trUtf8('Ouvrir Fichier'),
139 self.CONFIGURATION.savedir,
140 self.trUtf8('JDC Files (*.comm);;''All Files (*)'))
141 if fichier.isNull(): return
142 self.__file_open_name = fichier
143 self.notifyObserver(EficasEvent.EVENT_TYPES.OPEN)
144 self.__file_open_name = ""
146 def getOpenFileName(self):
147 return str(self.__file_open_name)
149 def selectCase(self, callbackId):
151 for editor, myCallbackId in self.__myCallbackId.iteritems():
152 if myCallbackId[0] == callbackId[0]:
153 if myCallbackId[1].GetID() == callbackId[1].GetID():
155 for indexEditor in self.viewmanager.dict_editors.keys():
156 if editor is self.viewmanager.dict_editors[indexEditor]:
157 self.viewmanager.myQtab.setCurrentIndex(indexEditor)
167 index = self.viewmanager.myQtab.currentIndex()
168 self.__close_editor = self.viewmanager.dict_editors[index]
169 res = self.viewmanager.handleClose(self)
170 if res != 2: # l utilsateur a annule
171 if self.__close_editor.fichier is None:
172 # We have to destroy the case
173 self.notifyObserver(EficasEvent.EVENT_TYPES.DESTROY)
174 self.__myCallbackId.pop(self.__close_editor)
176 # Il faudrait en faire plus -> Voir Edit dans SALOME !
177 self.notifyObserver(EficasEvent.EVENT_TYPES.SAVE)
178 self.__myCallbackId.pop(self.__close_editor)
179 self.__close_editor = None
182 def fileCloseAll(self):
186 while len(self.viewmanager.dict_editors) > 0:
187 self.viewmanager.myQtab.setCurrentIndex(0)
188 if self.viewmanager.myQtab.currentIndex() == 0:
189 res = self.fileClose()
190 if res==2 : return res # l utilsateur a annule
194 # ==========================================================================
195 # Function for the notification interface between an EficasWrapper an an
198 # Association de l'objet editor avec le callbackId
199 def setCallbackId(self, callbackId):
200 index = self.viewmanager.myQtab.currentIndex()
201 self.__myCallbackId[self.viewmanager.dict_editors[index]] = callbackId
203 def removeCallbackId(self, callbackId):
206 for k, v in self.__myCallbackId.iteritems():
208 if v[0] == callbackId[0] and v[1].GetID() == callbackId[1].GetID():
210 if key_to_remove is not None:
211 del self.__myCallbackId[key_to_remove]
213 print "Oups - cannot find callbackId"
215 def getCallbackId(self):
216 if self.__close_editor is None:
217 index = self.viewmanager.myQtab.currentIndex()
218 return self.__myCallbackId[self.viewmanager.dict_editors[index]]
220 return self.__myCallbackId[self.__close_editor]
222 def addObserver(self, observer):
224 In fact, only one observer may be defined for the moment.
227 observer.processEficasEvent
229 raise DevelException("the argument should implement the function processEficasEvent")
230 self.__observer = observer
232 def notifyObserver(self, eventType, callbackId=None):
233 if eventType != EficasEvent.EVENT_TYPES.OPEN:
234 if callbackId is None :
235 eficasEvent = EficasEvent(eventType, self.getCallbackId())
237 eficasEvent = EficasEvent(eventType, callbackId)
239 eficasEvent = EficasEvent(eventType)
240 self.__observer.processEficasEvent(self, eficasEvent)