Salome HOME
bug
[tools/eficas.git] / generator / generator_vers3DSalome.py
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2007-2017   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 from __future__ import absolute_import
27 from __future__ import print_function
28 from __future__ import division
29 try :
30   from builtins import range
31 except :
32   pass
33 import traceback
34 import types,re
35 import math
36
37 from Noyau import N_CR
38 from Noyau.N_utils import repr_float
39 import Accas
40 import Extensions
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
46
47 def entryPoint():
48    """
49        Retourne les informations necessaires pour le chargeur de plugins
50
51        Ces informations sont retournees dans un dictionnaire
52    """
53    return {
54         # Le nom du plugin
55           'name' : 'vers3DSalome',
56         # La factory pour creer une instance du plugin
57           'factory' : vers3DSalomeGenerator,
58           }
59
60
61 class vers3DSalomeGenerator(PythonGenerator):
62    """
63        Ce generateur parcourt un objet AFFE-CARA_ELEM
64        et produit un fichier au format texte contenant
65        les instructions idl pour PAL 
66    """
67
68    def __init__(self,cr=None):
69       self.list_commandes=[];
70       self.jdc=None
71       self.node=None
72       self.clefs=None
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"}
83
84       self.dict_suite_com={"RECTANGLE":"Rectangle","GENERALE":"Generale",
85                            "CERCLE":"Cercle"}
86
87       self.dict_traduit={"VARI_SECT":"extrusion","EXCENTREMENT":"Excentre","EPAIS":"Epais","VECTEUR":"Vecteur"}
88
89       self.initLigne () 
90
91    def initJdc(self,jdc) :
92       self.jdc=jdc
93
94    def initLigne  (self) :
95       self.boolGpMa = 0
96       self.commande = ""
97       self.dict_attributs = {} 
98
99    def gener(self,node,config=None,appli=None):
100       """
101       """
102       self.node=node
103       self.list_commandes=[];
104       self.generator(self.node.object)
105       return self.list_commandes
106
107    def generator(self,obj):
108       if (obj.nom in self.liste_motetat) and (self.calculeOuiNon(obj)):
109          PythonGenerator.generator(self,obj)
110       """
111         f1=PythonGenerator.generator(self,obj)
112       else :
113         return ""
114       """
115
116    def calculeOuiNon(self,obj):
117       ouinon=1
118       for l in obj.getGenealogie() :
119           if not l in self.liste_motetat :
120              ouinon=0
121              break
122       return ouinon
123
124        
125    def generETAPE(self,obj):
126       """
127       """
128       if obj.isValid() == 0 :
129          #showerror("Element non valide","Salome ne sait pas traiter les elements non valides")
130          return
131       for v in obj.mcListe:
132          liste=self.generator(v)
133
134    def generMACRO_ETAPE(self,obj):
135       """
136       """
137       if obj.isValid() == 0 :
138          #showerror("Element non valide","Salome ne sait pas traiter les elements non valides")
139          return
140       for v in obj.mcListe:
141          liste=self.generator(v)
142
143
144    def generMCSIMP(self,obj) :
145       """
146       """
147       if obj.nom in dir(self) :
148          suite = self.__class__.__dict__[obj.nom](self,obj)
149       else :
150          clef=self.dict_traduit[obj.nom]
151          # traitement des parametres
152          try :
153              self.dict_attributs[clef]=obj.val.eval()
154          except :
155              self.dict_attributs[clef]=obj.val
156
157
158    def generMCFACT(self,obj):
159       """
160           Convertit un objet MCFACT en une liste de chaines de caracteres a la
161           syntaxe python
162       """
163       self.initLigne ()
164       self.commande=self.dict_deb_com[obj.nom]
165       for v in obj.mcListe:
166          self.generator(v)
167       if self.boolGpMa == 1:
168          self.list_commandes.append((self.commande,self.dict_attributs)) 
169       else :
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"))
172          pass
173
174    def generMCList(self,obj):
175       """
176       """
177       for mcfact in obj.data:
178           self.generator(mcfact)
179
180    def generMCBLOC(self,obj):
181       """
182       """
183       for v in obj.mcListe:
184          self.generator(v)
185
186    def GROUP_MA(self,obj):
187       self.boolGpMa = 1
188       self.dict_attributs["Group_Maille"]=obj.val
189
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]
196
197    def CARA(self,obj) :
198        self.clefs=obj.val
199        if type(self.clefs) == bytes or  type(self.clefs) == str:
200           self.clefs=(obj.val,)
201
202    def VALE(self,obj) :
203        atraiter=obj.val
204        if len(self.clefs) > 1 :
205            assert (len(atraiter) == len(self.clefs))
206        else :
207            atraiter=(atraiter,)
208        for k in range(len(atraiter)) :
209            clef=self.clefs[k]
210            val =atraiter[k] 
211            if isinstance(val, (tuple, list)) and len(val) == 1:
212                val = val[0]
213            if isinstance (val, Extensions.parametre.PARAMETRE):
214               val=val.valeur
215               print(( val.__class))
216               context={}
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)
222                  val=res
223            self.dict_attributs[clef]=val
224
225    def ANGL_REP(self,obj) :
226       assert (len(obj.val) == 2)
227       alpha,beta=obj.val
228       self.dict_attributs["angleAlpha"]=alpha
229       self.dict_attributs["angleBeta"]=beta
230
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
237
238    def AXE(self,obj) :
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