1 # -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2021 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 Traducteur import removemocle
23 from Traducteur import inseremocle
24 from Traducteur.parseur import lastParen
25 from Traducteur.load 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())
110 removemocle.removeMotCleInFact(jdc,oper,factsource,mocle)
115 #-----------------------------------------------------------------------
116 def moveMotClefInOperToFact(jdc,oper,mocle,factcible,plusieursFois=True):
117 #-----------------------------------------------------------------------
118 # Attention le cas type est THETA_OLD dans calc_G
120 if oper not in jdcSet : return
121 if debug : print "movemocleinoper pour " ,oper,mocle,factcible
123 commands= jdc.root.childNodes[:]
126 if c.name != oper : continue
128 for mc in c.childNodes:
129 if mc.name != factcible :
135 if debug : print "Pas de changement pour ", oper, " ", factcible, " ", "cible non trouvée"
139 for mc in c.childNodes:
146 if debug : print "Pas de changement pour ", oper, " ", mocle, " source non trouvée"
148 MonTexte=source.getText(jdc);
150 inseremocle.insereMotCleDansFacteur(jdc,cible,MonTexte,plusieursFois)
151 if boolChange : jdc.reset(jdc.getSource())
152 removemocle.removeMotCle(jdc,oper,mocle)
154 #------------------------------------------------------
155 def copyMotClefInOperToFact(jdc,oper,mocle,factcible):
156 #------------------------------------------------------
158 if oper not in jdcSet : return
159 if debug : print "movemocleinoper pour " ,oper,mocle,factcible
161 commands= jdc.root.childNodes[:]
164 if c.name != oper : continue
166 for mc in c.childNodes:
167 if mc.name != factcible :
173 if debug : print "Pas de changement pour ", oper, " ", factcible, " ", "cible non trouvée"
177 for mc in c.childNodes:
184 if debug : print "Pas de changement pour ", oper, " ", mocle, " source non trouvée"
186 MonTexte=source.getText(jdc);
188 inseremocle.insereMotCleDansFacteur(jdc,cible,MonTexte)
189 if boolChange : jdc.reset(jdc.getSource())
191 #----------------------------------------------------------------------
192 def moveMCFToCommand(jdc,command,factsource,commandcible,factcible):
193 #----------------------------------------------------------------------
194 # exemple CONTACT en 10
195 # CONTACT devient commande DEFI_CONTACT/ZONE
197 if command not in jdcSet : return
199 commands= jdc.root.childNodes[:]
202 if c.name != command : continue
203 for mcF in c.childNodes:
204 if mcF.name != factsource : continue
206 texte=l.replace(factsource,factcible)
207 texte='xxxx='+commandcible+'('+texte+')\n'
208 jdc.splitLine(c.lineno,0)
209 jdc.addLine(texte,c.lineno)
210 logging.info("Deplacement de %s dans %s ligne %s",factsource,commandcible,c.lineno)
213 jdc.reset(jdc.getSource())
214 jdcSet.add(commandcible)
216 #-----------------------------------------------------
217 def fusionMotCleToFact(jdc,command,listeMc,factcible,defaut=0):
218 #-----------------------------------------------------
219 if command not in jdcSet : return
221 commands= jdc.root.childNodes[:]
224 if c.name != command : continue
227 for mc in c.childNodes:
228 if mc.name not in listeMc : continue
229 val=mc.getText(jdc).split("=")[1].split(",")[0]
233 TexteMC=factcible+"=("
234 for val in list_val : TexteMC=TexteMC+val+","
235 TexteMC=TexteMC[:-1]+"),"
236 inseremocle.insereMotCle(jdc,c,TexteMC)
237 jdc.reset(jdc.getSource())
240 jdc.reset(jdc.getSource())
242 removemocle.removeMotCle(jdc,command,mc)
243 jdc.reset(jdc.getSource())
245 #-----------------------------------------------------
246 def fusionMotCleInFact(jdc,command,fact,listeMc,new_name,defaut=0):
247 #-----------------------------------------------------
248 if command not in jdcSet : return
250 commands= jdc.root.childNodes[:]
253 if c.name != command : continue
256 for mcF in c.childNodes:
257 if mcF.name != fact: continue
258 for ll in mcF.childNodes[:]:
259 for mc in ll.childNodes:
260 if mc.name not in listeMc : continue
261 val=mc.getText(jdc).split("=")[1].split(",")[0]
265 TexteMC=new_name+"=("+",".join(list_val)+"),"
266 inseremocle.insereMotCleDansFacteur(jdc,mcF,TexteMC)
267 jdc.reset(jdc.getSource())
270 jdc.reset(jdc.getSource())
272 removemocle.removeMotCleInFact(jdc,command,fact,mc)
273 jdc.reset(jdc.getSource())
275 #-----------------------------------------------------
276 def fusionMCFToMCF(jdc,command,listeMcF,factcible,defaut=0):
277 #-----------------------------------------------------
278 if command not in jdcSet : return
280 commands= jdc.root.childNodes[:]
283 if c.name != command : continue
286 TexteMC=factcible+'=('
287 esp1=' '*len(TexteMC)
289 for mcF in c.childNodes:
290 if mcF.name not in listeMcF : continue
293 # esp=esp1+(inseremocle.chercheDebutFacteur(jdc,mcF)-len(mcF.name))*' '
294 esp=esp1+inseremocle.chercheAlignement(jdc,c)
296 for ll in mcF.childNodes[:]:
297 # if(pp>0): TexteMC+=esp
299 for mc in ll.childNodes:
301 TexteMC+=val+'\n '+esp
302 # if('#' in val.split('\n')[-1]): TexteMC+='\n'+esp+' '
303 lastkey = ''.join(val.split('=')[-1].split(' '))
304 if((len(lastkey.split('(')) - len(lastkey.split(')'))) >= 0):
305 TexteMC += '),\n'+esp
310 inseremocle.insereMotCle(jdc,c,TexteMC)
311 jdc.reset(jdc.getSource())
314 jdc.reset(jdc.getSource())
315 for mcF in listeMcF :
316 removemocle.removeMotCle(jdc,command,mcF)
317 jdc.reset(jdc.getSource())
321 #--------------------------------------------------------------------
322 def eclaMotCleToFact(jdc,command,motcle,mot1,mot2,defaut=0):
323 #--------------------------------------------------------------------------
324 # exemple STA10 pesanteur devient MCF avec eclatement des valeurs dans les MC
325 # On suppose que le MC est sur une seule ligne
326 if command not in jdcSet : return
328 for c in jdc.root.childNodes:
329 if c.name != command : continue
331 for mc in c.childNodes:
332 if mc.name != motcle : continue
334 TexteMC=mc.getText(jdc)
335 indexLigneGlob=mc.lineno-1
336 MaLigneGlob=jdc.getLines()[indexLigneGlob]
337 Ligne=TexteMC.split('(')[1].split(')')[0].split(',')
338 motcle1=mot1+"="+Ligne[0]
339 motcle2=mot2+"=("+Ligne[1]+','+Ligne[2]+','+Ligne[3]+')'
340 texte=motcle+'=_F('+motcle1+','+motcle2+')'
341 num=lastParen(TexteMC)
342 Nouveau=MaLigneGlob.replace(TexteMC[0:num],texte)
343 jdc.getLines()[indexLigneGlob]=Nouveau
344 logging.info("Transformation de %s dans %s ligne %s",motcle,command,c.lineno)
346 if boolChange : jdc.reset(jdc.getSource())