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