2 # -*- coding: utf-8 -*-
3 # Copyright (C) 2007-2017 EDF R&D
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.
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.
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
19 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 from __future__ import absolute_import
24 from __future__ import print_function
26 from builtins import str
29 from PyQt5.QtWidgets import QApplication
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")
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)
41 def getEficasSsIhm(code=None,fichier=None,ssCode=None,multi=False,langue='en',versionCode=None):
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])
50 def lanceEficas(code=None,fichier=None,ssCode=None,multi=False,langue='en'):
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
60 from InterfaceQT4.qtEficas import Appli
61 app = QApplication(sys.argv)
63 #import cProfile, pstats, StringIO
64 #pr = cProfile.Profile()
67 Eficas=Appli(code=code,salome=0,ssCode=ssCode,multi=multi,langue=langue)
69 #s = StringIO.StringIO()
70 #sortby = 'cumulative'
71 #ps = pstats.Stats(pr, stream=s).sort_stats(sortby)
81 def lanceEficas_ssIhm(code=None,fichier=None,ssCode=None,version=None,debug=False,langue='en'):
83 Lance l'appli EFICAS pour trouver les noms des groupes
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
92 from .qtEficas import Appli
93 Eficas=Appli(code=code,salome=0,ssCode=ssCode,ssIhm=True,langue=langue)
95 from .ssIhm import QWParentSSIhm
96 parent=QWParentSSIhm(code,Eficas,version)
98 from . import readercata
99 if not hasattr ( Eficas, 'readercata'):
100 monreadercata = readercata.ReaderCata( parent, Eficas )
101 Eficas.readercata=monreadercata
103 from .editor import JDCEditor
104 monEditeur=JDCEditor(Eficas,fichier)
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()))
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))
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)
119 fileName=fichier.split(".")[0]+"_reecrit.comm"
120 fn=fichier.split(".")[0]+"_cr.txt"
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)
130 import cProfile, pstats, StringIO
131 pr = cProfile.Profile()
133 monEditeur.saveFileAs(fileName=fileName)
135 s = StringIO.StringIO()
136 sortby = 'cumulative'
137 ps = pstats.Stats(pr, stream=s).sort_stats(sortby)
141 elif not leger : monEditeur.saveFileAs(fileName=fileName)
142 else : monEditeur.saveFileLegerAs(fileName=fileName)
144 f = open(fileCr, 'w')
145 f.write(str(monEditeur.jdc.report()))
148 def lanceEficas_param(code='Adao',fichier=None,version='V0',macro='ASSIMILATION_STUDY'):
150 Lance l'appli EFICAS pour trouver les noms des groupes
152 # Analyse des arguments de la ligne de commande
153 from Editeur import session
154 options=session.parse(sys.argv)
156 from .qtEficas import Appli
157 #app = QApplication(sys.argv)
158 #Eficas=Appli(code=code,ssCode=None,salome=0)
160 from .ssIhm import QWParentSSIhm
161 Eficas=QWParentSSIhm(code,version)
163 from . import readercata
164 if not hasattr ( Eficas, 'readercata'):
165 monreadercata = readercata.ReaderCata( parent, Eficas )
166 Eficas.readercata=monreadercata
168 from .editor import JDCEditor
169 monEditeur=JDCEditor(Eficas,fichier)
170 texte=loadJDC(fichier)
171 parameters=getJdcParameters(texte,macro)
174 #def getEficasSsIhm(code='Adao',versionCode='V0'):
175 # from .qtEficasSsIhm import AppliSsIhm
176 # Eficas=AppliSsIhm(code=code,ssCode=None,salome=0)
179 def getJdcParameters(jdc,macro):
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.
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')
192 parameters = context['parameters']
195 def loadJDC(filename):
197 This function loads the text from the specified JdC file. A JdC
198 file is the persistence file of Eficas (*.comm).
200 fcomm=open(filename,'r')
202 for line in fcomm.readlines():
203 if not (line[0]=='#'):
206 # Warning, we have to make sure that the jdc comes as a simple
207 # string without any extra spaces/newlines
210 if __name__ == "__main__":
212 sys.path.insert(0,os.path.abspath(os.path.join(os.getcwd(),'..')))
213 lanceEficas(code=None,fichier=None,ssCode=None,multi=True)