Salome HOME
onItem=Deplie
[tools/eficas.git] / generator / generator_dico.py
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2007-2013   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 import traceback
24 import types,string,re,os
25 from Extensions.i18n import tr
26 from generator_python import PythonGenerator
27
28 def entryPoint():
29    """
30       Retourne les informations necessaires pour le chargeur de plugins
31       Ces informations sont retournees dans un dictionnaire
32    """
33    return {
34         # Le nom du plugin
35           'name' : 'dico',
36         # La factory pour creer une instance du plugin
37           'factory' : DicoGenerator,
38           }
39
40
41 class DicoGenerator(PythonGenerator):
42    """
43       Ce generateur parcourt un objet de type JDC et produit
44       un texte au format eficas et 
45       un texte au format dictionnaire
46
47    """
48    # Les extensions de fichier permis?
49    extensions=('.comm',)
50
51 #----------------------------------------------------------------------------------------
52    def gener(self,obj,format='brut',config=None):
53        
54       self.initDico()
55       
56       # Cette instruction genere le contenu du fichier de commandes (persistance)
57       self.text=PythonGenerator.gener(self,obj,format)
58       return self.text
59
60
61 #----------------------------------------------------------------------------------------
62 # initialisations
63 #----------------------------------------------------------------------------------------
64    
65    def initDico(self) :
66  
67       self.texteDico = ""
68
69
70 #----------------------------------------------------------------------------------------
71 # ecriture
72 #----------------------------------------------------------------------------------------
73
74    def writeDefault(self,fn) :
75        fileDico = fn[:fn.rfind(".")] + '.py'
76        f = open( str(fileDico), 'wb')
77        f.write( self.texteDico )
78        print self.texteDico
79        f.close()
80
81 #----------------------------------------------------------------------------------------
82 #  analyse de chaque noeud de l'arbre 
83 #----------------------------------------------------------------------------------------
84
85    def generMCSIMP(self,obj) :
86         """recuperation de l objet MCSIMP"""
87         s=PythonGenerator.generMCSIMP(self,obj)
88         self.texteDico+=obj.nom+ "=" + s[0:-1]+ "\n"
89         return s
90
91