1 #-*-coding:iso-8859-1-*-
2 # Copyright (C) 2008-2015 EDF R&D
4 # This file is part of SALOME ADAO module
6 # This library is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU Lesser General Public
8 # License as published by the Free Software Foundation; either
9 # version 2.1 of the License.
11 # This library is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # Lesser General Public License for more details.
16 # You should have received a copy of the GNU Lesser General Public
17 # License along with this library; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
26 import eficasSalome # Import from EFICAS_SRC
27 from InterfaceQT4 import qtEficas # Import from Eficas
28 from PyQt4.QtGui import * # Import from PyQT
29 from PyQt4.QtCore import * # Import from PyQT
30 # from PyQt4.QtAssistant import * # Import from PyQT
32 from daUtils.adaoEficasEvent import *
33 from daUtils.adaoLogger import *
36 # ============================================
37 # Specialization of the EficasWrapper for ADAO
38 # ============================================
40 class AdaoEficasWrapper(eficasSalome.MyEficas):
42 def __init__(self, parent):
43 # Configuration de l'installation
44 # Permet à EFICAS de faire ses import correctement
45 my_path = os.path.dirname(os.path.abspath(__file__))
46 ADAO_INSTALL_DIR = my_path + "/../daEficas"
47 sys.path.insert(0,ADAO_INSTALL_DIR)
49 self.__parent = parent
53 eficasSalome.MyEficas.__init__(self, self.__parent, code="ADAO", module="ADAO")
54 self.connect(self.viewmanager.myQtab, SIGNAL('currentChanged(int)'), self.tabChanged)
58 def addJdcInSalome(self, jdcPath):
59 debug("addJdcInSalome is called " + str(jdcPath))
60 # On gere nous meme l'etude
65 # Gestion des évènements provenant des widgets QT d'Eficas
69 def tabChanged(self, index):
70 debug("tabChanged " + str(index))
71 # This signal is also emit when a new case is created/added
72 # On regarde que le dictionnaire contient l'index
73 if index in self.viewmanager.dict_editors.keys():
74 self.notifyObserver(EficasEvent.EVENT_TYPES.TABCHANGED, callbackId=self.viewmanager.dict_editors[index])
78 # Méthodes gérant les boutons dans SALOME
82 # Rq: Utilisation de la méthode str() pour passer d'un Qstring à un string
84 def adaofileNew(self, adao_case):
86 qtEficas.Appli.fileNew(self)
87 index = self.viewmanager.myQtab.currentIndex()
88 adao_case.name = str(self.viewmanager.myQtab.tabText(index))
89 adao_case.setEditor(self.viewmanager.dict_editors[index])
90 self.notifyObserver(EficasEvent.EVENT_TYPES.NEW, callbackId=adao_case)
92 def adaoFileSave(self, adao_case):
94 ok = qtEficas.Appli.fileSave(self)
96 index = self.viewmanager.myQtab.currentIndex()
97 adao_case.name = str(self.viewmanager.myQtab.tabText(index))
98 adao_case.filename = str(self.viewmanager.dict_editors[index].fichier)
99 adao_case.setEditor(self.viewmanager.dict_editors[index])
100 self.notifyObserver(EficasEvent.EVENT_TYPES.SAVE, callbackId=adao_case)
102 def adaoFileSaveAs(self, adao_case):
104 ok = qtEficas.Appli.fileSaveAs(self)
106 index = self.viewmanager.myQtab.currentIndex()
107 adao_case.name = str(self.viewmanager.myQtab.tabText(index))
108 adao_case.filename = str(self.viewmanager.dict_editors[index].fichier)
109 adao_case.setEditor(self.viewmanager.dict_editors[index])
110 self.notifyObserver(EficasEvent.EVENT_TYPES.SAVE, callbackId=adao_case)
112 def adaoFileOpen(self, adao_case):
114 tab_number = self.viewmanager.myQtab.count()
115 ok = self.viewmanager.handleOpen()
117 # On regarde si c'est un nouveau editeur
118 if self.viewmanager.myQtab.count() > tab_number:
119 index = self.viewmanager.myQtab.currentIndex()
120 adao_case.name = str(self.viewmanager.myQtab.tabText(index))
121 adao_case.filename = str(self.viewmanager.dict_editors[index].fichier)
122 adao_case.setEditor(self.viewmanager.dict_editors[index])
123 self.notifyObserver(EficasEvent.EVENT_TYPES.OPEN, callbackId=adao_case)
125 def adaoFileClose(self, adao_case):
127 index = self.viewmanager.myQtab.currentIndex()
128 close_editor = self.viewmanager.dict_editors[index]
129 res = self.viewmanager.handleClose(self)
130 if res != 2: # l utilsateur a annule
131 if close_editor.fichier is None:
133 self.notifyObserver(EficasEvent.EVENT_TYPES.CLOSE, callbackId=close_editor)
135 # Cas fichier existant
136 self.notifyObserver(EficasEvent.EVENT_TYPES.CLOSE, callbackId=close_editor)
140 # Méthodes auxiliares de gestion du GUI Eficas pour synchronisation
141 # avec la partie GUI de SALOME
145 def selectCase(self, editor):
147 for indexEditor in self.viewmanager.dict_editors.keys():
148 if editor is self.viewmanager.dict_editors[indexEditor]:
149 self.viewmanager.myQtab.setCurrentIndex(indexEditor)
154 def getCurrentEditor(self):
155 index = self.viewmanager.myQtab.currentIndex()
158 editor = self.viewmanager.dict_editors[index]
166 # Méthodes secondaires permettant de gérer les observeurs du
171 def addObserver(self, observer):
173 In fact, only one observer may be defined for the moment.
176 observer.processEficasEvent
178 raise DevelException("the argument should implement the function processEficasEvent")
179 self.__observer = observer
181 def notifyObserver(self, eventType, callbackId=None):
182 eficasEvent = EficasEvent(eventType, callbackId)
183 self.__observer.processEficasEvent(self, eficasEvent)