1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2007-2021 EDF R&D
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.
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.
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
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 Ce module contient le plugin generateur de fichier au format pyth pour EFICAS.
26 from builtins import str
27 from builtins import object
33 from Noyau import N_CR
34 from Accas import MCSIMP,MCFACT,MCList
35 from Extensions.i18n import tr
36 from Extensions.eficas_exception import EficasException
41 Retourne les informations necessaires pour le chargeur de plugins
43 Ces informations sont retournees dans un dictionnaire
48 # La factory pour creer une instance du plugin
49 'factory' : PythGenerator,
53 class PythGenerator(object):
55 Ce generateur parcourt un objet de type MCFACT et produit
56 un fichier au format pyth
58 L'acquisition et le parcours sont realises par la methode
59 generator.gener(objet_mcfact)
61 L'ecriture du fichier au format ini par appel de la methode
62 generator.writefile(nom_fichier)
64 Ses caracteristiques principales sont exposees dans des attributs
66 - extensions : qui donne une liste d'extensions de fichier preconisees
69 # Les extensions de fichier preconisees
70 extensions=('.py','.comm')
72 def __init__(self,cr=None):
73 # Si l'objet compte-rendu n'est pas fourni, on utilise le compte-rendu standard
77 self.cr=N_CR.CR(debut='CR generateur format ini',
78 fin='fin CR format ini')
79 # Le texte au format pyth est stocke dans l'attribut text
82 def writefile(self,filename):
87 def gener(self,obj,format='standard',config=None):
89 Tous les mots-cles simples du niveau haut sont transformes en variables
91 Tous les mots-cles facteurs sont convertis en dictionnaires
93 Les mots-cles multiples ne sont pas traites
96 if isinstance(obj,MCList):
98 raise EficasException(tr("Pas supporte"))
102 for mocle in obj.mc_liste:
103 if isinstance(mocle,MCList):
104 if len(mocle.data) > 1:
105 raise EficasException(tr("Pas supporte"))
107 valeur=self.generMCFACT(mocle.data[0])
108 s=s+"%s = %s\n" % (mocle.nom,valeur)
109 elif isinstance(mocle,MCFACT):
110 valeur=self.generMCFACT(mocle)
111 s=s+"%s = %s\n" % (mocle.nom,valeur)
112 elif isinstance(v,MCSIMP):
113 valeur = self.generMCSIMP(mocle)
114 s=s+"%s = %s\n" % (mocle.nom,valeur)
116 self.cr.fatal("Entite inconnue ou interdite : "+repr(mocle))
121 def generMCFACT(self,obj):
123 Cette methode convertit un mot-cle facteur
124 en une chaine de caracteres representative d'un dictionnaire
127 for mocle in obj.mc_liste:
128 if isinstance(mocle,MCSIMP):
129 valeur = self.generMCSIMP(mocle)
130 s=s+"'%s' : %s,\n" % (mocle.nom,valeur)
131 elif isinstance(mocle,MCFACT):
132 valeur=self.generMCFACT(mocle)
133 s=s+"'%s' : %s,\n" % (mocle.nom,valeur)
135 self.cr.fatal(tr("Entite inconnue ou interdite : %s. Elle est ignoree", repr(mocle)))
140 def generMCSIMP(self,obj):
142 Cette methode convertit un mot-cle simple en une chaine de caracteres
147 except Exception as e :
148 self.cr.fatal(tr("Type de valeur non supporte par le format pyth : n %(exception)s", \
149 {'nom': obj.nom, 'exception': str(e)}))