Salome HOME
commentaire
[tools/eficas.git] / Traducteur / removemocle.py
index 5f6335785a82709f80405940e1b78ddd7ede2f59..07bfbb3020a44de1e56b8095ec74b34c4b9c94e8 100644 (file)
@@ -1,12 +1,30 @@
 # -*- coding: utf-8 -*-
+# Copyright (C) 2007-2012   EDF R&D
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+#
+# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+#
 import logging
-import regles
-from parseur import FactNode
-from dictErreurs import EcritErreur
-from dictErreurs import jdcSet
+from Traducteur import regles
+from Traducteur.parseur import FactNode
+from Traducteur.dictErreurs import EcritErreur
+from Traducteur.load import jdcSet
 
-#debug=1
 debug=0
+#debug=1
 #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)
 #avant de supprimer un autre mocle, on remet à jour l'arbre syntaxique (lineno,colno,etc.)
 
@@ -64,9 +82,16 @@ def removeCommande(jdc,command,ensemble=regles.SansRegle,erreur=0):
         boolChange=1
         if erreur : EcritErreur((command,),c.lineno)
         jdc.supLignes(c.lineno,c.endline)
-        logging.warning("Suppression de: %s ligne %s",c.name,c.lineno)
+        logging.warning("Suppression de %s ligne %s",c.name,c.lineno)
     if boolChange : jdc.reset(jdc.getSource())
 
+#-------------------------------------------------------------
+def removeCommandeSiRegle(jdc,command,liste_regles):
+#-------------------------------------------------------------
+    if command not in jdcSet : return
+    mesRegles=regles.ensembleRegles(liste_regles)
+    removeCommande(jdc,command,mesRegles,0)
+
 #-------------------------------------------------------------
 def removeCommandeSiRegleAvecErreur(jdc,command,liste_regles):
 #-------------------------------------------------------------
@@ -78,7 +103,7 @@ def removeCommandeSiRegleAvecErreur(jdc,command,liste_regles):
 def removeMC(jdc,c,mc):
 #---------------------------------
     if debug : print "Suppression de:",c.name,mc.name,mc.lineno,mc.colno,mc.endline,mc.endcol
-    logging.info("Suppression de: %s, %s, ligne %d",c.name,mc.name,mc.lineno)
+    logging.info("Suppression de %s dans %s ligne %d",mc.name,c.name,mc.lineno)
 
     if mc.endline > mc.lineno:
         if debug:print "mocle sur plusieurs lignes--%s--" % jdc.getLines()[mc.lineno-1][mc.colno:]
@@ -135,6 +160,30 @@ def removeMotCleInFactSiRegleAvecErreur(jdc,command,fact,mocle,liste_regles):
     removeMotCleInFact(jdc,command,fact,mocle,mesRegles,erreur)
 
 
+#----------------------------------------------------------------------
+def removeMotCleInFactCourantSiRegle(jdc,command,fact,mocle,liste_regles,erreur=0):
+#----------------------------------------------------------------------
+    if command not in jdcSet : return
+    ensemble=regles.ensembleRegles(liste_regles)
+    commands= jdc.root.childNodes[:]
+    commands.reverse()
+    boolChange=0
+    for c in commands:
+        if c.name != command:continue
+        for mc in c.childNodes:
+            if mc.name != fact:continue
+            l=mc.childNodes[:]
+            l.reverse()
+            for ll in l:
+                if ensemble.verif(ll) == 0 : continue
+                for n in ll.childNodes:
+                    if n.name != mocle:continue
+                    if erreur : EcritErreur((command,fact,mocle),c.lineno)
+                    boolChange=1
+                    removeMC(jdc,c,n)
+
+    if boolChange : jdc.reset(jdc.getSource())
+    
 #------------------------------------------
 def fusionne(jdc,numLigne):
 #------------------------------------------
@@ -163,5 +212,4 @@ def fusionne(jdc,numLigne):
        fusion=0
  
     if fusion : 
-       import load 
        jdc.joinLineandNext(numLigne)