1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2007-2013 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.
24 import types,string,re,os
25 from Extensions.i18n import tr
26 from generator_python import PythonGenerator
30 Retourne les informations necessaires pour le chargeur de plugins
31 Ces informations sont retournees dans un dictionnaire
35 'name' : 'dicoImbrique',
36 # La factory pour creer une instance du plugin
37 'factory' : DicoImbriqueGenerator,
41 class DicoImbriqueGenerator(PythonGenerator):
43 Ce generateur parcourt un objet de type JDC et produit
44 un texte au format eficas et
45 un texte au format dictionnaire
48 # Les extensions de fichier permis?
51 #----------------------------------------------------------------------------------------
52 def gener(self,obj,format='brut',config=None, appli=None):
56 # Cette instruction genere le contenu du fichier de commandes (persistance)
57 self.text=PythonGenerator.gener(self,obj,format)
61 #----------------------------------------------------------------------------------------
63 #----------------------------------------------------------------------------------------
71 #----------------------------------------------------------------------------------------
73 #----------------------------------------------------------------------------------------
75 def writeDefault(self,fn) :
76 fileDico = fn[:fn.rfind(".")] + '.py'
77 f = open( str(fileDico), 'wb')
78 f.write( self.Entete + "Dico =" + str(self.Dico) )
81 #----------------------------------------------------------------------------------------
82 # analyse de chaque noeud de l'arbre
83 #----------------------------------------------------------------------------------------
85 def generMCSIMP(self,obj) :
86 """recuperation de l objet MCSIMP"""
88 s=PythonGenerator.generMCSIMP(self,obj)
89 liste=obj.get_genealogie()
91 if hasattr(obj.etape,'sdnom') and obj.etape.sdnom != None and obj.etape.sdnom != "" :
92 nom = nom+ obj.etape.sdnom
93 if not(self.Dico.has_key(nom)) : dicoCourant={}
94 else : dicoCourant=self.Dico [nom]
95 if hasattr(obj.valeur,'nom'):dicoCourant[liste[-1]]=obj.valeur.nom
97 if type(obj.valeur) in (types.ListType,types.TupleType):
99 #PNPNPN a remplacer par plus propre
100 if obj.definition.validators.typeDesTuples[0] !='R' :
103 for tupleElt in obj.valeur :
104 elt=(str(tupleElt[0]),tupleElt[1])
106 dicoCourant[liste[-1]]=val
107 else :dicoCourant[liste[-1]]=obj.valeur
109 dicoCourant[liste[-1]]=obj.valeurFormatee
110 else :dicoCourant[liste[-1]]=obj.valeurFormatee
111 self.Dico[nom]=dicoCourant