Salome HOME
gitignore V1
[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
23 texte_debut="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
31 def entryPoint():
32    """
33       Retourne les informations necessaires pour le chargeur de plugins
34       Ces informations sont retournees dans un dictionnaire
35    """
36    return {
37         # Le nom du plugin
38           'name' : 'ZCRACKS',
39         # La factory pour creer une instance du plugin
40           'factory' : ZCrackGenerator,
41           }
42
43
44 class ZCrackGenerator(PythonGenerator):
45    """
46       Ce generateur parcourt un objet de type JDC et produit
47       un texte au format eficas et 
48       un texte au format dictionnaire
49
50    """
51    # Les extensions de fichier permis?
52    extensions=('.comm',)
53
54 #----------------------------------------------------------------------------------------
55    def gener(self,obj,format='brut',config=None):
56
57       self.initDico()
58
59       # Cette instruction genere le contenu du fichier de commandes (persistance)
60       self.text=PythonGenerator.gener(self,obj,format)
61       return self.text
62
63
64 #----------------------------------------------------------------------------------------
65 # initialisations
66 #----------------------------------------------------------------------------------------
67    
68    def initDico(self) :
69       self.textePourRun = texte_debut
70
71
72 #----------------------------------------------------------------------------------------
73 # ecriture
74 #----------------------------------------------------------------------------------------
75
76    def writeDefault(self,fn) :
77         fileZcrack = fn[:fn.rfind(".")] + '.z7p'
78         f = open( str(fileZcrack), 'wb')
79         print self.textePourRun
80       
81         self.ajoutRun()
82         self.textePourRunAvecDouble=self.textePourRun.replace("'",'"')
83         f.write( self.textePourRunAvecDouble)
84         f.close()
85
86    def ajoutRun(self) :
87         self.textePourRun+="   write_mesh_crack();\n"
88         self.textePourRun+="   do_mesh_crack(0);\n"
89         self.textePourRun+="   nice_cut(20.);\n"
90         self.textePourRun+='   export_mesh("'+self.cracked_name+'","med");\n'
91         self.textePourRun+="}"
92
93 #----------------------------------------------------------------------------------------
94 #  analyse de chaque noeud de l'arbre 
95 #----------------------------------------------------------------------------------------
96
97    def generMCSIMP(self,obj) :
98         """recuperation de l objet MCSIMP"""
99         #print dir(obj)
100         s=PythonGenerator.generMCSIMP(self,obj)
101         if obj.nom in ListeConcatene : 
102            stringListe=""
103            for val in obj.val:
104                stringListe+=str(val)+" "
105            self.textePourRun+="   "+obj.nom+ "='"+ stringListe[0:-1]+ "';\n"
106            return s
107         if obj.nom=="elset_radius"  :
108            self.textePourRun+="   if_must_define_elset=1;\n"
109         if obj.nom=="sane_name" and obj.val!=None :
110            self.textePourRun+='   import_mesh("'+obj.val+'");\n'
111
112         if obj.nom=="cracked_name" and obj.val!=None : self.cracked_name=obj.val
113         if obj.nom=="repertoire" : 
114            print "PNPNPN a traiter"
115            return s
116         self.textePourRun+="   "+obj.nom+ "=" + s[0:-1]+ ";\n"
117         return s
118
119   
120 # si repertoire on change tous les noms de fichier
121 # exple repertoire='/home' __> fichier='/home/crack.med