1 # CONFIGURATION MANAGEMENT OF EDF VERSION
2 # ======================================================================
3 # COPYRIGHT (C) 1991 - 2002 EDF R&D WWW.CODE-ASTER.ORG
4 # THIS PROGRAM IS FREE SOFTWARE; YOU CAN REDISTRIBUTE IT AND/OR MODIFY
5 # IT UNDER THE TERMS OF THE GNU GENERAL PUBLIC LICENSE AS PUBLISHED BY
6 # THE FREE SOFTWARE FOUNDATION; EITHER VERSION 2 OF THE LICENSE, OR
7 # (AT YOUR OPTION) ANY LATER VERSION.
9 # THIS PROGRAM IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL, BUT
10 # WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF
11 # MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. SEE THE GNU
12 # GENERAL PUBLIC LICENSE FOR MORE DETAILS.
14 # YOU SHOULD HAVE RECEIVED A COPY OF THE GNU GENERAL PUBLIC LICENSE
15 # ALONG WITH THIS PROGRAM; IF NOT, WRITE TO EDF R&D CODE_ASTER,
16 # 1 AVENUE DU GENERAL DE GAULLE, 92141 CLAMART CEDEX, FRANCE.
19 # ======================================================================
23 from tables import ERRORS
26 __version__="$Name: $"
27 __Id__="$Id: conv.py,v 1.1.1.1 2002/03/26 09:08:45 eficas Exp $"
30 Keywords=('MAILLE_1','MAILLE_2','MAILLE_ESCL','MAILLE_FOND','MAILLE_MAIT','MAILLE_ORIG','MAILLE',
31 'NOEUD', 'NOEUD_1','NOEUD_2','NOEUD_INIT','NOEUD_FIN', 'NOEUD_ORIG','NOEUD_REFE','NOEUD_EXTR',
32 'NOEUD_I', 'NOEUD_J','NOEUD_CHOC','NOEUD_ANCRAGE','NOEUD_CENTRE','NOEUD_CMP','NOEUD_DOUBLE',
33 'NOEUD_ESCL','NOEUD_FOND','NOEUD_PARA','NOEUD_POIN_TANG',
34 'GROUP_MA', 'GROUP_MA_1','GROUP_MA_2','GROUP_MA_INT','GROUP_MA_EXT', 'GROUP_MA_ORIG',
35 'GROUP_MA_BORD','GROUP_MA_INTE','GROUP_MA_FLUIDE', 'GROUP_MA_INTERF','GROUP_MA_BETON',
36 'GROUP_MA_ESCL','GROUP_MA_FINAL','GROUP_MA_FLU_SOL','GROUP_MA_FLU_STR','GROUP_MA_FOND',
37 'GROUP_MA_MAIT','GROUP_MA_RADIER','GROUP_MA_SOL_SOL','GROUP_MA_INIT',
38 'GROUP_NO', 'GROUP_NO_1','GROUP_NO_2','GROUP_NO_EXT', 'GROUP_NO_ORIG','GROUP_NO_CHOC',
39 'GROUP_NO_ANCRAGE','GROUP_NO_CENTRE','GROUP_NO_ESCL','GROUP_NO_EXTR','GROUP_NO_FIN',
40 'GROUP_NO_FOND','GROUP_NO_INIT','GROUP_NO_POIN_TG','GROUP_NO_RADIER',
42 'SANS_NOEUD', 'SANS_GROUP_NO',
43 'INTERSEC', 'UNION','DIFFE',
44 'VECT_GRNO_ORIG','VECT_GRNO_EXTR',
48 liste_macros=('MACRO_MATR_ASSE','MACRO_ELAS_MULT','MACR_ASCOUF_MAIL','MACR_ASCOUF_CALC','MACR_ASPIC_MAIL',
49 'MACR_ASPIC_CALC','MACRO_MATR_AJOU','MACRO_ELAS_MULT','MACRO_MODE_MECA','MACRO_PROJ_BASE',
52 liste_concepts_produits=[]
55 def text_nom_ope(text,tags,left,right):
56 global commande_courante
58 tag,l,r,subtags=tags[0]
59 commande_courante=text[left:l]
60 return text[left:l]+'('+text[l:r]
62 commande_courante=text[left:right]
63 return text[left:right]+'('
65 def text_reuse(text,tags):
67 for tag,l,r,subtags in tags:
71 elif tag == 'nom_ope' : s=s+ '='+text_nom_ope(text,subtags,l,r)
73 s=s+ '='+text_affe(text,subtags)
75 if commande_courante in liste_macros:
76 s=s+'reuse='+sd+','+text_macro(text,subtags)+')'
78 s=s+'reuse='+sd+','+text_com(text,subtags)+')'
83 def text_noreuse(text,tags):
84 global commande_courante
86 for tag,l,r,subtags in tags:
90 elif tag == 'nom_ope' :
91 s=s+ '='+ text_nom_ope(text,subtags,l,r)
93 liste_concepts_produits.append(sd)
94 s=s+ '='+text_affe(text,subtags)
97 if sd in liste_macros:
98 s=s+'('+text_macro(text,subtags)+')'
100 s=s+'('+text_com(text,subtags)+')'
102 liste_concepts_produits.append(sd)
103 if commande_courante in liste_macros:
104 s=s+text_macro(text,subtags)+')'
106 s=s+text_com(text,subtags)+')'
112 def list_mc(lmc,mcs):
122 s=s+string.join((c,va,','),'')
127 def text_com(text,tags):
132 for tag,l,r,subtags in tags:
135 if not mcs.has_key(currid):
139 ll=text_mcf(text,subtags)
140 mcs[currid].append((ll,comment))
143 a=string.replace(text[l:r],'D','E')
144 mcs[currid].append((a,comment))
147 a=text_cplx(text,text[l:r],subtags)
148 mcs[currid].append((a,comment))
152 if currid in Keywords :
153 # FR : (SGDG) il faut tester s'il n'y a pas déjà des cotes !!!
154 if text[l]!="'" and text[r-1]!="'":
155 a=a+"'"+text[l:r]+"'"
160 mcs[currid].append((a,comment))
163 a=text_eval(text,subtags)
164 mcs[currid].append((a,comment))
166 elif tag == 'comment' :
167 comment=comment + '#'+text[l+1:r]
168 elif tag == 'comments' :
169 comment=comment + text[l:r]
171 if currid in Keywords:mcs[currid].append((text_larg2(text,subtags),comment))
172 else:mcs[currid].append((text_larg(text,subtags),comment))
176 if comment :s=s+comment
179 def text_macro(text,tags):
184 for tag,l,r,subtags in tags:
187 if not mcs.has_key(currid):
191 ll=text_macro_mcf(text,subtags)
192 mcs[currid].append((ll,comment))
195 a=string.replace(text[l:r],'D','E')
196 mcs[currid].append((a,comment))
199 a=text_cplx(text,text[l:r],subtags)
200 mcs[currid].append((a,comment))
205 # FR : (SGDG) il faut tester s'il n'y a pas déjà des cotes !!!
207 elif currid in Keywords :
208 a=a+"'"+text[l:r]+"'"
211 if sd not in liste_concepts_produits:
212 # Il s agit d un concept produit par la macro mais situe à droite de =
214 liste_concepts_produits.append(sd)
217 mcs[currid].append((a,comment))
220 a=text_eval(text,subtags)
221 mcs[currid].append((a,comment))
223 elif tag == 'comment' :
224 comment=comment + '#'+text[l+1:r]
225 elif tag == 'comments' :
226 comment=comment + text[l:r]
228 if currid in Keywords:mcs[currid].append((text_larg2(text,subtags),comment))
229 else:mcs[currid].append((text_larg(text,subtags),comment))
233 if comment :s=s+comment
236 def comments_text(text):
237 l=string.replace(text,'%','#')
240 def text_eval(text,tags):
241 # on retourne l expression sans conversion dans un objet EVAL et entre quotes
242 for tag,l,r,subtags in tags:
244 s='EVAL("""'+text[l:r]+'""")'
248 def text_mcf(text,tags):
251 for tag,l,r,subtags in tags:
258 if currid in Keywords :
259 # FR : (SGDG) il faut tester s'il n'y a pas déjà des cotes !!!
260 if text[l]!="'" and text[r-1]!="'":
261 s=s+"'"+text[l:r]+"',"
264 else:s=s+text[l:r]+","
266 s=s+string.replace(text[l:r],'D','E')+','
268 s=s+text_cplx(text,text[l:r],subtags)+','
270 s=s+text_eval(text,subtags)+','
272 if currid in Keywords:s=s+text_larg2(text,subtags)+','
273 else: s=s+text_larg(text,subtags)+','
274 elif tag == 'comments' :
275 comment=comment+text[l:r]
280 def text_macro_mcf(text,tags):
283 for tag,l,r,subtags in tags:
290 # FR : (SGDG) il faut tester s'il n'y a pas déjà des cotes !!!
292 elif currid in Keywords :
293 s=s+"'"+text[l:r]+"',"
296 if sd not in liste_concepts_produits:
297 # Il s agit d un concept produit par la macro mais situe à droite de =
299 liste_concepts_produits.append(sd)
304 s=s+string.replace(text[l:r],'D','E')+','
306 s=s+text_cplx(text,text[l:r],subtags)+','
309 s=s+text_eval(text,subtags)+','
312 if currid in Keywords:s=s+text_larg2(text,subtags)+','
313 else: s=s+text_larg(text,subtags)+','
315 elif tag == 'comments' :
316 comment=comment+text[l:r]
319 def text_cplx(texte,text,tags):
320 """ Retourne une chaîne de caractères représentant un complexe """
321 s="('"+text[0:2]+"'," #text[0:2] = RI ou MP
322 for tag,l,r,subtags in tags:
324 s=s+string.replace(texte[l:r],'D','E')+','
328 def text_larg2(text,tags):
329 """ Pareil que text_larg mais ajoute des cotes autour des arg """
331 for tag,l,r,subtags in tags:
333 # FR : (SGDG) il faut tester le cas où les cotes sont déjà là !!!!
334 if text[l] != "'" and text[r-1] != "'":
335 ll.append( "'"+text[l:r]+"',")
337 ll.append(text[l:r]+",")
339 ll.append(string.replace(text[l:r],'D','E')+',')
341 ll.append(text_cplx(text,text[l:r],subtags)+',')
342 elif tag == 'comments' :
344 return '('+string.join(ll,'')+')'
346 def text_larg(text,tags):
347 # Pour les listes d arguments il semble plus rapide de construire
348 # une liste puis de faire join (ne pas exagerer : voir ajout ,)
350 for tag,l,r,subtags in tags:
352 ll.append((text,l,r))
355 # cette facon de faire est un peu plus rapide que la suivante
356 ll.append(string.replace(text[l:r],'D','E')+',')
357 elif tag == 'comments' :
358 ll.append((text,l,r))
360 ll.append(text_eval(text,subtags)+',')
362 print "Argument ignore: ",text[l:r]
363 return '('+TextTools.join(ll,'')+')'
365 def comment_text(text):
366 l=string.replace(text,'\n','\n#')
367 if l[-1]=='#':return '#'+l[:-1]
370 def text_affe(text,tags):
372 for tag,l,r,subtags in tags:
376 s=s+text_eval(text,subtags)
378 s=s+text_larg(text,subtags)
380 s=s+string.replace(text[l:r],'D','E')
382 s=s+text_cplx(text,text[l:r],subtags)+','
385 def text_commande(text,tags):
387 Convertit une taglist de type commande en une chaine de caracteres
388 à la syntaxe Python représentative d'une commande
391 for tag,l,r,subtags in tags:
393 s=s+text_noreuse(text,subtags)
394 elif tag == 'reuse':s=s+text_reuse(text,subtags)
397 def text_formule(text,tags):
399 Convertit une taglist de type formule en une chaine de caracteres
400 à la syntaxe Python représentative d'une formule
405 for tag,l,r,subtags in tags:
408 s=text[l:r]+' = FORMULE('+ty+'="""('
417 s=s+ ') =\n'+text[l:r]
422 def text_comms(text,tags):
424 Convertit une taglist resultat d'un appel à TextTools.tag avec une table de type Aster
425 en une chaine de caracteres à la syntaxe Python
427 # On met la liste globale des concepts produits à zero
428 global liste_concepts_produits
429 liste_concepts_produits=[]
432 for tag,l,r,subtags in tags:
437 elif tag == 'formule':
438 s=s+ text_formule(text,subtags)
439 elif tag == 'commande' :
440 s=s+text_commande(text,subtags)
442 s=s+ comment_text(text[l:r])
445 def format_errs(text,tags):
448 for tag,l,r,subtags in tags:
450 err,warn=format_errs(text,subtags)
452 warnings=warnings+warn
454 s=s+ tag+" ligne : "+`TextTools.countlines(text[:l])`+" texte erroné : "+text[l-10:l]+'?'+text[l:r]+'\n'
455 if tag == 'passline':
456 warnings=warnings+ " ligne "+`TextTools.countlines(text[:l])`+" ignorée : " +text[l:r]+'\n'
460 from tables import aster_script
462 text=string.upper(text)
463 result, taglist, next = TextTools.tag(text,aster_script)
464 # Pour vérifier les résultats intermédiaires décommenter la ligne suivante
465 #TextTools.print_tags(text,taglist)
466 text=string.replace(text,'%','#')
467 s_errors,warnings = format_errs(text,taglist)
469 return None,s_errors,warnings
471 ss=text_comms(text,taglist)
472 return string.replace(ss,'\r\n','\n'),s_errors,warnings