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")
53 # On réouvre tous les fichiers comm
54 # On fait une copie pour ne pas tomber dans une boucle infinie
55 save_CallbackId = self.__myCallbackId.copy()
56 for editor, myCallbackId in save_CallbackId.iteritems():
57 self.notifyObserver(EficasEvent.EVENT_TYPES.REOPEN, callbackId=myCallbackId)
59 def addJdcInSalome( self, jdcPath ):
60 # On gere nous meme l'etude
67 qtEficas.Appli.fileNew(self)
68 self.notifyObserver(EficasEvent.EVENT_TYPES.NEW)
70 def openEmptyCase(self, callbackId):
71 qtEficas.Appli.fileNew(self)
72 self.removeCallbackId(callbackId)
73 self.setCallbackId(callbackId)
79 qtEficas.Appli.fileSave(self)
80 index = self.viewmanager.myQtab.currentIndex()
82 self.notifyObserver(EficasEvent.EVENT_TYPES.SAVE)
88 qtEficas.Appli.fileSaveAs(self)
89 self.notifyObserver(EficasEvent.EVENT_TYPES.SAVE)
91 def getCaseName(self):
92 if self.__close_editor is None:
93 index = self.viewmanager.myQtab.currentIndex()
94 CaseName = self.viewmanager.myQtab.tabText(index)
97 CaseName = str(self.__close_editor.fichier.split('/')[-1])
100 def getFileCaseName(self):
101 if self.__close_editor is None:
102 index = self.viewmanager.myQtab.currentIndex()
103 editor = self.viewmanager.dict_editors[index]
104 return editor.fichier
106 return self.__close_editor.fichier
108 def Openfile(self, filename):
109 self.viewmanager.handleOpen(fichier=filename)
111 def handleOpenRecent(self):
116 fichier = self.ficRecents[idx]
117 self.__file_open_name = fichier
118 self.notifyObserver(EficasEvent.EVENT_TYPES.OPEN)
119 self.__file_open_name = ""
125 fichier = QtGui.QFileDialog.getOpenFileName(self,
126 self.trUtf8('Ouvrir Fichier'),
127 self.CONFIGURATION.savedir,
128 self.trUtf8('JDC Files (*.comm);;''All Files (*)'))
129 if fichier.isNull(): return
130 self.__file_open_name = fichier
131 self.notifyObserver(EficasEvent.EVENT_TYPES.OPEN)
132 self.__file_open_name = ""
134 def getOpenFileName(self):
135 return str(self.__file_open_name)
137 def selectCase(self, callbackId):
139 for editor, myCallbackId in self.__myCallbackId.iteritems():
140 if myCallbackId[0] == callbackId[0]:
141 if myCallbackId[1].GetID() == callbackId[1].GetID():
143 for indexEditor in self.viewmanager.dict_editors.keys():
144 if editor is self.viewmanager.dict_editors[indexEditor]:
145 self.viewmanager.myQtab.setCurrentIndex(indexEditor)
155 index = self.viewmanager.myQtab.currentIndex()
156 self.__close_editor = self.viewmanager.dict_editors[index]
157 res = self.viewmanager.handleClose(self)
158 if res != 2: # l utilsateur a annule
159 if self.__close_editor.fichier is None:
160 # We have to destroy the case
161 self.notifyObserver(EficasEvent.EVENT_TYPES.DESTROY)
162 self.__myCallbackId.pop(self.__close_editor)
164 # Il faudrait en faire plus -> Voir Edit dans SALOME !
165 self.notifyObserver(EficasEvent.EVENT_TYPES.SAVE)
166 self.__myCallbackId.pop(self.__close_editor)
167 self.__close_editor = None
170 def fileCloseAll(self):
174 while len(self.viewmanager.dict_editors) > 0:
175 self.viewmanager.myQtab.setCurrentIndex(0)
176 if self.viewmanager.myQtab.currentIndex() == 0:
177 res = self.fileClose()
178 if res==2 : return res # l utilsateur a annule
182 # ==========================================================================
183 # Function for the notification interface between an EficasWrapper an an
186 # Association de l'objet editor avec le callbackId
187 def setCallbackId(self, callbackId):
188 index = self.viewmanager.myQtab.currentIndex()
189 self.__myCallbackId[self.viewmanager.dict_editors[index]] = callbackId
191 def removeCallbackId(self, callbackId):
193 for k, v in self.__myCallbackId.iteritems():
194 if v[0] == callbackId[0] and v[1].GetID() == callbackId[1].GetID():
196 if key_to_remove is not None:
197 del self.__myCallbackId[key_to_remove]
199 print "Oups - cannot find callbackId"
201 def getCallbackId(self):
202 if self.__close_editor is None:
203 index = self.viewmanager.myQtab.currentIndex()
204 return self.__myCallbackId[self.viewmanager.dict_editors[index]]
206 return self.__myCallbackId[self.__close_editor]
208 def addObserver(self, observer):
210 In fact, only one observer may be defined for the moment.
213 observer.processEficasEvent
215 raise DevelException("the argument should implement the function processEficasEvent")
216 self.__observer = observer
218 def notifyObserver(self, eventType, callbackId=None):
219 if eventType != EficasEvent.EVENT_TYPES.NEW and eventType != EficasEvent.EVENT_TYPES.OPEN:
220 if callbackId is None :
221 eficasEvent = EficasEvent(eventType, self.getCallbackId())
223 eficasEvent = EficasEvent(eventType, callbackId)
225 eficasEvent = EficasEvent(eventType)
226 self.__observer.processEficasEvent(self, eficasEvent)