Salome HOME
bug
[tools/eficas.git] / generator / generator_dico.py
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2007-2017   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' : 'dico',
42         # La factory pour creer une instance du plugin
43           'factory' : DicoGenerator,
44           }
45
46
47 class DicoGenerator(PythonGenerator):
48    """
49       Ce generateur parcourt un objet de type JDC et produit
50       un texte au format eficas et 
51       un texte au format dictionnaire
52
53    """
54    # Les extensions de fichier permis?
55    extensions=('.comm',)
56
57 #----------------------------------------------------------------------------------------
58    def gener(self,obj,format='brut',config=None,appli=None):
59        
60       self.initDico()
61       
62       # Cette instruction genere le contenu du fichier de commandes (persistance)
63       self.text=PythonGenerator.gener(self,obj,format)
64       return self.text
65
66
67 #----------------------------------------------------------------------------------------
68 # initialisations
69 #----------------------------------------------------------------------------------------
70    
71    def initDico(self) :
72  
73       self.Dico={}
74       self.texteDico = ""
75
76
77 #----------------------------------------------------------------------------------------
78 # ecriture
79 #----------------------------------------------------------------------------------------
80
81    def writeDefault(self,fn) :
82        fileDico = fn[:fn.rfind(".")] + '.py'
83        f = open( str(fileDico), 'w')
84        f.write('Dico = '+str(self.Dico))
85        f.close()
86
87 #----------------------------------------------------------------------------------------
88 #  analyse de chaque noeud de l'arbre 
89 #----------------------------------------------------------------------------------------
90
91    def generMCSIMP(self,obj) :
92         """recuperation de l objet MCSIMP"""
93         s=PythonGenerator.generMCSIMP(self,obj)
94         print ('jjjjjjjjjj')
95         print (obj.nom)
96         print (s)
97         courant=self.Dico
98         for p in obj.getGenealogiePrecise()[0:-1]:
99             if not (p in courant.keys()) : courant[p]={}
100             courant=courant[p]
101         courant[obj.nom]=obj.val
102         self.texteDico+=obj.nom+ "=" + s[0:-1]+ "\n"
103         return s
104