1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2007-2021 EDF R&D
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.
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.
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
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 """Ce module contient le plugin generateur de fichier au format Code_Carmel3D pour EFICAS.
23 from __future__ import absolute_import
25 from builtins import str
30 from Extensions.i18n import tr
31 from .generator_python import PythonGenerator
35 Retourne les informations necessaires pour le chargeur de plugins
36 Ces informations sont retournees dans un dictionnaire
40 'name' : 'dicoImbrique',
41 # La factory pour creer une instance du plugin
42 'factory' : DicoImbriqueGenerator,
46 class DicoImbriqueGenerator(PythonGenerator):
48 Ce generateur parcourt un objet de type JDC et produit
49 un texte au format eficas et
50 un texte au format dictionnaire
53 # Les extensions de fichier permis?
56 #----------------------------------------------------------------------------------------
57 def gener(self,obj,format='brut',config=None, appliEficas=None):
61 # Cette instruction genere le contenu du fichier de commandes (persistance)
62 self.text=PythonGenerator.gener(self,obj,format)
69 #----------------------------------------------------------------------------------------
71 #----------------------------------------------------------------------------------------
80 #----------------------------------------------------------------------------------------
82 #----------------------------------------------------------------------------------------
84 def writeDefault(self,fn) :
85 fileDico = fn[:fn.rfind(".")] + '.py'
86 f = open( str(fileDico), 'wb')
88 f.write( self.Entete + "Dico =" + str(self.Dico) )
91 #----------------------------------------------------------------------------------------
92 # analyse de chaque noeud de l'arbre
93 #----------------------------------------------------------------------------------------
95 def generMCSIMP(self,obj) :
96 """recuperation de l objet MCSIMP"""
98 s=PythonGenerator.generMCSIMP(self,obj)
99 if obj.isInformation() : return s
100 if not obj.isValid() : return s
102 liste=obj.getGenealogiePrecise()
104 if obj.etape.nom=='MODIFICATION_CATALOGUE' : return s
107 if hasattr(obj.etape,'sdnom') and obj.etape.sdnom != None and obj.etape.sdnom != "" :
108 nom = nom+ obj.etape.sdnom
110 if not(nom in self.Dico) : dicoCourant={}
111 else : dicoCourant=self.Dico [nom]
114 if nomFeuille in dicoCourant or nomFeuille in self.DicoDejaLa:
115 if nomFeuille in self.DicoDejaLa:
116 nomTravail= nomFeuille +'_'+str(self.DicoDejaLa[nomFeuille])
117 self.DicoDejaLa[nomFeuille]=self.DicoDejaLa[nomFeuille]+1
118 nomFeuille=nomTravail
120 self.DicoDejaLa[nomFeuille]=3
121 nom1=nomFeuille +'_1'
122 dicoCourant[nom1]= dicoCourant[nomFeuille]
123 del dicoCourant[nomFeuille]
124 nomFeuille=nomFeuille +'_2'
127 if hasattr(obj.valeur,'nom'): dicoCourant[nomFeuille]=obj.valeur.nom
129 if type(obj.valeur) in (list,tuple):
131 #PNPNPN a remplacer par plus propre
132 if obj.definition.validators.typeDesTuples[0] !='R' :
135 for tupleElt in obj.valeur :
136 elt=(str(tupleElt[0]),tupleElt[1])
138 dicoCourant[nomFeuille]=val
140 dicoCourant[nomFeuille]=obj.valeur
142 dicoCourant[nomFeuille]=obj.valeurFormatee
143 #else :dicoCourant[nomFeuille]=obj.valeurFormatee
145 dicoCourant[nomFeuille]=obj.valeurFormatee
146 #print nomFeuille, obj.valeurFormatee
147 self.Dico[nom]=dicoCourant