Salome HOME
dernieres modifs
[tools/eficas.git] / generator / generator_python6.py
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2007-2013   EDF R&D
3 #
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License.
8 #
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 # Lesser General Public License for more details.
13 #
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 #
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #
20 """
21     Ce module contient le plugin generateur de fichier au format 
22     python pour EFICAS.
23
24 """
25 import traceback
26 import types,string,re
27
28 from Noyau import N_CR
29 from Noyau.N_utils import repr_float
30 from Accas import ETAPE,PROC_ETAPE,MACRO_ETAPE,ETAPE_NIVEAU,JDC,FORM_ETAPE
31 from Accas import MCSIMP,MCFACT,MCBLOC,MCList,EVAL
32 from Accas import GEOM,ASSD,MCNUPLET
33 from Accas import COMMENTAIRE,PARAMETRE, PARAMETRE_EVAL,COMMANDE_COMM
34 from Formatage import Formatage
35
36 import generator_python
37
38 def entryPoint():
39    """
40        Retourne les informations nécessaires pour le chargeur de plugins
41
42        Ces informations sont retournées dans un dictionnaire
43    """
44    return {
45         # Le nom du plugin
46           'name' : 'python6',
47         # La factory pour créer une instance du plugin
48           'factory' : PythonGenerator,
49           }
50
51
52 class PythonGenerator(generator_python.PythonGenerator):
53    """
54        Ce generateur parcourt un objet de type JDC et produit
55        un fichier au format python6
56
57        L'acquisition et le parcours sont réalisés par la méthode
58        generator.gener(objet_jdc,format)
59
60        L'écriture du fichier au format python6 par appel de la méthode
61        generator.writefile(nom_fichier)
62
63        Ses caractéristiques principales sont exposées dans des attributs 
64        de classe :
65          - extensions : qui donne une liste d'extensions de fichier préconisées
66
67    """
68    # Les extensions de fichier préconisées
69    extensions=('.comm',)
70
71    def generFORM_ETAPE(self,obj):
72         """
73             Méthode particulière pour les objets de type FORMULE
74         """
75         l=[]
76         nom = obj.get_nom()
77         if nom == '' : nom = 'sansnom'
78         l.append(nom + ' = FORMULE(')
79         for v in obj.mc_liste:
80             text=self.generator(v)
81             l.append(v.nom+'='+text)
82         l.append(');')
83         return l
84
85    def gen_formule(self,obj):
86       """
87            Méthode particuliere aux objets de type FORMULE
88       """
89       try:
90         if obj.sd == None:
91           sdname=''
92         else:
93           sdname= self.generator(obj.sd)
94       except:
95         sdname='sansnom'
96       l=[]
97       label=sdname + ' = FORMULE('
98       l.append(label)
99       for v in obj.mc_liste:
100         s=''
101         s= v.nom+':'+sdname+'('+v.valeur+')'
102         l.append(s)
103       if len(l) == 1:
104         l[0]=label+');'
105       else :
106         l.append(');')
107       return l