]> SALOME platform Git repositories - modules/adao.git/blob - src/daSalome/daGUI/daEficasWrapper/adaoEficasWrapper.py
Salome HOME
Minor source update for OM compatibility
[modules/adao.git] / src / daSalome / daGUI / daEficasWrapper / adaoEficasWrapper.py
1 # -*- coding: utf-8 -*-
2 #
3 # Copyright (C) 2008-2024 EDF R&D
4 #
5 # This file is part of SALOME ADAO module
6 #
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.
11 #
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.
16 #
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
20 #
21 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 #
23
24 import sys
25 import os
26
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
31
32 from daUtils.adaoEficasEvent import *
33 from daUtils.adaoLogger import *
34
35 #
36 # ============================================
37 # Specialization of the EficasWrapper for ADAO
38 # ============================================
39 #
40 class AdaoEficasWrapper(eficasSalome.MyEficas):
41
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)
48
49         self.__parent = parent
50
51     def init_gui(self):
52
53       import salome ; salome.salome_init()
54
55       eficasSalome.MyEficas.__init__(self, None, code="ADAO", module="ADAO")
56       self.viewmanager.myQtab.currentChanged.connect(self.tabChanged)
57       # self.menubar.hide()
58       # self.toolBar.hide()
59       # self.frameEntete.close()
60       # self.closeEntete()
61
62     def addJdcInSalome(self, jdcPath):
63       debug("addJdcInSalome is called " + str(jdcPath))
64       # On gere nous meme l'etude
65
66 #######
67 #
68 # Gestion des évènements provenant des widgets QT d'Eficas
69 #
70 #######
71
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.dictEditors.keys():
77         self.notifyObserver(EficasEvent.EVENT_TYPES.TABCHANGED, callbackId=self.viewmanager.dictEditors[index])
78
79 #######
80 #
81 # Méthodes gérant les boutons dans SALOME
82 #
83 #######
84
85 # Rq: Utilisation de la méthode str() pour passer d'un Qstring à un string
86
87     def adaofileNew(self, adao_case):
88
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.dictEditors[index])
93       self.notifyObserver(EficasEvent.EVENT_TYPES.NEW, callbackId=adao_case)
94
95     def adaoFileSave(self, adao_case):
96
97       ok = qtEficas.Appli.fileSave(self)
98       if ok:
99         index = self.viewmanager.myQtab.currentIndex()
100         adao_case.name          = str(self.viewmanager.myQtab.tabText(index))
101         adao_case.filename      = str(self.viewmanager.dictEditors[index].fichier)
102         adao_case.setEditor(self.viewmanager.dictEditors[index])
103         self.notifyObserver(EficasEvent.EVENT_TYPES.SAVE, callbackId=adao_case)
104
105     def adaoFileSaveAs(self, adao_case):
106
107       ok = qtEficas.Appli.fileSaveAs(self)
108       if ok:
109         index = self.viewmanager.myQtab.currentIndex()
110         adao_case.name          = str(self.viewmanager.myQtab.tabText(index))
111         adao_case.filename      = str(self.viewmanager.dictEditors[index].fichier)
112         adao_case.setEditor(self.viewmanager.dictEditors[index])
113         self.notifyObserver(EficasEvent.EVENT_TYPES.SAVE, callbackId=adao_case)
114
115     def adaoFileOpen(self, adao_case):
116
117       tab_number = self.viewmanager.myQtab.count()
118       ok = self.viewmanager.handleOpen()
119       if ok:
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.dictEditors[index].fichier)
125           adao_case.setEditor(self.viewmanager.dictEditors[index])
126           self.notifyObserver(EficasEvent.EVENT_TYPES.OPEN, callbackId=adao_case)
127
128     def adaoFileClose(self, adao_case):
129
130         index = self.viewmanager.myQtab.currentIndex()
131         close_editor = self.viewmanager.dictEditors[index]
132         res = self.viewmanager.handleClose(self)
133         if res != 2: # l utilsateur a annule
134           if close_editor.fichier is None:
135             # Cas fichier vide
136             self.notifyObserver(EficasEvent.EVENT_TYPES.CLOSE, callbackId=close_editor)
137           else:
138             # Cas fichier existant
139             self.notifyObserver(EficasEvent.EVENT_TYPES.CLOSE, callbackId=close_editor)
140
141 #######
142 #
143 # Méthodes auxiliares de gestion du GUI Eficas pour synchronisation
144 # avec la partie GUI de SALOME
145 #
146 #######
147
148     def selectCase(self, editor):
149       rtn = False
150       for indexEditor in self.viewmanager.dictEditors.keys():
151         if editor is self.viewmanager.dictEditors[indexEditor]:
152           self.viewmanager.myQtab.setCurrentIndex(indexEditor)
153           rtn = True
154           break
155       return rtn
156
157     def getCurrentEditor(self):
158       index = self.viewmanager.myQtab.currentIndex()
159       editor = None
160       if index >= 0:
161         editor = self.viewmanager.dictEditors[index]
162       return editor
163
164
165
166
167 #######
168 #
169 # Méthodes secondaires permettant de gérer les observeurs du
170 # GUI d'Eficas
171 #
172 #######
173
174     def addObserver(self, observer):
175         """
176         In fact, only one observer may be defined for the moment.
177         """
178         try:
179             observer.processEficasEvent
180         except:
181             raise DevelException("the argument should implement the function processEficasEvent")
182         self.__observer = observer
183
184     def notifyObserver(self, eventType, callbackId=None):
185       eficasEvent = EficasEvent(eventType, callbackId)
186       self.__observer.processEficasEvent(self, eficasEvent)