1 # -*- coding: utf-8 -*-
3 # Copyright (C) 2008-2017 EDF R&D
5 # This file is part of SALOME ADAO module
7 # This library is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU Lesser General Public
9 # License as published by the Free Software Foundation; either
10 # version 2.1 of the License.
12 # This library is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # Lesser General Public License for more details.
17 # You should have received a copy of the GNU Lesser General Public
18 # License along with this library; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
27 import eficasSalome # Import from EFICAS_SRC
28 from InterfaceQT4 import qtEficas # Import from Eficas
29 from PyQt5.QtGui import * # Import from PyQT
30 from PyQt5.QtCore 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 import salome ; salome.salome_init()
55 eficasSalome.MyEficas.__init__(self, None, code="ADAO", module="ADAO")
56 self.viewmanager.myQtab.currentChanged.connect(self.tabChanged)
59 # self.frameEntete.close()
62 def addJdcInSalome(self, jdcPath):
63 debug("addJdcInSalome is called " + str(jdcPath))
64 # On gere nous meme l'etude
68 # Gestion des évènements provenant des widgets QT d'Eficas
72 def tabChanged(self, index):
73 debug("tabChanged " + str(index))
74 # This signal is also emit when a new case is created/added
75 # On regarde que le dictionnaire contient l'index
76 if index in self.viewmanager.dict_editors.keys():
77 self.notifyObserver(EficasEvent.EVENT_TYPES.TABCHANGED, callbackId=self.viewmanager.dict_editors[index])
81 # Méthodes gérant les boutons dans SALOME
85 # Rq: Utilisation de la méthode str() pour passer d'un Qstring à un string
87 def adaofileNew(self, adao_case):
89 qtEficas.Appli.fileNew(self)
90 index = self.viewmanager.myQtab.currentIndex()
91 adao_case.name = str(self.viewmanager.myQtab.tabText(index))
92 adao_case.setEditor(self.viewmanager.dict_editors[index])
93 self.notifyObserver(EficasEvent.EVENT_TYPES.NEW, callbackId=adao_case)
95 def adaoFileSave(self, adao_case):
97 ok = qtEficas.Appli.fileSave(self)
99 index = self.viewmanager.myQtab.currentIndex()
100 adao_case.name = str(self.viewmanager.myQtab.tabText(index))
101 adao_case.filename = str(self.viewmanager.dict_editors[index].fichier)
102 adao_case.setEditor(self.viewmanager.dict_editors[index])
103 self.notifyObserver(EficasEvent.EVENT_TYPES.SAVE, callbackId=adao_case)
105 def adaoFileSaveAs(self, adao_case):
107 ok = qtEficas.Appli.fileSaveAs(self)
109 index = self.viewmanager.myQtab.currentIndex()
110 adao_case.name = str(self.viewmanager.myQtab.tabText(index))
111 adao_case.filename = str(self.viewmanager.dict_editors[index].fichier)
112 adao_case.setEditor(self.viewmanager.dict_editors[index])
113 self.notifyObserver(EficasEvent.EVENT_TYPES.SAVE, callbackId=adao_case)
115 def adaoFileOpen(self, adao_case):
117 tab_number = self.viewmanager.myQtab.count()
118 ok = self.viewmanager.handleOpen()
120 # On regarde si c'est un nouveau editeur
121 if self.viewmanager.myQtab.count() > tab_number:
122 index = self.viewmanager.myQtab.currentIndex()
123 adao_case.name = str(self.viewmanager.myQtab.tabText(index))
124 adao_case.filename = str(self.viewmanager.dict_editors[index].fichier)
125 adao_case.setEditor(self.viewmanager.dict_editors[index])
126 self.notifyObserver(EficasEvent.EVENT_TYPES.OPEN, callbackId=adao_case)
128 def adaoFileClose(self, adao_case):
130 index = self.viewmanager.myQtab.currentIndex()
131 close_editor = self.viewmanager.dict_editors[index]
132 res = self.viewmanager.handleClose(self)
133 if res != 2: # l utilsateur a annule
134 if close_editor.fichier is None:
136 self.notifyObserver(EficasEvent.EVENT_TYPES.CLOSE, callbackId=close_editor)
138 # Cas fichier existant
139 self.notifyObserver(EficasEvent.EVENT_TYPES.CLOSE, callbackId=close_editor)
143 # Méthodes auxiliares de gestion du GUI Eficas pour synchronisation
144 # avec la partie GUI de SALOME
148 def selectCase(self, editor):
150 for indexEditor in self.viewmanager.dict_editors.keys():
151 if editor is self.viewmanager.dict_editors[indexEditor]:
152 self.viewmanager.myQtab.setCurrentIndex(indexEditor)
157 def getCurrentEditor(self):
158 index = self.viewmanager.myQtab.currentIndex()
161 editor = self.viewmanager.dict_editors[index]
169 # Méthodes secondaires permettant de gérer les observeurs du
174 def addObserver(self, observer):
176 In fact, only one observer may be defined for the moment.
179 observer.processEficasEvent
181 raise DevelException("the argument should implement the function processEficasEvent")
182 self.__observer = observer
184 def notifyObserver(self, eventType, callbackId=None):
185 eficasEvent = EficasEvent(eventType, callbackId)
186 self.__observer.processEficasEvent(self, eficasEvent)