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 import QtGui,QtCore # Import from PyQT
28 from daUtils.adaoEficasEvent import *
31 # ============================================
32 # Specialization of the EficasWrapper for ADAO
33 # ============================================
35 class AdaoEficasWrapper(eficasSalome.MyEficas):
37 def __init__(self, parent):
38 # Configuration de l'installation
39 # Permet à EFICAS de faire ses import correctement
40 my_path = os.path.dirname(os.path.abspath(__file__))
41 ADAO_INSTALL_DIR = my_path + "/../daEficas"
42 sys.path[:0]=[ADAO_INSTALL_DIR]
44 self.__myCallbackId = {}
45 self.__close_editor = None
46 self.__file_open_name = ""
47 self.__parent = parent
50 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
56 # Normalement on ne ferme plus le GUI donc on ne passe plus par là
57 save_CallbackId = self.__myCallbackId.copy()
58 for editor, myCallbackId in save_CallbackId.iteritems():
59 self.notifyObserver(EficasEvent.EVENT_TYPES.REOPEN, callbackId=myCallbackId)
61 def addJdcInSalome( self, jdcPath ):
62 # On gere nous meme l'etude
69 qtEficas.Appli.fileNew(self)
70 self.notifyObserver(EficasEvent.EVENT_TYPES.NEW)
72 def openEmptyCase(self, callbackId):
73 qtEficas.Appli.fileNew(self)
74 self.removeCallbackId(callbackId)
75 self.setCallbackId(callbackId)
81 qtEficas.Appli.fileSave(self)
82 index = self.viewmanager.myQtab.currentIndex()
84 self.notifyObserver(EficasEvent.EVENT_TYPES.SAVE)
90 qtEficas.Appli.fileSaveAs(self)
91 self.notifyObserver(EficasEvent.EVENT_TYPES.SAVE)
93 def getCaseName(self):
94 if self.__close_editor is None:
95 index = self.viewmanager.myQtab.currentIndex()
96 CaseName = self.viewmanager.myQtab.tabText(index)
99 CaseName = str(self.__close_editor.fichier.split('/')[-1])
102 def getFileCaseName(self):
103 if self.__close_editor is None:
104 index = self.viewmanager.myQtab.currentIndex()
105 editor = self.viewmanager.dict_editors[index]
106 return editor.fichier
108 return self.__close_editor.fichier
110 def Openfile(self, filename):
111 self.viewmanager.handleOpen(fichier=filename)
113 def handleOpenRecent(self):
118 fichier = self.ficRecents[idx]
119 self.__file_open_name = fichier
120 self.notifyObserver(EficasEvent.EVENT_TYPES.OPEN)
121 self.__file_open_name = ""
127 fichier = QtGui.QFileDialog.getOpenFileName(self,
128 self.trUtf8('Ouvrir Fichier'),
129 self.CONFIGURATION.savedir,
130 self.trUtf8('JDC Files (*.comm);;''All Files (*)'))
131 if fichier.isNull(): return
132 self.__file_open_name = fichier
133 self.notifyObserver(EficasEvent.EVENT_TYPES.OPEN)
134 self.__file_open_name = ""
136 def getOpenFileName(self):
137 return str(self.__file_open_name)
139 def selectCase(self, callbackId):
141 for editor, myCallbackId in self.__myCallbackId.iteritems():
142 if myCallbackId[0] == callbackId[0]:
143 if myCallbackId[1].GetID() == callbackId[1].GetID():
145 for indexEditor in self.viewmanager.dict_editors.keys():
146 if editor is self.viewmanager.dict_editors[indexEditor]:
147 self.viewmanager.myQtab.setCurrentIndex(indexEditor)
157 index = self.viewmanager.myQtab.currentIndex()
158 self.__close_editor = self.viewmanager.dict_editors[index]
159 res = self.viewmanager.handleClose(self)
160 if res != 2: # l utilsateur a annule
161 if self.__close_editor.fichier is None:
162 # We have to destroy the case
163 self.notifyObserver(EficasEvent.EVENT_TYPES.DESTROY)
164 self.__myCallbackId.pop(self.__close_editor)
166 # Il faudrait en faire plus -> Voir Edit dans SALOME !
167 self.notifyObserver(EficasEvent.EVENT_TYPES.SAVE)
168 self.__myCallbackId.pop(self.__close_editor)
169 self.__close_editor = None
172 def fileCloseAll(self):
176 while len(self.viewmanager.dict_editors) > 0:
177 self.viewmanager.myQtab.setCurrentIndex(0)
178 if self.viewmanager.myQtab.currentIndex() == 0:
179 res = self.fileClose()
180 if res==2 : return res # l utilsateur a annule
184 # ==========================================================================
185 # Function for the notification interface between an EficasWrapper an an
188 # Association de l'objet editor avec le callbackId
189 def setCallbackId(self, callbackId):
190 index = self.viewmanager.myQtab.currentIndex()
191 self.__myCallbackId[self.viewmanager.dict_editors[index]] = callbackId
193 def removeCallbackId(self, callbackId):
196 for k, v in self.__myCallbackId.iteritems():
198 if v[0] == callbackId[0] and v[1].GetID() == callbackId[1].GetID():
200 if key_to_remove is not None:
201 del self.__myCallbackId[key_to_remove]
203 print "Oups - cannot find callbackId"
205 def getCallbackId(self):
206 if self.__close_editor is None:
207 index = self.viewmanager.myQtab.currentIndex()
208 return self.__myCallbackId[self.viewmanager.dict_editors[index]]
210 return self.__myCallbackId[self.__close_editor]
212 def addObserver(self, observer):
214 In fact, only one observer may be defined for the moment.
217 observer.processEficasEvent
219 raise DevelException("the argument should implement the function processEficasEvent")
220 self.__observer = observer
222 def notifyObserver(self, eventType, callbackId=None):
223 if eventType != EficasEvent.EVENT_TYPES.NEW and eventType != EficasEvent.EVENT_TYPES.OPEN:
224 if callbackId is None :
225 eficasEvent = EficasEvent(eventType, self.getCallbackId())
227 eficasEvent = EficasEvent(eventType, callbackId)
229 eficasEvent = EficasEvent(eventType)
230 self.__observer.processEficasEvent(self, eficasEvent)