]> SALOME platform Git repositories - tools/eficas.git/blob - generator/generator_SEP.py
Salome HOME
*** empty log message ***
[tools/eficas.git] / generator / generator_SEP.py
1 # -*- coding: utf-8 -*-
2 #            CONFIGURATION MANAGEMENT OF EDF VERSION
3 # ======================================================================
4 # COPYRIGHT (C) 1991 - 2002  EDF R&D                  WWW.CODE-ASTER.ORG
5 # THIS PROGRAM IS FREE SOFTWARE; YOU CAN REDISTRIBUTE IT AND/OR MODIFY
6 # IT UNDER THE TERMS OF THE GNU GENERAL PUBLIC LICENSE AS PUBLISHED BY
7 # THE FREE SOFTWARE FOUNDATION; EITHER VERSION 2 OF THE LICENSE, OR
8 # (AT YOUR OPTION) ANY LATER VERSION.
9 #
10 # THIS PROGRAM IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL, BUT
11 # WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF
12 # MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. SEE THE GNU
13 # GENERAL PUBLIC LICENSE FOR MORE DETAILS.
14 #
15 # YOU SHOULD HAVE RECEIVED A COPY OF THE GNU GENERAL PUBLIC LICENSE
16 # ALONG WITH THIS PROGRAM; IF NOT, WRITE TO EDF R&D CODE_ASTER,
17 #    1 AVENUE DU GENERAL DE GAULLE, 92141 CLAMART CEDEX, FRANCE.
18 #
19 #
20 # ======================================================================
21 """
22    Ce module contient le plugin generateur de fichier au format 
23    SEP pour EFICAS.
24
25 """
26 import traceback
27 import types,string,re,os
28
29 from generator_python import PythonGenerator
30
31 def entryPoint():
32    """
33       Retourne les informations necessaires pour le chargeur de plugins
34
35       Ces informations sont retournees dans un dictionnaire
36    """
37    return {
38         # Le nom du plugin
39           'name' : 'SEP',
40         # La factory pour creer une instance du plugin
41           'factory' : SEPGenerator,
42           }
43
44
45 class SEPGenerator(PythonGenerator):
46    """
47       Ce generateur parcourt un objet de type JDC et produit
48       un texte au format eficas et 
49       un texte au format py 
50
51    """
52    # Les extensions de fichier permis?
53    extensions=('.comm',)
54
55    def gener(self,obj,format='brut',config=None):
56       self.initDico()
57       # Cette instruction génère le contenu du fichier de commandes (persistance)
58       self.text=PythonGenerator.gener(self,obj,format)
59       # Cette instruction génère le contenu du fichier de paramètres python
60       self.genereSEP()
61       return self.text
62
63    def getTubePy(self) :
64       return self.texteTubePy
65
66    def genereSEP(self) :
67       '''
68       Prépare le contenu du fichier de paramètres python. Le contenu
69       peut ensuite être obtenu au moyen de la fonction getTubePy().
70       '''
71       #self.__genereSEP_withVariables()
72       self.__genereSEP_withDico()
73
74    def __genereSEP_withVariables(self) :
75       '''
76       Les paramètres sont transcrits sous forme de variables nom=valeur.
77       '''
78       self.texteTubePy="# Parametres generes par Eficas \n"
79       for MC in self.dictMCVal.keys():
80          ligne = MC +"="+ repr(self.dictMCVal[MC])+'\n'
81          self.texteTubePy=self.texteTubePy+ligne
82
83       print self.texteTubePy
84
85       # __GBO__: Tester self.tube pour aiguiller en fonction du cas (au besoin)
86       fichier=os.path.join(os.path.dirname(__file__),"tube.py")
87       f=open(fichier,'r')
88       for ligne in f.readlines():
89          self.texteTubePy=self.texteTubePy+ligne
90       f.close
91
92    def __genereSEP_withDico(self) :
93       """
94       Les paramètres sont transcrits sous la forme d'un dictionnaire nom=valeur.
95       """
96       from Sep import properties
97       self.texteTubePy="# -*- coding: utf-8 -*-\n"
98       self.texteTubePy+="# ======================================================================================\n"
99       self.texteTubePy+="# FICHIER GENERE PAR EFICAS - OUTIL MÉTIER SOUS-EPAISSEUR - "
100       self.texteTubePy+="VERSION "+str(properties.version)+" du "+str(properties.date)+"\n"
101       self.texteTubePy+="# ======================================================================================\n"
102       self.texteTubePy+="\n"
103       self.texteTubePy+="# Parametres Utilisateur Eficas \n"
104       self.texteTubePy+="parameters={}\n"
105       
106       for MC in self.dictMCVal.keys():
107          ligne = "parameters['"+MC+"']="+ repr(self.dictMCVal[MC])+'\n'
108          self.texteTubePy=self.texteTubePy+ligne
109
110       # On ajoute des paramètres de configuration pour contrôle de
111       # cohérence avec la procédure outil métier
112       self.texteTubePy+="# Parametres de Configuration Eficas \n"
113       ligne = "parameters['OMVERSION']="+str(properties.version)+"\n"
114       self.texteTubePy+=ligne
115
116       # __GBO__: Tester self.tube pour aiguiller en fonction du cas (au besoin)
117       self.texteTubePy+="\n"
118       self.texteTubePy+="# Exécution de la procédure outil métier \n"
119       self.texteTubePy+="import os,sys\n"
120       self.texteTubePy+="sys.path.insert(0,os.environ['OM_ROOT_DIR'])\n"
121       self.texteTubePy+="import om_data\n"
122       self.texteTubePy+="om_data.setParameters(parameters)\n"
123       self.texteTubePy+="def run():\n"
124       self.texteTubePy+="    import om_smeca\n"
125       self.texteTubePy+="\n"
126       self.texteTubePy+='if __name__ == "__main__":\n'
127       self.texteTubePy+="    run()\n"
128
129       # For debug only
130       print self.texteTubePy
131
132
133    def initDico(self) :
134       self.tube=0
135       self.coude=0
136       self.dictMCVal={}
137       self.texteTubePy=""
138
139    # __GBO__: surcharge de PythonGenerator:
140    # voir example generator_cuve2dg.py (genea)
141    def generMCSIMP(self,obj) :
142       """
143       Convertit un objet MCSIMP en texte python
144       Remplit le dictionnaire des MCSIMP si nous ne sommes ni dans une loi, ni dans une variable
145       """
146       clef=""
147       for i in obj.get_genealogie() :
148          clef=clef+"__"+i
149       #self.dictMCVal[obj.nom]=obj.valeur
150       self.dictMCVal[clef]=obj.valeur
151
152       s=PythonGenerator.generMCSIMP(self,obj)
153       return s
154   
155    # __GBO__: surcharge de PythonGenerator
156    def generMACRO_ETAPE(self,obj):
157       print obj.nom
158       if obj.nom == "S_EP_INTERNE" :
159          self.tube=1
160       if obj.nom == "M_COUDE" :
161          self.coude=1
162       s=PythonGenerator.generMACRO_ETAPE(self,obj)
163       return s
164