Salome HOME
bug sur un mesage dans une exception sur un validator (cf JPA)
[tools/eficas.git] / InterfaceQT4 / viewManagerSsIhm.py
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2007-2021   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 __future__ import absolute_import
22 try :
23     from builtins import str
24     from builtins import object
25 except : pass
26
27 import os
28 from Extensions.i18n import tr
29
30 # --------------------------------
31 class JdcSsIhmHandler(object):
32 # --------------------------------
33 # retourne a l utilisateur
34
35     def __init__(self,viewManager):
36 #  --------------------------------------
37         self.viewManagerSsIhm=viewManager
38
39     def viewJdcPy(self) :
40 #  ---------------------
41         self.viewManagerSsIhm.handleViewJdcPy(self)
42
43     def viewJdcSource(self) :
44 #  ---------------------
45         self.viewManagerSsIhm.handleViewJdcSource(self)
46
47     def getFileName(self):
48 #  ---------------------
49         self.viewManagerSsIhm.getFileName(self)
50
51     def viewJdcRapport(self) :
52 #  ---------------------
53         self.viewManagerSsIhm.handleViewJdcRapport(self)
54
55     def getJdcRapport(self) :
56 #  ---------------------
57         return self.viewManagerSsIhm.handleGetJdcRapport(self)
58
59     def getDicoPython(self) :
60 #  -------------------------
61         return self.viewManagerSsIhm.generDico(self)
62
63     def isJdcValid(self) :
64 #  -------------------------
65         return self.viewManagerSsIhm.isJdcValid(self)
66
67     def fileSaveAs(self,fileName):
68 #  -------------------------
69         return self.viewManagerSsIhm.fileSaveAs(self,fileName)
70
71     def fileLegerSaveAs(self,fileName):
72 #  -----------------------------------
73         return self.viewManagerSsIhm.fileLegerSaveAs(self,fileName)
74
75
76
77 #--------------------------------
78 class MyViewManagerSsIhm(object):
79 #--------------------------------
80 # Symetrique de ViewManager mais pas d heritage entre les 2
81 # dans le viewManager pas de souci pour savoir qui est le jdc sur lequel on travaille
82 # ici en revanche.... c est moins sur . voir avec le fichier
83
84 #  --------------------------------
85     def __init__(self,appliEficas):
86 #  --------------------------------
87         self.appliEficas=appliEficas
88         self.tabWidgets = []
89         self.mesIndexes = {}
90         self.dictEditors={}
91         self.untitledCount = 0
92         self.doubles = {}
93
94 #  ------------------------------------------------------
95     def handleOpen(self,fichier=None, units=None):
96 #  ------------------------------------------------------
97         result = None
98         if fichier is None:
99             print ('nom de fichier obligatoire')
100             return None
101
102         for handler in self.dictEditors :
103             editor=self.dictEditors[handler]
104             if self.samePath(fichier, editor.getFileName()):
105                 print ('fichier deja ouvert . pas de nouvel editor')
106                 return handler
107
108         monNewHandler = self.getNewEditor(fichier,units)
109         return monNewHandler
110
111 #  ----------------------------------------------------------------------
112     def getNewEditor(self,fichier = None,jdc = None, units = None,include=0):
113 #  ----------------------------------------------------------------------
114 # il faudrait decider entre e handler ou non
115 # le cas d usage n est pas tout a fait identique  :
116 # avec handler pour les utilisateurs avance
117 # sans pour les utilisateurs encore plus ancvances et les tests
118
119         from InterfaceQT4.editorSsIhm import JDCEditorSsIhm
120         editor = JDCEditorSsIhm(self.appliEficas,fichier,jdc, units=units,include=include)
121
122         if editor.jdc: # le fichier est bien un jdc
123             monHandler = JdcSsIhmHandler(self)
124             self.dictEditors[monHandler]=editor
125             return monHandler
126         else:
127             print ('impossible de construire le jdc')
128             return None
129
130 #  --------------------------------------------------------------------------------
131     def getNewEditorNormal(self,fichier = None,jdc = None, units = None,include=0):
132 #  --------------------------------------------------------------------------------
133
134         from InterfaceQT4.editorSsIhm import JDCEditorSsIhm
135         editor = JDCEditorSsIhm(self.appliEficas,fichier,jdc, units=units,include=include)
136         self.editor=editor
137         return editor
138
139 #  -----------------------------
140     def samePath(self,f1, f2):
141 #  ------------------------------
142         """
143         compare two paths.
144         """
145         if f1 is None or f2 is None: return 0
146         if os.path.normcase(os.path.normpath(f1)) == os.path.normcase(os.path.normpath(f2)) : return 1
147         return 0
148
149 #  ---------------------------------
150     def handleViewJdcPy(self,handler):
151 #  ---------------------------------
152         if not (handler in self.dictEditors) :
153             print ('editor non trouve')
154             return
155         self.dictEditors[handler].viewJdcPy()
156
157 #  ---------------------------------
158     def getFileName(self,handler):
159 #  ---------------------------------
160         if not (handler in self.dictEditors) :
161             print ('editor non trouve')
162             return
163         return self.dictEditors[handler].getFileName()
164
165
166 #  ---------------------------------------------
167     def handleViewJdcSource(self,handler):
168 #  ---------------------------------------------
169         print (handler)
170         if not (handler in self.dictEditors) :
171             print ('editor non trouve')
172             return
173         self.dictEditors[handler].viewJdcSource()
174
175
176 #  ---------------------------------------------
177     def handleViewJdcRapport(self,handler):
178 #  ---------------------------------------------
179         print (handler)
180         if not (handler in self.dictEditors) :
181             print ('editor non trouve')
182             return
183         self.dictEditors[handler].viewJdcRapport()
184
185 #  ---------------------------------------------
186     def handleGetJdcRapport(self,handler):
187 #  ---------------------------------------------
188         if not (handler in self.dictEditors) :
189             print ('editor non trouve')
190             return
191         return self.dictEditors[handler].getJdcRapport()
192
193 #  ---------------------------------------------
194     def handleViewJdcRapport(self,handler):
195 #  ---------------------------------------------
196         print (handler)
197         if not (handler in self.dictEditors) :
198             print ('editor non trouve')
199             return
200         self.dictEditors[handler].viewJdcRapport()
201
202
203 #  ---------------------------------------------
204     def generDico(self,handler):
205 #  ---------------------------------------------
206         print (handler)
207         if not (handler in self.dictEditors) :
208             print ('editor non trouve')
209             return
210         return self.dictEditors[handler].generDico()
211
212
213 #  ---------------------------------------------
214     def isJdcValid(self,handler):
215 #  ---------------------------------------------
216         print (handler)
217         if not (handler in self.dictEditors) :
218             print ('editor non trouve')
219             return
220         return self.dictEditors[handler].jdc.isValid()
221
222
223 #  ---------------------------------------------
224     def fileSaveAs(self,handler,fileName):
225 #  ---------------------------------------------
226         print (handler)
227         if not (handler in self.dictEditors) :
228             print ('editor non trouve')
229             return
230         return self.dictEditors[handler].saveFile(fileName)
231
232 #  ---------------------------------------------
233     def fileLegerSaveAs(self, handler,fileName):
234 #  ---------------------------------------------
235 #        print (handler)
236         if not (handler in self.dictEditors) :
237             print ('editor non trouve')
238             return
239         self.dictEditors[handler].saveFileLegerAs(fileName)