1 # Copyright (C) 2007-2021 EDF R&D
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License.
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 # Lesser General Public License for more details.
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 from __future__ import absolute_import
22 #from Extensions.i18n import tr
23 #from Extensions import localisation
26 from .convert_python import Pythonparser
27 from Noyau import N_CR
38 Return a dictionary containing the description needed to load the plugin
42 'factory' : Dicoparser
45 class Dicoparser(Pythonparser):
47 This converter initializes model variable from a python dictionnary
50 def __init__(self,cr=None):
51 # Si l'objet compte-rendu n'est pas fourni, on utilise le
52 # compte-rendu standard
58 self.cr=N_CR.CR(debut='CR convertisseur format dico',
59 fin='fin CR format dico')
61 def readfile(self,filename):
62 self.filename=filename
64 self.text=open(filename).read()
66 self.cr.exception(tr("Impossible d'ouvrir le fichier %s" ,str(filename)))
67 self.cr.fatal(tr("Impossible d'ouvrir le fichier %s" ,str(filename)))
70 def convert(self,outformat,appli=None):
72 exec (self.text,globals(),monTexteDico)
73 if len(monTexteDico.keys()) != 1 :
74 self.cr.exception(tr("Impossible de traiter le fichier %s" ,str(filename)))
75 self.cr.fatal(tr("Impossible de traiter le fichier %s" ,str(filename)))
78 monDico=monTexteDico[monTexteDico.keys()[0]]
79 for commande in monDico :
80 valeurs=monDico[commande]
81 if valeurs.has_key('NomDeLaSdCommande') :
83 self.textePy+=valeurs['NomDeLaSdCommande']+' = '+commande+'('
84 del valeurs['NomDeLaSdCommande']
86 self.textePy+=commande+'('
88 if isinstance(valeurs[mot],dict) : self.traiteMCFact(mot,valeurs[mot])
89 else : self.textePy += mot+' = ' +str(valeurs[mot])+','
90 self.textePy+=');\n' # fin de la commande
94 def traiteMCFact(self,mot,valeurs):
95 self.textePy += mot + '=_F('
97 if isinstance(valeurs[mot],dict) : self.traiteMCFact(mot,valeurs[mot])
98 else : self.textePy +=mot+' = ' +str(valeurs[mot])+','