Salome HOME
Merge branch 'nouvelEficas' of http://git.forge-pleiade.der.edf.fr/git/eficas into...
[tools/eficas.git] / generator / generator_homard.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 """
21     Ce module contient le plugin generateur de fichier au format 
22     homard pour EFICAS.
23
24 """
25 import traceback
26 import types,string,re
27
28 from Noyau import N_CR
29 from Noyau.N_utils import repr_float
30 from Accas import ETAPE,PROC_ETAPE,MACRO_ETAPE,ETAPE_NIVEAU,JDC,FORM_ETAPE
31 from Accas import MCSIMP,MCFACT,MCBLOC,MCList,EVAL
32 from Accas import GEOM,ASSD,MCNUPLET
33 from Accas import COMMENTAIRE,PARAMETRE, PARAMETRE_EVAL,COMMANDE_COMM
34 from Formatage import Formatage
35 from generator_python import PythonGenerator
36
37 def entryPoint():
38    """
39        Retourne les informations necessaires pour le chargeur de plugins
40
41        Ces informations sont retournees dans un dictionnaire
42    """
43    return {
44         # Le nom du plugin
45           'name' : 'homard',
46         # La factory pour creer une instance du plugin
47           'factory' : HomardGenerator,
48           }
49
50
51 class HomardGenerator(PythonGenerator):
52    """
53        Ce generateur parcourt un objet de type JDC et produit
54        un texte au format eficas et 
55        un texte au format homard 
56
57    """
58    # Les extensions de fichier preconis�es
59    extensions=('.comm',)
60
61    def __init__(self,cr=None):
62       # Si l'objet compte-rendu n'est pas fourni, on utilise le compte-rendu standard
63       if cr :
64          self.cr=cr
65       else:
66          self.cr=N_CR.CR(debut='CR generateur format homard pour homard',
67                          fin='fin CR format homard pour homard')
68       # Le texte au format homard est stock� dans l'attribut text
69       self.dico_mot_clef={}
70       self.assoc={}
71       self.init_assoc()
72       self.text=''
73       self.textehomard=[]
74
75    def init_assoc(self):
76       self.lmots_clef_calcules = ('SuivFron','TypeBila','ModeHOMA','CCAssoci', 'CCNoChaI','HOMaiN__','HOMaiNP1','CCNumOrI', 'CCNumPTI')
77       self.lmot_clef  = ('CCMaiN__', 'CCNoMN__', 'CCIndica', 'CCSolN__', 'CCFronti', 'CCNoMFro', 'CCMaiNP1', 
78                          'CCNoMNP1', 'CCSolNP1', 'TypeRaff', 'TypeDera', 'NiveauMa', 'SeuilHau', 'SeuilHRe', 
79                          'SeuilHPE', 'NiveauMi', 'SeuilBas', 'SeuilBRe', 'SeuilBPE', 'ListeStd', 'NumeIter', 
80                          'Langue  ', 'CCGroFro', 'CCNoChaI', 'CCNumOrI', 'CCNumPTI', 'SuivFron', 'TypeBila', 
81                          'ModeHOMA', 'HOMaiN__', 'HOMaiNP1','CCCoChaI')
82
83 # Bizarre demander a Gerald : 
84 #                CVSolNP1
85       self.assoc['CCMaiN__']='FICHIER_MED_MAILLAGE_N'
86       self.assoc['CCNoMN__']='NOM_MED_MAILLAGE_N'
87       self.assoc['CCIndica']='FICHIER_MED_MAILLAGE_N'
88       self.assoc['CCSolN__']='FICHIER_MED_MAILLAGE_N'
89       self.assoc['CCFronti']='FIC_FRON'
90       self.assoc['CCNoMFro']='NOM_MED_MAILLAGE_FRONTIERE'
91       self.assoc['CCMaiNP1']='FICHIER_MED_MAILLAGE_NP1'
92       self.assoc['CCNoMNP1']='NOM_MED_MAILLAGE_NP1'
93       self.assoc['CCSolNP1']='FICHIER_MED_MAILLAGE_NP1'
94       self.assoc['TypeRaff']='RAFFINEMENT'
95       self.assoc['TypeDera']='DERAFFINEMENT'
96       self.assoc['NiveauMa']='NIVE_MAX'
97       self.assoc['SeuilHau']='CRIT_RAFF_ABS'
98       self.assoc['SeuilHRe']='CRIT_RAFF_REL'
99       self.assoc['SeuilHPE']='CRIT_RAFF_PE'
100       self.assoc['NiveauMi']='NIVE_MIN'
101       self.assoc['SeuilBas']='CRIT_DERA_ABS'
102       self.assoc['SeuilBRe']='CRIT_DERA_REL'
103       self.assoc['SeuilBPE']='CRIT_DERA_PE'
104       self.assoc['ListeStd']='MESSAGES'
105       self.assoc['NumeIter']='NITER'
106       self.assoc['Langue  ']='LANGUE'
107       self.assoc['CCGroFro']='GROUP_MA'
108 #     self.assoc['CCNoChaI']='NOM_MED' (on doit aussi ajouter 'COMPOSANTE')
109       self.assoc['CCNumOrI']='NUME_ORDRE'
110       self.assoc['CCNumPTI']='NUME_PAS_TEMPS'
111       self.assoc['CCCoChaI']='COMPOSANTE'
112      
113       self.dico_mot_depend={}
114      
115       # Attention a la synthaxe
116       self.dico_mot_depend['CCIndica'] ='self.dico_mot_clef["RAFFINEMENT"] == "LIBRE" or self.dico_mot_clef["DERAFFINEMENT"] == "LIBRE"'
117       self.dico_mot_depend['CCSolN__'] ='self.dico_mot_clef.has_key("NITER")'
118       self.dico_mot_depend['CCSolNP1'] ='self.dico_mot_clef.has_key("NITER")'
119
120    def gener(self,obj,format='brut',config=None):
121       self.text=PythonGenerator.gener(self,obj,format)
122       self.genereConfiguration()
123       return self.text
124
125    def generMCSIMP(self,obj) :
126       """
127           Convertit un objet MCSIMP en une liste de chaines de caract�res � la
128           syntaxe homard
129       """
130       s=PythonGenerator.generMCSIMP(self,obj)
131       clef=obj.nom
132       self.dico_mot_clef[clef]=obj.val
133       return s
134
135    def cherche_dependance(self,mot):
136        b_eval = 0
137        a_eval=self.dico_mot_depend[mot]
138        try :
139           b_eval=eval(self.dico_mot_depend[mot])
140        except :
141           for l in a_eval.split(" or "):
142               try:
143                  b_eval=eval(l)
144                  if not (b_eval == 0 ):
145                      break
146               except :
147                  pass
148        return b_eval
149
150
151    def genereConfiguration(self):
152       ligbla=31*' '
153       self.textehomard=[]
154       for mot in self.lmot_clef:
155
156 #          on verifie d'abord que le mot clef doit bien etre calcule
157           if self.dico_mot_depend.has_key(mot) :
158              if self.cherche_dependance(mot) == 0 :
159                       continue
160
161           if mot not in self.lmots_clef_calcules :
162              clef_eficas=self.assoc[mot]
163              if self.dico_mot_clef.has_key(clef_eficas):
164                 val=self.dico_mot_clef[clef_eficas]
165                 if val != None:
166                    try :
167                     ligne=mot+' '+val
168                    except:
169                     ligne=mot+' '+repr(val)
170                    ligne.rjust(32)
171                    self.textehomard.append(ligne)
172           else:
173              val=apply(HomardGenerator.__dict__[mot],(self,))
174              if val != None:
175                 mot.rjust(8)
176                 ligne=mot+' '+val
177                 ligne.rjust(32)
178                 self.textehomard.append(ligne)
179
180    def get_homard(self):
181        return self.textehomard
182
183    def SuivFron(self):
184         val="non"
185         if self.dico_mot_clef.has_key('NOM_MED_MAILLAGE_FRONTIERE'):
186            if self.dico_mot_clef['NOM_MED_MAILLAGE_FRONTIERE'] != None:
187                 val="oui"
188         return val
189
190    def TypeBila(self):
191         inttypeBilan = 1
192         retour=None
193         dict_val={'NOMBRE':7,'INTERPENETRATION':3,'QUALITE':5,'CONNEXITE':11,'TAILLE':13}
194         for mot in ('NOMBRE','QUALITE','INTERPENETRATION','CONNEXITE','TAILLE'):
195             if self.dico_mot_clef.has_key(mot):
196                if (self.dico_mot_clef[mot] == "OUI"):
197                   inttypeBilan=inttypeBilan*dict_val[mot]
198                   retour = repr(inttypeBilan)
199         return retour
200
201
202    def ModeHOMA(self):
203         intModeHOMA=1
204         if self.dico_mot_clef.has_key('INFORMATION'):
205            if self.dico_mot_clef['INFORMATION'] == "OUI":
206               intModeHOMA=2
207         return repr(intModeHOMA)
208            
209    def CCAssoci(self):
210         return 'MED' 
211
212    def CCNoChaI(self):
213         if not (self.dico_mot_clef.has_key('NOM_MED')):
214            return None
215         if (self.dico_mot_clef['NOM_MED']== None):
216            return None
217         if not (self.dico_mot_clef.has_key('COMPOSANTE')):
218            return None
219         if (self.dico_mot_clef['COMPOSANTE']== None):
220            return None
221         chaine=self.dico_mot_clef['COMPOSANTE']+' '+self.dico_mot_clef['NOM_MED']
222         return chaine
223
224    def HOMaiN__(self):
225        chaine=None
226        if self.dico_mot_clef.has_key('NITER'):
227           if self.dico_mot_clef['NITER'] != None :
228              num="M"+repr(self.dico_mot_clef['NITER'])
229              chaine=num+" "+num+".hom"
230        return chaine
231
232    def HOMaiNP1(self):
233        chaine=None
234        if self.dico_mot_clef.has_key('NITER'):
235           if self.dico_mot_clef['NITER'] != None :
236              num="M"+repr(self.dico_mot_clef['NITER']+1)
237              chaine=num+" "+num+".hom"
238        return chaine
239
240    def CCNumOrI(self):
241        chaine=repr(1)
242        if self.dico_mot_clef.has_key('NUME_ORDRE'):
243           if self.dico_mot_clef['NUME_ORDRE'] != None :
244              chaine=repr(self.dico_mot_clef['NUME_ORDRE'])
245        return chaine
246
247    def CCNumPTI(self):
248        chaine=repr(1)
249        if self.dico_mot_clef.has_key('NUME_PAS_TEMPS'):
250           if self.dico_mot_clef['NUME_PAS_TEMPS'] != None :
251              chaine=repr(self.dico_mot_clef['NUME_PAS_TEMPS'])
252        return chaine