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
31 repIni=os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(__file__)),".."))
32 ihmQTDir=os.path.join(repIni,"UiQT5")
33 editeurDir=os.path.join(repIni,"Editeur")
34 ihmDir=os.path.join(repIni,"InterfaceQT4")
36 if ihmDir not in sys.path : sys.path.append(ihmDir)
37 if ihmQTDir not in sys.path : sys.path.append(ihmQTDir)
38 if editeurDir not in sys.path :sys.path.append(editeurDir)
40 def getEficasSsIhm(code=None,fichier=None,ssCode=None,multi=False,langue='en',versionCode=None):
42 from InterfaceQT4.qtEficasSsIhm import AppliSsIhm
43 Eficas=AppliSsIhm(code=code,salome=0,ssCode=ssCode,multi=multi,langue=langue,versionCode=versionCode)
44 from Editeur import session
45 options=session.parse(['ssIhm','-k',code,'-v',versionCode])
49 def lanceEficas(code=None,fichier=None,ssCode=None,multi=False,langue='en'):
53 # Analyse des arguments de la ligne de commande
55 from PyQt5.QtWidgets import QApplication
57 print('Please, set qt environment')
60 from Editeur import session
61 options=session.parse(sys.argv)
62 if options.code!= None : code=options.code
63 if options.ssCode!= None : ssCode=options.ssCode
65 from InterfaceQT4.qtEficas import Appli
66 app = QApplication(sys.argv)
68 #import cProfile, pstats, StringIO
69 #pr = cProfile.Profile()
72 Eficas=Appli(code=code,salome=0,ssCode=ssCode,multi=multi,langue=langue)
74 #s = StringIO.StringIO()
75 #sortby = 'cumulative'
76 #ps = pstats.Stats(pr, stream=s).sort_stats(sortby)
86 def lanceEficas_ssIhm(code=None,fichier=None,ssCode=None,version=None,debug=False,langue='en'):
88 Lance l'appli EFICAS pour trouver les noms des groupes
90 # Analyse des arguments de la ligne de commande
91 from Editeur import session
92 options=session.parse(sys.argv)
93 if version!=None and options.cata==None : options.cata=version
94 if fichier==None : fichier=options.comm[0]
95 if code == None : code=options.code
97 from .qtEficas import Appli
98 Eficas=Appli(code=code,salome=0,ssCode=ssCode,ssIhm=True,langue=langue)
100 from .ssIhm import QWParentSSIhm
101 parent=QWParentSSIhm(code,Eficas,version)
103 from . import readercata
104 if not hasattr ( Eficas, 'readercata'):
105 monreadercata = readercata.ReaderCata( parent, Eficas )
106 Eficas.readercata=monreadercata
108 from .editor import JDCEditor
109 monEditeur=JDCEditor(Eficas,fichier)
112 def lanceEficas_ssIhm_chercheGroupes(code=None,fichier=None,ssCode=None,version=None):
113 monEditeur=lanceEficas_ssIhm(code,fichier,ssCode,version)
114 print((monEditeur.chercheGroupes()))
116 def lanceEficas_ssIhm_cherche_cr(code=None,fichier=None,ssCode=None,version=None):
117 monEditeur=lanceEficas_ssIhm(code,fichier,ssCode,version)
118 print((monEditeur.jdc.cr))
120 def lanceEficas_ssIhm_reecrit(code=None,fichier=None,ssCode=None,version=None,ou=None,cr=False,debug=False,leger=False,langue='ang'):
121 #print 'lanceEficas_ssIhm_reecrit', fichier
122 monEditeur=lanceEficas_ssIhm(code,fichier,ssCode,version,langue=langue)
124 fileName=fichier.split(".")[0]+"_reecrit.comm"
125 fn=fichier.split(".")[0]+"_cr.txt"
127 f=fichier.split(".")[0]+"_reecrit.comm"
128 f1=os.path.basename(f)
129 fn=fichier.split(".")[0]+"_cr.txt"
130 f2=os.path.basename(fn)
131 fileName=os.path.join(ou,f1)
132 fileCr=os.path.join(ou,f2)
135 import cProfile, pstats, StringIO
136 pr = cProfile.Profile()
138 monEditeur.saveFileAs(fileName=fileName)
140 s = StringIO.StringIO()
141 sortby = 'cumulative'
142 ps = pstats.Stats(pr, stream=s).sort_stats(sortby)
146 elif not leger : monEditeur.saveFileAs(fileName=fileName)
147 else : monEditeur.saveFileLegerAs(fileName=fileName)
149 f = open(fileCr, 'w')
150 f.write(str(monEditeur.jdc.report()))
153 def lanceEficas_param(code='Adao',fichier=None,version='V0',macro='ASSIMILATION_STUDY'):
155 Lance l'appli EFICAS pour trouver les noms des groupes
157 # Analyse des arguments de la ligne de commande
158 from Editeur import session
159 options=session.parse(sys.argv)
161 from .qtEficas import Appli
162 #app = QApplication(sys.argv)
163 #Eficas=Appli(code=code,ssCode=None,salome=0)
165 from .ssIhm import QWParentSSIhm
166 Eficas=QWParentSSIhm(code,version)
168 from . import readercata
169 if not hasattr ( Eficas, 'readercata'):
170 monreadercata = readercata.ReaderCata( parent, Eficas )
171 Eficas.readercata=monreadercata
173 from .editor import JDCEditor
174 monEditeur=JDCEditor(Eficas,fichier)
175 texte=loadJDC(fichier)
176 parameters=getJdcParameters(texte,macro)
179 #def getEficasSsIhm(code='Adao',versionCode='V0'):
180 # from .qtEficasSsIhm import AppliSsIhm
181 # Eficas=AppliSsIhm(code=code,ssCode=None,salome=0)
184 def getJdcParameters(jdc,macro):
186 This function converts the data from the specified macro of the
187 specified jdc text to a python dictionnary whose keys are the
188 names of the data of the macro.
191 source = "def args_to_dict(**kwargs): return kwargs \n"
192 source+= "%s = _F = args_to_dict \n"%macro
193 source+= "parameters="+jdc+" \n"
194 source+= "context['parameters'] = parameters \n"
195 code = compile(source, 'file.py', 'exec')
197 parameters = context['parameters']
200 def loadJDC(filename):
202 This function loads the text from the specified JdC file. A JdC
203 file is the persistence file of Eficas (*.comm).
205 fcomm=open(filename,'r')
207 for line in fcomm.readlines():
208 if not (line[0]=='#'):
211 # Warning, we have to make sure that the jdc comes as a simple
212 # string without any extra spaces/newlines
215 if __name__ == "__main__":
217 sys.path.insert(0,os.path.abspath(os.path.join(os.getcwd(),'..')))
218 lanceEficas(code=None,fichier=None,ssCode=None,multi=True)