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