1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2007-2013 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.
28 from Noyau import N_CR
29 from Accas import MCSIMP,MCFACT,MCList
30 from Extensions.i18n import tr
31 from Extensions.eficas_exception import EficasException
36 Retourne les informations nécessaires pour le chargeur de plugins
38 Ces informations sont retournées dans un dictionnaire
43 # La factory pour créer une instance du plugin
44 'factory' : PythGenerator,
50 Ce generateur parcourt un objet de type MCFACT et produit
51 un fichier au format pyth
53 L'acquisition et le parcours sont réalisés par la méthode
54 generator.gener(objet_mcfact)
56 L'écriture du fichier au format ini par appel de la méthode
57 generator.writefile(nom_fichier)
59 Ses caractéristiques principales sont exposées dans des attributs
61 - extensions : qui donne une liste d'extensions de fichier préconisées
64 # Les extensions de fichier préconisées
65 extensions=('.py','.comm')
67 def __init__(self,cr=None):
68 # Si l'objet compte-rendu n'est pas fourni, on utilise le compte-rendu standard
72 self.cr=N_CR.CR(debut='CR generateur format ini',
73 fin='fin CR format ini')
74 # Le texte au format pyth est stocké dans l'attribut text
77 def writefile(self,filename):
82 def gener(self,obj,format='standard',config=None):
84 Tous les mots-clés simples du niveau haut sont transformés en variables
86 Tous les mots-clés facteurs sont convertis en dictionnaires
88 Les mots-clés multiples ne sont pas traités
91 if isinstance(obj,MCList):
93 raise EficasException(tr("Pas supporte"))
97 for mocle in obj.mc_liste:
98 if isinstance(mocle,MCList):
99 if len(mocle.data) > 1:
100 raise EficasException(tr("Pas supporte"))
102 valeur=self.generMCFACT(mocle.data[0])
103 s=s+"%s = %s\n" % (mocle.nom,valeur)
104 elif isinstance(mocle,MCFACT):
105 valeur=self.generMCFACT(mocle)
106 s=s+"%s = %s\n" % (mocle.nom,valeur)
107 elif isinstance(v,MCSIMP):
108 valeur = self.generMCSIMP(mocle)
109 s=s+"%s = %s\n" % (mocle.nom,valeur)
111 self.cr.fatal("Entite inconnue ou interdite : "+`mocle`)
116 def generMCFACT(self,obj):
118 Cette méthode convertit un mot-clé facteur
119 en une chaine de caractères représentative d'un dictionnaire
122 for mocle in obj.mc_liste:
123 if isinstance(mocle,MCSIMP):
124 valeur = self.generMCSIMP(mocle)
125 s=s+"'%s' : %s,\n" % (mocle.nom,valeur)
126 elif isinstance(mocle,MCFACT):
127 valeur=self.generMCFACT(mocle)
128 s=s+"'%s' : %s,\n" % (mocle.nom,valeur)
130 self.cr.fatal(tr("Entite inconnue ou interdite : %s. Elle est ignoree", `mocle`))
135 def generMCSIMP(self,obj):
137 Cette méthode convertit un mot-clé simple en une chaine de caractères
142 except Exception as e :
143 self.cr.fatal(tr("Type de valeur non supporte par le format pyth : n %(exception)s", \
144 {'nom': obj.nom, 'exception': unicode(e)}))