1 # Copyright (C) 2007-2013 EDF R&D
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License.
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 # Lesser General Public License for more details.
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 from Extensions.i18n import tr
21 from Accas.A_BLOC import BLOC
25 from convert_python import PythonParser
27 pattern_comment_slash = re.compile(r"^\s*/")
28 pattern_eta = re.compile(r".*&ETA.*")
29 pattern_fin = re.compile(r".*&FIN.*")
30 pattern_blanc = re.compile(r"^ *$")
31 pattern_OUI = re.compile(r"^ *OUI *")
32 pattern_oui = re.compile(r"^ *oui *")
33 pattern_NON = re.compile(r"^ *NON *")
34 pattern_non = re.compile(r"^ *non *")
35 pattern_vide = re.compile(r"^ *$")
37 from aideAuxConvertisseurs import DicoEficasToCas, ListeSupprimeCasToEficas
38 from aideAuxConvertisseurs import ListeCalculCasToEficas, DicoAvecMajuscules
39 from enumDicoTelemac2 import DicoEnumCasEn
41 from Extensions import localisation
43 from determine import monEnvQT5
49 Return a dictionary containing the description needed to load the plugin
53 'factory' : TELEMACParser
56 class TELEMACParser(PythonParser):
58 This converter works like PythonParser, except that it also initializes all
59 model variables to None in order to avoid Python syntax errors when loading
60 a file with a different or inexistent definition of variables.
63 def convert(self, outformat, appli=None):
64 self.dicoInverseFrancais=appli.readercata.dicoInverseFrancais
65 self.dicoAnglaisFrancais=appli.readercata.dicoAnglaisFrancais
66 self.dicoFrancaisAnglais=appli.readercata.dicoFrancaisAnglais
67 self.dicoMC=appli.readercata.dicoMC
68 self.Ordre_Des_Commandes=appli.readercata.Ordre_Des_Commandes
71 #print self.dicoInverseFrancais
72 #text = PythonParser.convert(self, outformat, appli)
75 l_lignes = string.split(self.text,'\n')
77 for ligne in l_lignes :
78 if pattern_comment_slash.match(ligne) : continue
79 if pattern_eta.match(ligne) : continue
80 if pattern_fin.match(ligne) : continue
81 if pattern_blanc.match(ligne) : continue
82 ligne=re.sub('\t',' ',ligne)
83 ligne=re.sub("'",' ',ligne)
84 ligne=re.sub(":",'=',ligne)
85 if ligne.count('=') != 1 :
86 print "pb avec la ligne " , ligne
89 motsInLigne=string.split(ligne,' ')
92 for mot in motsInLigne:
93 if mot == "" : continue
96 while simp[-1] == " " : simp=simp[0:-1]
97 if simp.find('-') > 0 : simp=self.redecoupeSimp(simp)
100 mot=mot.replace('_','__')
101 simp=simp+mot[0].upper() +mot[1:].lower()+'_'
102 valeur=ligne.split('=')[1]
103 self.dictSimp[simp]=valeur
108 #print self.dicoInverseFrancais
111 #print ListeCalculCasToEficas
113 if 'Titre' not in self.dictSimp.keys():
115 self.dictSimp['Titre']=os.path.basename(self.filename)
117 for simp in self.dictSimp.keys():
118 if simp in ListeSupprimeCasToEficas: continue
119 if simp in TELEMACParser.__dict__.keys() : apply(TELEMACParser.__dict__[simp],(self,))
121 for simp in self.dictSimp.keys():
122 if simp not in self.dicoInverseFrancais.keys() :
124 print "pb avec ", simp,'------'
127 listeGenea=self.dicoInverseFrancais[simp]
129 for (u,v) in listeGenea :
130 if isinstance(v,BLOC): continue
131 listeGeneaReverse.append(u)
132 listeGeneaReverse.reverse()
133 dicoTravail=dicoParMC
135 #print (listeGeneaReverse[0:-1])
136 while i < len(listeGeneaReverse[0:-1]) :
137 mot=listeGeneaReverse[i]
139 if mot not in dicoTravail.keys(): dicoTravail[mot]={}
140 dicoTravail=dicoTravail[mot]
141 dicoTravail[simp]=self.dictSimp[simp]
144 #print "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"
146 #print "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"
147 listeMC=self.tri(dicoParMC.keys())
149 print "----------- traitement de " , k
150 self.textePy += self.dicoFrancaisAnglais[k] + "("
151 self.traiteMC(dicoParMC[k])
152 self.textePy += ");\n"
159 def traiteMC(self,dico) :
160 for k in dico.keys() :
162 if k not in self.dicoMC.keys() : kA=self.dicoFrancaisAnglais[k]
165 if isinstance(obj,FACT): self.generFACT(obj,kA,valeur)
166 elif isinstance(obj,BLOC): self.generBLOC(obj,kA,valeur)
167 elif isinstance(obj,SIMP): self.generSIMP(obj,kA,valeur)
168 else : print "%%%%%%%%%%%\n", "pb generation pour", k, obj, "\n%%%%%%%%%%%"
170 #print "_____________"
172 def generFACT(self,obj,nom,valeur):
173 if nom in TELEMACParser.__dict__.keys() :
174 apply(TELEMACParser.__dict__[nom],(self,))
176 self.textePy += nom + "=_F( "
177 self.traiteMC(valeur)
178 self.textePy += '),\n'
181 def generBLOC(self,obj,nom,valeur):
185 def generSIMP(self,obj,nom,valeur):
186 if nom in ("Prescribed_Flowrates", "Prescribed_Velocities", "Prescribed_Elevations" ): return
188 if 'TXM' in obj.type :
190 while valeur[-1] == " " : valeur=valeur[0:-1]
191 while valeur[0] == " " : valeur=valeur[1:]
192 valeur=valeur[0].upper()+valeur[1:].lower()
194 try : valeur=eval(valeur,{})
196 if nom in DicoEnumCasEn.keys():
197 try : valeur=DicoEnumCasEn[nom][valeur]
199 if 'Fichier' in obj.type or 'TXM' in obj.type or 'Repertoire' in obj.type :
201 while valeur[-1] == " " : valeur=valeur[0:-1]
202 while valeur[0] == " " : valeur=valeur[1:]
203 self.textePy += nom + "= '" + str(valeur) +"' ,"
205 if bool in obj.type :
206 if pattern_OUI.match(valeur) or pattern_oui.match(valeur) : self.textePy += nom + "= True,"
207 if pattern_NON.match(valeur) or pattern_non.match(valeur) : self.textePy += nom + "= False,"
209 self.textePy += nom + "=" + str(valeur) +","
211 if pattern_vide.match(valeur) : return
212 while valeur[-1] == " " : valeur=valeur[0:-1]
213 while valeur[0] == " " : valeur=valeur[1:]
215 if ";" in valeur : valeur=valeur.split(';')
216 elif "," in valeur : valeur=valeur.split(',')
218 if valeur == None : return
223 if nom in DicoEnumCasEn.keys():
224 try : v=DicoEnumCasEn[nom][v]
227 self.textePy += nom + "=" + str(newVal) +","
232 def tri(self, listeIn):
233 if len(listeIn) == 1 : return listeIn
234 if self.Ordre_Des_Commandes == None : return listeIn
235 #print self.Ordre_Des_Commandes
236 listeOut=[listeIn[0],]
237 for kF in listeIn[1:]:
238 k=str(self.dicoFrancaisAnglais[kF])
239 ordreK=self.Ordre_Des_Commandes.index(k)
241 while i < len(listeOut):
242 ordreI=self.Ordre_Des_Commandes.index(self.dicoFrancaisAnglais[listeOut[i]])
243 if ordreK < ordreI : break
245 listeOut.insert(i,kF)
248 def Processeurs_Paralleles(self):
250 if self.dictSimp["Processeurs_Paralleles"] == 0 : del self.dictSimp["Processeurs_Paralleles"]
251 else : self.dictSimp["Parallel_Computation"]="Parallel"
254 def Option_De_Supg(self):
255 print "ds Option_De_Supg"
258 def Forme_De_La_Convection(self):
259 print "ds Forme_De_La_Convection"
262 def redecoupeSimp(self,simp):
263 # replace('-','_') uniquement dans les identifiants
264 while simp.find('-') > 0 :
266 if ind==len(simp)-1 : break
267 simp=simp[0:ind]+'_'+simp[ind+1].upper()+simp[ind+2:]
272 def Liquid_Boundaries(self):
273 texte_Boundaries="Liquid_Boundaries=( "
275 if 'Prescribed_Elevations' in self.dictSimp.keys():
276 valeurs=self.dictSimp["Prescribed_Elevations"].split(";")
277 elif 'Cotes_Imposees' in self.dictSimp.keys():
278 valeurs=self.dictSimp["Cotes_Imposees"].split(";")
280 for e in range(len(valeurs)):
281 if valeurs[e] == "" or valeurs[e] == "\n" : continue
282 if eval(valeurs[e],{})==0 : continue
283 if not premier : premier=1
284 texte_Boundaries += "_F(Type_Condition = 'Prescribed Elevations',\n"
285 texte_Boundaries += "Prescribed_Elevations = " + str(valeurs[e]) + "),\n"
287 if 'Prescribed_Flowrates' in self.dictSimp.keys():
288 valeurs=self.dictSimp["Prescribed_Flowrates"].split(";")
289 elif 'Debits_Imposes' in self.dictSimp.keys():
290 valeurs=self.dictSimp["Debits_Imposes"].split(";")
292 for e in range(len(valeurs)):
293 if valeurs[e] == "" or valeurs[e] == "\n" : continue
294 if eval(valeurs[e],{})==0 : continue
295 if not premier : premier=1
296 texte_Boundaries += "_F(Type_Condition = 'Prescribed Flowrates',\n"
297 texte_Boundaries += "Prescribed_Flowrates = " + str(valeurs[e]) + "),\n"
299 if 'Prescribed_Velocity' in self.dictSimp.keys():
300 valeurs=self.dictSimp["Prescribed_Velocity"].split(";")
301 elif 'Vitesses_Imposees' in self.dictSimp.keys():
302 valeurs=self.dictSimp["Vitesses_Imposees"].split(";")
304 for e in range(len(valeurs)):
305 if valeurs[e] == "" or valeurs[e] == "\n" : continue
306 if eval(valeurs[e],{})==0 : continue
307 if not premier : premier=1
308 texte_Boundaries += "_F(Type_Condition = 'Prescribed Velocity',\n"
309 texte_Boundaries += "Prescribed_Velocity = " + str(valeurs[e]) + "),\n"
310 if premier : texte_Boundaries +="),\n"
311 else : texte_Boundaries="" ; print "pb texte_Boundaries "
312 self.textePy += texte_Boundaries