Salome HOME
les accents
[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
42 def lance_eficas(code=None,fichier=None,ssCode=None,multi=False,langue='en'):
43     """
44         Lance l'appli EFICAS
45     """
46     # Analyse des arguments de la ligne de commande
47     from Editeur  import session
48     options=session.parse(sys.argv)
49     if options.code!= None : code=options.code
50     if options.ssCode!= None : ssCode=options.ssCode
51
52     from InterfaceQT4.qtEficas import Appli
53     app = QApplication(sys.argv)
54     Eficas=Appli(code=code,salome=0,ssCode=ssCode,multi=multi,langue=langue)
55     Eficas.show()
56
57     res=app.exec_()
58     sys.exit(res)
59
60
61 def lance_eficas_ssIhm(code=None,fichier=None,ssCode=None,version=None,debug=False,langue='en'):
62     """
63         Lance l'appli EFICAS pour trouver les noms des groupes
64     """
65     # Analyse des arguments de la ligne de commande
66     from Editeur  import session
67     options=session.parse(sys.argv)
68     if version!=None and options.cata==None : options.cata=version
69     if fichier==None : fichier=options.comm[0]
70     if code == None : code=options.code
71
72     from .qtEficas import Appli
73     Eficas=Appli(code=code,salome=0,ssCode=ssCode,ssIhm=True,langue=langue)
74
75     from .ssIhm  import QWParentSSIhm
76     parent=QWParentSSIhm(code,Eficas,version)
77
78     from . import readercata
79     if not hasattr ( Eficas, 'readercata'):
80            monreadercata  = readercata.READERCATA( parent, Eficas )
81            Eficas.readercata=monreadercata
82
83     from .editor import JDCEditor
84     monEditeur=JDCEditor(Eficas,fichier)
85     return monEditeur
86
87 def lance_eficas_ssIhm_cherche_Groupes(code=None,fichier=None,ssCode=None,version=None):
88     monEditeur=lance_eficas_ssIhm(code,fichier,ssCode,version)
89     print((monEditeur.cherche_Groupes()))
90
91 def lance_eficas_ssIhm_cherche_cr(code=None,fichier=None,ssCode=None,version=None):
92     monEditeur=lance_eficas_ssIhm(code,fichier,ssCode,version)
93     print((monEditeur.jdc.cr))
94
95 def lance_eficas_ssIhm_reecrit(code=None,fichier=None,ssCode=None,version=None,ou=None,cr=False,debug=False,leger=False,langue='ang'):
96     #print 'lance_eficas_ssIhm_reecrit', fichier
97     monEditeur=lance_eficas_ssIhm(code,fichier,ssCode,version,langue=langue)
98     if ou == None : 
99        fileName=fichier.split(".")[0]+"_reecrit.comm"
100        fn=fichier.split(".")[0]+"_cr.txt"
101     else :
102        f=fichier.split(".")[0]+"_reecrit.comm"
103        f1=os.path.basename(f)
104        fn=fichier.split(".")[0]+"_cr.txt"
105        f2=os.path.basename(fn)
106        fileName=os.path.join(ou,f1)
107        fileCr=os.path.join(ou,f2)
108     debut=False
109     if debug :
110          import cProfile, pstats, StringIO
111          pr = cProfile.Profile()
112          pr.enable()
113          monEditeur.saveFileAs(fileName=fileName)
114          pr.disable()
115          s = StringIO.StringIO()
116          sortby = 'cumulative'
117          ps = pstats.Stats(pr, stream=s).sort_stats(sortby)
118          ps.print_stats()
119          print (s.getvalue())
120
121     elif not leger : monEditeur.saveFileAs(fileName=fileName)
122     else : monEditeur.saveFileLegerAs(fileName=fileName)
123     if cr:
124        f = open(fileCr, 'w')
125        f.write(str(monEditeur.jdc.report()))
126        f.close()
127
128 def lance_eficas_param(code='Adao',fichier=None,version='V0',macro='ASSIMILATION_STUDY'):
129     """
130         Lance l'appli EFICAS pour trouver les noms des groupes
131     """
132     # Analyse des arguments de la ligne de commande
133     from Editeur  import session
134     options=session.parse(sys.argv)
135
136     from .qtEficas import Appli
137     #app = QApplication(sys.argv)
138     #Eficas=Appli(code=code,ssCode=None,salome=0)
139
140     from .ssIhm  import QWParentSSIhm
141     Eficas=QWParentSSIhm(code,version)
142
143     from . import readercata
144     if not hasattr ( Eficas, 'readercata'):
145            monreadercata  = readercata.READERCATA( parent, Eficas )
146            Eficas.readercata=monreadercata
147
148     from .editor import JDCEditor
149     monEditeur=JDCEditor(Eficas,fichier)
150     texte=loadJDC(fichier)
151     parameters=getJdcParameters(texte,macro)
152     return parameters
153
154 def getEficasSsIhm(code='Adao',version='V0'):
155     from .qtEficasSsIhm import AppliSsIhm
156     app = QApplication(sys.argv)
157     Eficas=Appli(code=code,ssCode=None,salome=0)
158     return Eficas
159
160 def getJdcParameters(jdc,macro):
161     """
162     This function converts the data from the specified macro of the
163     specified jdc text to a python dictionnary whose keys are the
164     names of the data of the macro.
165     """
166     context = {}
167     source = "def args_to_dict(**kwargs): return kwargs \n"
168     source+= "%s = _F = args_to_dict          \n"%macro
169     source+= "parameters="+jdc+"                        \n"
170     source+= "context['parameters'] = parameters         \n"
171     code = compile(source, 'file.py', 'exec')
172     eval(code)
173     parameters = context['parameters']
174     return parameters
175
176 def loadJDC(filename):
177     """
178     This function loads the text from the specified JdC file. A JdC
179     file is the persistence file of Eficas (*.comm).
180     """
181     fcomm=open(filename,'r')
182     jdc = ""
183     for line in fcomm.readlines():
184         if not (line[0]=='#'):
185            jdc+="%s"%line
186
187     # Warning, we have to make sure that the jdc comes as a simple
188     # string without any extra spaces/newlines
189     return jdc.strip()
190
191 if __name__ == "__main__":
192     import sys
193     sys.path.insert(0,os.path.abspath(os.path.join(os.getcwd(),'..')))
194     lance_eficas(code=None,fichier=None,ssCode=None,multi=True)
195     
196