]> SALOME platform Git repositories - tools/eficas.git/blob - generator/generator_XML.py
Salome HOME
chgt Copyrigth
[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       print ('dans gener XMLGenerator Attention if 1 a la place de try ')
60       #try :
61       if 1 :
62         self.texteXML=obj.toXml()
63       #except : 
64       #  self.texteXML='erreur generation'
65       #  pass
66       
67       print (self.texteXML)
68       self.textePourAide =""
69       self.dictNbNomObj={}
70       # Cette instruction genere le contenu du fichier de commandes (persistance)
71       self.text=PythonGenerator.gener(self,obj,format)
72       return self.text
73
74
75 #----------------------------------------------------------------------------------------
76 # initialisations
77 #----------------------------------------------------------------------------------------
78    
79 # ecriture
80 #----------------------------------------------------------------------------------------
81
82    def writeDefault(self,fn) :
83        fileXML  = fn[:fn.rfind(".")] + '.xml'
84        #filePyxb = fn[:fn.rfind(".")] + '.py'
85        fileBase = os.path.basename(fileXML)
86        fileBase = fileBase[:fileBase.rfind(".")] + '.py'
87        filePyxb = '/tmp/' + fileBase
88        print (filePyxb)
89        #fileDico='/tmp/toto.xml'
90        #print (self.texteXML)
91        f = open( str(fileXML), 'w')
92        f.write(str(self.texteXML))
93        f.close()
94
95        f = open( str(filePyxb), 'w')
96        f.write(str(self.textePourAide))
97        f.close()
98
99
100    def generMCSIMP(self,obj) :
101        if obj.nom in self.dictNbNomObj.keys():
102           nomUtil = obj.nom + "_" + str(self.dictNbNomObj[obj.nom])
103           self.dictNbNomObj[obj.nom] += 1
104        else :
105           nomUtil = obj.nom 
106           self.dictNbNomObj[obj.nom] = 1
107        self.textePourAide +=  nomUtil + " = vimmpCase." + obj.getNomDsXML() + "\n"
108        #self.textePourAide +=  "print  '"+ nomUtil+ " ='  , " + str(nomUtil) + "\n"
109        #self.textePourAide +='txt += "' + nomUtil + '" + " = " +str( ' + nomUtil + ') ' + "\n"
110
111
112
113        s=PythonGenerator.generMCSIMP(self,obj)
114        return s