Salome HOME
PourLaura
[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 ihmQTDir=os.path.join(repIni,"UiQT4")
26 editeurDir=os.path.join(repIni,"Editeur")
27 ihmDir=os.path.join(repIni,"InterfaceQT4")
28 if ihmDir not in sys.path : sys.path.append(ihmDir)
29 if ihmQTDir not in sys.path : sys.path.append(ihmQTDir)
30 if editeurDir not in sys.path :sys.path.append(editeurDir)
31
32 from PyQt4.QtGui import *
33
34 def lance_eficas(code=None,fichier=None,ssCode=None,multi=False,langue='en'):
35     """
36         Lance l'appli EFICAS
37     """
38     # Analyse des arguments de la ligne de commande
39     from Editeur  import session
40     options=session.parse(sys.argv)
41     if options.code!= None : code=options.code
42     if options.ssCode!= None : ssCode=options.ssCode
43
44     from qtEficas import Appli
45     from Extensions import localisation
46     app = QApplication(sys.argv)
47     localisation.localise(app,langue)
48     Eficas=Appli(code=code,ssCode=ssCode,multi=multi,langue=langue)
49     Eficas.show()
50
51     res=app.exec_()
52     sys.exit(res)
53
54
55 def lance_eficas_ssIhm(code=None,fichier=None,ssCode=None,version=None):
56     """
57         Lance l'appli EFICAS pour trouver les noms des groupes
58     """
59     # Analyse des arguments de la ligne de commande
60     from Editeur  import session
61     options=session.parse(sys.argv)
62     if version!=None and options.cata==None : options.cata=version
63     if fichier==None : fichier=options.comm[0]
64     if code == None : code=options.code
65
66     from qtEficas import Appli
67     app = QApplication(sys.argv)
68     Eficas=Appli(code=code,ssCode=ssCode,ssIhm=True)
69
70     from ssIhm  import QWParentSSIhm
71     parent=QWParentSSIhm(code,Eficas,version)
72
73     import readercata
74     if not hasattr ( Eficas, 'readercata'):
75            monreadercata  = readercata.READERCATA( parent, Eficas )
76            Eficas.readercata=monreadercata
77
78     from editor import JDCEditor
79     monEditeur=JDCEditor(Eficas,fichier)
80     return monEditeur
81
82 def lance_eficas_ssIhm_cherche_Groupes(code=None,fichier=None,ssCode=None,version=None):
83     monEditeur=lance_eficas_ssIhm(code,fichier,ssCode,version)
84     print monEditeur.cherche_Groupes()
85
86 def lance_eficas_ssIhm_cherche_cr(code=None,fichier=None,ssCode=None,version=None):
87     monEditeur=lance_eficas_ssIhm(code,fichier,ssCode,version)
88     print monEditeur.jdc.cr
89
90 def lance_eficas_ssIhm_reecrit(code=None,fichier=None,ssCode=None,version=None):
91     monEditeur=lance_eficas_ssIhm(code,fichier,ssCode,version)
92     print fichier
93     fileName=fichier.split(".")[0]+"_reecrit.comm"
94     monEditeur.saveFileAs(fileName=fileName)
95
96 def lance_eficas_param(code='Adao',fichier=None,version='V0',macro='ASSIMILATION_STUDY'):
97     """
98         Lance l'appli EFICAS pour trouver les noms des groupes
99     """
100     # Analyse des arguments de la ligne de commande
101     from Editeur  import session
102     options=session.parse(sys.argv)
103
104     from qtEficas import Appli
105     app = QApplication(sys.argv)
106     Eficas=Appli(code=code,ssCode=None)
107
108     from ssIhm  import QWParentSSIhm
109     parent=QWParentSSIhm(code,Eficas,version)
110
111     import readercata
112     if not hasattr ( Eficas, 'readercata'):
113            monreadercata  = readercata.READERCATA( parent, Eficas )
114            Eficas.readercata=monreadercata
115
116     from editor import JDCEditor
117     monEditeur=JDCEditor(Eficas,fichier)
118     texte=loadJDC(fichier)
119     parameters=getJdcParameters(texte,macro)
120     return parameters
121
122 def getJdcParameters(jdc,macro):
123     """
124     This function converts the data from the specified macro of the
125     specified jdc text to a python dictionnary whose keys are the
126     names of the data of the macro.
127     """
128     context = {}
129     source = "def args_to_dict(**kwargs): return kwargs \n"
130     source+= "%s = _F = args_to_dict          \n"%macro
131     source+= "parameters="+jdc+"                        \n"
132     source+= "context['parameters'] = parameters         \n"
133     code = compile(source, 'file.py', 'exec')
134     eval(code)
135     parameters = context['parameters']
136     return parameters
137
138 def loadJDC(filename):
139     """
140     This function loads the text from the specified JdC file. A JdC
141     file is the persistence file of Eficas (*.comm).
142     """
143     fcomm=open(filename,'r')
144     jdc = ""
145     for line in fcomm.readlines():
146         if not (line[0]=='#'):
147            jdc+="%s"%line
148
149     # Warning, we have to make sure that the jdc comes as a simple
150     # string without any extra spaces/newlines
151     return jdc.strip()
152
153 if __name__ == "__main__":
154     import sys
155     sys.path.insert(0,os.path.abspath(os.path.join(os.getcwd(),'..')))
156     lance_eficas(code=None,fichier=None,ssCode=None,multi=True)
157     
158