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
21 Ce module contient le plugin generateur de fichier au format
27 import types,string,re
30 from Noyau import N_CR
31 from Noyau.N_utils import repr_float
34 from Extensions.parametre import ITEM_PARAMETRE
35 from Formatage import Formatage
36 from generator_python import PythonGenerator
37 #from Editeur.widgets import showerror
41 Retourne les informations nécessaires pour le chargeur de plugins
43 Ces informations sont retournées dans un dictionnaire
47 'name' : 'vers3DSalome',
48 # La factory pour créer une instance du plugin
49 'factory' : vers3DSalomeGenerator,
53 class vers3DSalomeGenerator(PythonGenerator):
55 Ce generateur parcourt un objet AFFE-CARA_ELEM
56 et produit un fichier au format texte contenant
57 les instructions idl pour PAL
60 def __init__(self,cr=None):
61 self.list_commandes=[];
65 self.liste_motetat = ("AFFE_CARA_ELEM", "ORIG_AXE", "AXE" ,
66 "BARRE", "CABLE", "CARA", "COQUE", "EPAIS",
67 "EXCENTREMENT", "GROUP_MA", "ORIENTATION",
68 "POUTRE", "SECTION", "VALE", "VARI_SECT",
69 "GRILLE", "ANGL_REP", "VECTEUR",
70 "b_constant", "b_homothetique",
71 "b_rectangle", "b_affine", "b_cercle", "b_generale" )
72 self.dict_deb_com={"POUTRE":"VisuPoutre", "CABLE" : "VisuCable",
73 "COQUE" : "VisuCoque", "GRILLE" : "VisuGrille",
74 "ORIENTATION" : "Orientation", "BARRE" : "VisuBarre"}
76 self.dict_suite_com={"RECTANGLE":"Rectangle","GENERALE":"Generale",
79 self.dict_traduit={"VARI_SECT":"extrusion","EXCENTREMENT":"Excentre","EPAIS":"Epais","VECTEUR":"Vecteur"}
83 def init_jdc(self,jdc) :
86 def init_ligne (self) :
89 self.dict_attributs = {}
91 def gener(self,node,config=None):
95 self.list_commandes=[];
96 self.generator(self.node.object)
97 #print self.list_commandes
98 return self.list_commandes
100 def generator(self,obj):
101 if (obj.nom in self.liste_motetat) and (self.calcule_ouinon(obj)):
102 PythonGenerator.generator(self,obj)
104 f1=PythonGenerator.generator(self,obj)
109 def calcule_ouinon(self,obj):
111 for l in obj.get_genealogie() :
112 if not l in self.liste_motetat :
118 def generETAPE(self,obj):
121 if obj.isvalid() == 0 :
122 #showerror("Element non valide","Salome ne sait pas traiter les elements non valides")
124 for v in obj.mc_liste:
125 liste=self.generator(v)
127 def generMACRO_ETAPE(self,obj):
130 if obj.isvalid() == 0 :
131 #showerror("Element non valide","Salome ne sait pas traiter les elements non valides")
133 for v in obj.mc_liste:
134 liste=self.generator(v)
137 def generMCSIMP(self,obj) :
140 if obj.nom in dir(self) :
141 suite = self.__class__.__dict__[obj.nom](self,obj)
143 clef=self.dict_traduit[obj.nom]
144 # Traitement des parametres
146 self.dict_attributs[clef]=obj.val.eval()
148 self.dict_attributs[clef]=obj.val
151 def generMCFACT(self,obj):
153 Convertit un objet MCFACT en une liste de chaines de caractères à la
157 self.commande=self.dict_deb_com[obj.nom]
158 for v in obj.mc_liste:
160 if self.boolGpMa == 1:
161 self.list_commandes.append((self.commande,self.dict_attributs))
163 #showerror("Elements ne portant pas sur un Groupe de Maille","Salome ne sait pas montrer ce type d' element")
164 print ("Elements ne portant pas sur un Groupe de Maille","Salome ne sait pas montrer ce type d' element")
167 def generMCList(self,obj):
170 for mcfact in obj.data:
171 self.generator(mcfact)
173 def generMCBLOC(self,obj):
176 for v in obj.mc_liste:
179 def GROUP_MA(self,obj):
181 self.dict_attributs["Group_Maille"]=obj.val
183 def SECTION(self,obj):
184 assert (self.commande != "" )
185 if self.commande == "VisuCable" :
186 self.dict_attributs["R"]= math.sqrt(obj.val/math.pi).eval()
187 elif (self.commande !="VisuGrille") :
188 self.commande=self.commande+self.dict_suite_com[obj.valeur]
192 if type(self.clefs) == types.StringType :
193 self.clefs=(obj.val,)
197 if len(self.clefs) > 1 :
198 assert (len(atraiter) == len(self.clefs))
201 for k in range(len(atraiter)) :
204 if isinstance(val, (types.TupleType, types.ListType)) and len(val) == 1:
206 if isinstance (val, Extensions.parametre.PARAMETRE):
210 if type(val) == type("aaa") :
211 for p in self.jdc.params:
212 context[p.nom]=eval(p.val,self.jdc.const_context, context)
214 res=eval(val,self.jdc.const_context, context)
216 self.dict_attributs[clef]=val
218 def ANGL_REP(self,obj) :
219 assert (len(obj.val) == 2)
221 self.dict_attributs["angleAlpha"]=alpha
222 self.dict_attributs["angleBeta"]=beta
224 def ORIG_AXE(self,obj) :
225 assert (len(obj.val) == 3)
226 alpha,beta,gamma=obj.val
227 self.dict_attributs["origAxeX"]=alpha
228 self.dict_attributs["origAxeY"]=beta
229 self.dict_attributs["origAxeZ"]=gamma
232 assert (len(obj.val) == 3)
233 alpha,beta,gamma=obj.val
234 self.dict_attributs["axeX"]=alpha
235 self.dict_attributs["axeY"]=beta
236 self.dict_attributs["axeZ"]=gamma