Salome HOME
pour traduction des mots-clefs
[tools/eficas.git] / generator / generator_PSEN.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_dicoImbrique import DicoImbriqueGenerator
29 import pdb
30 from numpy import zeros
31
32 def entryPoint():
33    """
34       Retourne les informations necessaires pour le chargeur de plugins
35       Ces informations sont retournees dans un dictionnaire
36    """
37    return {
38         # Le nom du plugin
39           'name' : 'PSEN',
40         # La factory pour creer une instance du plugin
41           'factory' : PSENGenerator,
42           }
43
44
45 class PSENGenerator(DicoImbriqueGenerator):
46    """
47       Ce generateur parcourt un objet de type JDC et produit
48       un texte au format eficas et 
49       un texte au format dictionnaire
50
51    """
52    # Les extensions de fichier permis?
53    extensions=('.comm',)
54
55 #----------------------------------------------------------------------------------------
56    def gener(self,obj,format='brut',config=None):
57
58       print "je passe dans gener"
59       try :
60          self.MachineDico = obj.MachineDico
61          self.LoadDico = obj.LoadDico
62          self.LineDico = obj.LineDico
63          self.TransfoDico = obj.TransfoDico
64       except :
65          self.MachineDico = None
66          self.LoadDico = None
67          self.LineDico = None
68          self.TransfoDico = None
69       
70       self.initDico()
71       # Cette instruction genere le contenu du fichier de commandes (persistance)
72       self.text=DicoImbriqueGenerator.gener(self,obj,format)
73       return self.text
74
75
76 #----------------------------------------------------------------------------------------
77 # initialisations
78 #----------------------------------------------------------------------------------------
79    
80    def initDico(self) :
81       DicoImbriqueGenerator.initDico(self)
82       self.Entete = 'MachineDico = ' + str(self.MachineDico) +'\n'
83       self.Entete += 'LoadDico = ' + str(self.LoadDico) +'\n'
84       self.Entete += 'LineDico = ' + str(self.LineDico) +'\n'
85       self.Entete += 'TransfoDico = ' + str(self.TransfoDico) +'\n'
86       self.Entete +='\n'
87
88
89 #----------------------------------------------------------------------------------------
90 # ecriture
91 #----------------------------------------------------------------------------------------
92
93    def writeDefault(self,fn) :
94        fileDico=os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(__file__)),'..','PSEN_Eficas','PSEN','PSENconfig.py'))
95        f = open( str(fileDico), 'wb')
96        f.write( self.Entete + "Dico =" + str(self.Dico) )
97        f.close()
98
99    
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 ##        self.dicoMCSIMP[obj.nom]=obj.val
109 ##        self.dicoTemp[obj.nom]=obj.val
110 ##        s=DicoImbriqueGenerator.generMCSIMP(self,obj)
111 ##        return s
112 ##
113 ##   def generETAPE(self,obj):
114 ##        self.dicoTemp={}
115 ##        s=DicoImbriqueGenerator.generETAPE(self,obj)
116 ##        if obj.nom=="DISTRIBUTION" : self.dicoLois[obj.sd.nom]=self.dicoTemp
117 ##        self.dicoTemp={}
118 ##        return s
119
120   
121 # si repertoire on change tous les noms de fichier