From: pascale.noyret Date: Wed, 27 Jun 2018 10:22:14 +0000 (+0200) Subject: ajout format xml dans les possibilites IO eficas X-Git-Tag: avantMenage~77 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=4761e78ac03eca44e899638134186f00a4605938;p=tools%2Feficas.git ajout format xml dans les possibilites IO eficas --- diff --git a/convert/convert_XML.py b/convert/convert_XML.py new file mode 100644 index 00000000..8d9f9b8e --- /dev/null +++ b/convert/convert_XML.py @@ -0,0 +1,78 @@ +# Copyright (C) 2007-2017 EDF R&D +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# +from __future__ import absolute_import + + +import re +from Extensions.i18n import tr + +#import traceback +#traceback.print_stack() + +from Extensions import localisation +from Noyau import N_CR + + +def entryPoint(): + """ + Return a dictionary containing the description needed to load the plugin + """ + return { + 'name' : 'xml', + 'factory' : XMLparser + } + +class XMLparser: + """ + This converter works like Pythonparser, except that it is supposed to read XML + """ + + def __init__(self,cr=None): + self.text='' + if cr : self.cr=cr + else: self.cr=N_CR.CR(debut='CR convertisseur format XML', + fin='fin CR format XML') + + def readfile(self,filename): + self.filename=filename + try: + self.text=open(filename).read() + except: + self.cr.exception(tr("Impossible d'ouvrir le fichier %s" ,str(filename))) + self.cr.fatal(tr("Impossible d'ouvrir le fichier %s" ,str(filename))) + return + + + + def convert(self, outformat, appli=None): + # ici on ne fait rien + # on le fera a la creation du JDC + try: + return self.text + except EficasException: + # Erreur lors de la conversion + l=traceback.format_exception(sys.exc_info()[0],sys.exc_info()[1], + sys.exc_info()[2]) + self.cr.exception(tr("Impossible de convertir le fichier XML\n %s", ''.join(l))) + return "" + + + + + diff --git a/generator/generator_XML.py b/generator/generator_XML.py new file mode 100644 index 00000000..4fc98f10 --- /dev/null +++ b/generator/generator_XML.py @@ -0,0 +1,86 @@ +# -*- coding: utf-8 -*- +# Copyright (C) 2007-2017 EDF R&D +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# +"""Ce module contient le plugin generateur de fichier au format Code_Carmel3D pour EFICAS. +""" + +from __future__ import absolute_import +from __future__ import print_function +try : + from builtins import str +except : pass + +import traceback +import types,re,os +from Extensions.i18n import tr +from .generator_python import PythonGenerator + +def entryPoint(): + """ + Retourne les informations necessaires pour le chargeur de plugins + Ces informations sont retournees dans un dictionnaire + """ + return { + # Le nom du plugin + 'name' : 'xml', + # La factory pour creer une instance du plugin + 'factory' : XMLGenerator, + } + + +class XMLGenerator(PythonGenerator): + """ + Ce generateur parcourt un objet de type JDC et produit + un texte au format eficas et + + """ + # Les extensions de fichier permis? + extensions=('.comm',) + +#---------------------------------------------------------------------------------------- + def gener(self,obj,format='brut',config=None,appli=None): + + try : + print (obj) + self.texteXML=obj.toXml() + except : + self.texteXML='erreur generation' + pass + + # Cette instruction genere le contenu du fichier de commandes (persistance) + self.text=PythonGenerator.gener(self,obj,format) + return self.text + + +#---------------------------------------------------------------------------------------- +# initialisations +#---------------------------------------------------------------------------------------- + +# ecriture +#---------------------------------------------------------------------------------------- + + def writeDefault(self,fn) : + #fileDico = fn[:fn.rfind(".")] + '.py' + fileDico='/tmp/toto.xml' + print (self.texteXML) + f = open( str(fileDico), 'w') + f.write('Dico = '+str(self.texteXML)) + f.close() + +