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 with open(filename) as fd :
67 self.cr.exception(tr("Impossible d'ouvrir le fichier %s" ,str(filename)))
68 self.cr.fatal(tr("Impossible d'ouvrir le fichier %s" ,str(filename)))
71 def convert(self,outformat,appli=None):
73 exec (self.text,globals(),monTexteDico)
74 if len(monTexteDico.keys()) != 1 :
75 self.cr.exception(tr("Impossible de traiter le fichier %s" ,str(filename)))
76 self.cr.fatal(tr("Impossible de traiter le fichier %s" ,str(filename)))
79 monDico=monTexteDico[monTexteDico.keys()[0]]
80 for commande in monDico :
81 valeurs=monDico[commande]
82 if valeurs.has_key('NomDeLaSdCommande') :
84 self.textePy+=valeurs['NomDeLaSdCommande']+' = '+commande+'('
85 del valeurs['NomDeLaSdCommande']
87 self.textePy+=commande+'('
89 if isinstance(valeurs[mot],dict) : self.traiteMCFact(mot,valeurs[mot])
90 else : self.textePy += mot+' = ' +str(valeurs[mot])+','
91 self.textePy+=');\n' # fin de la commande
95 def traiteMCFact(self,mot,valeurs):
96 self.textePy += mot + '=_F('
98 if isinstance(valeurs[mot],dict) : self.traiteMCFact(mot,valeurs[mot])
99 else : self.textePy +=mot+' = ' +str(valeurs[mot])+','