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
22 from parseur import FactNode
23 from dictErreurs import EcritErreur
24 from load import jdcSet
28 #on n'a qu'un mocle par commande. On peut donc supprimer le mocle sans trop de précautions (a part iterer a l'envers sur les commandes)
29 #avant de supprimer un autre mocle, on remet à jour l'arbre syntaxique (lineno,colno,etc.)
32 #-----------------------------------------------------------------------
33 def removeMotCle(jdc,command,mocle,ensemble=regles.SansRegle,erreur = 0):
34 #-----------------------------------------------------------------------
35 #on itere sur les commandes a l'envers pour ne pas polluer les numeros de ligne avec les modifications
36 if command not in jdcSet : return
38 commands= jdc.root.childNodes[:]
41 if c.name != command:continue
42 for mc in c.childNodes:
43 if mc.name != mocle:continue
44 if ensemble.verif(c) == 0 : continue
45 if erreur : EcritErreur((command,mocle),c.lineno)
49 if boolChange : jdc.reset(jdc.getSource())
51 #-------------------------------------------------------
52 def removeMotCleSiRegle(jdc,command,mocle,liste_regles) :
53 #-------------------------------------------------------
54 if command not in jdcSet : return
55 mesRegles=regles.ensembleRegles(liste_regles)
56 removeMotCle(jdc,command,mocle,mesRegles,erreur=0)
58 #----------------------------------------------------------------
59 def removeMotCleSiRegleAvecErreur(jdc,command,mocle,liste_regles) :
60 #--------------------------------------------------------------
61 if command not in jdcSet : return
62 mesRegles=regles.ensembleRegles(liste_regles)
63 removeMotCle(jdc,command,mocle,mesRegles,erreur=1)
65 #----------------------------------------------------------------
66 def removeMotCleAvecErreur(jdc,command,mocle) :
67 #--------------------------------------------------------------
68 if command not in jdcSet : return
69 removeMotCle(jdc,command,mocle,erreur=1)
72 #--------------------------------------------------------------------
73 def removeCommande(jdc,command,ensemble=regles.SansRegle,erreur=0):
74 #--------------------------------------------------------------------
75 if command not in jdcSet : return
77 commands= jdc.root.childNodes[:]
80 if c.name != command:continue
81 if ensemble.verif(c) == 0 : continue
83 if erreur : EcritErreur((command,),c.lineno)
84 jdc.supLignes(c.lineno,c.endline)
85 logging.warning("Suppression de %s ligne %s",c.name,c.lineno)
86 if boolChange : jdc.reset(jdc.getSource())
88 #-------------------------------------------------------------
89 def removeCommandeSiRegle(jdc,command,liste_regles):
90 #-------------------------------------------------------------
91 if command not in jdcSet : return
92 mesRegles=regles.ensembleRegles(liste_regles)
93 removeCommande(jdc,command,mesRegles,0)
95 #-------------------------------------------------------------
96 def removeCommandeSiRegleAvecErreur(jdc,command,liste_regles):
97 #-------------------------------------------------------------
98 if command not in jdcSet : return
99 mesRegles=regles.ensembleRegles(liste_regles)
100 removeCommande(jdc,command,mesRegles,1)
102 #---------------------------------
103 def removeMC(jdc,c,mc):
104 #---------------------------------
105 if debug : print "Suppression de:",c.name,mc.name,mc.lineno,mc.colno,mc.endline,mc.endcol
106 logging.info("Suppression de %s dans %s ligne %d",mc.name,c.name,mc.lineno)
108 if mc.endline > mc.lineno:
109 if debug:print "mocle sur plusieurs lignes--%s--" % jdc.getLines()[mc.lineno-1][mc.colno:]
110 jdc.getLines()[mc.lineno-1]=jdc.getLines()[mc.lineno-1][:mc.colno]
111 jdc.getLines()[mc.endline-1]=jdc.getLines()[mc.endline-1][mc.endcol:]
113 #attention : supprimer les lignes à la fin
114 jdc.getLines()[mc.lineno:mc.endline-1]=[]
116 if debug:print "mocle sur une ligne--%s--" % jdc.getLines()[mc.lineno-1][mc.colno:mc.endcol]
117 s=jdc.getLines()[mc.lineno-1]
118 jdc.getLines()[mc.lineno-1]=s[:mc.colno]+s[mc.endcol:]
119 fusionne(jdc,mc.lineno-1)
121 #---------------------------------------------------------------------------------
122 def removeMotCleInFact(jdc,command,fact,mocle,ensemble=regles.SansRegle,erreur=0):
123 #----------------------------------------------------------------------------------
124 # on itere sur les commandes a l'envers pour ne pas polluer
125 # les numeros de ligne avec les modifications
126 if command not in jdcSet : return
127 commands= jdc.root.childNodes[:]
131 if c.name != command:continue
132 for mc in c.childNodes:
133 if mc.name != fact:continue
137 for n in ll.childNodes:
138 if n.name != mocle:continue
139 if ensemble.verif(c) == 0 : continue
140 if erreur : EcritErreur((command,fact,mocle),c.lineno)
144 if boolChange : jdc.reset(jdc.getSource())
146 #------------------------------------------------------------------
147 def removeMotCleInFactSiRegle(jdc,command,fact,mocle,liste_regles):
148 #------------------------------------------------------------------
149 if command not in jdcSet : return
151 mesRegles=regles.ensembleRegles(liste_regles)
152 removeMotCleInFact(jdc,command,fact,mocle,mesRegles,erreur)
154 #----------------------------------------------------------------------
155 def removeMotCleInFactSiRegleAvecErreur(jdc,command,fact,mocle,liste_regles):
156 #----------------------------------------------------------------------
157 if command not in jdcSet : return
159 mesRegles=regles.ensembleRegles(liste_regles)
160 removeMotCleInFact(jdc,command,fact,mocle,mesRegles,erreur)
163 #----------------------------------------------------------------------
164 def removeMotCleInFactCourantSiRegle(jdc,command,fact,mocle,liste_regles,erreur=0):
165 #----------------------------------------------------------------------
166 if command not in jdcSet : return
167 ensemble=regles.ensembleRegles(liste_regles)
168 commands= jdc.root.childNodes[:]
172 if c.name != command:continue
173 for mc in c.childNodes:
174 if mc.name != fact:continue
178 if ensemble.verif(ll) == 0 : continue
179 for n in ll.childNodes:
180 if n.name != mocle:continue
181 if erreur : EcritErreur((command,fact,mocle),c.lineno)
185 if boolChange : jdc.reset(jdc.getSource())
187 #------------------------------------------
188 def fusionne(jdc,numLigne):
189 #------------------------------------------
190 # fusionne la ligne numLigne et numLigne+1
191 # si la ligne numLigne+1 ne contient que des parentheses
193 # et si la ligne numLigne ne contient pas par un "#"
194 # Attention a la difference de numerotation
195 # jdc.getLines()[numLigne] donne la ligne numLigne + 1
196 # alors que joinLineandNext(numLigne) travaille sur le tableau
198 texte=jdc.getLines()[numLigne]
200 while (index < len(texte)) :
201 if texte[index] not in (" ",",",")",";","\n") :
206 if fusion == 0 : return;
208 texte=jdc.getLines()[numLigne -1]
209 if texte.find("#") < 0 :
216 jdc.joinLineandNext(numLigne)