]> SALOME platform Git repositories - tools/eficas.git/blob - generator/generator_vers3DSalome.py
Salome HOME
merge de la branche BR_dev_mars_06 (tag V1_10b5) dans la branche principale
[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
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 nécessaires pour le chargeur de plugins
42
43        Ces informations sont retournées dans un dictionnaire
44    """
45    return {
46         # Le nom du plugin
47           'name' : 'vers3DSalome',
48         # La factory pour créer 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",
70                              "b_constant", "b_homothetique", 
71                             "b_rectangle", "b_affine", "b_cercle" )
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"}
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):
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 élements non valides")
122          return
123       for v in obj.mc_liste:
124          liste=self.generator(v)
125
126
127    def generMCSIMP(self,obj) :
128       """
129       """
130       #print "MCSIMP : ", obj.nom
131       if obj.nom in dir(self) :
132          suite = self.__class__.__dict__[obj.nom](self,obj)
133       else :
134          clef=self.dict_traduit[obj.nom]
135          self.dict_attributs[clef]=obj.val
136
137    def generMCFACT(self,obj):
138       """
139           Convertit un objet MCFACT en une liste de chaines de caractères à la
140           syntaxe python
141       """
142       self.init_ligne()
143       self.commande=self.dict_deb_com[obj.nom]
144       print self.commande
145       for v in obj.mc_liste:
146          self.generator(v)
147       #print self.commande
148       #print self.dict_attributs
149       if self.boolGpMa == 1:
150          self.list_commandes.append((self.commande,self.dict_attributs)) 
151       else :
152          showerror("Elements ne portant pas sur un Groupe de Maille","Salome ne sait pas montrer ce type d' element")
153
154    def generMCList(self,obj):
155       """
156       """
157       for mcfact in obj.data:
158           self.generator(mcfact)
159
160    def generMCBLOC(self,obj):
161       """
162       """
163       for v in obj.mc_liste:
164          self.generator(v)
165
166    def GROUP_MA(self,obj):
167       self.boolGpMa = 1
168       self.dict_attributs["Group_Maille"]=obj.val
169
170    def SECTION(self,obj):
171       assert (self.commande != "" )
172       if self.commande == "VisuCable" : 
173          self.dict_attributs["R"]=obj.val
174       elif (self.commande !="VisuGrille")  :
175          self.commande=self.commande+self.dict_suite_com[obj.valeur]
176
177    def CARA(self,obj) :
178        self.clefs=obj.val
179        if type(self.clefs) == types.StringType :
180           self.clefs=(obj.val,)
181
182    def VALE(self,obj) :
183        atraiter=obj.val
184        if len(self.clefs) > 1 :
185            assert (len(atraiter) == len(self.clefs))
186        else :
187            atraiter=(atraiter,)
188        for k in range(len(atraiter)) :
189            clef=self.clefs[k]
190            val =atraiter[k] 
191            if isinstance (val, Extensions.parametre.PARAMETRE):
192               val=val.valeur
193               print val.__class__
194               context={}
195               if type(val) == type("aaa") :
196                  for p in self.jdc.params:
197                      context[p.nom]=eval(p.val,self.jdc.const_context, context)
198                      print context[p.nom]
199                  res=eval(val,self.jdc.const_context, context)
200                  val=res
201            self.dict_attributs[clef]=val
202
203    def ANGL_REP(self,obj) :
204       assert (len(obj.val) == 2)
205       alpha,beta=obj.val
206       self.dict_attributs["angleAlpha"]=alpha
207       self.dict_attributs["angleBeta"]=beta
208
209    def ORIG_AXE(self,obj) :
210       assert (len(obj.val) == 3)
211       alpha,beta,gamma=obj.val
212       self.dict_attributs["origAxeX"]=alpha
213       self.dict_attributs["origAxeY"]=beta
214       self.dict_attributs["origAxeZ"]=gamma
215
216    def AXE(self,obj) :
217       assert (len(obj.val) == 3)
218       alpha,beta,gamma=obj.val
219       self.dict_attributs["axeX"]=alpha
220       self.dict_attributs["axeY"]=beta
221       self.dict_attributs["axeZ"]=gamma
222