]> SALOME platform Git repositories - tools/eficas.git/blob - Traducteur/movemocle.py
Salome HOME
fef058938d8859975f473b2d1df60a01bb131d02
[tools/eficas.git] / Traducteur / movemocle.py
1 # -*- coding: utf-8 -*-
2
3 import logging
4 import removemocle
5 import inseremocle
6 from parseur import FactNode
7 from dictErreurs import jdcSet
8 debug=0
9
10 #-----------------------------------------------------
11 def moveMotCleFromFactToFather(jdc,command,fact,mocle):
12 #-----------------------------------------------------
13 # exemple type : IMPR_GENE
14
15     if command not in jdcSet : return
16     boolChange=0
17     commands= jdc.root.childNodes[:]
18     commands.reverse()
19     for c in commands:
20         if c.name != command:continue
21         for mc in c.childNodes:
22             if mc.name != fact:continue
23             l=mc.childNodes[:]
24             for ll in l:
25                 for n in ll.childNodes:
26                     if n.name != mocle:continue
27                     if debug : print "Changement de place :", n.name, n.lineno, n.colno
28                     MonTexte=n.getText(jdc);
29                     boolChange=1
30                     inseremocle.insereMotCle(jdc,c,MonTexte)
31                     logging.info("Changement de place  %s ligne %s ",n.name, n.lineno)
32             
33     if boolChange : jdc.reset(jdc.getSource())
34     removemocle.removeMotCleInFact(jdc,command,fact,mocle)
35
36
37 #----------------------------------------------------------------------------
38 def moveMotCleFromFactToFactMulti(jdc,oper,factsource,mocle,liste_factcible):
39 #----------------------------------------------------------------------------
40 # exemple type STAT_NON_LINE et RESI_INTER_RELA
41     for factcible in liste_factcible :
42        moveMotCleFromFactToFact(jdc,oper,factsource,mocle,factcible)
43     removemocle.removeMotCleInFact(jdc,oper,factsource,mocle)
44
45
46 #----------------------------------------------------------------------------
47 def moveMotCleFromFactToFact(jdc,oper,factsource,mocle,factcible):
48 #----------------------------------------------------------------------------
49     if oper not in jdcSet : return
50     if debug : print "moveMotCleFromFactToFact pour " ,oper,factsource,mocle,factcible
51     boolChange=0
52     commands= jdc.root.childNodes[:]
53     commands.reverse()
54     for c in commands:
55         if c.name != oper : continue
56         cible=None
57         for mc in c.childNodes:
58            if mc.name != factcible : 
59               continue
60            else :
61               cible=mc
62               break
63         if cible==None :
64            if debug : print "Pas de changement pour ", oper, " ", factsource, " ",mocle, "cible non trouvée"
65            continue
66
67         for mc in c.childNodes:
68            source=None
69            if mc.name != factsource:
70               continue
71            else :
72               source=mc
73               break
74         if source==None :
75            if debug : print "Pas de changement pour ", oper, " ", factsource, " ",mocle, "source non trouvée"
76            continue
77
78         if debug : print "Changement pour ", oper, " ", factsource, " ",mocle, "cible et source trouvées"
79         l=source.childNodes[:]
80         for ll in l:
81            for n in ll.childNodes:
82               if n.name != mocle:continue
83               MonTexte=n.getText(jdc);
84               inseremocle.insereMotCleDansFacteur(jdc,cible,MonTexte)
85               boolChange=1
86               logging.info("Changement de place   %s ligne %s vers %s",n.name, n.lineno, cible.name)
87     if boolChange : jdc.reset(jdc.getSource())
88
89
90
91
92 #------------------------------------------------------
93 def moveMotClefInOperToFact(jdc,oper,mocle,factcible):
94 #------------------------------------------------------
95 # Attention le cas type est THETA_OLD dans calc_G
96
97     if oper not in jdcSet : return
98     if debug : print "movemocleinoper pour " ,oper,mocle,factcible
99     boolChange=9
100     commands= jdc.root.childNodes[:]
101     commands.reverse()
102     for c in commands:
103         if c.name != oper : continue
104         cible=None
105         for mc in c.childNodes:
106            if mc.name != factcible : 
107               continue
108            else :
109               cible=mc
110               break
111         if cible==None :
112            if debug : print "Pas de changement pour ", oper, " ", factcible, " ", "cible non trouvée"
113            continue
114
115         source=None
116         for mc in c.childNodes:
117            if mc.name != mocle:
118               continue
119            else :
120               source=mc
121               break
122         if source==None :
123            if debug : print "Pas de changement pour ", oper, " ", mocle, " source non trouvée"
124            continue
125         MonTexte=source.getText(jdc);
126         boolChange=1
127         inseremocle.insereMotCleDansFacteur(jdc,cible,MonTexte)
128     if boolChange : jdc.reset(jdc.getSource())
129     removemocle.removeMotCle(jdc,oper,mocle)