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
26 from __future__ import absolute_import
27 from __future__ import print_function
28 from __future__ import division
30 from builtins import range
37 from Noyau import N_CR
38 from Noyau.N_utils import repr_float
41 from Extensions.parametre import ITEM_PARAMETRE
42 from .Formatage import Formatage
43 from .generator_python import PythonGenerator
44 from six.moves import range
45 #from Editeur.widgets import showerror
49 Retourne les informations necessaires pour le chargeur de plugins
51 Ces informations sont retournees dans un dictionnaire
55 'name' : 'vers3DSalome',
56 # La factory pour creer une instance du plugin
57 'factory' : vers3DSalomeGenerator,
61 class vers3DSalomeGenerator(PythonGenerator):
63 Ce generateur parcourt un objet AFFE-CARA_ELEM
64 et produit un fichier au format texte contenant
65 les instructions idl pour PAL
68 def __init__(self,cr=None):
69 self.list_commandes=[];
73 self.liste_motetat = ("AFFE_CARA_ELEM", "ORIG_AXE", "AXE" ,
74 "BARRE", "CABLE", "CARA", "COQUE", "EPAIS",
75 "EXCENTREMENT", "GROUP_MA", "ORIENTATION",
76 "POUTRE", "SECTION", "VALE", "VARI_SECT",
77 "GRILLE", "ANGL_REP", "VECTEUR",
78 "b_constant", "b_homothetique",
79 "b_rectangle", "b_affine", "b_cercle", "b_generale" )
80 self.dict_deb_com={"POUTRE":"VisuPoutre", "CABLE" : "VisuCable",
81 "COQUE" : "VisuCoque", "GRILLE" : "VisuGrille",
82 "ORIENTATION" : "Orientation", "BARRE" : "VisuBarre"}
84 self.dict_suite_com={"RECTANGLE":"Rectangle","GENERALE":"Generale",
87 self.dict_traduit={"VARI_SECT":"extrusion","EXCENTREMENT":"Excentre","EPAIS":"Epais","VECTEUR":"Vecteur"}
91 def init_jdc(self,jdc) :
94 def init_ligne (self) :
97 self.dict_attributs = {}
99 def gener(self,node,config=None,appli=None):
103 self.list_commandes=[];
104 self.generator(self.node.object)
105 return self.list_commandes
107 def generator(self,obj):
108 if (obj.nom in self.liste_motetat) and (self.calcule_ouinon(obj)):
109 PythonGenerator.generator(self,obj)
111 f1=PythonGenerator.generator(self,obj)
116 def calcule_ouinon(self,obj):
118 for l in obj.get_genealogie() :
119 if not l in self.liste_motetat :
125 def generETAPE(self,obj):
128 if obj.isvalid() == 0 :
129 #showerror("Element non valide","Salome ne sait pas traiter les elements non valides")
131 for v in obj.mc_liste:
132 liste=self.generator(v)
134 def generMACRO_ETAPE(self,obj):
137 if obj.isvalid() == 0 :
138 #showerror("Element non valide","Salome ne sait pas traiter les elements non valides")
140 for v in obj.mc_liste:
141 liste=self.generator(v)
144 def generMCSIMP(self,obj) :
147 if obj.nom in dir(self) :
148 suite = self.__class__.__dict__[obj.nom](self,obj)
150 clef=self.dict_traduit[obj.nom]
151 # Traitement des parametres
153 self.dict_attributs[clef]=obj.val.eval()
155 self.dict_attributs[clef]=obj.val
158 def generMCFACT(self,obj):
160 Convertit un objet MCFACT en une liste de chaines de caracteres a la
164 self.commande=self.dict_deb_com[obj.nom]
165 for v in obj.mc_liste:
167 if self.boolGpMa == 1:
168 self.list_commandes.append((self.commande,self.dict_attributs))
170 #showerror("Elements ne portant pas sur un Groupe de Maille","Salome ne sait pas montrer ce type d' element")
171 print(("Elements ne portant pas sur un Groupe de Maille","Salome ne sait pas montrer ce type d' element"))
174 def generMCList(self,obj):
177 for mcfact in obj.data:
178 self.generator(mcfact)
180 def generMCBLOC(self,obj):
183 for v in obj.mc_liste:
186 def GROUP_MA(self,obj):
188 self.dict_attributs["Group_Maille"]=obj.val
190 def SECTION(self,obj):
191 assert (self.commande != "" )
192 if self.commande == "VisuCable" :
193 self.dict_attributs["R"]= math.sqrt(obj.val/math.pi).eval()
194 elif (self.commande !="VisuGrille") :
195 self.commande=self.commande+self.dict_suite_com[obj.valeur]
199 if type(self.clefs) == bytes :
200 self.clefs=(obj.val,)
204 if len(self.clefs) > 1 :
205 assert (len(atraiter) == len(self.clefs))
208 for k in range(len(atraiter)) :
211 if isinstance(val, (tuple, list)) and len(val) == 1:
213 if isinstance (val, Extensions.parametre.PARAMETRE):
215 print(( val.__class))
217 if type(val) == type("aaa") :
218 for p in self.jdc.params:
219 context[p.nom]=eval(p.val,self.jdc.const_context, context)
220 print((context[p.nom]))
221 res=eval(val,self.jdc.const_context, context)
223 self.dict_attributs[clef]=val
225 def ANGL_REP(self,obj) :
226 assert (len(obj.val) == 2)
228 self.dict_attributs["angleAlpha"]=alpha
229 self.dict_attributs["angleBeta"]=beta
231 def ORIG_AXE(self,obj) :
232 assert (len(obj.val) == 3)
233 alpha,beta,gamma=obj.val
234 self.dict_attributs["origAxeX"]=alpha
235 self.dict_attributs["origAxeY"]=beta
236 self.dict_attributs["origAxeZ"]=gamma
239 assert (len(obj.val) == 3)
240 alpha,beta,gamma=obj.val
241 self.dict_attributs["axeX"]=alpha
242 self.dict_attributs["axeY"]=beta
243 self.dict_attributs["axeZ"]=gamma