Salome HOME
Modifications liees a MT
[tools/eficas.git] / InterfaceQT4 / eficas_go.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 # Copyright (C) 2007-2017   EDF R&D
4 #
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 2.1 of the License.
9 #
10 # This library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 # Lesser General Public License for more details.
14 #
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with this library; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
18 #
19 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #
21
22 # Modules Python
23 from __future__ import absolute_import
24 from __future__ import print_function
25 try :
26    from builtins import str
27 except : pass
28
29 from PyQt5.QtWidgets import QApplication
30
31 import sys,os
32 repIni=os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(__file__)),".."))
33 ihmQTDir=os.path.join(repIni,"UiQT5")
34 editeurDir=os.path.join(repIni,"Editeur")
35 ihmDir=os.path.join(repIni,"InterfaceQT4")
36
37 if ihmDir not in sys.path : sys.path.append(ihmDir)
38 if ihmQTDir not in sys.path : sys.path.append(ihmQTDir)
39 if editeurDir not in sys.path :sys.path.append(editeurDir)
40
41 def getEficasSsIhm(code=None,fichier=None,ssCode=None,multi=False,langue='en',versionCode=None):
42     #print (versionCode)
43     from InterfaceQT4.qtEficasSsIhm import AppliSsIhm
44     Eficas=AppliSsIhm(code=code,salome=0,ssCode=ssCode,multi=multi,langue=langue,versionCode=versionCode)
45     from Editeur  import session
46     options=session.parse(['ssIhm','-k',code,'-v',versionCode])
47     return Eficas
48
49
50 def lanceEficas(code=None,fichier=None,ssCode=None,multi=False,langue='en'):
51     """
52         Lance l'appli EFICAS
53     """
54     # Analyse des arguments de la ligne de commande
55     from Editeur  import session
56     options=session.parse(sys.argv)
57     if options.code!= None : code=options.code
58     if options.ssCode!= None : ssCode=options.ssCode
59
60     from InterfaceQT4.qtEficas import Appli
61     app = QApplication(sys.argv)
62
63     #import cProfile, pstats, StringIO
64     #pr = cProfile.Profile()
65     #pr.enable()
66
67     Eficas=Appli(code=code,salome=0,ssCode=ssCode,multi=multi,langue=langue)
68     #pr.disable()
69     #s = StringIO.StringIO()
70     #sortby = 'cumulative'
71     #ps = pstats.Stats(pr, stream=s).sort_stats(sortby)
72     #ps.print_stats()
73     #print (s.getValue())
74
75     Eficas.show()
76
77     res=app.exec_()
78     sys.exit(res)
79
80
81 def lanceEficas_ssIhm(code=None,fichier=None,ssCode=None,version=None,debug=False,langue='en'):
82     """
83         Lance l'appli EFICAS pour trouver les noms des groupes
84     """
85     # Analyse des arguments de la ligne de commande
86     from Editeur  import session
87     options=session.parse(sys.argv)
88     if version!=None and options.cata==None : options.cata=version
89     if fichier==None : fichier=options.comm[0]
90     if code == None : code=options.code
91
92     from .qtEficas import Appli
93     Eficas=Appli(code=code,salome=0,ssCode=ssCode,ssIhm=True,langue=langue)
94
95     from .ssIhm  import QWParentSSIhm
96     parent=QWParentSSIhm(code,Eficas,version)
97
98     from . import readercata
99     if not hasattr ( Eficas, 'readercata'):
100            monreadercata  = readercata.ReaderCata( parent, Eficas )
101            Eficas.readercata=monreadercata
102
103     from .editor import JDCEditor
104     monEditeur=JDCEditor(Eficas,fichier)
105     return monEditeur
106
107 def lanceEficas_ssIhm_chercheGroupes(code=None,fichier=None,ssCode=None,version=None):
108     monEditeur=lanceEficas_ssIhm(code,fichier,ssCode,version)
109     print((monEditeur.chercheGroupes()))
110
111 def lanceEficas_ssIhm_cherche_cr(code=None,fichier=None,ssCode=None,version=None):
112     monEditeur=lanceEficas_ssIhm(code,fichier,ssCode,version)
113     print((monEditeur.jdc.cr))
114
115 def lanceEficas_ssIhm_reecrit(code=None,fichier=None,ssCode=None,version=None,ou=None,cr=False,debug=False,leger=False,langue='ang'):
116     #print 'lanceEficas_ssIhm_reecrit', fichier
117     monEditeur=lanceEficas_ssIhm(code,fichier,ssCode,version,langue=langue)
118     if ou == None : 
119        fileName=fichier.split(".")[0]+"_reecrit.comm"
120        fn=fichier.split(".")[0]+"_cr.txt"
121     else :
122        f=fichier.split(".")[0]+"_reecrit.comm"
123        f1=os.path.basename(f)
124        fn=fichier.split(".")[0]+"_cr.txt"
125        f2=os.path.basename(fn)
126        fileName=os.path.join(ou,f1)
127        fileCr=os.path.join(ou,f2)
128     debut=False
129     if debug :
130          import cProfile, pstats, StringIO
131          pr = cProfile.Profile()
132          pr.enable()
133          monEditeur.saveFileAs(fileName=fileName)
134          pr.disable()
135          s = StringIO.StringIO()
136          sortby = 'cumulative'
137          ps = pstats.Stats(pr, stream=s).sort_stats(sortby)
138          ps.print_stats()
139          print (s.getValue())
140
141     elif not leger : monEditeur.saveFileAs(fileName=fileName)
142     else : monEditeur.saveFileLegerAs(fileName=fileName)
143     if cr:
144        f = open(fileCr, 'w')
145        f.write(str(monEditeur.jdc.report()))
146        f.close()
147
148 def lanceEficas_param(code='Adao',fichier=None,version='V0',macro='ASSIMILATION_STUDY'):
149     """
150         Lance l'appli EFICAS pour trouver les noms des groupes
151     """
152     # Analyse des arguments de la ligne de commande
153     from Editeur  import session
154     options=session.parse(sys.argv)
155
156     from .qtEficas import Appli
157     #app = QApplication(sys.argv)
158     #Eficas=Appli(code=code,ssCode=None,salome=0)
159
160     from .ssIhm  import QWParentSSIhm
161     Eficas=QWParentSSIhm(code,version)
162
163     from . import readercata
164     if not hasattr ( Eficas, 'readercata'):
165            monreadercata  = readercata.ReaderCata( parent, Eficas )
166            Eficas.readercata=monreadercata
167
168     from .editor import JDCEditor
169     monEditeur=JDCEditor(Eficas,fichier)
170     texte=loadJDC(fichier)
171     parameters=getJdcParameters(texte,macro)
172     return parameters
173
174 #def getEficasSsIhm(code='Adao',versionCode='V0'):
175 #    from .qtEficasSsIhm import AppliSsIhm
176 #    Eficas=AppliSsIhm(code=code,ssCode=None,salome=0)
177 #    return Eficas
178
179 def getJdcParameters(jdc,macro):
180     """
181     This function converts the data from the specified macro of the
182     specified jdc text to a python dictionnary whose keys are the
183     names of the data of the macro.
184     """
185     context = {}
186     source = "def args_to_dict(**kwargs): return kwargs \n"
187     source+= "%s = _F = args_to_dict          \n"%macro
188     source+= "parameters="+jdc+"                        \n"
189     source+= "context['parameters'] = parameters         \n"
190     code = compile(source, 'file.py', 'exec')
191     eval(code)
192     parameters = context['parameters']
193     return parameters
194
195 def loadJDC(filename):
196     """
197     This function loads the text from the specified JdC file. A JdC
198     file is the persistence file of Eficas (*.comm).
199     """
200     fcomm=open(filename,'r')
201     jdc = ""
202     for line in fcomm.readlines():
203         if not (line[0]=='#'):
204            jdc+="%s"%line
205
206     # Warning, we have to make sure that the jdc comes as a simple
207     # string without any extra spaces/newlines
208     return jdc.strip()
209
210 if __name__ == "__main__":
211     import sys
212     sys.path.insert(0,os.path.abspath(os.path.join(os.getcwd(),'..')))
213     lanceEficas(code=None,fichier=None,ssCode=None,multi=True)
214     
215