]> SALOME platform Git repositories - tools/eficas.git/blob - Traducteur/changeValeur.py
Salome HOME
CCAR: rabattre la version V1_15a4 dans la branche principale
[tools/eficas.git] / Traducteur / changeValeur.py
1 # -*- coding: utf-8 -*-
2 import logging
3 from dictErreurs import EcritErreur
4 from dictErreurs import jdcSet
5 from renamemocle import decaleLignesdeNBlancs
6 from removemocle import removeMotCleInFact
7
8
9 #--------------------------------------------------------------------------
10 def ChangementValeur(jdc,command,motcle,DictNouvVal,liste=(),defaut=0):
11 #--------------------------------------------------------------------------
12     if command  not in jdcSet : return
13     boolChange=0
14     for c in jdc.root.childNodes:
15        if c.name != command  : continue
16        trouveUnMC=0
17        for mc in c.childNodes:
18           if mc.name != motcle : continue
19           trouveUnMC=1
20           TexteMC=mc.getText(jdc)
21           liste_ligne_MC=TexteMC.splitlines()
22           indexLigneGlob=mc.lineno-1
23           indexTexteMC=0
24           while indexLigneGlob < mc.endline  :
25              if indexTexteMC > len(liste_ligne_MC)-1 : break
26              MaLigneGlob=jdc.getLines()[indexLigneGlob]
27              MaLigneTexte=liste_ligne_MC[indexTexteMC]
28              for Valeur in DictNouvVal.keys() :
29                 trouve=MaLigneTexte.find(Valeur)
30                 if trouve > -1 :
31                    debut=MaLigneGlob.find(motcle)
32                    if debut==-1 : debut=0
33                    Nouveau=MaLigneGlob[debut:].replace(Valeur,DictNouvVal[Valeur])
34                    Nouveau=MaLigneGlob[0:debut]+Nouveau
35                    jdc.getLines()[indexLigneGlob]=Nouveau
36                    MaLigneTexte=Nouveau # raccourci honteux mais ...
37                    MaLigneGlob=Nouveau
38                    if Valeur in liste :
39                       EcritErreur((command,motcle,Valeur),indexLigneGlob)
40                    else :
41                       logging.info("Changement de %s par %s dans %s ligne %d",Valeur,DictNouvVal[Valeur],command,indexLigneGlob)
42                    boolChange=1
43              indexLigneGlob=indexLigneGlob+1
44              indexTexteMC=indexTexteMC+1
45        if (trouveUnMC == 0) and ( defaut == 1):
46           EcritErreur((command,motcle,"DEFAUT"),c.lineno)
47     if boolChange : jdc.reset(jdc.getSource())
48              
49 #--------------------------------------------------------------------------------
50 def ChangementValeurDsMCF(jdc,command,fact,motcle,DictNouvVal,liste=(),defaut=0):
51 #--------------------------------------------------------------------------------
52
53     if command  not in jdcSet : return
54     boolChange=0
55     for c in jdc.root.childNodes:
56        if c.name != command  : continue
57        for mcF in c.childNodes:
58           if mcF.name != fact : continue
59           l=mcF.childNodes[:]
60           l.reverse()
61           for ll in l:
62              trouveUnMC=0
63              for mc in ll.childNodes:
64                 if mc.name != motcle:continue
65                 trouveUnMC=1
66                 TexteMC=mc.getText(jdc)
67                 liste_ligne_MC=TexteMC.splitlines()
68                 indexLigneGlob=mc.lineno-1
69                 indexTexteMC=0
70                 while indexLigneGlob < mc.endline  :
71                    if indexTexteMC > len(liste_ligne_MC)-1 : break
72                    MaLigneGlob=jdc.getLines()[indexLigneGlob]
73                    MaLigneTexte=liste_ligne_MC[indexTexteMC]
74                    for Valeur in DictNouvVal.keys() :
75                       trouve=MaLigneTexte.find(Valeur)
76                       if trouve > -1 :
77                          debut=MaLigneGlob.find(motcle)
78                          if debut==-1 : debut=0
79                          Nouveau=MaLigneGlob[debut:].replace(Valeur,DictNouvVal[Valeur])
80                          Nouveau=MaLigneGlob[0:debut]+Nouveau
81                          jdc.getLines()[indexLigneGlob]=Nouveau
82                          MaLigneTexte=Nouveau # raccourci honteux mais ...
83                          MaLigneGlob=Nouveau
84                          if Valeur in liste :
85                             EcritErreur((command,fact,motcle,Valeur),indexLigneGlob)
86                          else :
87                             logging.info("Changement de %s par %s dans %s ligne %d",Valeur,DictNouvVal[Valeur],command,indexLigneGlob)
88                    boolChange=1
89                    indexLigneGlob=indexLigneGlob+1
90                    indexTexteMC=indexTexteMC+1
91              if (trouveUnMC == 0) and ( defaut == 1):
92                 logging.warning("OPTION  (defaut) de CALCG à verifier ligne %s" ,c.lineno )                     
93                 EcritErreur((command,fact,motcle,"DEFAUT"),c.lineno)
94     if boolChange : jdc.reset(jdc.getSource())
95              
96 #---------------------------------------------------------------------------------------
97 def ChangementValeurDsMCFAvecAvertissement(jdc, command, fact,motcle,DictNouvVal,liste):
98 #---------------------------------------------------------------------------------------
99     if command  not in jdcSet : return
100     defaut=0
101     if liste[-1] == "defaut" : 
102        defaut=1
103     ChangementValeurDsMCF(jdc,command,fact,motcle,DictNouvVal,liste,defaut)
104
105 #--------------------------------------------------------------------------
106 def ChangementValeurAvecAvertissement(jdc, command,motcle,DictNouvVal,liste):
107 #--------------------------------------------------------------------------
108     if command  not in jdcSet : return
109     defaut=0
110     if liste[-1] == "defaut" : 
111        defaut=1
112     ChangementValeur(jdc,command,motcle,DictNouvVal,liste,defaut)
113
114 #--------------------------------------------------------------------------
115 def SuppressionValeurs(jdc, command,motcle,liste):
116 #--------------------------------------------------------------------------
117
118     if command not in jdcSet : return
119     boolChange=0
120     for c in jdc.root.childNodes:
121        if c.name != command  : continue
122        for mc in c.childNodes:
123           if mc.name != motcle : continue
124           indexLigneGlob=mc.lineno-1
125           while indexLigneGlob < mc.endline  :
126              MaLigneTexte = jdc.getLines()[indexLigneGlob]
127              MaLigne=MaLigneTexte
128              for Valeur in liste :
129                 debutMC =MaLigne.find(motcle)
130                 if debutMC ==-1 : debutMC=0
131                 debut1=MaLigne[0:debutMC]
132                 chercheLigne=MaLigne[debutMC:]
133                 trouve=chercheLigne.find(Valeur)
134                 premier=0
135                 if trouve > 0 : 
136                    debut=debut1 + chercheLigne[0:trouve]
137                    index = -1
138                    while (-1 * index) < len(debut) :
139                       if (debut[index] == "(")  :
140                          premier = 1
141                          if index == -1 :
142                             index=len(debut)
143                          else :
144                             index=index+1
145                          break
146                       if (debut[index] == "," ) : 
147                           break
148                       if (debut[index] != " " ) :
149                          assert(0)
150                       index = index -1
151                    debLigne = debut[0:index]
152                    fin=trouve+len(Valeur)
153                    if premier == 1 : fin = fin + 1 # on supprime la ,
154                    finLigne = chercheLigne[fin:]
155                    MaLigne=debLigne+finLigne
156                    boolChange=1
157                 jdc.getLines()[indexLigneGlob]=MaLigne
158              indexLigneGlob=indexLigneGlob+1
159     if boolChange : jdc.reset(jdc.getSource())
160
161 #----------------------------------------------
162 def AppelleMacroSelonValeurConcept(jdc,macro,genea):
163 #----------------------------------------------
164     if macro  not in jdcSet : return
165     boolChange=0
166     fact=genea[0]
167     motcle=genea[1]
168     chaine="CO"
169     for c in jdc.root.childNodes:
170        if c.name != macro  : continue
171        for mcF in c.childNodes:
172           if mcF.name != fact : continue
173           l=mcF.childNodes[:]
174           l.reverse()
175           for ll in l:
176              trouveValeur=0
177              for mc in ll.childNodes:
178                 if mc.name != motcle:continue
179                 TexteMC=mc.getText(jdc)
180                 liste_ligne_MC=TexteMC.splitlines()
181                 indexLigneGlob=mc.lineno-2
182                 trouveTexteMC=0
183                 trouveegal=0
184                 trouvechaine=0
185                 trouveparent=0
186                 trouvequote=0
187                 while indexLigneGlob < mc.endline  :
188                    indexLigneGlob=indexLigneGlob+1
189                    MaLigneTexte=jdc.getLines()[indexLigneGlob]
190
191                    # on commence par chercher TABLE par exemple
192                    # si on ne trouve pas on passe a la ligne suivante
193                    if ( trouveTexteMC == 0 ) :
194                        indice=MaLigneTexte.find(motcle)
195                        if indice < 0 : continue
196                        trouveTexteMC=1
197                    else :
198                       indice=0
199
200                    # on cherche =
201                    aChercher=MaLigneTexte[indice:]
202                    if (trouveegal == 0 ):
203                        indice=aChercher.find("=")
204                        if indice < 0 : continue
205                        trouveegal = 1
206                    else :
207                        indice = 0
208
209                    # on cherche CO
210                    aChercher2=aChercher[indice:]
211                    if (trouvechaine == 0 ):
212                        indice=aChercher2.find(chaine)
213                        if indice < 0 : continue
214                        trouvechaine = 1
215                    else :
216                        indice = 0
217
218                    #on cherche (
219                    aChercher3=aChercher2[indice:]
220                    if (trouveparent == 0 ):
221                        indice=aChercher3.find('(')
222                        if indice < 0 : continue
223                        trouveparent = 1
224                    else :
225                        indice = 0
226                  
227                    #on cherche la '
228                    aChercher4=aChercher3[indice:]
229                    if (trouvequote == 0 ):
230                        indice=aChercher4.find("'")
231                        indice2=aChercher4.find('"')
232                        if (indice < 0) and (indice2 < 0): continue
233                        if (indice < 0) : indice=indice2
234                        trouvequote = 1
235                    else :
236                        indice = 0
237
238                    trouveValeur=1
239                    aChercher5=aChercher4[indice+1:]
240                    indice=aChercher5.find("'")
241                    if indice < 0 :  indice=aChercher5.find('"')
242                    valeur=aChercher5[:indice]
243                    break
244                     
245              if trouveValeur==0 :
246                   logging.error("Pb de traduction pour MACR_LIGNE_COUPE : Pas de nom de Concept identifiable")
247                   return
248              
249              if boolChange :
250                   jdc.reset(jdc.getSource())
251                   logging.error("Pb du traduction pour MACR_LIGNE_COUPE : Deux noms de Concept possibles")
252                   return
253
254              boolChange=1
255              ligneaTraiter=jdc.getLines()[c.lineno-1]
256              debut=ligneaTraiter[0:c.colno]
257              suite=valeur+"="
258              fin=ligneaTraiter[c.colno:]
259              ligne=debut+suite+fin
260              jdc.getLines()[c.lineno-1]=ligne
261              nbBlanc=len(valeur)+1
262              if c.lineno < c.endline:
263                 decaleLignesdeNBlancs(jdc,c.lineno,c.endline-1,nbBlanc)
264     if boolChange : jdc.reset(jdc.getSource())
265
266 #----------------------------------------------
267 def ChangeTouteValeur(jdc,command,motcle,DictNouvVal,liste=(),defaut=0):
268 #----------------------------------------------
269     if macro  not in jdcSet : return
270     boolChange=0