Salome HOME
Modif V6_4_°
[tools/eficas.git] / generator / generator_vers3DSalome.py
1 # -*- coding: utf-8 -*-
2 #            CONFIGURATION MANAGEMENT OF EDF VERSION
3 # ======================================================================
4 # COPYRIGHT (C) 1991 - 2002  EDF R&D                  WWW.CODE-ASTER.ORG
5 # THIS PROGRAM IS FREE SOFTWARE; YOU CAN REDISTRIBUTE IT AND/OR MODIFY
6 # IT UNDER THE TERMS OF THE GNU GENERAL PUBLIC LICENSE AS PUBLISHED BY
7 # THE FREE SOFTWARE FOUNDATION; EITHER VERSION 2 OF THE LICENSE, OR
8 # (AT YOUR OPTION) ANY LATER VERSION.
9 #
10 # THIS PROGRAM IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL, BUT
11 # WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF
12 # MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. SEE THE GNU
13 # GENERAL PUBLIC LICENSE FOR MORE DETAILS.
14 #
15 # YOU SHOULD HAVE RECEIVED A COPY OF THE GNU GENERAL PUBLIC LICENSE
16 # ALONG WITH THIS PROGRAM; IF NOT, WRITE TO EDF R&D CODE_ASTER,
17 #    1 AVENUE DU GENERAL DE GAULLE, 92141 CLAMART CEDEX, FRANCE.
18 #
19 #
20 # ======================================================================
21 """
22     Ce module contient le plugin generateur de fichier au format 
23     python pour EFICAS.
24     PN
25
26 """
27 import traceback
28 import types,string,re
29 import math
30
31 from Noyau import N_CR
32 from Noyau.N_utils import repr_float
33 import Accas
34 import Extensions
35 from Extensions.parametre import ITEM_PARAMETRE
36 from Formatage import Formatage
37 from generator_python import PythonGenerator
38 #from Editeur.widgets import showerror
39
40 def entryPoint():
41    """
42        Retourne les informations nécessaires pour le chargeur de plugins
43
44        Ces informations sont retournées dans un dictionnaire
45    """
46    return {
47         # Le nom du plugin
48           'name' : 'vers3DSalome',
49         # La factory pour créer une instance du plugin
50           'factory' : vers3DSalomeGenerator,
51           }
52
53
54 class vers3DSalomeGenerator(PythonGenerator):
55    """
56        Ce generateur parcourt un objet AFFE-CARA_ELEM
57        et produit un fichier au format texte contenant
58        les instructions idl pour PAL 
59    """
60
61    def __init__(self,cr=None):
62       self.list_commandes=[];
63       self.jdc=None
64       self.node=None
65       self.clefs=None
66       self.liste_motetat = ("AFFE_CARA_ELEM", "ORIG_AXE", "AXE" , 
67                             "BARRE", "CABLE", "CARA", "COQUE", "EPAIS", 
68                             "EXCENTREMENT", "GROUP_MA", "ORIENTATION", 
69                             "POUTRE", "SECTION", "VALE", "VARI_SECT",
70                             "GRILLE", "ANGL_REP", "VECTEUR",
71                              "b_constant", "b_homothetique", 
72                             "b_rectangle", "b_affine", "b_cercle" )
73       self.dict_deb_com={"POUTRE":"VisuPoutre", "CABLE" : "VisuCable",
74                          "COQUE" : "VisuCoque", "GRILLE" : "VisuGrille",
75                          "ORIENTATION" : "Orientation", "BARRE" : "VisuBarre"}
76
77       self.dict_suite_com={"RECTANGLE":"Rectangle","GENERALE":"Generale",
78                            "CERCLE":"Cercle"}
79
80       self.dict_traduit={"VARI_SECT":"extrusion","EXCENTREMENT":"Excentre","EPAIS":"Epais","VECTEUR":"Vecteur"}
81
82       self.init_ligne() 
83
84    def init_jdc(self,jdc) :
85       self.jdc=jdc
86
87    def init_ligne (self) :
88       self.boolGpMa = 0
89       self.commande = ""
90       self.dict_attributs = {} 
91
92    def gener(self,node,config=None):
93       """
94       """
95       self.node=node
96       self.list_commandes=[];
97       self.generator(self.node.object)
98       #print self.list_commandes
99       return self.list_commandes
100
101    def generator(self,obj):
102       if (obj.nom in self.liste_motetat) and (self.calcule_ouinon(obj)):
103          PythonGenerator.generator(self,obj)
104       """
105         f1=PythonGenerator.generator(self,obj)
106       else :
107         return ""
108       """
109
110    def calcule_ouinon(self,obj):
111       ouinon=1
112       for l in obj.get_genealogie() :
113           if not l in self.liste_motetat :
114              ouinon=0
115              break
116       return ouinon
117
118        
119    def generETAPE(self,obj):
120       """
121       """
122       if obj.isvalid() == 0 :
123          #showerror("Element non valide","Salome ne sait pas traiter les elements non valides")
124          return
125       for v in obj.mc_liste:
126          liste=self.generator(v)
127
128
129    def generMCSIMP(self,obj) :
130       """
131       """
132       if obj.nom in dir(self) :
133          suite = self.__class__.__dict__[obj.nom](self,obj)
134       else :
135          clef=self.dict_traduit[obj.nom]
136          # Traitement des parametres
137          try :
138              self.dict_attributs[clef]=obj.val.eval()
139          except :
140              self.dict_attributs[clef]=obj.val
141
142
143    def generMCFACT(self,obj):
144       """
145           Convertit un objet MCFACT en une liste de chaines de caractères à la
146           syntaxe python
147       """
148       self.init_ligne()
149       self.commande=self.dict_deb_com[obj.nom]
150       for v in obj.mc_liste:
151          self.generator(v)
152       if self.boolGpMa == 1:
153          self.list_commandes.append((self.commande,self.dict_attributs)) 
154       else :
155          #showerror("Elements ne portant pas sur un Groupe de Maille","Salome ne sait pas montrer ce type d' element")
156          print ("Elements ne portant pas sur un Groupe de Maille","Salome ne sait pas montrer ce type d' element")
157          pass
158
159    def generMCList(self,obj):
160       """
161       """
162       for mcfact in obj.data:
163           self.generator(mcfact)
164
165    def generMCBLOC(self,obj):
166       """
167       """
168       for v in obj.mc_liste:
169          self.generator(v)
170
171    def GROUP_MA(self,obj):
172       self.boolGpMa = 1
173       self.dict_attributs["Group_Maille"]=obj.val
174
175    def SECTION(self,obj):
176       assert (self.commande != "" )
177       if self.commande == "VisuCable" :
178          self.dict_attributs["R"]= math.sqrt(obj.val/math.pi).eval()
179       elif (self.commande !="VisuGrille")  :
180          self.commande=self.commande+self.dict_suite_com[obj.valeur]
181
182    def CARA(self,obj) :
183        self.clefs=obj.val
184        if type(self.clefs) == types.StringType :
185           self.clefs=(obj.val,)
186
187    def VALE(self,obj) :
188        atraiter=obj.val
189        if len(self.clefs) > 1 :
190            assert (len(atraiter) == len(self.clefs))
191        else :
192            atraiter=(atraiter,)
193        for k in range(len(atraiter)) :
194            clef=self.clefs[k]
195            val =atraiter[k] 
196            if isinstance(val, (types.TupleType, types.ListType)) and len(val) == 1:
197                val = val[0]
198            if isinstance (val, Extensions.parametre.PARAMETRE):
199               val=val.valeur
200               print val.__class__
201               context={}
202               if type(val) == type("aaa") :
203                  for p in self.jdc.params:
204                      context[p.nom]=eval(p.val,self.jdc.const_context, context)
205                      print context[p.nom]
206                  res=eval(val,self.jdc.const_context, context)
207                  val=res
208            self.dict_attributs[clef]=val
209
210    def ANGL_REP(self,obj) :
211       assert (len(obj.val) == 2)
212       alpha,beta=obj.val
213       self.dict_attributs["angleAlpha"]=alpha
214       self.dict_attributs["angleBeta"]=beta
215
216    def ORIG_AXE(self,obj) :
217       assert (len(obj.val) == 3)
218       alpha,beta,gamma=obj.val
219       self.dict_attributs["origAxeX"]=alpha
220       self.dict_attributs["origAxeY"]=beta
221       self.dict_attributs["origAxeZ"]=gamma
222
223    def AXE(self,obj) :
224       assert (len(obj.val) == 3)
225       alpha,beta,gamma=obj.val
226       self.dict_attributs["axeX"]=alpha
227       self.dict_attributs["axeY"]=beta
228       self.dict_attributs["axeZ"]=gamma