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 *")
36 from aideAuxConvertisseurs import DicoEficasToCas, ListeSupprimeCasToEficas
37 from aideAuxConvertisseurs import ListeCalculCasToEficas, DicoAvecMajuscules
38 from enumDicoTelemac import DicoEnumCasEn
40 from Extensions import localisation
42 from determine import monEnvQT5
48 Return a dictionary containing the description needed to load the plugin
52 'factory' : TELEMACParser
55 class TELEMACParser(PythonParser):
57 This converter works like PythonParser, except that it also initializes all
58 model variables to None in order to avoid Python syntax errors when loading
59 a file with a different or inexistent definition of variables.
62 def convert(self, outformat, appli=None):
63 self.dicoInverseFrancais=appli.readercata.dicoInverseFrancais
64 self.dicoAnglaisFrancais=appli.readercata.dicoAnglaisFrancais
65 self.dicoFrancaisAnglais=appli.readercata.dicoFrancaisAnglais
66 self.dicoMC=appli.readercata.dicoMC
67 self.Ordre_Des_Commandes=appli.readercata.Ordre_Des_Commandes
70 #print self.dicoInverseFrancais
71 #text = PythonParser.convert(self, outformat, appli)
74 l_lignes = string.split(self.text,'\n')
76 for ligne in l_lignes :
77 if pattern_comment_slash.match(ligne) : continue
78 if pattern_eta.match(ligne) : continue
79 if pattern_fin.match(ligne) : continue
80 if pattern_blanc.match(ligne) : continue
81 ligne=re.sub('\t',' ',ligne)
82 ligne=re.sub("'",' ',ligne)
83 ligne=re.sub(":",'=',ligne)
84 if ligne.count('=') != 1 :
85 print "pb avec la ligne " , ligne
88 motsInLigne=string.split(ligne,' ')
91 for mot in motsInLigne:
92 if mot == "" : continue
95 while simp[-1] == " " : simp=simp[0:-1]
96 if simp.find('-') > 0 : simp=self.redecoupeSimp(simp)
99 mot=mot.replace('_','__')
100 simp=simp+mot[0].upper() +mot[1:].lower()+'_'
101 valeur=ligne.split('=')[1]
102 self.dictSimp[simp]=valeur
107 #print self.dicoInverseFrancais
110 #print ListeCalculCasToEficas
112 if 'Titre' not in self.dictSimp.keys():
114 self.dictSimp['Titre']=os.path.basename(self.filename)
116 for simp in self.dictSimp.keys():
117 if simp in ListeSupprimeCasToEficas: continue
118 if simp in TELEMACParser.__dict__.keys() : apply(TELEMACParser.__dict__[simp],(self,))
120 for simp in self.dictSimp.keys():
121 if simp not in self.dicoInverseFrancais.keys() :
123 print "pb avec ", simp,'------'
126 listeGenea=self.dicoInverseFrancais[simp]
128 for (u,v) in listeGenea :
129 if isinstance(v,BLOC): continue
130 listeGeneaReverse.append(u)
131 listeGeneaReverse.reverse()
132 dicoTravail=dicoParMC
134 #print (listeGeneaReverse[0:-1])
135 while i < len(listeGeneaReverse[0:-1]) :
136 mot=listeGeneaReverse[i]
138 if mot not in dicoTravail.keys(): dicoTravail[mot]={}
139 dicoTravail=dicoTravail[mot]
140 dicoTravail[simp]=self.dictSimp[simp]
143 #print "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"
145 #print "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"
146 listeMC=self.tri(dicoParMC.keys())
148 print "----------- traitement de " , k
149 self.textePy += self.dicoFrancaisAnglais[k] + "("
150 self.traiteMC(dicoParMC[k])
151 self.textePy += ");\n"
158 def traiteMC(self,dico) :
159 for k in dico.keys() :
161 if k not in self.dicoMC.keys() : kA=self.dicoFrancaisAnglais[k]
164 if isinstance(obj,FACT): self.generFACT(obj,kA,valeur)
165 elif isinstance(obj,BLOC): self.generBLOC(obj,kA,valeur)
166 elif isinstance(obj,SIMP): self.generSIMP(obj,kA,valeur)
167 else : print "%%%%%%%%%%%\n", "pb generation pour", k, obj, "\n%%%%%%%%%%%"
169 #print "_____________"
171 def generFACT(self,obj,nom,valeur):
172 if nom in TELEMACParser.__dict__.keys() :
173 apply(TELEMACParser.__dict__[nom],(self,))
175 self.textePy += nom + "=_F( "
176 self.traiteMC(valeur)
177 self.textePy += '),\n'
180 def generBLOC(self,obj,nom,valeur):
184 def generSIMP(self,obj,nom,valeur):
185 if nom in ("Prescribed_Flowrates", "Prescribed_Velocities", "Prescribed_Elevations" ): return
187 if 'TXM' in obj.type :
189 while valeur[-1] == " " : valeur=valeur[0:-1]
190 while valeur[0] == " " : valeur=valeur[1:]
191 valeur=valeur[0].upper()+valeur[1:].lower()
193 if 'Fichier' in obj.type or 'TXM' in obj.type or 'Repertoire' in obj.type :
195 while valeur[-1] == " " : valeur=valeur[0:-1]
196 while valeur[0] == " " : valeur=valeur[1:]
197 self.textePy += nom + "= '" + str(valeur) +"' ,"
199 if bool in obj.type :
200 if pattern_OUI.match(valeur) or pattern_oui.match(valeur) : self.textePy += nom + "= True,"
201 if pattern_NON.match(valeur) or pattern_non.match(valeur) : self.textePy += nom + "= False,"
203 if nom in DicoEnumCasEn.keys():
204 valeur=DicoEnumCasEn[nom][valeur]
205 self.textePy += nom + "=" + str(valeur) +","
209 def tri(self, listeIn):
210 if len(listeIn) == 1 : return listeIn
211 if self.Ordre_Des_Commandes == None : return listeIn
212 #print self.Ordre_Des_Commandes
213 listeOut=[listeIn[0],]
214 for kF in listeIn[1:]:
215 k=str(self.dicoFrancaisAnglais[kF])
216 ordreK=self.Ordre_Des_Commandes.index(k)
218 while i < len(listeOut):
219 ordreI=self.Ordre_Des_Commandes.index(self.dicoFrancaisAnglais[listeOut[i]])
220 if ordreK < ordreI : break
222 listeOut.insert(i,kF)
225 def Processeurs_Paralleles(self):
227 if self.dictSimp["Processeurs_Paralleles"] == 0 : del self.dictSimp["Processeurs_Paralleles"]
228 else : self.dictSimp["Parallel_Computation"]="Parallel"
231 def Option_De_Supg(self):
232 print "ds Option_De_Supg"
235 def Forme_De_La_Convection(self):
236 print "ds Forme_De_La_Convection"
239 def redecoupeSimp(self,simp):
240 # replace('-','_') uniquement dans les identifiants
241 while simp.find('-') > 0 :
243 if ind==len(simp)-1 : break
244 simp=simp[0:ind]+'_'+simp[ind+1].upper()+simp[ind+2:]
249 def Liquid_Boundaries(self):
250 texte_Boundaries="Liquid_Boundaries=( "
252 if 'Prescribed_Elevations' in self.dictSimp.keys():
253 valeurs=self.dictSimp["Prescribed_Elevations"].split(";")
254 elif 'Cotes_Imposees' in self.dictSimp.keys():
255 valeurs=self.dictSimp["Cotes_Imposees"].split(";")
257 for e in range(len(valeurs)):
258 if valeurs[e] == "" or valeurs[e] == "\n" : continue
259 if eval(valeurs[e],{})==0 : continue
260 if not premier : premier=1
261 texte_Boundaries += "_F(Type_Condition = 'Prescribed Elevations',\n"
262 texte_Boundaries += "Prescribed_Elevations = " + str(valeurs[e]) + "),\n"
264 if 'Prescribed_Flowrates' in self.dictSimp.keys():
265 valeurs=self.dictSimp["Prescribed_Flowrates"].split(";")
266 elif 'Debits_Imposes' in self.dictSimp.keys():
267 valeurs=self.dictSimp["Debits_Imposes"].split(";")
269 for e in range(len(valeurs)):
270 if valeurs[e] == "" or valeurs[e] == "\n" : continue
271 if eval(valeurs[e],{})==0 : continue
272 if not premier : premier=1
273 texte_Boundaries += "_F(Type_Condition = 'Prescribed Flowrates',\n"
274 texte_Boundaries += "Prescribed_Flowrates = " + str(valeurs[e]) + "),\n"
276 if 'Prescribed_Velocity' in self.dictSimp.keys():
277 valeurs=self.dictSimp["Prescribed_Velocity"].split(";")
278 elif 'Vitesses_Imposees' in self.dictSimp.keys():
279 valeurs=self.dictSimp["Vitesses_Imposees"].split(";")
281 for e in range(len(valeurs)):
282 if valeurs[e] == "" or valeurs[e] == "\n" : continue
283 if eval(valeurs[e],{})==0 : continue
284 if not premier : premier=1
285 texte_Boundaries += "_F(Type_Condition = 'Prescribed Velocity',\n"
286 texte_Boundaries += "Prescribed_Velocity = " + str(valeurs[e]) + "),\n"
287 if premier : texte_Boundaries +="),\n"
288 else : texte_Boundaries="" ; print "pb texte_Boundaries "
289 self.textePy += texte_Boundaries