Salome HOME
Telemac 1eres lectures/ecriture
[tools/eficas.git] / generator / generator_ZCracks.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 """Ce module contient le plugin generateur de fichier au format  Code_Carmel3D pour EFICAS.
21 """
22 import pickle
23 texte_debut="#include <Zcracks_base.z7p> \n int main() \n{ \n   init_var();\n"
24 texte_debut+='   format="med";\n'
25 import traceback
26 import types,string,re,os
27 from Extensions.i18n import tr
28 from generator_python import PythonGenerator
29 #ListeConcatene=('ridge_names','topo_names','geom_names','elset_names','faset_names','liset_names','nset_names','center','normal','dir')
30 ListeConcatene=('ridge_names','topo_names','geom_names','elset_names','faset_names','liset_names','nset_names')
31 ListeConcatene2=('center','normal','dir')
32 ListeConcatene3=('ra','rb')
33 if_ellipse=False
34
35 def entryPoint():
36    """
37       Retourne les informations necessaires pour le chargeur de plugins
38       Ces informations sont retournees dans un dictionnaire
39    """
40    return {
41         # Le nom du plugin
42           'name' : 'ZCRACKS',
43         # La factory pour creer une instance du plugin
44           'factory' : ZCrackGenerator,
45           }
46
47
48 class ZCrackGenerator(PythonGenerator):
49    """
50       Ce generateur parcourt un objet de type JDC et produit
51       un texte au format eficas et 
52       un texte au format dictionnaire
53
54    """
55    # Les extensions de fichier permis?
56    extensions=('.comm',)
57
58 #----------------------------------------------------------------------------------------
59    def gener(self,obj,format='brut',config=None):
60
61       self.initDico()
62
63       # Cette instruction genere le contenu du fichier de commandes (persistance)
64       self.text=PythonGenerator.gener(self,obj,format)
65       return self.text
66
67
68 #----------------------------------------------------------------------------------------
69 # initialisations
70 #----------------------------------------------------------------------------------------
71    
72    def initDico(self) :
73       self.textePourRun = texte_debut
74
75
76 #----------------------------------------------------------------------------------------
77 # ecriture
78 #----------------------------------------------------------------------------------------
79
80    def writeDefault(self,fn) :
81         fileZcrack = fn[:fn.rfind(".")] + '.z7p'
82         f = open( str(fileZcrack), 'wb')
83         print self.textePourRun
84       
85         self.ajoutRun()
86         self.textePourRunAvecDouble=self.textePourRun.replace("'",'"')
87         f.write( self.textePourRunAvecDouble)
88         f.close()
89
90    def ajoutRun(self) :
91         self.textePourRun+="   write_mesh_crack();\n"
92         self.textePourRun+="   do_mesh_crack(0);\n"
93         self.textePourRun+="   write_refine_mesh();\n"
94         self.textePourRun+="   do_refine_mesh(0);\n"
95         self.textePourRun+="   write_cut_mesh();\n"
96         self.textePourRun+="   do_cut_mesh(0);\n"
97 #        self.textePourRun+="   nice_cut("+str(self.maximum_aspect_ratio)+");\n"
98         self.textePourRun+='   export_mesh("'+self.cracked_name+'","med");\n'
99         self.textePourRun+="}"
100
101 #----------------------------------------------------------------------------------------
102 #  analyse de chaque noeud de l'arbre 
103 #----------------------------------------------------------------------------------------
104
105    def generMCSIMP(self,obj) :
106         """recuperation de l objet MCSIMP"""
107         #print dir(obj)
108         s=PythonGenerator.generMCSIMP(self,obj)
109         if obj.nom=="sane_name" :
110            self.textePourRun+='   import_mesh("'+obj.val+'", "med");\n'
111         if obj.nom in ListeConcatene :
112 #           obj.val=obj.val+" "
113            stringListe=""
114            for val in obj.val:
115                stringListe+=val+""
116 #           pickle.dump( stringListe, open( "/home/H60874/test.pickle", "wb" ) )
117 #           self.textePourRun+="   "+obj.nom+ "='"+ stringListe[0:-1]+ "';\n"
118 #           self.textePourRun+="   "+obj.nom+ "='"+ stringListe+ "';\n"
119            return s
120         if obj.nom in ListeConcatene3 :
121            if (obj.nom=="ra") :
122               self.textePourRun+="   "+"if_ellipse=1;\n" 
123            self.textePourRun+="   "+obj.nom+ "="+str(obj.val)+";\n"
124            if_ellipse_ellipse=True
125            return s
126
127         if obj.nom in ListeConcatene2 : 
128            stringListe=""
129 #           self.textePourRun+="GGGGGGG%"+obj.nom+"\n"
130 #           if (len(val)>1) :
131            for val in obj.val:
132                stringListe+=str(val)+","
133            self.textePourRun+="   "+obj.nom+ "=set_vector3("+ stringListe[0:-1]+ ");\n"
134 #           else :
135 #             self.textePourRun+="   "+obj.nom+ str(obj.val+ ";\n"
136 #               stringListe+=str(val)+" "
137 #           self.textePourRun+="   "+obj.nom+ "=set_vector3("+stringListe[0]+","+stringListe[1]+","+stringListe[2]+");\n"
138 #           self.textePourRun+="   "+obj.nom+ "=set_vector3("+obj.val+","+");\n"
139            return s
140 #        if obj.nom=="center" :
141 #           self.textePourRun+="   set_vector3("+obj.val+'");\n"
142 #        if obj.nom=="center" :
143 #           self.textePourRun+="   set_vector3("+obj.val+'");\n"
144 #        if obj.nom=="normal" :
145 #           self.textePourRun+="   set_vector3("+obj.val+'");\n"
146 #        if obj.nom=="dir" :
147 #           self.textePourRun+="   set_vector3("+obj.val+'");\n"
148         if obj.nom=="elset_radius" :
149            self.textePourRun+="   if_must_define_elset=1;\n"
150
151
152         if obj.nom=="cracked_name" : self.cracked_name=obj.val
153         if obj.nom=="maximum_aspect_ratio" : self.maximum_aspect_ratio=obj.val
154         if obj.nom=="repertoire" : 
155            print "PNPNPN a traiter"
156            return s
157         self.textePourRun+="   "+obj.nom+ "=" + s[0:-1]+ ";\n"
158         return s
159
160   
161 # si repertoire on change tous les noms de fichier
162 # exple repertoire='/home' __> fichier='/home/crack.med