Salome HOME
sauve0206
[tools/eficas.git] / Traducteur / movemocle.py
index 293d4b0ae06d2ac7a55f5a8de584c6ccb47ee9d4..10c2aa5498f75386c2217ebc5d983ddd1846374f 100644 (file)
@@ -1,10 +1,28 @@
-# -*- coding: utf-8 -*-
+# -*- coding: iso-8859-1 -*-
+# 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 removemocle
-import inseremocle
-from parseur import lastparen
-from dictErreurs import jdcSet
+from Traducteur import removemocle
+from Traducteur import inseremocle
+from Traducteur.parseur import lastparen
+from Traducteur.load import jdcSet
 debug=0
 
 #-----------------------------------------------------
@@ -89,13 +107,14 @@ def moveMotCleFromFactToFact(jdc,oper,factsource,mocle,factcible):
               boolChange=1
               logging.info("Changement de place   %s ligne %s vers %s",n.name, n.lineno, cible.name)
     if boolChange : jdc.reset(jdc.getSource())
+    removemocle.removeMotCleInFact(jdc,oper,factsource,mocle)
 
 
 
 
-#------------------------------------------------------
-def moveMotClefInOperToFact(jdc,oper,mocle,factcible):
-#------------------------------------------------------
+#-----------------------------------------------------------------------
+def moveMotClefInOperToFact(jdc,oper,mocle,factcible,plusieursFois=True):
+#-----------------------------------------------------------------------
 # Attention le cas type est THETA_OLD dans calc_G
 
     if oper not in jdcSet : return
@@ -128,7 +147,7 @@ def moveMotClefInOperToFact(jdc,oper,mocle,factcible):
            continue
         MonTexte=source.getText(jdc);
         boolChange=1
-        inseremocle.insereMotCleDansFacteur(jdc,cible,MonTexte)
+        inseremocle.insereMotCleDansFacteur(jdc,cible,MonTexte,plusieursFois)
     if boolChange : jdc.reset(jdc.getSource())
     removemocle.removeMotCle(jdc,oper,mocle)
 
@@ -194,6 +213,111 @@ def moveMCFToCommand(jdc,command,factsource,commandcible,factcible):
         jdc.reset(jdc.getSource())
         jdcSet.add(commandcible)
 
+#-----------------------------------------------------
+def FusionMotCleToFact(jdc,command,liste_mc,factcible,defaut=0):
+#-----------------------------------------------------
+    if command  not in jdcSet : return
+    boolChange=0
+    commands= jdc.root.childNodes[:]
+    commands.reverse()
+    for c in commands:
+       if c.name != command  : continue
+       list_val=[]
+       trouveUnMC=0
+       for mc in c.childNodes:
+           if mc.name not in liste_mc : continue
+           val=mc.getText(jdc).split("=")[1].split(",")[0]
+           list_val.append(val)
+           trouveUnMC=1
+       if trouveUnMC :
+           TexteMC=factcible+"=("
+           for val in list_val : TexteMC=TexteMC+val+","
+           TexteMC=TexteMC[:-1]+"),"
+           inseremocle.insereMotCle(jdc,c,TexteMC)
+           jdc.reset(jdc.getSource())
+           boolChange=1
+    if boolChange :
+        jdc.reset(jdc.getSource())
+        for mc in liste_mc : 
+           removemocle.removeMotCle(jdc,command,mc)
+           jdc.reset(jdc.getSource())
+
+#-----------------------------------------------------
+def FusionMotCleInFact(jdc,command,fact,liste_mc,new_name,defaut=0):
+#-----------------------------------------------------
+    if command  not in jdcSet : return
+    boolChange=0
+    commands= jdc.root.childNodes[:]
+    commands.reverse()
+    for c in commands:
+        if c.name != command  : continue
+        list_val=[]
+        trouveUnMC=0
+        for mcF in c.childNodes:
+            if mcF.name != fact: continue
+            for ll in mcF.childNodes[:]:
+                for mc in ll.childNodes:
+                    if mc.name not in liste_mc : continue
+                    val=mc.getText(jdc).split("=")[1].split(",")[0]
+                    list_val.append(val)
+                    trouveUnMC=1
+                if trouveUnMC :
+                    TexteMC=new_name+"=("+",".join(list_val)+"),"
+                    inseremocle.insereMotCleDansFacteur(jdc,mcF,TexteMC)
+                    jdc.reset(jdc.getSource())
+                    boolChange=1
+    if boolChange :
+        jdc.reset(jdc.getSource())
+        for mc in liste_mc : 
+           removemocle.removeMotCleInFact(jdc,command,fact,mc)
+           jdc.reset(jdc.getSource())
+
+#-----------------------------------------------------
+def FusionMCFToMCF(jdc,command,liste_mcf,factcible,defaut=0):
+#-----------------------------------------------------
+    if command  not in jdcSet : return
+    boolChange=0
+    commands= jdc.root.childNodes[:]
+    commands.reverse()
+    for c in commands:
+        if c.name != command  : continue
+        list_val=[]
+        trouveUnMC=0
+        TexteMC=factcible+'=('
+        esp1=' '*len(TexteMC)
+        pp=0
+        for mcF in c.childNodes:
+            if mcF.name not in liste_mcf : continue
+            trouveUnMC=1
+            val=mcF.getText(jdc)
+            # esp=esp1+(inseremocle.chercheDebutFacteur(jdc,mcF)-len(mcF.name))*' '
+            esp=esp1+inseremocle.chercheAlignement(jdc,c)
+            # print len(esp)
+            for ll in mcF.childNodes[:]:
+                # if(pp>0): TexteMC+=esp
+                TexteMC+='_F('
+                for mc in ll.childNodes:
+                    val=mc.getText(jdc)
+                    TexteMC+=val+'\n   '+esp
+                    # if('#' in val.split('\n')[-1]): TexteMC+='\n'+esp+'  '
+                lastkey = ''.join(val.split('=')[-1].split(' '))
+                if((len(lastkey.split('(')) - len(lastkey.split(')'))) >= 0):
+                    TexteMC += '),\n'+esp
+            # TexteMC+='),'
+        TexteMC+='),'
+        # print TexteMC
+        if(trouveUnMC):
+            inseremocle.insereMotCle(jdc,c,TexteMC)
+            jdc.reset(jdc.getSource())
+            boolChange=1
+    if boolChange :
+        jdc.reset(jdc.getSource())
+        for mcF in liste_mcf : 
+            removemocle.removeMotCle(jdc,command,mcF)
+            jdc.reset(jdc.getSource())
+
+
+
 #--------------------------------------------------------------------
 def EclaMotCleToFact(jdc,command,motcle,mot1,mot2,defaut=0):
 #--------------------------------------------------------------------------