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
21 from dictErreurs import EcritErreur
22 from dictErreurs import jdcSet
23 from renamemocle import decaleLignesdeNBlancs
24 from removemocle import removeMotCleInFact
27 #--------------------------------------------------------------------------
28 def ChangementValeur(jdc,command,motcle,DictNouvVal,liste=(),defaut=0):
29 #--------------------------------------------------------------------------
30 if command not in jdcSet : return
32 for c in jdc.root.childNodes:
33 if c.name != command : continue
35 for mc in c.childNodes:
36 if mc.name != motcle : continue
38 TexteMC=mc.getText(jdc)
39 liste_ligne_MC=TexteMC.splitlines()
40 indexLigneGlob=mc.lineno-1
42 while indexLigneGlob < mc.endline :
43 if indexTexteMC > len(liste_ligne_MC)-1 : break
44 MaLigneGlob=jdc.getLines()[indexLigneGlob]
45 MaLigneTexte=liste_ligne_MC[indexTexteMC]
46 for Valeur in DictNouvVal.keys() :
47 trouve=MaLigneTexte.find(Valeur)
49 debut=MaLigneGlob.find(motcle)
50 if debut==-1 : debut=0
51 Nouveau=MaLigneGlob[debut:].replace(Valeur,DictNouvVal[Valeur])
52 Nouveau=MaLigneGlob[0:debut]+Nouveau
53 jdc.getLines()[indexLigneGlob]=Nouveau
54 MaLigneTexte=Nouveau # raccourci honteux mais ...
57 EcritErreur((command,motcle,Valeur),indexLigneGlob)
59 logging.info("Changement de %s par %s dans %s ligne %d",Valeur,DictNouvVal[Valeur],command,indexLigneGlob)
61 indexLigneGlob=indexLigneGlob+1
62 indexTexteMC=indexTexteMC+1
63 if (trouveUnMC == 0) and ( defaut == 1):
64 EcritErreur((command,motcle,"DEFAUT"),c.lineno)
65 if boolChange : jdc.reset(jdc.getSource())
67 #--------------------------------------------------------------------------------
68 def ChangementValeurDsMCF(jdc,command,fact,motcle,DictNouvVal,liste=(),defaut=0):
69 #--------------------------------------------------------------------------------
71 if command not in jdcSet : return
73 for c in jdc.root.childNodes:
74 if c.name != command : continue
75 for mcF in c.childNodes:
76 if mcF.name != fact : continue
81 for mc in ll.childNodes:
82 if mc.name != motcle:continue
84 TexteMC=mc.getText(jdc)
85 liste_ligne_MC=TexteMC.splitlines()
86 indexLigneGlob=mc.lineno-1
88 while indexLigneGlob < mc.endline :
89 if indexTexteMC > len(liste_ligne_MC)-1 : break
90 MaLigneGlob=jdc.getLines()[indexLigneGlob]
91 MaLigneTexte=liste_ligne_MC[indexTexteMC]
92 for Valeur in DictNouvVal.keys() :
93 trouve=MaLigneTexte.find(Valeur)
95 debut=MaLigneGlob.find(motcle)
96 if debut==-1 : debut=0
97 Nouveau=MaLigneGlob[debut:].replace(Valeur,DictNouvVal[Valeur])
98 Nouveau=MaLigneGlob[0:debut]+Nouveau
99 jdc.getLines()[indexLigneGlob]=Nouveau
100 MaLigneTexte=Nouveau # raccourci honteux mais ...
103 EcritErreur((command,fact,motcle,Valeur),indexLigneGlob)
105 logging.info("Changement de %s par %s dans %s ligne %d",Valeur,DictNouvVal[Valeur],command,indexLigneGlob)
107 indexLigneGlob=indexLigneGlob+1
108 indexTexteMC=indexTexteMC+1
109 if (trouveUnMC == 0) and ( defaut == 1):
110 logging.warning("OPTION (defaut) de CALCG à verifier ligne %s" ,c.lineno )
111 EcritErreur((command,fact,motcle,"DEFAUT"),c.lineno)
112 if boolChange : jdc.reset(jdc.getSource())
114 #---------------------------------------------------------------------------------------
115 def ChangementValeurDsMCFAvecAvertissement(jdc, command, fact,motcle,DictNouvVal,liste):
116 #---------------------------------------------------------------------------------------
117 if command not in jdcSet : return
119 if liste[-1] == "defaut" :
121 ChangementValeurDsMCF(jdc,command,fact,motcle,DictNouvVal,liste,defaut)
123 #--------------------------------------------------------------------------
124 def ChangementValeurAvecAvertissement(jdc, command,motcle,DictNouvVal,liste):
125 #--------------------------------------------------------------------------
126 if command not in jdcSet : return
128 if liste[-1] == "defaut" :
130 ChangementValeur(jdc,command,motcle,DictNouvVal,liste,defaut)
132 #--------------------------------------------------------------------------
133 def SuppressionValeurs(jdc, command,motcle,liste):
134 #--------------------------------------------------------------------------
136 if command not in jdcSet : return
138 for c in jdc.root.childNodes:
139 if c.name != command : continue
140 for mc in c.childNodes:
141 if mc.name != motcle : continue
142 indexLigneGlob=mc.lineno-1
143 while indexLigneGlob < mc.endline-1 :
144 MaLigneTexte = jdc.getLines()[indexLigneGlob]
146 for Valeur in liste :
147 debutMC =MaLigne.find(motcle)
148 if debutMC ==-1 : debutMC=0
149 debut1=MaLigne[0:debutMC]
150 chercheLigne=MaLigne[debutMC:]
151 trouve=chercheLigne.find(Valeur)
153 if trouve > 1 : #on a au moins une quote
154 debut=debut1 + chercheLigne[0:trouve-1]
156 while (-1 * index) < len(debut) :
157 if (debut[index] == "(") :
164 if (debut[index] == "," ) :
166 if (debut[index] != " " ) :
169 debLigne = debut[0:index]
170 fin=trouve+len(Valeur)+1
171 if premier == 1 and chercheLigne[fin] == ',': fin = fin + 1 # on supprime la ,
172 finLigne = chercheLigne[fin:]
173 MaLigne_tmp=debLigne+finLigne
174 # Traitement ligne commancant par ,
175 if len(MaLigne_tmp.strip()) > 0 :
176 if MaLigne_tmp.strip()[0]==',' :
177 MaLigne=MaLigne_tmp.strip()[1:]
179 MaLigne=MaLigne_tmp[0:]
181 MaLigne=MaLigne_tmp[0:]
183 jdc.getLines()[indexLigneGlob]=MaLigne
184 indexLigneGlob=indexLigneGlob+1
185 if boolChange : jdc.reset(jdc.getSource())
187 #----------------------------------------------
188 def AppelleMacroSelonValeurConcept(jdc,macro,genea):
189 #----------------------------------------------
190 if macro not in jdcSet : return
195 for c in jdc.root.childNodes:
196 if c.name != macro : continue
197 for mcF in c.childNodes:
198 if mcF.name != fact : continue
203 for mc in ll.childNodes:
204 if mc.name != motcle:continue
205 TexteMC=mc.getText(jdc)
206 liste_ligne_MC=TexteMC.splitlines()
207 indexLigneGlob=mc.lineno-2
213 while indexLigneGlob < mc.endline :
214 indexLigneGlob=indexLigneGlob+1
215 MaLigneTexte=jdc.getLines()[indexLigneGlob]
217 # on commence par chercher TABLE par exemple
218 # si on ne trouve pas on passe a la ligne suivante
219 if ( trouveTexteMC == 0 ) :
220 indice=MaLigneTexte.find(motcle)
221 if indice < 0 : continue
227 aChercher=MaLigneTexte[indice:]
228 if (trouveegal == 0 ):
229 indice=aChercher.find("=")
230 if indice < 0 : continue
236 aChercher2=aChercher[indice:]
237 if (trouvechaine == 0 ):
238 indice=aChercher2.find(chaine)
239 if indice < 0 : continue
245 aChercher3=aChercher2[indice:]
246 if (trouveparent == 0 ):
247 indice=aChercher3.find('(')
248 if indice < 0 : continue
254 aChercher4=aChercher3[indice:]
255 if (trouvequote == 0 ):
256 indice=aChercher4.find("'")
257 indice2=aChercher4.find('"')
258 if (indice < 0) and (indice2 < 0): continue
259 if (indice < 0) : indice=indice2
265 aChercher5=aChercher4[indice+1:]
266 indice=aChercher5.find("'")
267 if indice < 0 : indice=aChercher5.find('"')
268 valeur=aChercher5[:indice]
272 logging.error("Pb de traduction pour MACR_LIGNE_COUPE : Pas de nom de Concept identifiable")
276 jdc.reset(jdc.getSource())
277 logging.error("Pb du traduction pour MACR_LIGNE_COUPE : Deux noms de Concept possibles")
281 ligneaTraiter=jdc.getLines()[c.lineno-1]
282 debut=ligneaTraiter[0:c.colno]
284 fin=ligneaTraiter[c.colno:]
285 ligne=debut+suite+fin
286 jdc.getLines()[c.lineno-1]=ligne
287 nbBlanc=len(valeur)+1
288 if c.lineno < c.endline:
289 decaleLignesdeNBlancs(jdc,c.lineno,c.endline-1,nbBlanc)
290 if boolChange : jdc.reset(jdc.getSource())
292 #----------------------------------------------
293 def ChangeTouteValeur(jdc,command,motcle,DictNouvVal,liste=(),defaut=0):
294 #----------------------------------------------
295 if macro not in jdcSet : return