Salome HOME
Updating copyright date information and version
[modules/adao.git] / src / daSalome / daGUI / daEficasWrapper / adaoEficasWrapper.py
1 #-*-coding:iso-8859-1-*-
2 # Copyright (C) 2008-2015 EDF R&D
3 #
4 # This file is part of SALOME ADAO module
5 #
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.
10 #
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.
15 #
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
19 #
20 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 #
22
23 import sys
24 import os
25
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
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       eficasSalome.MyEficas.__init__(self, self.__parent, code="ADAO", module="ADAO")
54       self.connect(self.viewmanager.myQtab, SIGNAL('currentChanged(int)'), self.tabChanged)
55       self.menubar.hide()
56       self.toolBar.hide()
57
58     def addJdcInSalome(self, jdcPath):
59       debug("addJdcInSalome is called " + str(jdcPath))
60       # On gere nous meme l'etude
61       pass
62
63 #######
64 #
65 # Gestion des évènements provenant des widgets QT d'Eficas
66 #
67 #######
68
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])
75
76 #######
77 #
78 # Méthodes gérant les boutons dans SALOME
79 #
80 #######
81
82 # Rq: Utilisation de la méthode str() pour passer d'un Qstring à un string
83
84     def adaofileNew(self, adao_case):
85
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)
91
92     def adaoFileSave(self, adao_case):
93
94       ok = qtEficas.Appli.fileSave(self)
95       if ok:
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)
101
102     def adaoFileSaveAs(self, adao_case):
103
104       ok = qtEficas.Appli.fileSaveAs(self)
105       if ok:
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)
111
112     def adaoFileOpen(self, adao_case):
113
114       tab_number = self.viewmanager.myQtab.count()
115       ok = self.viewmanager.handleOpen()
116       if ok:
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)
124
125     def adaoFileClose(self, adao_case):
126
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:
132             # Cas fichier vide
133             self.notifyObserver(EficasEvent.EVENT_TYPES.CLOSE, callbackId=close_editor)
134           else:
135             # Cas fichier existant
136             self.notifyObserver(EficasEvent.EVENT_TYPES.CLOSE, callbackId=close_editor)
137
138 #######
139 #
140 # Méthodes auxiliares de gestion du GUI Eficas pour synchronisation
141 # avec la partie GUI de SALOME
142 #
143 #######
144
145     def selectCase(self, editor):
146       rtn = False
147       for indexEditor in self.viewmanager.dict_editors.keys():
148         if editor is self.viewmanager.dict_editors[indexEditor]:
149           self.viewmanager.myQtab.setCurrentIndex(indexEditor)
150           rtn = True
151           break
152       return rtn
153
154     def getCurrentEditor(self):
155       index = self.viewmanager.myQtab.currentIndex()
156       editor = None
157       if index >= 0:
158         editor = self.viewmanager.dict_editors[index]
159       return editor
160
161
162
163
164 #######
165 #
166 # Méthodes secondaires permettant de gérer les observeurs du
167 # GUI d'Eficas
168 #
169 #######
170
171     def addObserver(self, observer):
172         """
173         In fact, only one observer may be defined for the moment.
174         """
175         try:
176             observer.processEficasEvent
177         except:
178             raise DevelException("the argument should implement the function processEficasEvent")
179         self.__observer = observer
180
181     def notifyObserver(self, eventType, callbackId=None):
182       eficasEvent = EficasEvent(eventType, callbackId)
183       self.__observer.processEficasEvent(self, eficasEvent)