1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2007-2013 EDF R&D
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.
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.
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
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 """Ce module contient le plugin generateur de fichier au format Code_Carmel3D pour EFICAS.
23 texte_debut="#include <Zcracks_base.z7p> \n int main() \n{ \n init_var();\n"
24 texte_debut+=' format="med";\n'
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')
37 Retourne les informations necessaires pour le chargeur de plugins
38 Ces informations sont retournees dans un dictionnaire
43 # La factory pour creer une instance du plugin
44 'factory' : ZCrackGenerator,
48 class ZCrackGenerator(PythonGenerator):
50 Ce generateur parcourt un objet de type JDC et produit
51 un texte au format eficas et
52 un texte au format dictionnaire
55 # Les extensions de fichier permis?
58 #----------------------------------------------------------------------------------------
59 def gener(self,obj,format='brut',config=None):
63 # Cette instruction genere le contenu du fichier de commandes (persistance)
64 self.text=PythonGenerator.gener(self,obj,format)
68 #----------------------------------------------------------------------------------------
70 #----------------------------------------------------------------------------------------
73 self.textePourRun = texte_debut
76 #----------------------------------------------------------------------------------------
78 #----------------------------------------------------------------------------------------
80 def writeDefault(self,fn) :
81 fileZcrack = fn[:fn.rfind(".")] + '.z7p'
82 f = open( str(fileZcrack), 'wb')
83 print self.textePourRun
86 self.textePourRunAvecDouble=self.textePourRun.replace("'",'"')
87 f.write( self.textePourRunAvecDouble)
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+="}"
101 #----------------------------------------------------------------------------------------
102 # analyse de chaque noeud de l'arbre
103 #----------------------------------------------------------------------------------------
105 def generMCSIMP(self,obj) :
106 """recuperation de l objet MCSIMP"""
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+" "
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"
120 if obj.nom in ListeConcatene3 :
122 self.textePourRun+=" "+"if_ellipse=1;\n"
123 self.textePourRun+=" "+obj.nom+ "="+str(obj.val)+";\n"
124 if_ellipse_ellipse=True
127 if obj.nom in ListeConcatene2 :
129 # self.textePourRun+="GGGGGGG%"+obj.nom+"\n"
132 stringListe+=str(val)+","
133 self.textePourRun+=" "+obj.nom+ "=set_vector3("+ stringListe[0:-1]+ ");\n"
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"
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"
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"
157 self.textePourRun+=" "+obj.nom+ "=" + s[0:-1]+ ";\n"
161 # si repertoire on change tous les noms de fichier
162 # exple repertoire='/home' __> fichier='/home/crack.med