Salome HOME
f2fb2245c6e9a442bd412462c18b39b0b811f743
[tools/eficas.git] / InterfaceQT4 / qtEficasSsIhm.py
1 # -*- coding: iso-8859-1 -*-
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
22 from __future__ import absolute_import
23 from __future__ import print_function
24 try :
25    from builtins import str
26 except : pass
27
28 import os, sys
29
30 from Extensions.eficas_exception import EficasException
31 from Extensions import param2
32
33 from InterfaceQT4.getVersion import getEficasVersion
34 from InterfaceQT4.viewManagerSsIhm import MyViewManagerSsIhm
35
36 from Editeur        import session
37
38
39 class AppliSsIhm:
40     """
41     Class implementing the main user interface.
42     """
43     def __init__(self,code=None,salome=1,parent=None,multi=False,langue='fr',ssIhm=True,labelCode=None,genereXSD=False):
44         """
45         Constructor
46         """
47         version=getEficasVersion()
48         self.VERSION_EFICAS="Eficas QT5 Salome " + version
49         self.labelCode=labelCode
50
51         self.salome=salome
52         self.ssIhm=True
53         self.code=code
54         self.genereXSD=genereXSD
55
56         self.dict_reels={}
57         self.fichierIn=None
58         self.fichierOut=None
59
60         self.recent =  []
61         self.ficRecents={}
62         self.mesScripts={}
63         self.listeAEnlever=[]
64         self.ListePathCode=['Adao','ADAO','Carmel3D','Telemac','CF','MAP','ZCracks', 'SEP','SPECA','PSEN_Eficas','PSEN_N1']
65         self.listeCode=['Adao','ADAO','Carmel3D','Telemac','CF','MAP','ZCracks', 'SEP','SPECA','PSEN_Eficas','PSEN_N1']
66         self.repIcon=os.path.join( os.path.dirname(os.path.abspath(__file__)),'..','Editeur','icons')
67
68         self.fichierCata=session.d_env.fichierCata
69         if session.d_env.labelCode : self.labelCode=session.d_env.labelCode
70         self.withXSD=session.d_env.withXSD
71
72         if self.salome:
73           import Accas
74           try :
75             import eficasSalome
76             Accas.SalomeEntry = eficasSalome.SalomeEntry
77           except : 
78             print ('eficas hors salome')
79
80         self.multi=multi
81         if self.multi : 
82               print ('pas de multi sans ihm')
83
84
85         if langue=='fr': self.langue=langue
86         else           : self.langue="ang"
87
88         if self.multi == False :
89              self.definitCode(code,None)
90              if code==None: return
91
92         self.suiteTelemac=False
93         self.viewmanager=MyViewManagerSsIhm(self)
94
95
96     def definitCode(self,code,ssCode) :
97         self.code=code
98         self.ssCode=ssCode
99         if self.code == None:return # pour le cancel de la fenetre choix code
100
101         try : 
102           name='prefs_'+self.code
103           prefsCode=__import__(name)
104           self.repIni=prefsCode.repIni
105         except : 
106           self.repIni=os.path.dirname(os.path.abspath(__file__))
107           
108
109         if ssCode != None :
110            self.formatFichierOut = ssCode  #par defaut
111            prefsCode.NAME_SCHEME = ssCode
112         else :
113            self.formatFichierIn  = "python" #par defaut
114            self.formatFichierOut = "python" #par defaut
115
116         nameConf='configuration_'+self.code
117         try :
118           configuration=__import__(nameConf)
119           self.maConfiguration = configuration.make_config(self,self.repIni)
120         except :
121           from InterfaceQT4.configuration import makeConfig
122           #self.maConfiguration = configuration.makeConfig(self,prefsCode.repIni)
123           self.maConfiguration = makeConfig(self,self.repIni)
124
125         if hasattr (self,'maConfiguration') and self.maConfiguration.translatorFichier :
126            from Extensions import localisation
127            localisation.localise(None,self.langue,translatorFichier=self.maConfiguration.translatorFichier)
128         if self.withXSD : self.maConfiguration.withXSD=True
129
130
131     def getSource(self,file):
132     # appele par Editeur/session.py
133         import convert
134         p=convert.plugins['python']()
135         p.readfile(file)
136         texte=p.convert('execnoparseur')
137         return texte
138
139
140     def initEditor(self,fichier = None,jdc = None, units = None,include=0):
141         if (hasattr(self, 'editor')) and self.editor != None : 
142            print ('un seul editeur par application')
143            sys.exit()
144         self.editor = self.viewmanager.getNewEditorNormal()
145         
146     def initEditorNormal(self,fichier = None,jdc = None, units = None,include=0):
147         if (hasattr(self, 'editor')) and self.editor != None : 
148            print ('un seul editeur par application')
149            sys.Exit()
150         #self.editor = JDCEditorSsIhm(self,fichier, jdc, self.myQtab,units=units,include=include)
151         self.editor = self.viewmanager.getNewEditorNormal()
152         
153
154     def fileNew(self):
155         self.editor=self.initEditor()
156
157     def getEditor(self):
158         if (hasattr(self, 'editor')) and self.editor != None : return self.editor
159         self.initEditor()
160         return self.editor
161
162     def fileOpen(self,fichier):
163         fichierIn = os.path.abspath(fichier)
164         try:
165             monEditor=self.viewmanager.handleOpen(fichierIn)
166         except EficasException as exc:
167             print ('poum')
168             monEditor=None
169         return monEditor
170
171     def fileSave(self):
172         if self.editor == None : return False
173         ok, newName = editor.saveFileAs()
174         print ('ok, newName ',ok, newName)
175
176     def fileSaveAs(self,fileName):
177         if self.editor == None : return False
178         ok = editor.saveFileAs()
179         print ('ok ',ok)
180
181     def dumpXsd(self, avecEltAbstrait = False):
182         current_cata    = CONTEXT.getCurrentCata()
183         texteXSD = current_cata.dumpXsd( avecEltAbstrait)
184         return texteXSD
185         #if self.maConfiguration.afficheIhm==False : exit()
186         #else : return texteXSD
187
188 #,self.fileSaveAs
189 #,self.fileClose
190 #,self.fileExit
191 #,self.jdcRapport
192 #,self.jdcRegles
193 #,self.jdcFichierSource
194 #,self.visuJdcPy
195        
196
197
198 if __name__=='__main__':
199
200     # Modules Eficas
201     monEficas= AppliSsIhm(code='Adao',salome=0,labelCode='V83')