Salome HOME
sauve0206
[tools/eficas.git] / InterfaceQT4 / eficas_go.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 # Copyright (C) 2007-2013   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 import sys,os
24 repIni=os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(__file__)),".."))
25 from  determine import monEnvQT5
26 if monEnvQT5 : 
27     ihmQTDir=os.path.join(repIni,"UiQT5")
28     from PyQt5.QtWidgets import QApplication
29 else         : 
30     ihmQTDir=os.path.join(repIni,"UiQT4")
31     from PyQt4.QtGui import QApplication
32 editeurDir=os.path.join(repIni,"Editeur")
33 ihmDir=os.path.join(repIni,"InterfaceQT4")
34 if ihmDir not in sys.path : sys.path.append(ihmDir)
35 if ihmQTDir not in sys.path : sys.path.append(ihmQTDir)
36 if editeurDir not in sys.path :sys.path.append(editeurDir)
37
38
39 def lance_eficas(code=None,fichier=None,ssCode=None,multi=False,langue='en'):
40     """
41         Lance l'appli EFICAS
42     """
43     # Analyse des arguments de la ligne de commande
44     from Editeur  import session
45     options=session.parse(sys.argv)
46     if options.code!= None : code=options.code
47     if options.ssCode!= None : ssCode=options.ssCode
48
49     from qtEficas import Appli
50     from Extensions import localisation
51     app = QApplication(sys.argv)
52     #localisation.localise(app,langue)
53     Eficas=Appli(code=code,ssCode=ssCode,multi=multi,langue=langue)
54     Eficas.show()
55
56     res=app.exec_()
57     sys.exit(res)
58
59
60 def lance_eficas_ssIhm(code=None,fichier=None,ssCode=None,version=None):
61     """
62         Lance l'appli EFICAS pour trouver les noms des groupes
63     """
64     # Analyse des arguments de la ligne de commande
65     from Editeur  import session
66     options=session.parse(sys.argv)
67     if version!=None and options.cata==None : options.cata=version
68     if fichier==None : fichier=options.comm[0]
69     if code == None : code=options.code
70
71     from qtEficas import Appli
72     app = QApplication(sys.argv)
73     Eficas=Appli(code=code,ssCode=ssCode,ssIhm=True)
74
75     from ssIhm  import QWParentSSIhm
76     parent=QWParentSSIhm(code,Eficas,version)
77
78     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):
96     monEditeur=lance_eficas_ssIhm(code,fichier,ssCode,version)
97     if ou == None : 
98        fileName=fichier.split(".")[0]+"_reecrit.comm"
99        fn=fichier.split(".")[0]+"_cr.txt"
100     else :
101        f=fichier.split(".")[0]+"_reecrit.comm"
102        f1=os.path.basename(f)
103        fn=fichier.split(".")[0]+"_cr.txt"
104        f2=os.path.basename(fn)
105        fileName=os.path.join(ou,f1)
106        fileCr=os.path.join(ou,f2)
107     monEditeur.saveFileAs(fileName=fileName)
108     if cr:
109        f = open(fileCr, 'wb')
110        f.write(str(monEditeur.jdc.report()))
111        f.close()
112
113
114 def lance_eficas_param(code='Adao',fichier=None,version='V0',macro='ASSIMILATION_STUDY'):
115     """
116         Lance l'appli EFICAS pour trouver les noms des groupes
117     """
118     # Analyse des arguments de la ligne de commande
119     from Editeur  import session
120     options=session.parse(sys.argv)
121
122     from qtEficas import Appli
123     app = QApplication(sys.argv)
124     Eficas=Appli(code=code,ssCode=None)
125
126     from ssIhm  import QWParentSSIhm
127     parent=QWParentSSIhm(code,Eficas,version)
128
129     import readercata
130     if not hasattr ( Eficas, 'readercata'):
131            monreadercata  = readercata.READERCATA( parent, Eficas )
132            Eficas.readercata=monreadercata
133
134     from editor import JDCEditor
135     monEditeur=JDCEditor(Eficas,fichier)
136     texte=loadJDC(fichier)
137     parameters=getJdcParameters(texte,macro)
138     return parameters
139
140 def getJdcParameters(jdc,macro):
141     """
142     This function converts the data from the specified macro of the
143     specified jdc text to a python dictionnary whose keys are the
144     names of the data of the macro.
145     """
146     context = {}
147     source = "def args_to_dict(**kwargs): return kwargs \n"
148     source+= "%s = _F = args_to_dict          \n"%macro
149     source+= "parameters="+jdc+"                        \n"
150     source+= "context['parameters'] = parameters         \n"
151     code = compile(source, 'file.py', 'exec')
152     eval(code)
153     parameters = context['parameters']
154     return parameters
155
156 def loadJDC(filename):
157     """
158     This function loads the text from the specified JdC file. A JdC
159     file is the persistence file of Eficas (*.comm).
160     """
161     fcomm=open(filename,'r')
162     jdc = ""
163     for line in fcomm.readlines():
164         if not (line[0]=='#'):
165            jdc+="%s"%line
166
167     # Warning, we have to make sure that the jdc comes as a simple
168     # string without any extra spaces/newlines
169     return jdc.strip()
170
171 if __name__ == "__main__":
172     import sys
173     sys.path.insert(0,os.path.abspath(os.path.join(os.getcwd(),'..')))
174     lance_eficas(code=None,fichier=None,ssCode=None,multi=True)
175     
176