Salome HOME
Tout ok sauf la gestion de la duplication...
[modules/adao.git] / src / daSalome / daGUI / daEficasWrapper / datassimEficasWrapper.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 DATASSIM_INSTALL_DIR = my_path + "/../daEficas"
28 sys.path[:0]=[DATASSIM_INSTALL_DIR]
29
30 #
31 # ================================================
32 # Specialization of the EficasWrapper for DATASSIM
33 # ================================================
34 #
35 class DatassimEficasWrapper(EficasWrapper):
36
37     __myCallbackId = {}
38     __close_editor = None
39     __file_open_name = ""
40
41     def __init__(self, parent, code="DATASSIM"):
42         EficasWrapper.__init__(self, parent, code)
43
44     # Association de l'objet editor avec le callbackId
45     def setCallbackId(self, callbackId):
46       index = self.viewmanager.myQtab.currentIndex()
47       self.__myCallbackId[self.viewmanager.dict_editors[index]] = callbackId
48
49     def getCallbackId(self):
50       if self.__close_editor is None:
51         index = self.viewmanager.myQtab.currentIndex()
52         return self.__myCallbackId[self.viewmanager.dict_editors[index]]
53       else:
54         return self.__myCallbackId[self.__close_editor]
55
56     def fileSave(self):
57         """
58         @overload
59         """
60         qtEficas.Appli.fileSave(self)
61         index = self.viewmanager.myQtab.currentIndex()
62         if index > -1 :
63           self.notifyObserver(EficasEvent.EVENT_TYPES.SAVE)
64
65     def fileSaveAs(self):
66         """
67         @overload
68         """
69         qtEficas.Appli.fileSaveAs(self)
70         self.notifyObserver(EficasEvent.EVENT_TYPES.SAVE)
71
72     def getCaseName(self):
73       if self.__close_editor is None:
74         index = self.viewmanager.myQtab.currentIndex()
75         CaseName = self.viewmanager.myQtab.tabText(index)
76         return CaseName
77       else:
78         CaseName = str(self.__close_editor.fichier.split('/')[-1])
79         return CaseName
80
81     def getFileCaseName(self):
82       if self.__close_editor is None:
83         index = self.viewmanager.myQtab.currentIndex()
84         editor = self.viewmanager.dict_editors[index]
85         return editor.fichier
86       else:
87         return self.__close_editor.fichier
88
89     def Openfile(self, filename):
90       self.viewmanager.handleOpen(fichier=filename)
91
92     def handleOpenRecent(self):
93       """
94       @overload
95       """
96       idx = self.sender()
97       fichier = self.ficRecents[idx]
98       self.__file_open_name = fichier
99       self.notifyObserver(EficasEvent.EVENT_TYPES.OPEN)
100       self.__file_open_name = ""
101
102     def fileOpen(self):
103         """
104         @overload
105         """
106         fichier = QtGui.QFileDialog.getOpenFileName(self,
107                                                     self.trUtf8('Ouvrir Fichier'),
108                                                     self.CONFIGURATION.savedir,
109                                                     self.trUtf8('JDC Files (*.comm);;''All Files (*)'))
110         if fichier.isNull(): return
111         self.__file_open_name = fichier
112         self.notifyObserver(EficasEvent.EVENT_TYPES.OPEN)
113         self.__file_open_name = ""
114
115     def getOpenFileName(self):
116       return str(self.__file_open_name)
117
118     def fileClose(self):
119         """
120         @overload
121         """
122         index = self.viewmanager.myQtab.currentIndex()
123         self.__close_editor = self.viewmanager.dict_editors[index]
124         res = self.viewmanager.handleClose(self)
125         if res != 2: # l utilsateur a annule
126           if self.__close_editor.fichier is None:
127             # We have to destroy the case
128             self.notifyObserver(EficasEvent.EVENT_TYPES.DESTROY)
129             self.__myCallbackId.pop(self.__close_editor)
130           else:
131             # Il faudrait en faire plus -> Voir Edit dans SALOME !
132             self.notifyObserver(EficasEvent.EVENT_TYPES.SAVE)
133             self.__myCallbackId.pop(self.__close_editor)
134         self.__close_editor = None
135         return res
136
137     def fileCloseAll(self):
138       """
139       @overload
140       """
141       while len(self.viewmanager.dict_editors) > 0:
142         self.viewmanager.myQtab.setCurrentIndex(0)
143         if self.viewmanager.myQtab.currentIndex() == 0:
144           res = self.fileClose()
145           if res==2 : return res   # l utilsateur a annule
146         else:
147           return 0
148