Salome HOME
debug intempestif
[tools/eficas.git] / generator / generator_XML.py
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2007-2021   EDF R&D
3 #
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.
8 #
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.
13 #
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
17 #
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #
20 """Ce module contient le plugin generateur de fichier au format  Code_Carmel3D pour EFICAS.
21 """
22
23 from __future__ import absolute_import
24 from __future__ import print_function
25 try :
26     from builtins import str
27 except : pass
28
29 import traceback
30 import types,re,os
31 from Extensions.i18n import tr
32 from .generator_python import PythonGenerator
33
34 def entryPoint():
35     """
36        Retourne les informations necessaires pour le chargeur de plugins
37        Ces informations sont retournees dans un dictionnaire
38     """
39     return {
40          # Le nom du plugin
41            'name' : 'xml',
42          # La factory pour creer une instance du plugin
43            'factory' : XMLGenerator,
44            }
45
46
47 class XMLGenerator(PythonGenerator):
48     """
49        Ce generateur parcourt un objet de type JDC et produit
50        un texte au format eficas et
51
52     """
53     # Les extensions de fichier permis?
54     extensions=('.comm',)
55
56 #----------------------------------------------------------------------------------------
57     def gener(self,obj,format='brut',config=None,appliEficas=None):
58
59         try :
60         #if 1 :
61             self.texteXML=obj.toXml()
62         except :
63             self.texteXML='erreur generation'
64             #print (self.texteXML)
65         #  pass
66
67         self.textePourAide =""
68         self.dictNbNomObj={}
69         # Cette instruction genere le contenu du fichier de commandes (persistance)
70         self.text=PythonGenerator.gener(self,obj,format)
71         return self.text
72
73
74 #----------------------------------------------------------------------------------------
75 # initialisations
76 #----------------------------------------------------------------------------------------
77
78 # ecriture
79 #----------------------------------------------------------------------------------------
80
81     def writeDefault(self,fn) :
82         fileXML  = fn[:fn.rfind(".")] + '.xml'
83         #filePyxb = fn[:fn.rfind(".")] + '.py'
84         fileBase = os.path.basename(fileXML)
85         fileBase = fileBase[:fileBase.rfind(".")] + '.py'
86         filePyxb = '/tmp/example_' + fileBase
87         #print (filePyxb)
88         #fileDico='/tmp/toto.xml'
89         #print (self.texteXML)
90         f = open( str(fileXML), 'w')
91         f.write(str(self.texteXML))
92         f.close()
93
94         f = open( str(filePyxb), 'w')
95         self.textePourAide='txt=""'+'\n'+self.textePourAide
96         self.textePourAide=self.textePourAide+'print (txt)'+'\n'
97         f.write(str(self.textePourAide))
98         f.close()
99
100
101     def generMCSIMP(self,obj) :
102         if obj.nom != 'Consigne' :
103             if obj.nom in self.dictNbNomObj.keys():
104                 nomUtil = obj.nom + "_" + str(self.dictNbNomObj[obj.nom])
105                 self.dictNbNomObj[obj.nom] += 1
106             else :
107                 nomUtil = obj.nom
108                 self.dictNbNomObj[obj.nom] = 1
109             if obj.definition.avecBlancs : self.textePourAide +=  nomUtil + " = vimmpCase." + obj.getNomDsXML() + ".s\n"
110             else : self.textePourAide +=  nomUtil + " = vimmpCase." + obj.getNomDsXML() + "\n"
111             self.textePourAide +='txt += "' + nomUtil + '" + " = " +str( ' + nomUtil + ')+"\\n"'+ "\n"
112
113
114
115         s=PythonGenerator.generMCSIMP(self,obj)
116         return s