]> SALOME platform Git repositories - modules/adao.git/blob - src/daSalome/daGUI/daEficasWrapper/adaoEficasWrapper.py
Salome HOME
DATASSIM -> ADAO
[modules/adao.git] / src / daSalome / daGUI / daEficasWrapper / adaoEficasWrapper.py
1 # -*- coding: iso-8859-1 -*-
2 #  Copyright (C) 2010 EDF R&D
3 #
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.
8 #
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.
13 #
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
17 #
18 #  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #
20
21 from eficasWrapper import *
22 from PyQt4 import QtGui,QtCore
23 import sys
24
25 # Configuration de l'installation
26 my_path = os.path.dirname(os.path.abspath(__file__))
27 ADAO_INSTALL_DIR = my_path + "/../daEficas"
28 sys.path[:0]=[ADAO_INSTALL_DIR]
29
30 #
31 # ============================================
32 # Specialization of the EficasWrapper for ADAO
33 # ============================================
34 #
35 class AdaoEficasWrapper(EficasWrapper):
36
37     def __init__(self, parent, code="ADAO"):
38         EficasWrapper.__init__(self, parent, code)
39         self.__myCallbackId = {}
40         self.__close_editor = None
41         self.__file_open_name = ""
42
43     def init_gui(self):
44       EficasWrapper.init_gui(self)
45       print "self.__myCallbackId", self.__myCallbackId
46       save_CallbackId =  self.__myCallbackId.copy()
47       for editor, myCallbackId in save_CallbackId.iteritems():
48         self.notifyObserver(EficasEvent.EVENT_TYPES.REOPEN, callbackId=myCallbackId)
49
50     # Association de l'objet editor avec le callbackId
51     def setCallbackId(self, callbackId):
52       index = self.viewmanager.myQtab.currentIndex()
53       self.__myCallbackId[self.viewmanager.dict_editors[index]] = callbackId
54
55     def getCallbackId(self):
56       if self.__close_editor is None:
57         index = self.viewmanager.myQtab.currentIndex()
58         return self.__myCallbackId[self.viewmanager.dict_editors[index]]
59       else:
60         return self.__myCallbackId[self.__close_editor]
61
62     def fileSave(self):
63         """
64         @overload
65         """
66         qtEficas.Appli.fileSave(self)
67         index = self.viewmanager.myQtab.currentIndex()
68         if index > -1 :
69           self.notifyObserver(EficasEvent.EVENT_TYPES.SAVE)
70
71     def fileSaveAs(self):
72         """
73         @overload
74         """
75         qtEficas.Appli.fileSaveAs(self)
76         self.notifyObserver(EficasEvent.EVENT_TYPES.SAVE)
77
78     def getCaseName(self):
79       if self.__close_editor is None:
80         index = self.viewmanager.myQtab.currentIndex()
81         CaseName = self.viewmanager.myQtab.tabText(index)
82         return CaseName
83       else:
84         CaseName = str(self.__close_editor.fichier.split('/')[-1])
85         return CaseName
86
87     def getFileCaseName(self):
88       if self.__close_editor is None:
89         index = self.viewmanager.myQtab.currentIndex()
90         editor = self.viewmanager.dict_editors[index]
91         return editor.fichier
92       else:
93         return self.__close_editor.fichier
94
95     def Openfile(self, filename):
96       self.viewmanager.handleOpen(fichier=filename)
97
98     def handleOpenRecent(self):
99       """
100       @overload
101       """
102       idx = self.sender()
103       fichier = self.ficRecents[idx]
104       self.__file_open_name = fichier
105       self.notifyObserver(EficasEvent.EVENT_TYPES.OPEN)
106       self.__file_open_name = ""
107
108     def fileOpen(self):
109         """
110         @overload
111         """
112         fichier = QtGui.QFileDialog.getOpenFileName(self,
113                                                     self.trUtf8('Ouvrir Fichier'),
114                                                     self.CONFIGURATION.savedir,
115                                                     self.trUtf8('JDC Files (*.comm);;''All Files (*)'))
116         if fichier.isNull(): return
117         self.__file_open_name = fichier
118         self.notifyObserver(EficasEvent.EVENT_TYPES.OPEN)
119         self.__file_open_name = ""
120
121     def getOpenFileName(self):
122       return str(self.__file_open_name)
123
124     def selectCase(self, callbackId):
125       rtn = False
126       for editor, myCallbackId in self.__myCallbackId.iteritems():
127         if myCallbackId[0] == callbackId[0]:
128           if myCallbackId[1].GetID() == callbackId[1].GetID():
129             try:
130               for indexEditor in self.viewmanager.dict_editors.keys():
131                 if editor is self.viewmanager.dict_editors[indexEditor]:
132                   self.viewmanager.myQtab.setCurrentIndex(indexEditor)
133                   rtn = True
134             except:
135               pass
136       return rtn
137
138     def fileClose(self):
139         """
140         @overload
141         """
142         index = self.viewmanager.myQtab.currentIndex()
143         self.__close_editor = self.viewmanager.dict_editors[index]
144         res = self.viewmanager.handleClose(self)
145         if res != 2: # l utilsateur a annule
146           if self.__close_editor.fichier is None:
147             # We have to destroy the case
148             self.notifyObserver(EficasEvent.EVENT_TYPES.DESTROY)
149             self.__myCallbackId.pop(self.__close_editor)
150           else:
151             # Il faudrait en faire plus -> Voir Edit dans SALOME !
152             self.notifyObserver(EficasEvent.EVENT_TYPES.SAVE)
153             self.__myCallbackId.pop(self.__close_editor)
154         self.__close_editor = None
155         return res
156
157     def fileCloseAll(self):
158       """
159       @overload
160       """
161       while len(self.viewmanager.dict_editors) > 0:
162         self.viewmanager.myQtab.setCurrentIndex(0)
163         if self.viewmanager.myQtab.currentIndex() == 0:
164           res = self.fileClose()
165           if res==2 : return res   # l utilsateur a annule
166         else:
167           return 0
168