]> SALOME platform Git repositories - tools/eficas.git/blob - generator/generator_dicoImbrique.py
Salome HOME
menage
[tools/eficas.git] / generator / generator_dicoImbrique.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' : 'dicoImbrique',
36         # La factory pour creer une instance du plugin
37           'factory' : DicoImbriqueGenerator,
38           }
39
40
41 class DicoImbriqueGenerator(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, appli=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.Dico={}
68       self.DicoDejaLa={}
69       self.Entete = ''
70
71
72 #----------------------------------------------------------------------------------------
73 # ecriture
74 #----------------------------------------------------------------------------------------
75
76    def writeDefault(self,fn) :
77        fileDico = fn[:fn.rfind(".")] + '.py'
78        f = open( str(fileDico), 'wb')
79
80        f.write( self.Entete + "Dico =" + str(self.Dico) )
81        f.close()
82
83 #----------------------------------------------------------------------------------------
84 #  analyse de chaque noeud de l'arbre 
85 #----------------------------------------------------------------------------------------
86
87    def generMCSIMP(self,obj) :
88         """recuperation de l objet MCSIMP"""
89
90         s=PythonGenerator.generMCSIMP(self,obj)
91         if obj.isInformation() : return s
92         if not obj.isvalid() :  return s 
93
94         liste=obj.get_genealogie_precise() 
95
96         if obj.etape.nom=='MODIFICATION_CATALOGUE' : return s
97         nom = obj.etape.nom
98         
99         if hasattr(obj.etape,'sdnom') and obj.etape.sdnom != None and obj.etape.sdnom != "" : 
100            nom = nom+ obj.etape.sdnom
101
102         if not(self.Dico.has_key(nom)) : dicoCourant={}
103         else : dicoCourant=self.Dico [nom]
104
105         nomFeuille=liste[-1]
106         if dicoCourant.has_key(nomFeuille) or self.DicoDejaLa.has_key(nomFeuille) :
107            if self.DicoDejaLa.has_key(nomFeuille):
108               nomTravail= nomFeuille +'_'+str(self.DicoDejaLa[nomFeuille])
109               self.DicoDejaLa[nomFeuille]=self.DicoDejaLa[nomFeuille]+1
110               nomFeuille=nomTravail
111            else :
112               self.DicoDejaLa[nomFeuille]=3
113               nom1=nomFeuille +'_1'
114               dicoCourant[nom1]= dicoCourant[nomFeuille]
115               del dicoCourant[nomFeuille]
116               nomFeuille=nomFeuille +'_2'
117
118
119         if hasattr(obj.valeur,'nom'): dicoCourant[nomFeuille]=obj.valeur.nom
120         else : 
121            if type(obj.valeur)  in (types.ListType,types.TupleType):
122               try :
123 #PNPNPN a remplacer par plus propre
124                  if obj.definition.validators.typeDesTuples[0] !='R' :
125                     val=[]
126                     elt=[]
127                     for tupleElt in obj.valeur :
128                         elt=(str(tupleElt[0]),tupleElt[1])
129                         val.append(elt)
130                     dicoCourant[nomFeuille]=val
131                  else :
132                     dicoCourant[nomFeuille]=obj.valeur
133               except :
134                  dicoCourant[nomFeuille]=obj.valeurFormatee
135            #else :dicoCourant[nomFeuille]=obj.valeurFormatee
136            else :
137               dicoCourant[nomFeuille]=obj.valeurFormatee
138               #print nomFeuille, obj.valeurFormatee
139         self.Dico[nom]=dicoCourant
140
141         return s
142
143