]> SALOME platform Git repositories - tools/eficas.git/blob - generator/generator_vers3DSalome.py
Salome HOME
menage
[tools/eficas.git] / generator / generator_vers3DSalome.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 """
21     Ce module contient le plugin generateur de fichier au format 
22     python pour EFICAS.
23     PN
24
25 """
26 import traceback
27 import types,string,re
28 import math
29
30 from Noyau import N_CR
31 from Noyau.N_utils import repr_float
32 import Accas
33 import Extensions
34 from Extensions.parametre import ITEM_PARAMETRE
35 from Formatage import Formatage
36 from generator_python import PythonGenerator
37 #from Editeur.widgets import showerror
38
39 def entryPoint():
40    """
41        Retourne les informations necessaires pour le chargeur de plugins
42
43        Ces informations sont retournees dans un dictionnaire
44    """
45    return {
46         # Le nom du plugin
47           'name' : 'vers3DSalome',
48         # La factory pour creer une instance du plugin
49           'factory' : vers3DSalomeGenerator,
50           }
51
52
53 class vers3DSalomeGenerator(PythonGenerator):
54    """
55        Ce generateur parcourt un objet AFFE-CARA_ELEM
56        et produit un fichier au format texte contenant
57        les instructions idl pour PAL 
58    """
59
60    def __init__(self,cr=None):
61       self.list_commandes=[];
62       self.jdc=None
63       self.node=None
64       self.clefs=None
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"}
75
76       self.dict_suite_com={"RECTANGLE":"Rectangle","GENERALE":"Generale",
77                            "CERCLE":"Cercle"}
78
79       self.dict_traduit={"VARI_SECT":"extrusion","EXCENTREMENT":"Excentre","EPAIS":"Epais","VECTEUR":"Vecteur"}
80
81       self.init_ligne() 
82
83    def init_jdc(self,jdc) :
84       self.jdc=jdc
85
86    def init_ligne (self) :
87       self.boolGpMa = 0
88       self.commande = ""
89       self.dict_attributs = {} 
90
91    def gener(self,node,config=None,appli=None):
92       """
93       """
94       self.node=node
95       self.list_commandes=[];
96       self.generator(self.node.object)
97       return self.list_commandes
98
99    def generator(self,obj):
100       if (obj.nom in self.liste_motetat) and (self.calcule_ouinon(obj)):
101          PythonGenerator.generator(self,obj)
102       """
103         f1=PythonGenerator.generator(self,obj)
104       else :
105         return ""
106       """
107
108    def calcule_ouinon(self,obj):
109       ouinon=1
110       for l in obj.get_genealogie() :
111           if not l in self.liste_motetat :
112              ouinon=0
113              break
114       return ouinon
115
116        
117    def generETAPE(self,obj):
118       """
119       """
120       if obj.isvalid() == 0 :
121          #showerror("Element non valide","Salome ne sait pas traiter les elements non valides")
122          return
123       for v in obj.mc_liste:
124          liste=self.generator(v)
125
126    def generMACRO_ETAPE(self,obj):
127       """
128       """
129       if obj.isvalid() == 0 :
130          #showerror("Element non valide","Salome ne sait pas traiter les elements non valides")
131          return
132       for v in obj.mc_liste:
133          liste=self.generator(v)
134
135
136    def generMCSIMP(self,obj) :
137       """
138       """
139       if obj.nom in dir(self) :
140          suite = self.__class__.__dict__[obj.nom](self,obj)
141       else :
142          clef=self.dict_traduit[obj.nom]
143          # Traitement des parametres
144          try :
145              self.dict_attributs[clef]=obj.val.eval()
146          except :
147              self.dict_attributs[clef]=obj.val
148
149
150    def generMCFACT(self,obj):
151       """
152           Convertit un objet MCFACT en une liste de chaines de caracteres a la
153           syntaxe python
154       """
155       self.init_ligne()
156       self.commande=self.dict_deb_com[obj.nom]
157       for v in obj.mc_liste:
158          self.generator(v)
159       if self.boolGpMa == 1:
160          self.list_commandes.append((self.commande,self.dict_attributs)) 
161       else :
162          #showerror("Elements ne portant pas sur un Groupe de Maille","Salome ne sait pas montrer ce type d' element")
163          print ("Elements ne portant pas sur un Groupe de Maille","Salome ne sait pas montrer ce type d' element")
164          pass
165
166    def generMCList(self,obj):
167       """
168       """
169       for mcfact in obj.data:
170           self.generator(mcfact)
171
172    def generMCBLOC(self,obj):
173       """
174       """
175       for v in obj.mc_liste:
176          self.generator(v)
177
178    def GROUP_MA(self,obj):
179       self.boolGpMa = 1
180       self.dict_attributs["Group_Maille"]=obj.val
181
182    def SECTION(self,obj):
183       assert (self.commande != "" )
184       if self.commande == "VisuCable" :
185          self.dict_attributs["R"]= math.sqrt(obj.val/math.pi).eval()
186       elif (self.commande !="VisuGrille")  :
187          self.commande=self.commande+self.dict_suite_com[obj.valeur]
188
189    def CARA(self,obj) :
190        self.clefs=obj.val
191        if type(self.clefs) == types.StringType :
192           self.clefs=(obj.val,)
193
194    def VALE(self,obj) :
195        atraiter=obj.val
196        if len(self.clefs) > 1 :
197            assert (len(atraiter) == len(self.clefs))
198        else :
199            atraiter=(atraiter,)
200        for k in range(len(atraiter)) :
201            clef=self.clefs[k]
202            val =atraiter[k] 
203            if isinstance(val, (types.TupleType, types.ListType)) and len(val) == 1:
204                val = val[0]
205            if isinstance (val, Extensions.parametre.PARAMETRE):
206               val=val.valeur
207               print ( val.__class)
208               context={}
209               if type(val) == type("aaa") :
210                  for p in self.jdc.params:
211                      context[p.nom]=eval(p.val,self.jdc.const_context, context)
212                      print (context[p.nom])
213                  res=eval(val,self.jdc.const_context, context)
214                  val=res
215            self.dict_attributs[clef]=val
216
217    def ANGL_REP(self,obj) :
218       assert (len(obj.val) == 2)
219       alpha,beta=obj.val
220       self.dict_attributs["angleAlpha"]=alpha
221       self.dict_attributs["angleBeta"]=beta
222
223    def ORIG_AXE(self,obj) :
224       assert (len(obj.val) == 3)
225       alpha,beta,gamma=obj.val
226       self.dict_attributs["origAxeX"]=alpha
227       self.dict_attributs["origAxeY"]=beta
228       self.dict_attributs["origAxeZ"]=gamma
229
230    def AXE(self,obj) :
231       assert (len(obj.val) == 3)
232       alpha,beta,gamma=obj.val
233       self.dict_attributs["axeX"]=alpha
234       self.dict_attributs["axeY"]=beta
235       self.dict_attributs["axeZ"]=gamma