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
23 from PyQt4 import QtGui,QtCore
25 # Import from EFICAS_SRC
28 from InterfaceQT4 import qtEficas
30 from adaoWrapperUtils import *
33 # ============================================
34 # Specialization of the EficasWrapper for ADAO
35 # ============================================
37 class AdaoEficasWrapper(eficasSalome.MyEficas):
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]
46 self.__myCallbackId = {}
47 self.__close_editor = None
48 self.__file_open_name = ""
49 self.__parent = parent
52 eficasSalome.MyEficas.__init__(self, self.__parent, code="ADAO", module="ADAO")
55 # On réouvre tous les fichiers comm
56 # On fait une copie pour ne pas tomber dans une boucle infinie
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)
63 def addJdcInSalome( self, jdcPath ):
64 # On gere nous meme l'etude
71 qtEficas.Appli.fileNew(self)
72 self.notifyObserver(EficasEvent.EVENT_TYPES.NEW)
74 def openEmptyCase(self, callbackId):
75 qtEficas.Appli.fileNew(self)
76 self.removeCallbackId(callbackId)
77 self.setCallbackId(callbackId)
83 qtEficas.Appli.fileSave(self)
84 index = self.viewmanager.myQtab.currentIndex()
86 self.notifyObserver(EficasEvent.EVENT_TYPES.SAVE)
92 qtEficas.Appli.fileSaveAs(self)
93 self.notifyObserver(EficasEvent.EVENT_TYPES.SAVE)
95 def getCaseName(self):
96 if self.__close_editor is None:
97 index = self.viewmanager.myQtab.currentIndex()
98 CaseName = self.viewmanager.myQtab.tabText(index)
101 CaseName = str(self.__close_editor.fichier.split('/')[-1])
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
110 return self.__close_editor.fichier
112 def Openfile(self, filename):
113 self.viewmanager.handleOpen(fichier=filename)
115 def handleOpenRecent(self):
120 fichier = self.ficRecents[idx]
121 self.__file_open_name = fichier
122 self.notifyObserver(EficasEvent.EVENT_TYPES.OPEN)
123 self.__file_open_name = ""
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 = ""
138 def getOpenFileName(self):
139 return str(self.__file_open_name)
141 def selectCase(self, callbackId):
143 for editor, myCallbackId in self.__myCallbackId.iteritems():
144 if myCallbackId[0] == callbackId[0]:
145 if myCallbackId[1].GetID() == callbackId[1].GetID():
147 for indexEditor in self.viewmanager.dict_editors.keys():
148 if editor is self.viewmanager.dict_editors[indexEditor]:
149 self.viewmanager.myQtab.setCurrentIndex(indexEditor)
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)
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
174 def fileCloseAll(self):
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
186 # ==========================================================================
187 # Function for the notification interface between an EficasWrapper an an
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
195 def removeCallbackId(self, callbackId):
198 for k, v in self.__myCallbackId.iteritems():
200 if v[0] == callbackId[0] and v[1].GetID() == callbackId[1].GetID():
202 if key_to_remove is not None:
203 del self.__myCallbackId[key_to_remove]
205 print "Oups - cannot find callbackId"
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]]
212 return self.__myCallbackId[self.__close_editor]
214 def addObserver(self, observer):
216 In fact, only one observer may be defined for the moment.
219 observer.processEficasEvent
221 raise DevelException("the argument should implement the function processEficasEvent")
222 self.__observer = observer
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())
229 eficasEvent = EficasEvent(eventType, callbackId)
231 eficasEvent = EficasEvent(eventType)
232 self.__observer.processEficasEvent(self, eficasEvent)