1 # -*- coding: iso-8859-1 -*-
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
24 from parseur import lastparen
25 from dictErreurs import jdcSet
28 #-----------------------------------------------------
29 def moveMotCleFromFactToFather(jdc,command,fact,mocle):
30 #-----------------------------------------------------
31 # exemple type : IMPR_GENE
33 if command not in jdcSet : return
35 commands= jdc.root.childNodes[:]
38 if c.name != command:continue
40 for mc in c.childNodes:
41 if mc.name != fact:continue
44 for n in ll.childNodes:
45 if n.name != mocle:continue
46 # test boolchange_c :il faut le faire une seule fois par commande sinon duplication du mot clé
47 if boolchange_c != 0 :continue
48 if debug : print "Changement de place :", n.name, n.lineno, n.colno
49 MonTexte=n.getText(jdc);
52 inseremocle.insereMotCle(jdc,c,MonTexte)
53 logging.info("Changement de place %s ligne %s ",n.name, n.lineno)
55 if boolChange : jdc.reset(jdc.getSource())
56 removemocle.removeMotCleInFact(jdc,command,fact,mocle)
59 #----------------------------------------------------------------------------
60 def moveMotCleFromFactToFactMulti(jdc,oper,factsource,mocle,liste_factcible):
61 #----------------------------------------------------------------------------
62 # exemple type STAT_NON_LINE et RESI_INTER_RELA
63 for factcible in liste_factcible :
64 moveMotCleFromFactToFact(jdc,oper,factsource,mocle,factcible)
65 removemocle.removeMotCleInFact(jdc,oper,factsource,mocle)
68 #----------------------------------------------------------------------------
69 def moveMotCleFromFactToFact(jdc,oper,factsource,mocle,factcible):
70 #----------------------------------------------------------------------------
71 if oper not in jdcSet : return
72 if debug : print "moveMotCleFromFactToFact pour " ,oper,factsource,mocle,factcible
74 commands= jdc.root.childNodes[:]
77 if c.name != oper : continue
79 for mc in c.childNodes:
80 if mc.name != factcible :
86 if debug : print "Pas de changement pour ", oper, " ", factsource, " ",mocle, "cible non trouvée"
89 for mc in c.childNodes:
91 if mc.name != factsource:
97 if debug : print "Pas de changement pour ", oper, " ", factsource, " ",mocle, "source non trouvée"
100 if debug : print "Changement pour ", oper, " ", factsource, " ",mocle, "cible et source trouvées"
101 l=source.childNodes[:]
103 for n in ll.childNodes:
104 if n.name != mocle:continue
105 MonTexte=n.getText(jdc);
106 inseremocle.insereMotCleDansFacteur(jdc,cible,MonTexte)
108 logging.info("Changement de place %s ligne %s vers %s",n.name, n.lineno, cible.name)
109 if boolChange : jdc.reset(jdc.getSource())
114 #------------------------------------------------------
115 def moveMotClefInOperToFact(jdc,oper,mocle,factcible):
116 #------------------------------------------------------
117 # Attention le cas type est THETA_OLD dans calc_G
119 if oper not in jdcSet : return
120 if debug : print "movemocleinoper pour " ,oper,mocle,factcible
122 commands= jdc.root.childNodes[:]
125 if c.name != oper : continue
127 for mc in c.childNodes:
128 if mc.name != factcible :
134 if debug : print "Pas de changement pour ", oper, " ", factcible, " ", "cible non trouvée"
138 for mc in c.childNodes:
145 if debug : print "Pas de changement pour ", oper, " ", mocle, " source non trouvée"
147 MonTexte=source.getText(jdc);
149 inseremocle.insereMotCleDansFacteur(jdc,cible,MonTexte)
150 if boolChange : jdc.reset(jdc.getSource())
151 removemocle.removeMotCle(jdc,oper,mocle)
153 #------------------------------------------------------
154 def copyMotClefInOperToFact(jdc,oper,mocle,factcible):
155 #------------------------------------------------------
157 if oper not in jdcSet : return
158 if debug : print "movemocleinoper pour " ,oper,mocle,factcible
160 commands= jdc.root.childNodes[:]
163 if c.name != oper : continue
165 for mc in c.childNodes:
166 if mc.name != factcible :
172 if debug : print "Pas de changement pour ", oper, " ", factcible, " ", "cible non trouvée"
176 for mc in c.childNodes:
183 if debug : print "Pas de changement pour ", oper, " ", mocle, " source non trouvée"
185 MonTexte=source.getText(jdc);
187 inseremocle.insereMotCleDansFacteur(jdc,cible,MonTexte)
188 if boolChange : jdc.reset(jdc.getSource())
190 #----------------------------------------------------------------------
191 def moveMCFToCommand(jdc,command,factsource,commandcible,factcible):
192 #----------------------------------------------------------------------
193 # exemple CONTACT en 10
194 # CONTACT devient commande DEFI_CONTACT/ZONE
196 if command not in jdcSet : return
198 commands= jdc.root.childNodes[:]
201 if c.name != command : continue
202 for mcF in c.childNodes:
203 if mcF.name != factsource : continue
205 texte=l.replace(factsource,factcible)
206 texte='xxxx='+commandcible+'('+texte+')\n'
207 jdc.splitLine(c.lineno,0)
208 jdc.addLine(texte,c.lineno)
209 logging.info("Deplacement de %s dans %s ligne %s",factsource,commandcible,c.lineno)
212 jdc.reset(jdc.getSource())
213 jdcSet.add(commandcible)
215 #-----------------------------------------------------
216 def FusionMotCleToFact(jdc,command,liste_mc,factcible,defaut=0):
217 #-----------------------------------------------------
218 if command not in jdcSet : return
220 commands= jdc.root.childNodes[:]
223 if c.name != command : continue
226 for mc in c.childNodes:
227 if mc.name not in liste_mc : continue
228 val=mc.getText(jdc).split("=")[1].split(",")[0]
232 TexteMC=factcible+"=("
233 for val in list_val : TexteMC=TexteMC+val+","
234 TexteMC=TexteMC[:-1]+"),"
235 inseremocle.insereMotCle(jdc,c,TexteMC)
236 jdc.reset(jdc.getSource())
239 jdc.reset(jdc.getSource())
241 removemocle.removeMotCle(jdc,command,mc)
242 jdc.reset(jdc.getSource())
244 #--------------------------------------------------------------------
245 def EclaMotCleToFact(jdc,command,motcle,mot1,mot2,defaut=0):
246 #--------------------------------------------------------------------------
247 # exemple STA10 pesanteur devient MCF avec eclatement des valeurs dans les MC
248 # On suppose que le MC est sur une seule ligne
249 if command not in jdcSet : return
251 for c in jdc.root.childNodes:
252 if c.name != command : continue
254 for mc in c.childNodes:
255 if mc.name != motcle : continue
257 TexteMC=mc.getText(jdc)
258 indexLigneGlob=mc.lineno-1
259 MaLigneGlob=jdc.getLines()[indexLigneGlob]
260 Ligne=TexteMC.split('(')[1].split(')')[0].split(',')
261 motcle1=mot1+"="+Ligne[0]
262 motcle2=mot2+"=("+Ligne[1]+','+Ligne[2]+','+Ligne[3]+')'
263 texte=motcle+'=_F('+motcle1+','+motcle2+')'
264 num=lastparen(TexteMC)
265 Nouveau=MaLigneGlob.replace(TexteMC[0:num],texte)
266 jdc.getLines()[indexLigneGlob]=Nouveau
267 logging.info("Transformation de %s dans %s ligne %s",motcle,command,c.lineno)
269 if boolChange : jdc.reset(jdc.getSource())