From: Pascale Noyret Date: Wed, 20 Sep 2006 07:04:45 +0000 (+0000) Subject: PN : pour sauvegarde X-Git-Tag: CC_param_poursuite~8 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=d229fcb92512f09bbd0571173c52fb7e9f56b341;p=modules%2Feficas.git PN : pour sauvegarde --- diff --git a/Traducteur/calcG.py b/Traducteur/calcG.py index e9f1e43d..8a7aa47b 100644 --- a/Traducteur/calcG.py +++ b/Traducteur/calcG.py @@ -3,6 +3,7 @@ from parseur import FactNode dict_commande={} dict_contexte={} +dict_contexte_option={} #-------------------------------------------------------------------------- def traitementRayon(jdc): @@ -73,7 +74,6 @@ def chercheValeurSelonGenea2(jdc,liste_cherche_valeur): #-------------------------------------------------------------------------- def chercheValeurSelonGenea3(jdc,liste_cherche_valeur): -# #-------------------------------------------------------------------------- liste_valeurs=[] for genea in liste_cherche_valeur: @@ -105,3 +105,36 @@ def chercheValeurSelonGenea3(jdc,liste_cherche_valeur): pass return liste_valeurs + +#-------------------------------------------------------------------------- +def traitementOption(jdc): +#-------------------------------------------------------------------------- + dtheta={"CALC_G_LAGR":"G_LAGR_GLOB", "G_BILINEAIRE":"G_BILI_GLOB", "CALC_G_MAX":"G_MAX_GLOB", "CALC_G":"CALC_G_MAX"} + dlocal={"CALC_G_LGLO":"G_LAGR", "G_BILINEAIRE":"G_BILI", "CALC_G_MAX":"G_MAX"} + + for c in jdc.root.childNodes: + if c.name != "CALC_G_THETA_T" and c.name != "CALC_G_LOCAL_T" : continue + if c.name == "CALC_G_LOCAL_T" : + DictNouvVal=dlocal + else : + DictNouvVal=dtheta + for mc in c.childNodes: + if mc.name != "OPTION" : continue + TexteMC=mc.getText(jdc) + liste_ligne_MC=TexteMC.splitlines() + indexLigneGlob=mc.lineno-1 + indexTexteMC=0 + while indexLigneGlob < mc.endline - 1 : + MaLigneGlob=jdc.getLines()[indexLigneGlob] + MaLigneTexte=liste_ligne_MC[indexTexteMC] + for Valeur in DictNouvVal.keys() : + trouve=MaLigneTexte.find(Valeur) + if trouve > -1 : + debut=MaLigneGlob.find(MaLigneTexte) + Nouveau=MaLigneGlob[debut:].replace(Valeur,DictNouvVal[Valeur]) + Nouveau=MaLigneGlob[0:debut]+Nouveau + jdc.getLines()[indexLigneGlob]=Nouveau + break + if trouve > -1 : break + indexLigneGlob=indexLigneGlob+1 + indexTexteMC=indexTexteMC+1 diff --git a/Traducteur/changeValeur.py b/Traducteur/changeValeur.py new file mode 100644 index 00000000..002f155c --- /dev/null +++ b/Traducteur/changeValeur.py @@ -0,0 +1,65 @@ +# -*- coding: utf-8 -*- +import logging + +#-------------------------------------------------------------------------- +def ChangementValeur(jdc,command,motcle,DictNouvVal,liste=(),defaut=0): +#-------------------------------------------------------------------------- + + for c in jdc.root.childNodes: + if c.name != command : continue + trouveUnMC=0 + for mc in c.childNodes: + if mc.name != motcle : continue + trouveUnMC=1 + TexteMC=mc.getText(jdc) + liste_ligne_MC=TexteMC.splitlines() + indexLigneGlob=mc.lineno-1 + indexTexteMC=0 + while indexLigneGlob < mc.endline - 1 : + MaLigneGlob=jdc.getLines()[indexLigneGlob] + MaLigneTexte=liste_ligne_MC[indexTexteMC] + for Valeur in DictNouvVal.keys() : + trouve=MaLigneTexte.find(Valeur) + if trouve > -1 : + debut=MaLigneGlob.find(MaLigneTexte) + Nouveau=MaLigneGlob[debut:].replace(Valeur,DictNouvVal[Valeur]) + Nouveau=MaLigneGlob[0:debut]+Nouveau + jdc.getLines()[indexLigneGlob]=Nouveau + if Valeur in liste : + logging.error("OPTION de CALCG à verifier ligne %s" , indexLigneGlob) + break + if trouve > -1 : break + indexLigneGlob=indexLigneGlob+1 + indexTexteMC=indexTexteMC+1 + if (trouveUnMC == 0) and ( defaut == 1): + logging.error("OPTION (defaut) de CALCG à verifier ligne %s" ,c.lineno ) + + +#-------------------------------------------------------------------------- +def ChangementValeurAvecAvertissement(jdc, command,motcle,DictNouvVal,liste): +#-------------------------------------------------------------------------- + defaut=0 + if liste[-1] == "defaut" : + defaut=1 + ChangementValeur(jdc,command,motcle,DictNouvVal,liste,defaut) + +#-------------------------------------------------------------------------- +def SuppressionValeurs(jdc, command,motcle,liste): +#-------------------------------------------------------------------------- + + for c in jdc.root.childNodes: + if c.name != command : continue + for mc in c.childNodes: + if mc.name != motcle : continue + TexteMC=mc.getText(jdc) + liste_ligne_MC=TexteMC.splitlines() + indexLigneGlob=mc.lineno-1 + while indexLigneGlob < mc.endline - 1 : + MaLigneGlob=jdc.getLines()[indexLigneGlob] + MaLigneTexte=liste_ligne_MC[indexTexteMC] + MaLigne=MaLigneTexte + for Valeur in liste : + trouve=MaLigneTexte.find(Valeur) + debut=MaLigneGlob.find(MaLigneTexte) + index = -1 + while index < -1 * len(MaLigne) : diff --git a/Traducteur/jdcparser.py b/Traducteur/jdcparser.py index caa70cf0..13553ff7 100644 --- a/Traducteur/jdcparser.py +++ b/Traducteur/jdcparser.py @@ -10,17 +10,20 @@ Typical use is: import log import optparse -from load import getJDC +from load import getJDC from mocles import parseKeywords -import removemocle -import renamemocle -import movemocle -import inseremocle +from removemocle import * +from renamemocle import * +from renamemocle import * +from inseremocle import * +from changeValeur import * +from movemocle import * import calcG atraiter=("IMPR_GENE","CALC_FONCTION", "DEFI_MATERIAU","STAT_NON_LINE", "CALC_G_LOCAL_T","CALC_G_THETA_T","CALC_G","AFFE_CHAR_MECA", "AFFE_CHAR_THER_F","IMPR_CO","DEFI_SQUELETTE","DEFI_FONCTION", + "CALC_THETA","AFFE_MODELE","DYNA_NON_LINE", ) #atraiter=("CALC_FONCTION","IMPR_GENE","STAT_NON_LINE","DEFI_MATERIAU", @@ -35,33 +38,33 @@ def traduc(infile,outfile): #Parse les mocles des commandes parseKeywords(root) - #removemocle.removeMotCleInFact(jdc,"AFFE_MATERIAU","AFFE","TOUT") - #removemocle.removeMotCle(jdc,"STAT_NONLINE","SOLVEUR") - #renamemocle.renameMotCleInFact(jdc,"AFFE_MODELE","AFFE","PHENOMENE","TOTO") - #renamemocle.renameMotCleInFact(jdc,"AFFE_MODELE","AFFE","MODELISATION","TITI") - #renamemocle.renameMotCleInFact(jdc,"DEFI_GROUP","CREA_GROUP_NO","GROUP_MA","TUTU") - #removemocle.removeMotCle(jdc,"LIRE_MAILLAGE","INFO") - #removemocle.removeMotCle(jdc,"LIRE_MAILLAGE","UNITE") - #renamemocle.renameMotCle(jdc,"DEFI_MATERIAU","ELAS","ELASTIC") - #renamemocle.renameMotCle(jdc,"AFFE_MATERIAU","MAILLAGE","MAILL") - #removemocle.removeMotCleInFact(jdc,"STAT_NONLINE","SOLV","METHOD") - #removemocle.removeMotCle(jdc,"STAT_NONLINE","AFFE") - #renamemocle.renameCommande(jdc,"AFFE_CHAR_MECA","AFFE_CHAR_MECA_PN") - #renamemocle.renameCommande(jdc,"DEBUT","DEBUT_PN") + #removeMotCleInFact(jdc,"AFFE_MATERIAU","AFFE","TOUT") + #removeMotCle(jdc,"STAT_NONLINE","SOLVEUR") + #renameMotCleInFact(jdc,"AFFE_MODELE","AFFE","PHENOMENE","TOTO") + #renameMotCleInFact(jdc,"AFFE_MODELE","AFFE","MODELISATION","TITI") + #renameMotCleInFact(jdc,"DEFI_GROUP","CREA_GROUP_NO","GROUP_MA","TUTU") + #removeMotCle(jdc,"LIRE_MAILLAGE","INFO") + #removeMotCle(jdc,"LIRE_MAILLAGE","UNITE") + #renameMotCle(jdc,"DEFI_MATERIAU","ELAS","ELASTIC") + #renameMotCle(jdc,"AFFE_MATERIAU","MAILLAGE","MAILL") + #removeMotCleInFact(jdc,"STAT_NONLINE","SOLV","METHOD") + #removeMotCle(jdc,"STAT_NONLINE","AFFE") + #renameCommande(jdc,"AFFE_CHAR_MECA","AFFE_CHAR_MECA_PN") + #renameCommande(jdc,"DEBUT","DEBUT_PN") # A decommenter a partir d ici # les arguments sont jdc,ancien-nom-de-commande,nouveau-nom-de-commande - renamemocle.renameCommandeSiRegle(jdc,"CALC_FONCTION","INFO_FONCTION", ((("RMS","MAX","NOCI_SEISME","NORME","ECART-TYPE"),"existeMCFParmi"),)) + renameCommandeSiRegle(jdc,"CALC_FONCTION","INFO_FONCTION", ((("RMS","MAX","NOCI_SEISME","NORME","ECART-TYPE"),"existeMCFParmi"),)) # Les arguments sont - jdc, # - nom de la procedure (pas teste avec autre chose) # - nom du mot clef facteur contenant, # - nom du mot cle simple # Attention ne fonctionne pas pour l instant avec +sieurs occurences du mot cle à déplacer - movemocle.moveMotCleFromFactToFather(jdc,"IMPR_GENE","GENE","UNITE") - movemocle.moveMotCleFromFactToFather(jdc,"IMPR_GENE","GENE","FORMAT") + moveMotCleFromFactToFather(jdc,"IMPR_GENE","GENE","UNITE") + moveMotCleFromFactToFather(jdc,"IMPR_GENE","GENE","FORMAT") # Les arguments sont - jdc # - nom de l operateur (pas teste avec autre chose) @@ -69,38 +72,50 @@ def traduc(infile,outfile): # - nom du mot cle simple # - liste de mots clef facteur arrivée possible # Attention ne fonctionne pas pour l instant avec +sieurs occurences du mot cle à déplacer - movemocle.moveMotCleFromFactToFactMulti(jdc,"STAT_NON_LINE","CONVERGENCE","RESI_INTE_RELA",("COMP_INCR","COMP_ELAS")) - movemocle.moveMotCleFromFactToFactMulti(jdc,"STAT_NON_LINE","CONVERGENCE","ITER_INTE_MAXI",("COMP_INCR","COMP_ELAS")) - movemocle.moveMotCleFromFactToFactMulti(jdc,"STAT_NON_LINE","CONVERGENCE","ITER_INTE_PAS",("COMP_INCR","COMP_ELAS")) - movemocle.moveMotCleFromFactToFactMulti(jdc,"STAT_NON_LINE","CONVERGENCE","RESO_INTE",("COMP_INCR","COMP_ELAS")) + moveMotCleFromFactToFactMulti(jdc,"STAT_NON_LINE","CONVERGENCE","RESI_INTE_RELA",("COMP_INCR","COMP_ELAS")) + moveMotCleFromFactToFactMulti(jdc,"STAT_NON_LINE","CONVERGENCE","ITER_INTE_MAXI",("COMP_INCR","COMP_ELAS")) + moveMotCleFromFactToFactMulti(jdc,"STAT_NON_LINE","CONVERGENCE","ITER_INTE_PAS",("COMP_INCR","COMP_ELAS")) + moveMotCleFromFactToFactMulti(jdc,"STAT_NON_LINE","CONVERGENCE","RESO_INTE",("COMP_INCR","COMP_ELAS")) + moveMotCleFromFactToFactMulti(jdc,"DYNA_NON_LINE","CONVERGENCE","RESI_INTE_RELA",("COMP_INCR","COMP_ELAS")) + moveMotCleFromFactToFactMulti(jdc,"DYNA_NON_LINE","CONVERGENCE","ITER_INTE_MAXI",("COMP_INCR","COMP_ELAS")) + moveMotCleFromFactToFactMulti(jdc,"DYNA_NON_LINE","CONVERGENCE","ITER_INTE_PAS",("COMP_INCR","COMP_ELAS")) + moveMotCleFromFactToFactMulti(jdc,"DYNA_NON_LINE","CONVERGENCE","RESO_INTE",("COMP_INCR","COMP_ELAS")) - renamemocle.renameMotCle(jdc,"DEFI_MATERIAU","LEMAITRE","LEMAITRE_IRRA") - movemocle.moveMotCleFromFactToFactMulti(jdc,"DEFI_MATERIAU","FLU_IRRA","QSR_K",("LEMAITRE_IRRA",)) - movemocle.moveMotCleFromFactToFactMulti(jdc,"DEFI_MATERIAU","FLU_IRRA","BETA",("LEMAITRE_IRRA",)) - movemocle.moveMotCleFromFactToFactMulti(jdc,"DEFI_MATERIAU","FLU_IRRA","PHI_ZERO",("LEMAITRE_IRRA",)) - movemocle.moveMotCleFromFactToFactMulti(jdc,"DEFI_MATERIAU","FLU_IRRA","L",("LEMAITRE_IRRA",)) - removemocle.removeMotCle(jdc,"DEFI_MATERIAU","FLU_IRRA") + renameMotCle(jdc,"DEFI_MATERIAU","LEMAITRE","LEMAITRE_IRRA") + moveMotCleFromFactToFactMulti(jdc,"DEFI_MATERIAU","FLU_IRRA","QSR_K",("LEMAITRE_IRRA",)) + moveMotCleFromFactToFactMulti(jdc,"DEFI_MATERIAU","FLU_IRRA","BETA",("LEMAITRE_IRRA",)) + moveMotCleFromFactToFactMulti(jdc,"DEFI_MATERIAU","FLU_IRRA","PHI_ZERO",("LEMAITRE_IRRA",)) + moveMotCleFromFactToFactMulti(jdc,"DEFI_MATERIAU","FLU_IRRA","L",("LEMAITRE_IRRA",)) + removeMotCle(jdc,"DEFI_MATERIAU","FLU_IRRA") - renamemocle.renameMotCleInFact(jdc,"DEFI_MATERIAU","GRAN_IRRA","A","GRAN_A") - renamemocle.renameMotCleInFact(jdc,"DEFI_MATERIAU","GRAN_IRRA","B","GRAN_B") - renamemocle.renameMotCleInFact(jdc,"DEFI_MATERIAU","GRAN_IRRA","S","GRAN_S") - movemocle.moveMotCleFromFactToFactMulti(jdc,"DEFI_MATERIAU","GRAN_IRRA","GRAN_A",("LEMAITRE_IRRA",)) - movemocle.moveMotCleFromFactToFactMulti(jdc,"DEFI_MATERIAU","GRAN_IRRA","GRAN_B",("LEMAITRE_IRRA",)) - movemocle.moveMotCleFromFactToFactMulti(jdc,"DEFI_MATERIAU","GRAN_IRRA","GRAN_S",("LEMAITRE_IRRA",)) - removemocle.removeMotCle(jdc,"DEFI_MATERIAU","GRAN_IRRA") + renameMotCleInFact(jdc,"DEFI_MATERIAU","GRAN_IRRA","A","GRAN_A") + renameMotCleInFact(jdc,"DEFI_MATERIAU","GRAN_IRRA","B","GRAN_B") + renameMotCleInFact(jdc,"DEFI_MATERIAU","GRAN_IRRA","S","GRAN_S") + moveMotCleFromFactToFactMulti(jdc,"DEFI_MATERIAU","GRAN_IRRA","GRAN_A",("LEMAITRE_IRRA",)) + moveMotCleFromFactToFactMulti(jdc,"DEFI_MATERIAU","GRAN_IRRA","GRAN_B",("LEMAITRE_IRRA",)) + moveMotCleFromFactToFactMulti(jdc,"DEFI_MATERIAU","GRAN_IRRA","GRAN_S",("LEMAITRE_IRRA",)) + removeMotCle(jdc,"DEFI_MATERIAU","GRAN_IRRA") - inseremocle.chercheOperInsereFacteur(jdc,"IMPR_CO","CONCEPT") - movemocle.moveMotClefInOperToFact(jdc,"IMPR_CO","CO","CONCEPT") - renamemocle.renameMotCleInFact(jdc,"IMPR_CO","CONCEPT","CO","NOM") + chercheOperInsereFacteur(jdc,"IMPR_CO","CONCEPT") + moveMotClefInOperToFact(jdc,"IMPR_CO","CO","CONCEPT") + renameMotCleInFact(jdc,"IMPR_CO","CONCEPT","CO","NOM") - inseremocle.chercheOperInsereFacteur(jdc,"DEFI_SQUELETTE","CYCLIQUE") - movemocle.moveMotClefInOperToFact(jdc,"DEFI_SQUELETTE","MODE_CYCL","CYCLIQUE") + chercheOperInsereFacteur(jdc,"DEFI_SQUELETTE","CYCLIQUE") + moveMotClefInOperToFact(jdc,"DEFI_SQUELETTE","MODE_CYCL","CYCLIQUE") - removemocle.removeMotCle(jdc,"AFFE_CHAR_MECA","VERI_DDL") - removemocle.removeMotCle(jdc,"AFFE_CHAR_THER_F","VERI_DDL") - renamemocle.renameOper(jdc,"CALC_G_LOCAL_T","CALC_G") - renamemocle.renameOper(jdc,"CALC_G_THETA_T","CALC_G") + removeMotCle(jdc,"AFFE_CHAR_MECA","VERI_DDL") + removeMotCle(jdc,"AFFE_CHAR_THER_F","VERI_DDL") + + dlocal={"CALC_G_LGLO":"G_LAGR", "G_BILINEAIRE":"G_BILI", "CALC_G_MAX":"G_MAX"} + ChangementValeur(jdc,"CALC_G_LOCAL_T","OPTION",dlocal) + + dtheta={"CALC_G_LAGR":"G_LAGR_GLOB", "G_BILINEAIRE":"G_BILI_GLOB", "CALC_G_MAX":"G_MAX_GLOB","CALC_G":"CALC_G_GLOB"} + # Attention si le defaut doit generer un avertissement Il faut le mettre comme dernier mot de la liste + lavertit=("CALC_G_LAGR","CALC_G","defaut") + ChangementValeurAvecAvertissement(jdc,"CALC_G_THETA_T","OPTION",dtheta,lavertit) + renameOper(jdc,"CALC_G_LOCAL_T","CALC_G") + renameOper(jdc,"CALC_G_THETA_T","CALC_G") # Attention cela necessite un traitement particulier et ne peut pas @@ -109,21 +124,22 @@ def traduc(infile,outfile): calcG.traitementRayon(jdc) - renamemocle.renameMotCle(jdc,"CALC_G","THETA","THETA_OLD") - inseremocle.chercheOperInsereFacteur(jdc,"CALC_G","THETA") - movemocle.moveMotClefInOperToFact(jdc,"CALC_G","THETA_OLD","THETA") - renamemocle.renameMotCleInFact(jdc,"CALC_G","THETA","THETA_OLD","THETA") + renameMotCle(jdc,"CALC_G","THETA","THETA_OLD") + chercheOperInsereFacteur(jdc,"CALC_G","THETA") + moveMotClefInOperToFact(jdc,"CALC_G","THETA_OLD","THETA") + renameMotCleInFact(jdc,"CALC_G","THETA","THETA_OLD","THETA") - movemocle.moveMotClefInOperToFact(jdc,"CALC_G","FOND_FISS","THETA") - movemocle.moveMotClefInOperToFact(jdc,"CALC_G","R_INF_FO","THETA") - movemocle.moveMotClefInOperToFact(jdc,"CALC_G","R_SUP_FO","THETA") - inseremocle.chercheOperInsereFacteurSiRegle(jdc,"CALC_G","LISSAGE",((("DEGRE",),"existe"),)) - movemocle.moveMotClefInOperToFact(jdc,"CALC_G","DEGRE","LISSAGE") + moveMotClefInOperToFact(jdc,"CALC_G","FOND_FISS","THETA") + moveMotClefInOperToFact(jdc,"CALC_G","R_INF_FO","THETA") + moveMotClefInOperToFact(jdc,"CALC_G","R_SUP_FO","THETA") + chercheOperInsereFacteurSiRegle(jdc,"CALC_G","LISSAGE",((("DEGRE",),"existe"),)) + moveMotClefInOperToFact(jdc,"CALC_G","DEGRE","LISSAGE") f=open(outfile,'w') f.write(jdc.getSource()) f.close() + def main(): parser = optparse.OptionParser(usage=usage) diff --git a/Traducteur/renamemocle.py b/Traducteur/renamemocle.py index 9caa952b..016bcac3 100644 --- a/Traducteur/renamemocle.py +++ b/Traducteur/renamemocle.py @@ -28,6 +28,9 @@ def renameMotCle(jdc,command,mocle,new_name): #------------------------------------------- def renameOper(jdc,command,new_name): #------------------------------------------- + logging.info("Traitement de %s renomme en %s ", command, new_name) + logging.info ("_________________________________________________") + logging.info (" ") for c in jdc.root.childNodes: if c.name != command:continue if debug:print "Renommage de:",c.name,c.lineno,c.colno @@ -55,6 +58,9 @@ def decaleLignesdeNBlancs(jdc,premiere,derniere,nbBlanc): #---------------------------------------------------------- def renameMotCleInFact(jdc,command,fact,mocle,new_name): #---------------------------------------------------------- + logging.info("Traitement de %s sous %s de %s renomme en %s ", mocle,fact,command, new_name) + logging.info ("_______________________________________________________________________") + logging.info (" ") for c in jdc.root.childNodes: if c.name != command:continue for mc in c.childNodes: @@ -67,6 +73,7 @@ def renameMotCleInFact(jdc,command,fact,mocle,new_name): if n.name != mocle:continue s=jdc.getLines()[n.lineno-1] jdc.getLines()[n.lineno-1]=s[:n.colno]+new_name+s[n.colno+len(mocle):] + logging.info("Renommage de: %s, %s, %s, en %s",n.name,n.lineno,n.colno,new_name) jdc.reset(jdc.getSource()) @@ -74,6 +81,12 @@ def renameMotCleInFact(jdc,command,fact,mocle,new_name): def renameCommande(jdc,command,new_name,ensemble=regles.SansRegle): #----------------------------------------------------------------- # nom de la commande "ancien format" , nom de la commande " nouveau format " + if ensemble != regles.SansRegle : + logging.info("Traitement de %s renomme en %s sous conditions", command, new_name) + else : + logging.info("Traitement de %s renomme en %s ", command, new_name) + logging.info ("_______________________________________________________________________") + logging.info (" ") for c in jdc.root.childNodes: if c.name != command:continue if ensemble.verif(c) == 0 : continue @@ -83,6 +96,7 @@ def renameCommande(jdc,command,new_name,ensemble=regles.SansRegle): jdc.getLines()[c.lineno-1]=s[:c.colno]+new_name+s[c.colno+len(command):] jdc.reset(jdc.getSource()) + logging.info (" ") #----------------------------------------------------------- def renameCommandeSiRegle(jdc,command,new_name,liste_regles):