Salome HOME
7.7 rc0
[tools/eficas.git] / generator / generator_TELEMAC.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 import traceback
24 import types,string,re,os
25 from Extensions.i18n import tr
26 from generator_python import PythonGenerator
27
28 extensions=('.comm',)
29 listeSupprime=('Jour','Mois','An','Heure','Minute','Seconde')
30 DicoTransforme= {'MASS LUMPING':'MASS-LUMPING','MATRIX VECTOR' : 'MATRIX-VECTOR' , 
31                   'C U PRECON':'C-U PRECON','STAGE DISCHARGE' : 'STAGE-DISCHARGE'}
32
33 def entryPoint():
34    """
35       Retourne les informations necessaires pour le chargeur de plugins
36       Ces informations sont retournees dans un dictionnaire
37    """
38    return {
39         # Le nom du plugin
40           'name' : 'TELEMAC',
41         # La factory pour creer une instance du plugin
42           'factory' : TELEMACGenerator,
43           }
44
45
46 class TELEMACGenerator(PythonGenerator):
47    """
48       Ce generateur parcourt un objet de type JDC et produit
49       un texte au format eficas et 
50       un texte au format dictionnaire
51
52    """
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  
70       self.texteDico = ""
71
72
73 #----------------------------------------------------------------------------------------
74 # ecriture
75 #----------------------------------------------------------------------------------------
76
77    def writeDefault(self,fn) :
78        fileDico = fn[:fn.rfind(".")] + '.py'
79        f = open( str(fileDico), 'wb')
80        f.write( self.texteDico )
81        print self.texteDico
82        f.close()
83
84 #----------------------------------------------------------------------------------------
85 #  analyse de chaque noeud de l'arbre 
86 #----------------------------------------------------------------------------------------
87
88    def generMCSIMP(self,obj) :
89         """recuperation de l objet MCSIMP"""
90         s=PythonGenerator.generMCSIMP(self,obj)
91         nomMajuscule=obj.nom.upper()
92         nom=nomMajuscule.replace('_',' ') 
93         if nom in listeSupprime : return s
94         nomNouveau=nom
95         for k in DicoTransforme.keys() :
96             if k in nom :
97                nomNouveau=nom.replace(k,DicoTransforme[k])
98         self.texteDico+=nomNouveau+ "=" + s[0:-1]+ "\n"
99         return s
100
101    def generMCFACT(self,obj):
102       """
103         Recalule les jours et les heures
104       """
105       s=PythonGenerator.generMCFACT(self,obj)
106       return s
107
108