1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2007-2012 EDF R&D
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.
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.
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
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 from Traducteur.utils import lineToDict
22 from Traducteur.dictErreurs import EcritErreur
23 from Traducteur.load import jdcSet
24 from Traducteur.renamemocle import decaleLignesdeNBlancs
25 from Traducteur.removemocle import removeMotCleInFact
26 from Traducteur import regles
29 #--------------------------------------------------------------------------
30 def ChangementValeur(jdc,command,motcle,DictNouvVal,liste=(),defaut=0):
31 #--------------------------------------------------------------------------
32 if command not in jdcSet : return
34 for c in jdc.root.childNodes:
35 if c.name != command : continue
37 for mc in c.childNodes:
38 if mc.name != motcle : continue
40 TexteMC=mc.getText(jdc)
41 liste_ligne_MC=TexteMC.splitlines()
42 indexLigneGlob=mc.lineno-1
44 while indexLigneGlob < mc.endline :
45 if indexTexteMC > len(liste_ligne_MC)-1 : break
46 MaLigneGlob=jdc.getLines()[indexLigneGlob]
47 MaLigneTexte=liste_ligne_MC[indexTexteMC]
48 for Valeur in DictNouvVal.keys() :
49 MaLigneTexteDict=lineToDict(MaLigneTexte)
50 trouvecol=MaLigneTexte.find(Valeur)
52 trouve=(Valeur==MaLigneTexteDict[trouvecol])
56 debut=MaLigneGlob.find(motcle)
57 if debut==-1 : debut=0
58 Nouveau=MaLigneGlob[debut:].replace(Valeur,DictNouvVal[Valeur])
59 Nouveau=MaLigneGlob[0:debut]+Nouveau
60 jdc.getLines()[indexLigneGlob]=Nouveau
61 MaLigneTexte=Nouveau # raccourci honteux mais ...
64 EcritErreur((command,motcle,Valeur),indexLigneGlob)
66 logging.info("Changement de %s par %s dans %s ligne %d",Valeur,DictNouvVal[Valeur],command,indexLigneGlob)
68 indexLigneGlob=indexLigneGlob+1
69 indexTexteMC=indexTexteMC+1
70 if (trouveUnMC == 0) and ( defaut == 1):
71 EcritErreur((command,motcle,"DEFAUT"),c.lineno)
72 if boolChange : jdc.reset(jdc.getSource())
74 #--------------------------------------------------------------------------------
75 def ChangementValeurDsMCF(jdc,command,fact,motcle,DictNouvVal,liste=(),ensemble=regles.SansRegle,defaut=0):
76 #--------------------------------------------------------------------------------
78 if command not in jdcSet : return
80 for c in jdc.root.childNodes:
81 if c.name != command : continue
82 for mcF in c.childNodes:
83 if mcF.name != fact : continue
88 for mc in ll.childNodes:
89 if mc.name != motcle:continue
90 if ensemble.verif(c) == 0 : continue
92 TexteMC=mc.getText(jdc)
93 liste_ligne_MC=TexteMC.splitlines()
94 indexLigneGlob=mc.lineno-1
96 while indexLigneGlob < mc.endline :
97 if indexTexteMC > len(liste_ligne_MC)-1 : break
98 MaLigneGlob=jdc.getLines()[indexLigneGlob]
99 MaLigneTexte=liste_ligne_MC[indexTexteMC]
100 for Valeur in DictNouvVal.keys() :
101 MaLigneTexteDict=lineToDict(MaLigneTexte)
102 trouvecol=MaLigneTexte.find(Valeur)
104 trouve=(Valeur==MaLigneTexteDict[trouvecol])
108 debut=MaLigneGlob.find(motcle)
109 if debut==-1 : debut=0
110 Nouveau=MaLigneGlob[debut:].replace(Valeur,DictNouvVal[Valeur])
111 Nouveau=MaLigneGlob[0:debut]+Nouveau
112 jdc.getLines()[indexLigneGlob]=Nouveau
113 MaLigneTexte=Nouveau # raccourci honteux mais ...
116 EcritErreur((command,fact,motcle,Valeur),indexLigneGlob)
118 logging.info("Changement de %s par %s dans %s ligne %d",Valeur,DictNouvVal[Valeur],command,indexLigneGlob)
120 indexLigneGlob=indexLigneGlob+1
121 indexTexteMC=indexTexteMC+1
122 if (trouveUnMC == 0) and ( defaut == 1):
123 logging.warning("OPTION (defaut) de CALCG à verifier ligne %s" ,c.lineno )
124 EcritErreur((command,fact,motcle,"DEFAUT"),c.lineno)
125 if boolChange : jdc.reset(jdc.getSource())
127 #--------------------------------------------------------------------------------
128 def ChangementValeurDsMCFSiRegle(jdc,command,fact,motcle,DictNouvVal,liste_regles,defaut=0):
129 #--------------------------------------------------------------------------------
130 if command not in jdcSet : return
131 mesRegles=regles.ensembleRegles(liste_regles)
133 ChangementValeurDsMCF(jdc,command,fact,motcle,DictNouvVal,liste,mesRegles,defaut)
135 #---------------------------------------------------------------------------------------
136 def ChangementValeurDsMCFAvecAvertissement(jdc, command, fact,motcle,DictNouvVal,liste):
137 #---------------------------------------------------------------------------------------
138 if command not in jdcSet : return
140 if liste[-1] == "defaut" :
142 ChangementValeurDsMCF(jdc,command,fact,motcle,DictNouvVal,liste,defaut)
144 #--------------------------------------------------------------------------
145 def ChangementValeurAvecAvertissement(jdc, command,motcle,DictNouvVal,liste):
146 #--------------------------------------------------------------------------
147 if command not in jdcSet : return
149 if liste[-1] == "defaut" :
151 ChangementValeur(jdc,command,motcle,DictNouvVal,liste,defaut)
153 #--------------------------------------------------------------------------
154 def SuppressionValeurs(jdc, command,motcle,liste):
155 #--------------------------------------------------------------------------
157 if command not in jdcSet : return
159 for c in jdc.root.childNodes:
160 if c.name != command : continue
161 for mc in c.childNodes:
162 if mc.name != motcle : continue
163 indexLigneGlob=mc.lineno-1
164 while indexLigneGlob < mc.endline-1 :
165 MaLigneTexte = jdc.getLines()[indexLigneGlob]
167 for Valeur in liste :
168 debutMC =MaLigne.find(motcle)
169 if debutMC ==-1 : debutMC=0
170 debut1=MaLigne[0:debutMC]
171 chercheLigne=MaLigne[debutMC:]
172 trouve=chercheLigne.find(Valeur)
174 if trouve > 1 : #on a au moins une quote
175 debut=debut1 + chercheLigne[0:trouve-1]
177 while (-1 * index) < len(debut) :
178 if (debut[index] == "(") :
185 if (debut[index] == "," ) :
187 if (debut[index] != " " ) :
190 debLigne = debut[0:index]
191 fin=trouve+len(Valeur)+1
192 if premier == 1 and chercheLigne[fin] == ',': fin = fin + 1 # on supprime la ,
193 finLigne = chercheLigne[fin:]
194 MaLigne_tmp=debLigne+finLigne
195 # Traitement ligne commancant par ,
196 if len(MaLigne_tmp.strip()) > 0 :
197 if MaLigne_tmp.strip()[0]==',' :
198 MaLigne=MaLigne_tmp.strip()[1:]
200 MaLigne=MaLigne_tmp[0:]
202 MaLigne=MaLigne_tmp[0:]
204 jdc.getLines()[indexLigneGlob]=MaLigne
205 indexLigneGlob=indexLigneGlob+1
206 if boolChange : jdc.reset(jdc.getSource())
208 #----------------------------------------------
209 def AppelleMacroSelonValeurConcept(jdc,macro,genea):
210 #----------------------------------------------
211 if macro not in jdcSet : return
216 for c in jdc.root.childNodes:
217 if c.name != macro : continue
218 for mcF in c.childNodes:
219 if mcF.name != fact : continue
224 for mc in ll.childNodes:
225 if mc.name != motcle:continue
226 TexteMC=mc.getText(jdc)
227 liste_ligne_MC=TexteMC.splitlines()
228 indexLigneGlob=mc.lineno-2
234 while indexLigneGlob < mc.endline :
235 indexLigneGlob=indexLigneGlob+1
236 MaLigneTexte=jdc.getLines()[indexLigneGlob]
238 # on commence par chercher TABLE par exemple
239 # si on ne trouve pas on passe a la ligne suivante
240 if ( trouveTexteMC == 0 ) :
241 indice=MaLigneTexte.find(motcle)
242 if indice < 0 : continue
248 aChercher=MaLigneTexte[indice:]
249 if (trouveegal == 0 ):
250 indice=aChercher.find("=")
251 if indice < 0 : continue
257 aChercher2=aChercher[indice:]
258 if (trouvechaine == 0 ):
259 indice=aChercher2.find(chaine)
260 if indice < 0 : continue
266 aChercher3=aChercher2[indice:]
267 if (trouveparent == 0 ):
268 indice=aChercher3.find('(')
269 if indice < 0 : continue
275 aChercher4=aChercher3[indice:]
276 if (trouvequote == 0 ):
277 indice=aChercher4.find("'")
278 indice2=aChercher4.find('"')
279 if (indice < 0) and (indice2 < 0): continue
280 if (indice < 0) : indice=indice2
286 aChercher5=aChercher4[indice+1:]
287 indice=aChercher5.find("'")
288 if indice < 0 : indice=aChercher5.find('"')
289 valeur=aChercher5[:indice]
293 logging.error("Pb de traduction pour MACR_LIGNE_COUPE : Pas de nom de Concept identifiable")
297 jdc.reset(jdc.getSource())
298 logging.error("Pb du traduction pour MACR_LIGNE_COUPE : Deux noms de Concept possibles")
302 ligneaTraiter=jdc.getLines()[c.lineno-1]
303 debut=ligneaTraiter[0:c.colno]
305 fin=ligneaTraiter[c.colno:]
306 ligne=debut+suite+fin
307 jdc.getLines()[c.lineno-1]=ligne
308 nbBlanc=len(valeur)+1
309 if c.lineno < c.endline:
310 decaleLignesdeNBlancs(jdc,c.lineno,c.endline-1,nbBlanc)
311 if boolChange : jdc.reset(jdc.getSource())
313 #----------------------------------------------
314 def ChangeTouteValeur(jdc,command,motcle,DictNouvVal,liste=(),defaut=0):
315 #----------------------------------------------
316 if macro not in jdcSet : return