From: PASCALE NOYRET Date: Thu, 25 Nov 2021 15:03:13 +0000 (+0100) Subject: Traducteur3 deveint Traducteur (python3) X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=6372dddc309cd044de325a3a0300c8ca0eb81a39;p=tools%2Feficas.git Traducteur3 deveint Traducteur (python3) --- diff --git a/Noyau/.context.py.swp b/Noyau/.context.py.swp deleted file mode 100644 index 1a3e2cfc..00000000 Binary files a/Noyau/.context.py.swp and /dev/null differ diff --git a/Noyau/N_MCSIMP.py.pn b/Noyau/N_MCSIMP.py.pn deleted file mode 100644 index 3e2c24bb..00000000 --- a/Noyau/N_MCSIMP.py.pn +++ /dev/null @@ -1,350 +0,0 @@ -# coding=utf-8 -# Copyright (C) 2007-2021 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 - - -""" - Ce module contient la classe MCSIMP qui sert à controler la valeur - d'un mot-clé simple par rapport à sa définition portée par un objet - de type ENTITE -""" - -from __future__ import absolute_import -from copy import copy - -from Noyau.N_ASSD import ASSD -from Noyau.N_UserASSDMultiple import UserASSDMultiple -from Noyau.N_CO import CO -from . import N_OBJECT -from .N_CONVERT import ConversionFactory -from .N_types import forceList, isSequence - - -class MCSIMP(N_OBJECT.OBJECT): - - """ - """ - nature = 'MCSIMP' - - def __init__(self, val, definition, nom, parent,objPyxbDeConstruction): - """ - Attributs : - - - val : valeur du mot clé simple - - definition - - nom - - parent - - Autres attributs : - - - valeur : valeur du mot-clé simple en tenant compte de la valeur par défaut - - """ - self.definition = definition - self.nom = nom - self.val = val - self.parent = parent - self.objPyxbDeConstruction = objPyxbDeConstruction - if parent: - self.jdc = self.parent.jdc - if self.jdc : self.cata = self.jdc.cata - else : self.cata = None - self.niveau = self.parent.niveau - self.etape = self.parent.etape - else: - # Le mot cle simple a été créé sans parent - # est-ce possible ? - self.jdc = None - self.cata = None - self.niveau = None - self.etape = None - if self.definition.creeDesObjets : - if issubclass(self.definition.creeDesObjetsDeType, UserASSDMultiple) : - self.convProto = ConversionFactory('UserASSDMultiple', self.definition.creeDesObjetsDeType) - else : - self.convProto = ConversionFactory('UserASSD', self.definition.creeDesObjetsDeType) - else : - self.convProto = ConversionFactory('type', typ=self.definition.type) - self.valeur = self.getValeurEffective(self.val) - if self.definition.utiliseUneReference : - if self.valeur != None: - if not type(self.valeur) in (list, tuple): self.valeur.ajoutUtilisePar(self) - else : - #PNPN --> chgt pour Vimmp - for v in self.valeur : - try : v.ajoutUtilisePar(self) - except : print ('il y a un souci ici', self.nom, self.valeur) - self.buildObjPyxb() - self.listeNomsObjsCrees = [] - - def getValeurEffective(self, val): - """ - Retourne la valeur effective du mot-clé en fonction - de la valeur donnée. Defaut si val == None - Attention aux UserASSD et aux into (exple Wall gp de maille et 'Wall') - """ - #print ('getValeurEffective ________________', val) - if (val is None and hasattr(self.definition, 'defaut')): val = self.definition.defaut - if self.definition.type[0] == 'TXM' and isinstance(val,str) : return val - if self.definition.creeDesObjets : - # isinstance(val, self.definition.creeDesObjetsDeType) ne fonctionne pas car il y a un avec cata devant et l autre non - if val == None : return val - if not isinstance(val,(list,tuple)) : valATraiter=[val,] - else : valATraiter=val - listeRetour=[] - for v in valATraiter: - #print (v.__class__.__name__, self.definition.creeDesObjetsDeType.__name__) - if (not(v.__class__.__name__ == self.definition.creeDesObjetsDeType.__name__)) : - if self.jdc != None and v in list(self.jdc.sdsDict.keys()): v=self.jdc.sdsDict[v] - else : v=self.convProto.convert(v) - if v.parent== None : v.initialiseParent(self) - if issubclass(self.definition.creeDesObjetsDeType, UserASSDMultiple) : - v.ajouteUnPere(self) - else : - if v.nom=='sansNom' : - for leNom,laVariable in self.jdc.g_context.items(): - if id(laVariable)== id(v) and (leNom != 'sansNom'): - v.initialiseNom(leNom) - if v.parent== None : v.initialiseParent(self) - if issubclass(self.definition.creeDesObjetsDeType, UserASSDMultiple) : - v.ajouteUnPere(self) - listeRetour.append(v) - if isinstance(val,(list,tuple)) :newVal=listeRetour - else : newVal=listeRetour[0] - return newVal - if self.convProto: - val = self.convProto.convert(val) - return val - - def creeUserASSDetSetValeur(self, val): - self.state='changed' - nomVal=val - if nomVal in self.jdc.sdsDict.keys(): - if isinstance(self.jdc.sdsDict[nomVal],self.definition.creeDesObjetsDeType): - if issubclass(self.definition.creeDesObjetsDeType, UserASSDMultiple) : - p=self.parent - while p in self.parent : - if hasattr(p, 'listeDesReferencesCrees') : p.listeDesReferencesCrees.append(self.jdc.sdsDict[nomVal]) - else : p.listeDesReferencesCrees=[self.jdc.sdsDict[nomVal],] - p=p.parent - self.jdc.sdsDict[nomVal].ajouteUnPere(self) - #return (1, 'reference ajoutee') - else : - return (0, 'concept non multiple deja reference') - else : return (0, 'concept d un autre type existe deja') - if self.convProto: - objVal = self.convProto.convert(nomVal) - objVal.initialiseNom(nomVal) - if objVal.parent== None : objVal.initialiseParent(self) - objVal.ajouteUnPere(self) - p=self.parent - while p in self.parent : - if hasattr(p, 'listeDesReferencesCrees') : p.listeDesReferencesCrees.append(objVal) - else : p.listeDesReferencesCrees=[objVal,] - p=p.parent - return (self.setValeur(objVal), 'reference creee') - - def creeUserASSD(self, val): - self.state='changed' - nomVal=val - if nomVal in self.jdc.sdsDict.keys(): - if isinstance(self.jdc.sdsDict[nomVal],self.definition.creeDesObjetsDeType): - if issubclass(self.definition.creeDesObjetsDeType, UserASSDMultiple) : - p=self.parent - while p in self.parent : - if hasattr(p, 'listeDesReferencesCrees') : p.listeDesReferencesCrees.append(self.jdc.sdsDict[nomVal]) - else : p.listeDesReferencesCrees=[self.jdc.sdsDict[nomVal],] - p=p.parent - self.jdc.sdsDict[nomVal].ajouteUnPere(self) - return (1,self.jdc.sdsDict[nomVal], 'reference ajoutee') - else : return (0, None, 'concept d un autre type existe deja') - else : return (0, None, 'concept d un autre type existe deja') - if self.convProto: - objVal = self.convProto.convert(nomVal) - objVal.initialiseNom(nomVal) - objVal.ajouteUnPere(self) - return (1, objVal, 'reference creee') - - def rattacheUserASSD(self, objASSD): - if objASSD.parent== None : objASSD.initialiseParent(self) - p=self.parent - while p in self.parent : - if hasattr(p, 'listeDesReferencesCrees') : p.listeDesReferencesCrees.append(objASSD) - else : p.listeDesReferencesCrees=[objASSD,] - p=p.parent - - - def getValeur(self): - """ - Retourne la "valeur" d'un mot-clé simple. - Cette valeur est utilisée lors de la création d'un contexte - d'évaluation d'expressions à l'aide d'un interpréteur Python - """ - v = self.valeur - # Si singleton et max=1, on retourne la valeur. - # Si une valeur simple et max='**', on retourne un singleton. - # (si liste de longueur > 1 et max=1, on sera arrêté plus tard) - # Pour accepter les numpy.array, on remplace : "type(v) not in (list, tuple)" - # par "not has_attr(v, '__iter__')". - if v is None: - pass - elif isSequence(v) and len(v) == 1 and self.definition.max == 1: - v = v[0] - elif not isSequence(v) and self.definition.max != 1: - v = (v, ) - # traitement particulier pour les complexes ('RI', r, i) - if 'C' in self.definition.type and self.definition.max != 1 and v != None and v[0] in ('RI', 'MP'): - v = (v, ) - return v - - def getVal(self): - """ - Une autre méthode qui retourne une "autre" valeur du mot clé simple. - Elle est utilisée par la méthode getMocle - """ - return self.valeur - - def accept(self, visitor): - """ - Cette methode permet de parcourir l'arborescence des objets - en utilisant le pattern VISITEUR - """ - visitor.visitMCSIMP(self) - - def copy(self): - """ Retourne une copie de self """ - objet = self.makeobjet() - # il faut copier les listes et les tuples mais pas les autres valeurs - # possibles (réel,SD,...) - if type(self.valeur) in (list, tuple): - objet.valeur = copy(self.valeur) - else: - objet.valeur = self.valeur - objet.val = objet.valeur - return objet - - def makeobjet(self): - return self.definition(val=None, nom=self.nom, parent=self.parent) - - def reparent(self, parent): - """ - Cette methode sert a reinitialiser la parente de l'objet - """ - self.parent = parent - self.jdc = parent.jdc - self.etape = parent.etape - - def getSd_utilisees(self): - """ - Retourne une liste qui contient la ou les SD utilisée par self si c'est le cas - ou alors une liste vide - """ - l = [] - if isinstance(self.valeur, ASSD): - l.append(self.valeur) - elif type(self.valeur) in (list, tuple): - for val in self.valeur: - if isinstance(val, ASSD): - l.append(val) - return l - - def getSd_mcs_utilisees(self): - """ - Retourne la ou les SD utilisée par self sous forme d'un dictionnaire : - - Si aucune sd n'est utilisée, le dictionnaire est vide. - - Sinon, la clé du dictionnaire est le mot-clé simple ; la valeur est - la liste des sd attenante. - - Exemple :: - { 'VALE_F': [ , - ] } - """ - l = self.getSd_utilisees() - dico = {} - if len(l) > 0: - dico[self.nom] = l - return dico - - - def getMcsWithCo(self, co): - """ - Cette methode retourne l'objet MCSIMP self s'il a le concept co - comme valeur. - """ - if co in forceList(self.valeur): - return [self, ] - return [] - - def getAllCo(self): - """ - Cette methode retourne la liste de tous les concepts co - associés au mot cle simple - """ - return [co for co in forceList(self.valeur) - if isinstance(co, CO) and co.isTypCO()] - - def supprime(self): - if not type(self.valeur) in (list, tuple): lesValeurs=(self.valeur,) - else : lesValeurs=self.valeur - if self.valeur == None or self.valeur == [] : lesValeurs=[] - for val in lesValeurs: - if self.definition.creeDesObjets : val.deleteReference(self) - else : - if (hasattr (val, 'enleveUtilisePar')) : val.enleveUtilisePar(self) - N_OBJECT.OBJECT.supprime(self) - - def getUserAssdPossible(self): - classeAChercher = self.definition.type - l=[] - dicoValeurs={} - d={} - if self.definition.filtreVariables != None : - for (nomMC, Xpath) in self.definition.filtreVariables : - # print (nomMC, Xpath) - if Xpath == None : dicoValeurs[nomMC] = getattr(self,nomMC) - else : - try: #if 1 : - pereMC=eval(Xpath) - if pereMC : - exp=Xpath+'.getChild("'+nomMC+'")' - leMotCle=eval(exp) - else : leMotCle=None - if leMotCle : - if leMotCle.val : dicoValeurs[nomMC]=leMotCle.val - elif leMotCle.definition.max != 1 : dicoValeurs[nomMC] = [] - else : dicoValeurs[nomMC] = None - else : - #PN PN est-ce sur ? sinon quoi None ou [] - # je pense que les 2 valeurs doivent être renseignees si le filtre depend de 2 valeurs - return l - except: - return l - - - for k,v in self.parent.jdc.sdsDict.items(): - if (isinstance(v, classeAChercher)) : - if self.definition.filtreExpression : - try : - if v.executeExpression(self.definition.filtreExpression ,dicoValeurs) : l.append(v) - except : - print ('il faut comprendre except pour', self.nom) - #print (self.nom) - #print (self.parent.nom) - #print (k,v) - else : l.append(v) - return l diff --git a/Traducteur/.mocles.py.swp b/Traducteur/.mocles.py.swp new file mode 100644 index 00000000..9a2f5669 Binary files /dev/null and b/Traducteur/.mocles.py.swp differ diff --git a/Traducteur/.toto.comm.swp b/Traducteur/.toto.comm.swp new file mode 100644 index 00000000..824366dd Binary files /dev/null and b/Traducteur/.toto.comm.swp differ diff --git a/Traducteur/.visiteur.py.swp b/Traducteur/.visiteur.py.swp new file mode 100644 index 00000000..9ad7b735 Binary files /dev/null and b/Traducteur/.visiteur.py.swp differ diff --git a/Traducteur/CMakeLists.txt b/Traducteur/CMakeLists.txt new file mode 100644 index 00000000..d1c51c80 --- /dev/null +++ b/Traducteur/CMakeLists.txt @@ -0,0 +1,34 @@ +# -*- coding: utf-8 -*- +# CONFIGURATION MANAGEMENT OF EDF VERSION +# ====================================================================== +# COPYRIGHT (C) 1991 - 2002 EDF R&D WWW.CODE-ASTER.ORG +# THIS PROGRAM IS FREE SOFTWARE; YOU CAN REDISTRIBUTE IT AND/OR MODIFY +# IT UNDER THE TERMS OF THE GNU GENERAL PUBLIC LICENSE AS PUBLISHED BY +# THE FREE SOFTWARE FOUNDATION; EITHER VERSION 2 OF THE LICENSE, OR +# (AT YOUR OPTION) ANY LATER VERSION. +# +# THIS PROGRAM 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 +# GENERAL PUBLIC LICENSE FOR MORE DETAILS. +# +# YOU SHOULD HAVE RECEIVED A COPY OF THE GNU GENERAL PUBLIC LICENSE +# ALONG WITH THIS PROGRAM; IF NOT, WRITE TO EDF R&D CODE_ASTER, +# 1 AVENUE DU GENERAL DE GAULLE, 92141 CLAMART CEDEX, FRANCE. +# +# +# ====================================================================== + +# Installation de tous les fichiers Python, texte et images du repertoire et des sous-repertoires (sauf CVS) +install ( + FILES + calcG.py changeValeur.py dictErreurs.py __init__.py inseremocle.py + load.py log.py mocles.py movemocle.py parseur.py regles.py removemocle.py + renamemocle.py traduitV7V8.py traduitV8V9.py traduitV9V10.py utils.py + visiteur.py + DESTINATION ${CMAKE_INSTALL_PREFIX}/Traducteur + ) + +### Local Variables: +### mode: cmake +### End: diff --git a/Traducteur/__init__.py b/Traducteur/__init__.py new file mode 100644 index 00000000..e4044aec --- /dev/null +++ b/Traducteur/__init__.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +# Copyright (C) 2007-2017 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 +# diff --git a/Traducteur/changeValeur.py b/Traducteur/changeValeur.py new file mode 100644 index 00000000..50b0c9c9 --- /dev/null +++ b/Traducteur/changeValeur.py @@ -0,0 +1,317 @@ +# -*- coding: utf-8 -*- +# Copyright (C) 2007-2017 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 +# +from Traducteur.utils import lineToDict +import logging +from Traducteur.dictErreurs import ecritErreur +from Traducteur.load import jdcSet +from Traducteur.renamemocle import decaleLignesdeNBlancs +from Traducteur.removemocle import removeMotCleInFact +from Traducteur import regles + + +#-------------------------------------------------------------------------- +def changementValeur(jdc,command,motcle,DictNouvVal,liste=(),defaut=0): +#-------------------------------------------------------------------------- + if command not in jdcSet : return + boolChange=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 : + if indexTexteMC > len(liste_ligne_MC)-1 : break + MaLigneGlob=jdc.getLines()[indexLigneGlob] + MaLigneTexte=liste_ligne_MC[indexTexteMC] + for Valeur in DictNouvVal : + MaLigneTexteDict=lineToDict(MaLigneTexte) + trouvecol=MaLigneTexte.find(Valeur) + if trouvecol > -1: + trouve=(Valeur==MaLigneTexteDict[trouvecol]) + else: + trouve=False + if trouve: + debut=MaLigneGlob.find(motcle) + if debut==-1 : debut=0 + Nouveau=MaLigneGlob[debut:].replace(Valeur,DictNouvVal[Valeur]) + Nouveau=MaLigneGlob[0:debut]+Nouveau + jdc.getLines()[indexLigneGlob]=Nouveau + MaLigneTexte=Nouveau # raccourci honteux mais ... + MaLigneGlob=Nouveau + if Valeur in liste : + ecritErreur((command,motcle,Valeur),indexLigneGlob) + else : + logging.info("Changement de %s par %s dans %s ligne %d",Valeur,DictNouvVal[Valeur],command,indexLigneGlob) + boolChange=1 + indexLigneGlob=indexLigneGlob+1 + indexTexteMC=indexTexteMC+1 + if (trouveUnMC == 0) and ( defaut == 1): + ecritErreur((command,motcle,"DEFAUT"),c.lineno) + if boolChange : jdc.reset(jdc.getSource()) + +#-------------------------------------------------------------------------------- +def changementValeurDsMCF(jdc,command,fact,motcle,DictNouvVal,liste=(),ensemble=regles.SansRegle,defaut=0): +#-------------------------------------------------------------------------------- + + if command not in jdcSet : return + boolChange=0 + for c in jdc.root.childNodes: + if c.name != command : continue + for mcF in c.childNodes: + if mcF.name != fact : continue + l=mcF.childNodes[:] + l.reverse() + for ll in l: + trouveUnMC=0 + for mc in ll.childNodes: + if mc.name != motcle:continue + if ensemble.verif(c) == 0 : continue + trouveUnMC=1 + TexteMC=mc.getText(jdc) + liste_ligne_MC=TexteMC.splitlines() + indexLigneGlob=mc.lineno-1 + indexTexteMC=0 + while indexLigneGlob < mc.endline : + if indexTexteMC > len(liste_ligne_MC)-1 : break + MaLigneGlob=jdc.getLines()[indexLigneGlob] + MaLigneTexte=liste_ligne_MC[indexTexteMC] + for Valeur in DictNouvVal : + MaLigneTexteDict=lineToDict(MaLigneTexte) + trouvecol=MaLigneTexte.find(Valeur) + if trouvecol > -1: + trouve=(Valeur==MaLigneTexteDict[trouvecol]) + else: + trouve=False + if trouve: + debut=MaLigneGlob.find(motcle) + if debut==-1 : debut=0 + Nouveau=MaLigneGlob[debut:].replace(Valeur,DictNouvVal[Valeur]) + Nouveau=MaLigneGlob[0:debut]+Nouveau + jdc.getLines()[indexLigneGlob]=Nouveau + MaLigneTexte=Nouveau # raccourci honteux mais ... + MaLigneGlob=Nouveau + if Valeur in liste : + ecritErreur((command,fact,motcle,Valeur),indexLigneGlob) + else : + logging.info("Changement de %s par %s dans %s ligne %d",Valeur,DictNouvVal[Valeur],command,indexLigneGlob) + boolChange=1 + indexLigneGlob=indexLigneGlob+1 + indexTexteMC=indexTexteMC+1 + if (trouveUnMC == 0) and ( defaut == 1): + logging.warning("OPTION (defaut) de CALCG a verifier ligne %s" ,c.lineno ) + ecritErreur((command,fact,motcle,"DEFAUT"),c.lineno) + if boolChange : jdc.reset(jdc.getSource()) + +#-------------------------------------------------------------------------------- +def changementValeurDsMCFSiRegle(jdc,command,fact,motcle,DictNouvVal,liste_regles,defaut=0): +#-------------------------------------------------------------------------------- + if command not in jdcSet : return + mesRegles=regles.ensembleRegles(liste_regles) + liste=() + changementValeurDsMCF(jdc,command,fact,motcle,DictNouvVal,liste,mesRegles,defaut) + +#--------------------------------------------------------------------------------------- +def changementValeurDsMCFAvecAvertissement(jdc, command, fact,motcle,DictNouvVal,liste): +#--------------------------------------------------------------------------------------- + if command not in jdcSet : return + defaut=0 + if liste[-1] == "defaut" : + defaut=1 + changementValeurDsMCF(jdc,command,fact,motcle,DictNouvVal,liste,defaut) + +#-------------------------------------------------------------------------- +def changementValeurAvecAvertissement(jdc, command,motcle,DictNouvVal,liste): +#-------------------------------------------------------------------------- + if command not in jdcSet : return + defaut=0 + if liste[-1] == "defaut" : + defaut=1 + changementValeur(jdc,command,motcle,DictNouvVal,liste,defaut) + +#-------------------------------------------------------------------------- +def suppressionValeurs(jdc, command,motcle,liste): +#-------------------------------------------------------------------------- + + if command not in jdcSet : return + boolChange=0 + for c in jdc.root.childNodes: + if c.name != command : continue + for mc in c.childNodes: + if mc.name != motcle : continue + indexLigneGlob=mc.lineno-1 + while indexLigneGlob < mc.endline-1 : + MaLigneTexte = jdc.getLines()[indexLigneGlob] + MaLigne=MaLigneTexte + for Valeur in liste : + debutMC =MaLigne.find(motcle) + if debutMC ==-1 : debutMC=0 + debut1=MaLigne[0:debutMC] + chercheLigne=MaLigne[debutMC:] + trouve=chercheLigne.find(Valeur) + premier=0 + if trouve > 1 : #on a au moins une quote + debut=debut1 + chercheLigne[0:trouve-1] + index = -1 + while (-1 * index) < len(debut) : + if (debut[index] == "(") : + premier = 1 + if index == -1 : + index=len(debut) + else : + index=index+1 + break + if (debut[index] == "," ) : + break + if (debut[index] != " " ) : + assert(0) + index = index -1 + debLigne = debut[0:index] + fin=trouve+len(Valeur)+1 + if premier == 1 and chercheLigne[fin] == ',': fin = fin + 1 # on supprime la , + finLigne = chercheLigne[fin:] + MaLigne_tmp=debLigne+finLigne + # traitement ligne commancant par , + if len(MaLigne_tmp.strip()) > 0 : + if MaLigne_tmp.strip()[0]==',' : + MaLigne=MaLigne_tmp.strip()[1:] + else : + MaLigne=MaLigne_tmp[0:] + else : + MaLigne=MaLigne_tmp[0:] + boolChange=1 + jdc.getLines()[indexLigneGlob]=MaLigne + indexLigneGlob=indexLigneGlob+1 + if boolChange : jdc.reset(jdc.getSource()) + +#---------------------------------------------- +def appelleMacroSelonValeurConcept(jdc,macro,genea): +#---------------------------------------------- + if macro not in jdcSet : return + boolChange=0 + fact=genea[0] + motcle=genea[1] + chaine="CO" + for c in jdc.root.childNodes: + if c.name != macro : continue + for mcF in c.childNodes: + if mcF.name != fact : continue + l=mcF.childNodes[:] + l.reverse() + for ll in l: + trouveValeur=0 + for mc in ll.childNodes: + if mc.name != motcle:continue + TexteMC=mc.getText(jdc) + liste_ligne_MC=TexteMC.splitlines() + indexLigneGlob=mc.lineno-2 + trouveTexteMC=0 + trouveegal=0 + trouvechaine=0 + trouveparent=0 + trouvequote=0 + while indexLigneGlob < mc.endline : + indexLigneGlob=indexLigneGlob+1 + MaLigneTexte=jdc.getLines()[indexLigneGlob] + + # on commence par chercher TABLE par exemple + # si on ne trouve pas on passe a la ligne suivante + if ( trouveTexteMC == 0 ) : + indice=MaLigneTexte.find(motcle) + if indice < 0 : continue + trouveTexteMC=1 + else : + indice=0 + + # on cherche = + aChercher=MaLigneTexte[indice:] + if (trouveegal == 0 ): + indice=aChercher.find("=") + if indice < 0 : continue + trouveegal = 1 + else : + indice = 0 + + # on cherche CO + aChercher2=aChercher[indice:] + if (trouvechaine == 0 ): + indice=aChercher2.find(chaine) + if indice < 0 : continue + trouvechaine = 1 + else : + indice = 0 + + #on cherche ( + aChercher3=aChercher2[indice:] + if (trouveparent == 0 ): + indice=aChercher3.find('(') + if indice < 0 : continue + trouveparent = 1 + else : + indice = 0 + + #on cherche la ' + aChercher4=aChercher3[indice:] + if (trouvequote == 0 ): + indice=aChercher4.find("'") + indice2=aChercher4.find('"') + if (indice < 0) and (indice2 < 0): continue + if (indice < 0) : indice=indice2 + trouvequote = 1 + else : + indice = 0 + + trouveValeur=1 + aChercher5=aChercher4[indice+1:] + indice=aChercher5.find("'") + if indice < 0 : indice=aChercher5.find('"') + valeur=aChercher5[:indice] + break + + if trouveValeur==0 : + logging.error("Pb de traduction pour MACR_LIGNE_COUPE : Pas de nom de Concept identifiable") + return + + if boolChange : + jdc.reset(jdc.getSource()) + logging.error("Pb du traduction pour MACR_LIGNE_COUPE : Deux noms de Concept possibles") + return + + boolChange=1 + ligneaTraiter=jdc.getLines()[c.lineno-1] + debut=ligneaTraiter[0:c.colno] + suite=valeur+"=" + fin=ligneaTraiter[c.colno:] + ligne=debut+suite+fin + jdc.getLines()[c.lineno-1]=ligne + nbBlanc=len(valeur)+1 + if c.lineno < c.endline: + decaleLignesdeNBlancs(jdc,c.lineno,c.endline-1,nbBlanc) + if boolChange : jdc.reset(jdc.getSource()) + +#---------------------------------------------- +def changeTouteValeur(jdc,command,motcle,DictNouvVal,liste=(),defaut=0): +#---------------------------------------------- + if macro not in jdcSet : return + boolChange=0 diff --git a/Traducteur/demosRN.py b/Traducteur/demosRN.py new file mode 100755 index 00000000..477603f4 --- /dev/null +++ b/Traducteur/demosRN.py @@ -0,0 +1,94 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# Copyright (C) 2007-2017 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 +# +""" +""" +usage="""usage: %prog [options] +Typical use is: + python traduitV11V12.py --infile=xxxx --outfile=yyyy +""" + +import os, sys +sys.path.append(os.path.join(os.path.abspath(os.path.dirname(__file__)),'..')) + +import optparse + +from Traducteur.load import getJDC +from Traducteur.mocles import parseKeywords +from Traducteur.removemocle import * +from Traducteur.renamemocle import * +from Traducteur.renamemocle import * +from Traducteur.inseremocle import * +from Traducteur.changeValeur import * +from Traducteur.movemocle import * +from Traducteur.dictErreurs import * +from Traducteur.regles import pasDeRegle +from Traducteur import log + + + +atraiter=( + "Genere_Une_Erreur_Traduction", + "RodBank", + "Assembly", + "Techno_data", + "Model_data", + ) + +dict_erreurs={ + "Genere_Une_Erreur_Traduction":"Message pour test de genereErreurpourCommande ", + } + +sys.dict_erreurs=dict_erreurs + +def traduc(infile,outfile,flog=None): + + hdlr=log.initialise(flog) + jdc=getJDC(infile,atraiter) + root=jdc.root + + #Parse les mocles des commandes + parseKeywords(root) + + # genere une erreur si on trouve la commande dans le jdc # + genereErreurPourCommande(jdc,"Genere_Une_Erreur_Traduction") + + f=open(outfile,'w') + f.write(jdc.getSource()) + f.close() + + log.ferme(hdlr) + +def main(): + parser = optparse.OptionParser(usage=usage) + + parser.add_option('-i','--infile', dest="infile", default='toto.comm', + help="Le fichier à traduire") + parser.add_option('-o','--outfile', dest="outfile", default='tutu.comm', + help="Le fichier traduit") + + parser.add_option('-l','--logfile', dest="flog", default='log.txt', + help="fichier de log") + + options, args = parser.parse_args() + traduc(options.infile,options.outfile,options.flog) + +if __name__ == '__main__': + main() diff --git a/Traducteur/dictErreurs.py b/Traducteur/dictErreurs.py new file mode 100644 index 00000000..82fc058f --- /dev/null +++ b/Traducteur/dictErreurs.py @@ -0,0 +1,110 @@ +# -*- coding: utf-8 -*- +# Copyright (C) 2007-2017 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 +from Traducteur.load import jdcSet + + +def ecritErreur(listeGena,ligne=None) : + from sys import dict_erreurs + maCle="" + for Mot in listeGena : + maCle=maCle+"_"+Mot + #try : + if ( 1 == 1) : + maClef=maCle[1:] + if maClef in dict_erreurs : + if ligne != None : + logging.warning("ligne %d : %s ",ligne,dict_erreurs[maClef]) + else : + logging.warning("%s",dict_erreurs[maClef]) + else : + maCle="" + for Mot in listeGena[:-1] : + maCle=maCle+"_"+Mot + maClef=maCle[1:] + maClef=maCle+"_"+"VALEUR" + if maClef in dict_erreurs : + if ligne != None : + logging.warning("ligne %d : %s ",ligne,dict_erreurs[maClef]) + else : + logging.warning("%s",dict_erreurs[maClef]) + #except : + # pass + +def genereErreurPourCommande(jdc,listeCommande) : + commands= jdc.root.childNodes[:] + commands.reverse() + for c in commands: + if type(listeCommande)==list: + for Mot in listeCommande : + if c.name != Mot :continue + ecritErreur((Mot,),c.lineno) + else: + if c.name != listeCommande :continue + ecritErreur((listeCommande,),c.lineno) + +def genereErreurMotCleInFact(jdc,command,fact,mocle): + for c in jdc.root.childNodes: + if c.name != command:continue + for mc in c.childNodes: + if mc.name != fact:continue + l=mc.childNodes[:] + for ll in l: + for n in ll.childNodes: + if n.name != mocle: + continue + else : + ecritErreur((command,fact,mocle,),c.lineno) + +def genereErreurMCF(jdc,command,fact): + for c in jdc.root.childNodes: + if c.name != command:continue + for mc in c.childNodes: + if mc.name != fact: + continue + else : + ecritErreur((command,fact,),c.lineno) + +def genereErreurValeur(jdc,command,fact,list_valeur): + for c in jdc.root.childNodes: + if c.name != command:continue + for mc in c.childNodes: + if mc.name != fact:continue + texte=mc.getText(jdc) + for valeur in list_valeur: + trouve=texte.find(valeur) + if trouve > -1 : + logging.warning("%s doit etre supprimee ou modifiee dans %s : ligne %d",valeur,c.name,mc.lineno) + +def genereErreurValeurDsMCF(jdc,command,fact,mocle,list_valeur): + for c in jdc.root.childNodes: + if c.name != command:continue + for mc in c.childNodes: + if mc.name != fact:continue + l=mc.childNodes[:] + for ll in l: + for n in ll.childNodes: + if n.name != mocle:continue + texte=n.getText(jdc) + for valeur in list_valeur: + trouve=texte.find(valeur) + if trouve > -1 : + logging.warning("%s doit etre supprimee ou modifiee dans %s : ligne %d",valeur,c.name,n.lineno) diff --git a/Traducteur/edg_REP1300_FULL_PN.comm b/Traducteur/edg_REP1300_FULL_PN.comm new file mode 100755 index 00000000..ee4744a9 --- /dev/null +++ b/Traducteur/edg_REP1300_FULL_PN.comm @@ -0,0 +1,159 @@ + +REF=Assembly(assembly_type='REF',); + +U1=Assembly(assembly_type='UOX', + assembly_width=0.21504, + fuel_density=0.95, + radial_description=_F(clad_outer_radius=0.00475, + guide_tube_outer_radius=0.006025, + fuel_rod_pitch=0.0126, + nfuel_rods=264,), + axial_description=_F(active_length_start=0.21, + active_length_end=4.4772,), + grids=_F(mixing=_F(positions=(0.69216,1.19766,1.70316,2.20866,2.71416,3.20416,3.69416,4.18416,), + size=0.033,), + non_mixing=_F(positions=(0.026,4.2412,), + size=0.033,),),); + +UGD=Assembly(assembly_type='UOX', + assembly_width=0.21504, + fuel_density=0.95, + radial_description=_F(clad_outer_radius=0.00475, + guide_tube_outer_radius=0.006025, + fuel_rod_pitch=0.0126, + nfuel_rods=264,), + axial_description=_F(active_length_start=0.21, + active_length_end=4.4772,), + grids=_F(mixing=_F(positions=(0.69216,1.19766,1.70316,2.20866,2.71416,3.20416,3.69416,4.18416,), + size=0.033,), + non_mixing=_F(positions=(0.026,), + size=0.033,),),); + +RB=RodBank(rod_type='heterogeneous', + bottom_composition='AIC', + splitting_heigh=1.4224, + upper_composition='B4C', + step_height=0.016, + nsteps=260,); + +N1=RodBank(rod_type='heterogeneous', + bottom_composition='AIC', + splitting_heigh=1.4224, + upper_composition='B4C', + step_height=0.016, + nsteps=260,); + +N2=RodBank(rod_type='heterogeneous', + bottom_composition='AIC', + splitting_heigh=1.4226, + upper_composition='B4C', + step_height=0.016, + nsteps=260,); + +G1=RodBank(rod_type='homogeneous', + rod_composition='Grey', + step_height=0.016, + nsteps=260,); + +G2=RodBank(rod_type='homogeneous', + rod_composition='Grey', + step_height=0.016, + nsteps=260,); + +techno_data=Techno_data(assembly_list=(REF,U1,UGD,), + rodbank_list=(RB,G1,G2,N1,N2,), + radial_description=_F(nb_assembly=15, + xaxis=('RW','S','R','P','N','L','K','J','H','G','F','E','D','C','B','A','RE',), + yaxis= + ('RS','15','14','13','12','11', + '10','09','08','07','06','05','04','03','02','01','RN',), + assembly_map=((REF,REF,REF,REF,REF,REF,REF,REF,REF,REF,REF,REF,REF,REF,REF,REF,REF,),(REF,REF,REF,REF,REF,U1,U1,U1,U1,U1,U1,U1,REF,REF,REF,REF,REF,),(REF,REF,REF,UGD,U1,UGD,UGD,U1,U1,U1,UGD,UGD,U1,UGD,REF,REF,REF,),(REF,REF,UGD,U1,U1,U1,U1,UGD,U1,UGD,U1,U1,U1,U1,UGD,REF,REF,),(REF,REF,U1,U1,U1,UGD,U1,UGD,U1,UGD,U1,UGD,U1,U1,U1,REF,REF,),(REF,U1,UGD,U1,UGD,U1,U1,UGD,U1,UGD,U1,U1,UGD,U1,UGD,U1,REF,),(REF,U1,UGD,U1,U1,U1,UGD,UGD,U1,UGD,UGD,U1,U1,U1,UGD,U1,REF,),(REF,U1,U1,UGD,UGD,UGD,UGD,U1,UGD,U1,UGD,UGD,UGD,UGD,U1,U1,REF,),(REF,U1,U1,U1,U1,U1,U1,UGD,UGD,UGD,U1,U1,U1,U1,U1,U1,REF,),(REF,U1,U1,UGD,UGD,UGD,UGD,U1,UGD,U1,UGD,UGD,UGD,UGD,U1,U1,REF,),(REF,U1,UGD,U1,U1,U1,UGD,UGD,U1,UGD,UGD,U1,U1,U1,UGD,U1,REF,),(REF,U1,UGD,U1,UGD,U1,U1,UGD,U1,UGD,U1,U1,UGD,U1,UGD,U1,REF,),(REF,REF,U1,U1,U1,UGD,U1,UGD,U1,UGD,U1,UGD,U1,U1,U1,REF,REF,),(REF,REF,UGD,U1,U1,U1,U1,UGD,U1,UGD,U1,U1,U1,U1,UGD,REF,REF,),(REF,REF,REF,UGD,U1,UGD,UGD,U1,U1,U1,UGD,UGD,U1,UGD,REF,REF,REF,),(REF,REF,REF,REF,REF,U1,U1,U1,U1,U1,U1,U1,REF,REF,REF,REF,REF,),(REF,REF,REF,REF,REF,REF,REF,REF,REF,REF,REF,REF,REF,REF,REF,REF,REF,),), + rod_map= + (['#','#','#','#','#','#','#', + '#','#','#','#','#','#','#','#','#','#'],['#','#','#','#','#','.', + '.','.','.','.','.','.','#','#','#','#','#'],['#','#','#','.','.', + '.','.','.','RB','.','.','.','.','.','#','#','#'],['#','#','.','.', + '.','G2','.','N2','.','N2','.','G2','.','.','.','#','#'],['#','#', + '.','.','N1','.','.','.','G1','.','.','.','N1','.','.','#','#'], + ['#','.','.','G2','.','RB','.','.','.','.','.','RB','.','G2','.', + '.','#'],['#','.','.','.','.','.','.','.','N1','.','.','.','.','.', + '.','.','#'],['#','.','.','N2','.','.','.','.','.','.','.','.','.', + 'N2','.','.','#'],['#','.','RB','.','G1','.','N1','.','RB','.','N1', + '.','G1','.','RB','.','#'],['#','.','.','N2','.','.','.','.','.', + '.','.','.','.','N2','.','.','#'],['#','.','.','.','.','.','.','.', + 'N1','.','.','.','.','.','.','.','#'],['#','.','.','G2','.','RB', + '.','.','.','.','.','RB','.','G2','.','.','#'],['#','#','.','.', + 'N1','.','.','.','G1','.','.','.','N1','.','.','#','#'],['#','#', + '.','.','.','G2','.','N2','.','N2','.','G2','.','.','.','#','#'], + ['#','#','#','.','.','.','.','.','RB','.','.','.','.','.','#','#', + '#'],['#','#','#','#','#','.','.','.','.','.','.','.','#','#','#', + '#','#'],['#','#','#','#','#','#','#','#','#','#','#','#','#','#', + '#','#','#'],), + BU_map= + ([0.0,0.0,0.0,0.0,0.0,0.0,0.0, + 0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],[0.0,0.0,0.0,0.0,0.0,0.0,0.0, + 0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],[0.0,0.0,0.0,40.0,0.0,0.0, + 40.0,40.0,20.0,40.0,40.0,0.0,0.0,40.0,0.0,0.0,0.0],[0.0,0.0,40.0,0.0, + 40.0,20.0,40.0,0.0,40.0,0.0,40.0,20.0,40.0,0.0,40.0,0.0,0.0],[0.0,0.0, + 0.0,40.0,20.0,20.0,20.0,40.0,20.0,40.0,20.0,20.0,20.0,40.0,0.0,0.0, + 0.0],[0.0,0.0,0.0,20.0,20.0,20.0,40.0,0.0,40.0,0.0,40.0,20.0,20.0, + 20.0,0.0,0.0,0.0],[0.0,0.0,40.0,40.0,20.0,40.0,20.0,40.0,20.0,40.0, + 20.0,40.0,20.0,40.0,40.0,0.0,0.0],[0.0,0.0,40.0,0.0,40.0,0.0,40.0, + 20.0,20.0,20.0,40.0,0.0,40.0,0.0,40.0,0.0,0.0],[0.0,0.0,20.0,40.0, + 20.0,40.0,20.0,20.0,60.0,20.0,20.0,40.0,20.0,40.0,20.0,0.0,0.0],[0.0, + 0.0,40.0,0.0,40.0,0.0,40.0,20.0,20.0,20.0,40.0,0.0,40.0,0.0,40.0,0.0, + 0.0],[0.0,0.0,40.0,40.0,20.0,40.0,20.0,40.0,20.0,40.0,20.0,40.0,20.0, + 40.0,40.0,0.0,0.0],[0.0,0.0,0.0,20.0,20.0,20.0,40.0,0.0,40.0,0.0,40.0, + 20.0,20.0,20.0,0.0,0.0,0.0],[0.0,0.0,0.0,40.0,20.0,20.0,20.0,40.0, + 20.0,40.0,20.0,20.0,20.0,40.0,0.0,0.0,0.0],[0.0,0.0,40.0,0.0,40.0, + 20.0,40.0,0.0,40.0,0.0,40.0,20.0,40.0,0.0,40.0,0.0,0.0],[0.0,0.0,0.0, + 40.0,0.0,0.0,40.0,40.0,20.0,40.0,40.0,0.0,0.0,40.0,0.0,0.0,0.0],[0.0, + 0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],[0.0, + 0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],),), + axial_description=_F(lower_refl_size=0.21, + upper_refl_size=0.21,), + nominal_power=4000000000.0, + Fuel_power_fraction=0.974, + by_pass=0.07, + core_volumic_flowrate=90940.0,); + +neutro_model=Model_data(physics='Neutronics', + scale='component', + code='APOLLO3', + radial_meshing=_F(flux_solver='subdivision', + flux_subdivision=2, + feedback_solver='subdivision', + feedback_subdivision=1,), + axial_meshing=_F(lower_refl=2, + fuel=42, + upper_refl=2,),); + +thermo_model=Model_data(physics='Thermalhydraulics', + scale='component', + code='FLICA4', + radial_meshing=_F(fluid='subdivision', + fluid_subdivision=1, + pellet=8, + clad=2,), + axial_meshing=_F(lower_refl=1, + fuel=40, + upper_refl=1,),); + +scenario_data=Scenario_data(initial_power=0.1, + initial_power_unit='% Nominal power', + initial_core_inlet_temperature=290.0, + initial_boron_concentration=1300.0, + initial_inlet_pressure=160.2, + initial_outlet_pressure=157.2, + initial_rod_positions=(('Rodbank@RB',201),('Rodbank@N1',96),('Rodbank@N2',260),('Rodbank@G1',260),('Rodbank@G2',260),('Rodcluster@H08',260)), + scenario_type='RIA', + ejected_rod='H02', + rod_position_program=((0.0,0),(0.1,260)), + SCRAM='YES', + SCRAM_power=1130.0, + complete_SCRAM_time=1.0, + post_processing=(('Fuel temperature@Thermalhydraulics','MAX'),('Neutronic power@Neutronics','SUM'),('Fuel temperature@Thermalhydraulics','MED'),('Neutronic power@Neutronics','MED')),); + +Genere_Une_Erreur_Traduction(essai='3',); +#VERSION_CATALOGUE:V_0:FIN VERSION_CATALOGUE +#CHECKSUM:f62a6f71fcde9f983479fc749f7e334c -:FIN CHECKSUM \ No newline at end of file diff --git a/Traducteur/inseremocle.py b/Traducteur/inseremocle.py new file mode 100644 index 00000000..19dc1ceb --- /dev/null +++ b/Traducteur/inseremocle.py @@ -0,0 +1,289 @@ +# -*- coding: utf-8 -*- +# Copyright (C) 2007-2017 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 +from Traducteur.parseur import FactNode +from Traducteur.load import jdcSet +from Traducteur.dictErreurs import ecritErreur +from Traducteur import regles +debug=0 + + +#----------------------------------- +def insereMotCle(jdc,recepteur,texte): +#----------------------------------- +# appelle la methode selon la classe +# du recepteur + + if recepteur.name not in jdcSet : return + if recepteur.__class__.__name__ == "Command" : + if debug : print (" Ajout de ", texte, "dans la commande : " ,recepteur.name ) + insereMotCleDansCommande(jdc,recepteur,texte) + return + + +#-------------------------------------------- +def insereMotCleDansCommande(jdc,command,texte): +#--------------------------------------------- +# insere le texte comme 1er mot cle +# de la commande + if command.name not in jdcSet : return + if debug : print ("insereMotCle ", texte , " dans ", command.name) + numcol=chercheDebut1Mot(jdc,command) + if numcol > 0 : + jdc.splitLine(command.lineno,numcol) + indice = -1 + while texte[indice] == " " or texte[indice] == "\n": + indice = indice -1 + if texte[indice] != "," : texte=texte+"," + texteinfo=texte + texte=texte+'\n' + jdc.addLine(texte,command.lineno) + logging.info("Insertion de : %s ligne %d", texteinfo,command.lineno) + if numcol > 0 : # Les mots clefs etaient sur la meme ligne + jdc.joinLineandNext(command.lineno) + +#------------------------------------------------------------- +def insereMotCleDansFacteur(jdc,facteur,texte,plusieursFois=True): +#---------------------------------------------------------------- + if debug : print ("insereMotCle ", texte , " dans ", facteur.name) + + if texte[-1] == "\n" : texte=texte[0:-1] + ancien=jdc.getLine(facteur.lineno) + + # On va chercher la derniere ) pour ajouter avant + # on va verifier s il il y a un , avant + # si le texte ne finit pas par une "," + # on en met une + + indice = -1 + while texte[indice] == " " : + indice = indice -1 + if texte[indice] != "," : + texte=texte+"," + if (texte.find("#") > -1) and (texte.find("#") < texte.find(",")) : + texte=texte+"\n," + + texteinfo=texte + texte=texte+"\n" + + ligneaCouper=facteur.lineno + while ligneaCouper < facteur.endline + 1 : + trouve=0 + trouveF=0 + trouveP=0 + indiceDeCoupe=0 + while ancien.find("_F") > 0 : + longueur=len(ancien) + indice=ancien.find("_F") + indiceParcours=0 + # pour ne pas tenir compte des autres noms + # Attention si 2 MCF sur la meme ligne (la 1ere) + if trouveF == 0 : + if ((ligneaCouper!=facteur.lineno) or ((ancien.find(facteur.name) < indice ) or (ancien.find(facteur.name) < 0))) : + trouveF=1 + indiceParcours=indice + 2 + # attention pour regler DEFI_FONCTION .. + else : + indiceDeCoupe=indiceDeCoupe+indice+2 + ancien=ancien[indice +2:] + continue + if trouveF == 1 : + indiceDeCoupe=indiceDeCoupe+indice + # print "indice de Parcours" ,indiceParcours + # print ancien[indiceParcours] + # print ancien[indiceParcours+1] + # print ancien[indiceParcours+2] + while indiceParcours < longueur : + if ancien[indiceParcours] == "(" : + trouveP=1 + # print ("trouve". + break + if ancien[indiceParcours] != " " : + trouveP=0 + # print ("mouv") + break + indiceParcours = indiceParcours+1 + trouve = trouveP * trouveF + if trouve : break + ancien=ancien[indice+1:] + if trouve : + debut=indiceDeCoupe + 3 + if(jdc.getLine(ligneaCouper)[debut:]!="\n"): + jdc.splitLine(ligneaCouper,debut) + jdc.addLine(texte,ligneaCouper) + jdc.joinLineandNext(ligneaCouper) + logging.info("Insertion de %s ligne %d", texteinfo,ligneaCouper) + + # Gestion du cas particulier du mot clef facteur vide + if facteur.childNodes == []: + jdc.joinLineandNext(facteur.lineno) + + ligneaCouper=ligneaCouper+1 + ancien=jdc.getLine(ligneaCouper) + if not plusieursFois and trouve : break + + +#----------------------------------- +def chercheDebut1Mot(jdc,command): +#----------------------------------- +# Retourne le numero de colonne si le 1er mot clef est +# sur la meme ligne que le mot clef facteur +# -1 sinon + assert (command.childNodes != []) + debut=-1 + node1=command.childNodes[0] + if hasattr(node1,"lineno"): + if node1.lineno == command.lineno : + debut=node1.colno + else: + debut=chercheDebutFacteur(jdc,command) + if debut == -1 and debug : print ("attention!!! pb pour trouver le debut dans ", command) + return debut + +#----------------------------------- +def chercheDebutFacteur(jdc,facteur): +#----------------------------------- + debut=-1 + ligne=jdc.getLines()[facteur.lineno] + debut=ligne.find("_F") + if debut > -1 : debut=debut + 3 + return debut + + +#----------------------------------- +def chercheAlignement(jdc,command): +#----------------------------------- +# Retourne le nb de blanc +# pour aligner sur le 1er mot clef fils + assert (command.childNodes != []) + node1=command.childNodes[0] + nbBlanc=node1.colno + return " "*nbBlanc + +#--------------------------------------------------------------------------------------------------------- +def chercheOperInsereFacteur(jdc,nomcommande,nouveau,ensemble=regles.SansRegle, estunFacteur=1, erreur=0): +#-------------------------------------------------------------------------------------------------------- +# Cherche l oper +# cree le texte +# appelle insereMotCle pour ajouter le texte +# + boolChange=0 + if estunFacteur : + texte=nouveau+"=_F()," + else : + texte=nouveau + if nomcommande not in jdcSet : return + commands= jdc.root.childNodes[:] + commands.reverse() + for c in commands: + if c.name != nomcommande:continue + if ensemble.verif(c) == 0 : continue + if erreur : ecritErreur((nomcommande,nouveau),c.lineno) + boolChange=1 + insereMotCle(jdc,c,texte) + if boolChange : jdc.reset(jdc.getSource()) + +#---------------------------------------------------------------------------------------- +def chercheOperInsereFacteurSiRegle(jdc,nomcommande,nouveau,liste_regles, estunFacteur=1): +#---------------------------------------------------------------------------------------- +# Cherche l oper +# cree le texte +# appelle insereMotCle pour ajouter le texte +# + if nomcommande not in jdcSet : return + mesRegles=regles.ensembleRegles(liste_regles) + chercheOperInsereFacteur(jdc,nomcommande,nouveau,mesRegles,estunFacteur) + +#---------------------------------------------------------------------------------------- +def chercheOperInsereMotCleSiRegle(jdc,nomcommande,nouveau,liste_regles, estunFacteur=0): +#---------------------------------------------------------------------------------------- + if nomcommande not in jdcSet : return + mesRegles=regles.ensembleRegles(liste_regles) + chercheOperInsereFacteur(jdc,nomcommande,nouveau,mesRegles,estunFacteur) + + +#--------------------------------------------------------------------------------------------------------- +def chercheOperInsereFacteurSiRegleAvecAvertissement(jdc,nomcommande,nouveau,liste_regles, estunFacteur=1): +#--------------------------------------------------------------------------------------------------------- + if nomcommande not in jdcSet : return + mesRegles=regles.ensembleRegles(liste_regles) + chercheOperInsereFacteur(jdc,nomcommande,nouveau,mesRegles,estunFacteur,erreur=1) + +#------------------------------------------------------------------------------------------------- +def ajouteMotClefDansFacteur(jdc,commande,fact,nouveau,ensemble=regles.SansRegle, estunFacteur=0): +#------------------------------------------------------------------------------------------------- +# Cherche la commande +# Cherche le MCF +# cree le texte +# appelle insereMotCle pour ajouter le texte +# + if commande not in jdcSet : return + if estunFacteur : + texte=nouveau+"=_F()," + else : + texte=nouveau + commands= jdc.root.childNodes[:] + commands.reverse() + boolChange=0 + for c in commands: + if c.name != commande : continue + for mcF in c.childNodes: + if mcF.name != fact : continue + if ensemble.verif(c) == 0 : continue + boolChange=1 + insereMotCleDansFacteur(jdc,mcF,texte) + if boolChange : jdc.reset(jdc.getSource()) + +#------------------------------------------------------------------------------------------- +def ajouteMotClefDansFacteurSiRegle(jdc,commande,fact,nouveau,liste_regles,estunFacteur=0): +#------------------------------------------------------------------------------------------- +# + if commande not in jdcSet : return + mesRegles=regles.ensembleRegles(liste_regles) + ajouteMotClefDansFacteur(jdc,commande,fact,nouveau,mesRegles,estunFacteur) + +#------------------------------------------------------------------------------------------- +def ajouteMotClefDansFacteurCourantSiRegle(jdc,commande,fact,nouveau,liste_regles): +#------------------------------------------------------------------------------------------- +# + if commande not in jdcSet : return + ensemble=regles.ensembleRegles(liste_regles) + commands= jdc.root.childNodes[:] + commands.reverse() + boolChange=0 + for c in commands: + if c.name != commande : continue + for mcF in c.childNodes: + if mcF.name != fact : continue + l=mcF.childNodes[:] + l.reverse() + for ll in l: + if ensemble.verif(ll) == 0 : continue + boolChange=1 + n=ll.childNodes[0] + ligneaCouper=n.lineno-1 + numcol=n.colno + jdc.splitLine(ligneaCouper+1,numcol) + texte=nouveau+",\n" + jdc.addLine(texte,ligneaCouper+1) + logging.info("Insertion de %s dans %s : ligne %d", nouveau,c.name,ligneaCouper+1) + if numcol > 0 : + jdc.joinLineandNext(ligneaCouper+1) + if boolChange : jdc.reset(jdc.getSource()) diff --git a/Traducteur/load.py b/Traducteur/load.py new file mode 100644 index 00000000..f5aa5b52 --- /dev/null +++ b/Traducteur/load.py @@ -0,0 +1,146 @@ +# -*- coding: utf-8 -*- +# Copyright (C) 2007-2017 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 os +import re +from Traducteur import parseur +from Traducteur.mocles import parseKeywords + +jdcSet=set() + + +class JDCTrad: + """Cet objet conserve toutes les informations relatives a un fichier de commandes .comm""" + + def __init__(self,src,atraiter): + #---------------------------------------- + self.atraiter=atraiter + self.init(src,atraiter) + commands= self.root.childNodes[:] + commands.reverse() + for c in commands: + jdcSet.add(c.name) + + def init(self,src,atraiter): + #--------------------------- + # construction de self.lines + self.root=parseur.parser(src,atraiter) + self.lines=src.splitlines(1) + + def parseKeywords(self): + #----------------------- + # construction de fils (cf mocles.py) + parseKeywords(self.root) + + def reset(self,src): + #----------------------- + # reconstruction + self.init(src,self.atraiter) + self.parseKeywords() + + def getSource(self): + #----------------------- + # retourne la concatenation de + # toutes les lignes + return "".join(self.getLines()) + + def getLine(self,linenum): + #----------------------- + # retourne la linenumieme ligne + return self.getLines()[linenum-1] + + def getLines(self): + #---------------------------- + # retourne toutes les lignes + return self.lines + + def addLine(self,ligne,numero) : + #---------------------------- + # insere le texte contenu dans ligne + # dans la liste self.lines au rang numero + Ldebut=self.lines[0:numero] + Lmilieu=[ligne,] + Lfin=self.lines[numero:] + self.lines=Ldebut+Lmilieu+Lfin + + + def splitLine(self,numeroLigne,numeroColonne) : + #---------------------------------------------- + # coupe la ligne numeroLigne en 2 a numeroColonne + # ajoute des blancs en debut de 2nde Ligne pour + # aligner + numeroLigne = numeroLigne -1 + Ldebut=self.lines[0:numeroLigne] + if len(self.lines) > numeroLigne : + Lfin=self.lines[numeroLigne+1:] + else : + Lfin=[] + Lsplit=self.lines[numeroLigne] + LigneSplitDebut=Lsplit[0:numeroColonne]+"\n" + LigneSplitFin=" "*numeroColonne+Lsplit[numeroColonne:] + Lmilieu=[LigneSplitDebut,LigneSplitFin] + + self.lines=Ldebut+Lmilieu+Lfin + + def joinLineandNext(self,numeroLigne) : + #-------------------------------------- + # concatene les lignes numeroLigne et numeroLigne +1 + # enleve les blancs de debut de la ligne (numeroLigne +1) + Ldebut=self.lines[0:numeroLigne-1] + if len(self.lines) > numeroLigne : + Lfin=self.lines[numeroLigne+1:] + else : + Lfin=[] + + ligneMilieuDeb=self.lines[numeroLigne - 1 ] + ligneMilieuDeb=ligneMilieuDeb[0:-1] + ligneMilieuFin=self.lines[numeroLigne] + for i in range(len(ligneMilieuFin)): + if ligneMilieuFin[i] != " " : + ligneMilieuFin=ligneMilieuFin[i:] + break + Lmilieu=[ligneMilieuDeb+ligneMilieuFin,] + + self.lines=Ldebut+Lmilieu+Lfin + + def supLignes(self,debut,fin): + #------------------------ + Ldebut=self.lines[0:debut-1] + Lfin=self.lines[fin:] + self.lines=Ldebut+Lfin + + def remplaceLine(self,numeroLigne,nouveauTexte) : + #------------------------------------------------ + self.lines[numeroLigne]=nouveauTexte + +def getJDC(filename,atraiter): +#---------------------------- +# lit le JDC + f=open(filename) + src=f.read() + f.close() + jdc=JDCTrad(src,atraiter) + return jdc + +def getJDCFromTexte(texte,atraiter): +#----------------------------------- +# lit le JDC + jdc=JDCTrad(texte,atraiter) + return jdc diff --git a/Traducteur/log.py b/Traducteur/log.py new file mode 100644 index 00000000..21c4ab61 --- /dev/null +++ b/Traducteur/log.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +# Copyright (C) 2007-2017 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 os +logger=logging.getLogger() + +def initialise(flog=None): + if flog == None : + MonHome=os.environ['HOME'] + MaDir=MonHome+"/Eficas_install" + try : + os.mkdir(MaDir) + except : + pass + try : + os.listdir(MaDir) + flog=MaDir+"/convert.log" + except : + flog='/tmp/convert.log' + + hdlr=logging.FileHandler(flog,'w') + formatter = logging.Formatter('%(levelname)s: %(message)s') + hdlr.setFormatter(formatter) + logger.addHandler(hdlr) + logger.setLevel(logging.INFO) + return hdlr + + +def ferme (hdlr) : + logger.removeHandler(hdlr) diff --git a/Traducteur/log.txt b/Traducteur/log.txt new file mode 100644 index 00000000..85f57675 --- /dev/null +++ b/Traducteur/log.txt @@ -0,0 +1 @@ +WARNING: ligne 159 : Message pour test de genereErreurpourCommande diff --git a/Traducteur/mocles.py b/Traducteur/mocles.py new file mode 100644 index 00000000..0c890f8b --- /dev/null +++ b/Traducteur/mocles.py @@ -0,0 +1,168 @@ +# -*- coding: utf-8 -*- +# Copyright (C) 2007-2017 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 compiler +import ast +import types +from Traducteur.parseur import Keyword, FactNode, lastParen, lastParen2,maskStringsAndComments +from Traducteur.visiteur import KeywordFinder, NodeVisitor +from Traducteur.utils import indexToCoordinates, lineToDict, dictToLine + +debug=0 + +#------------------------ +def parseFact(match,c,kw): +#------------------------ + submatch=match[2] + lastpar=match[0]+lastParen(c.src[match[0]:]) + #if type(submatch[0][0]) ==types.IntType: + if isinstance(submatch[0][0], int) : + #mot cle facteur isole + no=FactNode() + kw.addChild(no) + for ii in range(len(submatch)-1): + e=submatch[ii] + x,y=indexToCoordinates(c.src,e[0]) + lineno=y+c.lineno + colno=x + x,y=indexToCoordinates(c.src,submatch[ii+1][0]) + endline=y+c.lineno + endcol=x + no.addChild(Keyword(e[1],lineno,colno,endline,endcol)) + #last one + e=submatch[-1] + x,y=indexToCoordinates(c.src,e[0]) + lineno=y+c.lineno + colno=x + x,y=indexToCoordinates(c.src,lastpar-1) + endline=y+c.lineno + endcol=x + no.addChild(Keyword(e[1],lineno,colno,endline,endcol)) + else: + #mot cle facteur multiple + ii=0 + for l in submatch: + lastpar=l[0][0]+lastParen2(c.src[l[0][0]:]) + ii=ii+1 + no=FactNode() + kw.addChild(no) + for j in range(len(l)-1): + e=l[j] + x,y=indexToCoordinates(c.src,e[0]) + lineno=y+c.lineno + colno=x + x,y=indexToCoordinates(c.src,l[j+1][0]) + endline=y+c.lineno + endcol=x + no.addChild(Keyword(e[1],lineno,colno,endline,endcol)) + #last one + e=l[-1] + x,y=indexToCoordinates(c.src,e[0]) + lineno=y+c.lineno + colno=x + x,y=indexToCoordinates(c.src,lastpar-1) + endline=y+c.lineno + endcol=x + no.addChild(Keyword(e[1],lineno,colno,endline,endcol)) + + +#----------------------- +def parseKeywords(root): +#----------------------- + """A partir d'un arbre contenant des commandes, ajoute les noeuds + fils correspondant aux mocles de la commande + """ + debug=1 + #traceback.print_stack(limit=5) + + matchFinder=KeywordFinder() + + for c in root.childNodes: + if debug : print ('parse -------------- ', c.name) + maskedsrc=maskStringsAndComments(c.src) + #on supprime seulement les blancs du debut pour pouvoir compiler + #meme si la commande est sur plusieurs lignes seul le debut compte + #ast=compiler.parse(c.src.lstrip()) + #print ast + monAst=ast.parse(c.src.lstrip()) + if debug : print (ast.dump(monAst)) + #Ne pas supprimer les blancs du debut pour avoir les bons numeros de colonne + matchFinder.reset(maskedsrc) + matchFinder.visit(monAst) + if debug : print ("matchFinder.matches", matchFinder.matches) + if len(matchFinder.matches) > 1: + # plusieurs mocles trouves : + # un mocle commence au debut du keyword (matchFinder.matches[i][0]) + # et finit juste avant le keyword suivant + # (matchFinder.matches[i+1][0]]) + for i in range(len(matchFinder.matches)-1): + if debug:print ("texte:",c.src[matchFinder.matches[i][0]:matchFinder.matches[i+1][0]]) + x,y=indexToCoordinates(c.src,matchFinder.matches[i][0]) + lineno=y+c.lineno + colno=x + x,y=indexToCoordinates(c.src,matchFinder.matches[i+1][0]) + endline=y+c.lineno + endcol=x + if debug:print (matchFinder.matches[i][0],matchFinder.matches[i][1],lineno,colno,endline,endcol) + kw=Keyword(matchFinder.matches[i][1],lineno,colno,endline,endcol) + c.addChild(kw) + submatch= matchFinder.matches[i][2] + if submatch: + parseFact(matchFinder.matches[i],c,kw) + + # dernier mocle : + # il commence au debut du dernier keyword + # (matchFinder.matches[i+1][0]) et + # finit avant la parenthese fermante de la commande (c.lastParen) + + if debug:print ("texte:",c.src[matchFinder.matches[i+1][0]:c.lastParen]) + x,y=indexToCoordinates(c.src,matchFinder.matches[i+1][0]) + lineno=y+c.lineno + colno=x + x,y=indexToCoordinates(c.src,c.lastParen) + endline=y+c.lineno + endcol=x + if debug:print (matchFinder.matches[i+1][0],matchFinder.matches[i+1][1],lineno,colno,endline,endcol) + kw=Keyword(matchFinder.matches[i+1][1],lineno,colno,endline,endcol) + c.addChild(kw) + submatch= matchFinder.matches[i+1][2] + if submatch: + parseFact(matchFinder.matches[i+1],c,kw) + + elif len(matchFinder.matches) == 1: + #un seul mocle trouve : + # il commence au debut du keyword (matchFinder.matches[0][0]) et + # finit juste avant la parenthese fermante de la + # commande (c.lastParen) + if debug:print ("texte:",c.src[matchFinder.matches[0][0]:c.lastParen]) + x,y=indexToCoordinates(c.src,matchFinder.matches[0][0]) + lineno=y+c.lineno + colno=x + x,y=indexToCoordinates(c.src,c.lastParen) + endline=y+c.lineno + endcol=x + if debug:print ( matchFinder.matches[0][0],matchFinder.matches[0][1],lineno,colno,endline,endcol) + kw=Keyword(matchFinder.matches[0][1],lineno,colno,endline,endcol) + c.addChild(kw) + submatch= matchFinder.matches[0][2] + if submatch: + parseFact(matchFinder.matches[0],c,kw) + else: + pass diff --git a/Traducteur/movemocle.py b/Traducteur/movemocle.py new file mode 100644 index 00000000..4a43752f --- /dev/null +++ b/Traducteur/movemocle.py @@ -0,0 +1,346 @@ +# -*- coding: iso-8859-1 -*- +# Copyright (C) 2007-2017 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 +from Traducteur import removemocle +from Traducteur import inseremocle +from Traducteur.parseur import lastParen +from Traducteur.load import jdcSet +debug=0 + +#----------------------------------------------------- +def moveMotCleFromFactToFather(jdc,command,fact,mocle): +#----------------------------------------------------- +# exemple type : IMPR_GENE + + if command not in jdcSet : return + boolChange=0 + commands= jdc.root.childNodes[:] + commands.reverse() + for c in commands: + if c.name != command:continue + boolchange_c=0 + for mc in c.childNodes: + if mc.name != fact:continue + l=mc.childNodes[:] + for ll in l: + for n in ll.childNodes: + if n.name != mocle:continue + # test boolchange_c :il faut le faire une seule fois par commande sinon duplication du mot clé + if boolchange_c != 0 :continue + if debug : print ("Changement de place :", n.name, n.lineno, n.colno) + MonTexte=n.getText(jdc); + boolChange=1 + boolchange_c=1 + inseremocle.insereMotCle(jdc,c,MonTexte) + logging.info("Changement de place %s ligne %s ",n.name, n.lineno) + + if boolChange : jdc.reset(jdc.getSource()) + removemocle.removeMotCleInFact(jdc,command,fact,mocle) + + +#---------------------------------------------------------------------------- +def moveMotCleFromFactToFactMulti(jdc,oper,factsource,mocle,liste_factcible): +#---------------------------------------------------------------------------- +# exemple type STAT_NON_LINE et RESI_INTER_RELA + for factcible in liste_factcible : + moveMotCleFromFactToFact(jdc,oper,factsource,mocle,factcible) + removemocle.removeMotCleInFact(jdc,oper,factsource,mocle) + + +#---------------------------------------------------------------------------- +def moveMotCleFromFactToFact(jdc,oper,factsource,mocle,factcible): +#---------------------------------------------------------------------------- + if oper not in jdcSet : return + if debug : print ("moveMotCleFromFactToFact pour " ,oper,factsource,mocle,factcible) + boolChange=0 + commands= jdc.root.childNodes[:] + commands.reverse() + for c in commands: + if c.name != oper : continue + cible=None + for mc in c.childNodes: + if mc.name != factcible : + continue + else : + cible=mc + break + if cible==None : + if debug : print ("Pas de changement pour ", oper, " ", factsource, " ",mocle, "cible non trouvée") + continue + + for mc in c.childNodes: + source=None + if mc.name != factsource: + continue + else : + source=mc + break + if source==None : + if debug : print ("Pas de changement pour ", oper, " ", factsource, " ",mocle, "source non trouvée") + continue + + if debug : print ("Changement pour ", oper, " ", factsource, " ",mocle, "cible et source trouvées") + l=source.childNodes[:] + for ll in l: + for n in ll.childNodes: + if n.name != mocle:continue + MonTexte=n.getText(jdc); + inseremocle.insereMotCleDansFacteur(jdc,cible,MonTexte) + 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,plusieursFois=True): +#----------------------------------------------------------------------- +# Attention le cas type est THETA_OLD dans calc_G + + if oper not in jdcSet : return + if debug : print ( "movemocleinoper pour " ,oper,mocle,factcible) + boolChange=9 + commands= jdc.root.childNodes[:] + commands.reverse() + for c in commands: + if c.name != oper : continue + cible=None + for mc in c.childNodes: + if mc.name != factcible : + continue + else : + cible=mc + break + if cible==None : + if debug : print ("Pas de changement pour ", oper, " ", factcible, " ", "cible non trouvée") + continue + + source=None + for mc in c.childNodes: + if mc.name != mocle: + continue + else : + source=mc + break + if source==None : + if debug : print ("Pas de changement pour ", oper, " ", mocle, " source non trouvée") + continue + MonTexte=source.getText(jdc); + boolChange=1 + inseremocle.insereMotCleDansFacteur(jdc,cible,MonTexte,plusieursFois) + if boolChange : jdc.reset(jdc.getSource()) + removemocle.removeMotCle(jdc,oper,mocle) + +#------------------------------------------------------ +def copyMotClefInOperToFact(jdc,oper,mocle,factcible): +#------------------------------------------------------ + + if oper not in jdcSet : return + if debug : print ("movemocleinoper pour " ,oper,mocle,factcible) + boolChange=9 + commands= jdc.root.childNodes[:] + commands.reverse() + for c in commands: + if c.name != oper : continue + cible=None + for mc in c.childNodes: + if mc.name != factcible : + continue + else : + cible=mc + break + if cible==None : + if debug : print ("Pas de changement pour ", oper, " ", factcible, " ", "cible non trouvée") + continue + + source=None + for mc in c.childNodes: + if mc.name != mocle: + continue + else : + source=mc + break + if source==None : + if debug : print ("Pas de changement pour ", oper, " ", mocle, " source non trouvée") + continue + MonTexte=source.getText(jdc); + boolChange=1 + inseremocle.insereMotCleDansFacteur(jdc,cible,MonTexte) + if boolChange : jdc.reset(jdc.getSource()) + +#---------------------------------------------------------------------- +def moveMCFToCommand(jdc,command,factsource,commandcible,factcible): +#---------------------------------------------------------------------- +# exemple CONTACT en 10 +# CONTACT devient commande DEFI_CONTACT/ZONE +# + if command not in jdcSet : return + boolChange=0 + commands= jdc.root.childNodes[:] + commands.reverse() + for c in commands: + if c.name != command : continue + for mcF in c.childNodes: + if mcF.name != factsource : continue + l=mcF.getText(jdc) + texte=l.replace(factsource,factcible) + texte='xxxx='+commandcible+'('+texte+')\n' + jdc.splitLine(c.lineno,0) + jdc.addLine(texte,c.lineno) + logging.info("Deplacement de %s dans %s ligne %s",factsource,commandcible,c.lineno) + boolChange=1 + if boolChange : + jdc.reset(jdc.getSource()) + jdcSet.add(commandcible) + +#----------------------------------------------------- +def fusionMotCleToFact(jdc,command,listeMc,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 listeMc : 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 listeMc : + removemocle.removeMotCle(jdc,command,mc) + jdc.reset(jdc.getSource()) + +#----------------------------------------------------- +def fusionMotCleInFact(jdc,command,fact,listeMc,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 listeMc : 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 listeMc : + removemocle.removeMotCleInFact(jdc,command,fact,mc) + jdc.reset(jdc.getSource()) + +#----------------------------------------------------- +def fusionMCFToMCF(jdc,command,listeMcF,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 listeMcF : 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 listeMcF : + removemocle.removeMotCle(jdc,command,mcF) + jdc.reset(jdc.getSource()) + + + +#-------------------------------------------------------------------- +def eclaMotCleToFact(jdc,command,motcle,mot1,mot2,defaut=0): +#-------------------------------------------------------------------------- +# exemple STA10 pesanteur devient MCF avec eclatement des valeurs dans les MC +# On suppose que le MC est sur une seule ligne + if command not in jdcSet : return + boolChange=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) + indexLigneGlob=mc.lineno-1 + MaLigneGlob=jdc.getLines()[indexLigneGlob] + Ligne=TexteMC.split('(')[1].split(')')[0].split(',') + motcle1=mot1+"="+Ligne[0] + motcle2=mot2+"=("+Ligne[1]+','+Ligne[2]+','+Ligne[3]+')' + texte=motcle+'=_F('+motcle1+','+motcle2+')' + num=lastParen(TexteMC) + Nouveau=MaLigneGlob.replace(TexteMC[0:num],texte) + jdc.getLines()[indexLigneGlob]=Nouveau + logging.info("Transformation de %s dans %s ligne %s",motcle,command,c.lineno) + boolChange=1 + if boolChange : jdc.reset(jdc.getSource()) diff --git a/Traducteur/parseur.py b/Traducteur/parseur.py new file mode 100644 index 00000000..2635b9ab --- /dev/null +++ b/Traducteur/parseur.py @@ -0,0 +1,280 @@ +# -*- coding: utf-8 -*- +# Copyright (C) 2007-2017 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 re,string + +debug=0 + +escapedQuotesRE = re.compile(r"(\\\\|\\\"|\\\')") +stringsAndCommentsRE = \ + re.compile("(\"\"\".*?\"\"\"|'''.*?'''|\"[^\"]*\"|\'[^\']*\'|#.*?\n)", re.DOTALL) + +import six +if six.PY2 : + allchars = string.maketrans(u"", "") + allcharsExceptNewline = allchars[: allchars.index('\n')]+allchars[allchars.index('\n')+1:] + allcharsExceptNewlineTranstable = string.maketrans(allcharsExceptNewline, '*'*len(allcharsExceptNewline)) +else : + allchars=bytes.maketrans(b"",b"") + allcharsExceptNewline = allchars[: allchars.index(b'\n')]+allchars[allchars.index(b'\n')+1:] + allcharsExceptNewlineTranstable = bytes.maketrans(allcharsExceptNewline, b'*'*len(allcharsExceptNewline)) + + +#------------------------------ +def maskStringsAndComments(src): +#------------------------------ + """Remplace tous les caracteres dans commentaires et strings par des * """ + + src = escapedQuotesRE.sub("**", src) + allstrings = stringsAndCommentsRE.split(src) + # every odd element is a string or comment + for i in range(1, len(allstrings), 2): + if allstrings[i].startswith("'''")or allstrings[i].startswith('"""'): + allstrings[i] = allstrings[i][:3]+ \ + allstrings[i][3:-3].translate(allcharsExceptNewlineTranstable)+ \ + allstrings[i][-3:] + else: + allstrings[i] = allstrings[i][0]+ \ + allstrings[i][1:-1].translate(allcharsExceptNewlineTranstable)+ \ + allstrings[i][-1] + + return "".join(allstrings) + +#un nombre queconque de blancs,un nom,des blancs +pattern_oper = re.compile(r"^\s*(.*?=\s*)?([a-zA-Z_]\w*)(\s*)(\()(.*)",re.DOTALL) +pattern_proc = re.compile(r"^\s*([a-zA-Z_]\w*)(\s*)(\()(.*)",re.DOTALL) + +implicitContinuationChars = (('(', ')'), ('[', ']'), ('{', '}')) +linecontinueRE = re.compile(r"\\\s*(#.*)?$") +emptyHangingBraces = [0,0,0,0,0] + +#-------------------------------------- +class UnbalancedBracesException: pass +#-------------------------------------- + +#----------- +class Node: +#----------- + def __init__(self): + self.childNodes=[] + + def addChild(self,node): + self.childNodes.append(node) + + +#------------------- +class FactNode(Node): +#------------------- + pass + + +#------------------- +class JDCNode(Node): +#------------------- + def __init__(self,src): + Node.__init__(self) + self.src=src + +#------------------- +class Command(Node): +#------------------- + def __init__(self,name,lineno,colno,firstparen): + Node.__init__(self) + self.name=name + self.lineno=lineno + self.colno=colno + self.firstparen=firstparen + +#------------------- +class Keyword(Node): +#------------------- + def __init__(self,name,lineno,colno,endline,endcol): + Node.__init__(self) + self.name=name + self.lineno=lineno + self.colno=colno + self.endline=endline + self.endcol=endcol + + def getText(self,jdc): + if self.endline > self.lineno: + debut=jdc.getLines()[self.lineno-1][self.colno:] + fin = jdc.getLines()[self.endline-1][:self.endcol] + texte=debut + lignecourante=self.lineno + while lignecourante < self.endline -1 : + texte = texte + jdc.getLines()[lignecourante] + lignecourante = lignecourante + 1 + if chaineBlanche(fin) == 0 : + texte=texte + fin + if texte[-1] == "\n" : + texte=texte[0:-1] + else: + texte = jdc.getLines()[self.lineno-1][self.colno:self.endcol] + return texte + +#------------------------- +def chaineBlanche(texte) : +#------------------------- +# retourne 1 si la chaine est composee de " " +# retourne 0 sinon + bool = 1 ; + for i in range(len(texte)) : + if texte[i] != " " : bool = 0 + return bool + +#------------------- +def printNode(node): +#------------------- + if hasattr(node,'name'): + print (node.name) + else: + print ("pas de nom pour:",node) + for c in node.childNodes: + printNode(c) + +#------------------------ +def parser(src,atraiter): +#------------------------ + """Parse le texte src et retourne un arbre syntaxique (root). + + Cet arbre syntaxique a comme noeuds (childNodes) les commandes a traiter (liste atraiter) + """ + lines=src.splitlines(1) + maskedSrc=maskStringsAndComments(src) + maskedLines=maskedSrc.splitlines(1) + + root=JDCNode(src) + + # (a) dans un premier temps on extrait les commandes et on les insere + # dans un arbre (root) les noeuds fils sont stockes dans + # root.childNodes (liste) + lineno=0 + for line in maskedLines: + lineno=lineno+1 + if debug:print ("line",lineno,":",line) + m=pattern_proc.match(line) + if m and (m.group(1) in atraiter): + if debug:print (m.start(3),m.end(3),m.start(4)) + root.addChild(Command(m.group(1),lineno,m.start(1),m.end(3))) + else: + m=pattern_oper.match(line) + if m and (m.group(2) in atraiter): + root.addChild(Command(m.group(2),lineno,m.start(2),m.end(4))) + + #(b) dans un deuxieme temps , on recupere le texte complet de la commande + # jusqu'a la derniere parenthese fermante + + # iterateur sur les lignes physiques masquees + iterlines=iter(maskedLines) + + linenum=0 + for c in root.childNodes: + lineno=c.lineno + colno=c.colno # debut de la commande + while linenum < lineno: + line=iterlines.__next__() + linenum=linenum+1 + if linenum != lineno: + if debug:print ("line %s:"%linenum, line) + tmp = [] + hangingBraces = list(emptyHangingBraces) + hangingComments = 0 + while 1: + # update hanging braces + for i in range(len(implicitContinuationChars)): + contchar = implicitContinuationChars[i] + numHanging = hangingBraces[i] + + hangingBraces[i] = numHanging+line.count(contchar[0]) - \ + line.count(contchar[1]) + + hangingComments ^= line.count('"""') % 2 + hangingComments ^= line.count("'''") % 2 + + if hangingBraces[0] < 0 or hangingBraces[1] < 0 or hangingBraces[2] < 0: + raise UnbalancedBracesException() + + if linecontinueRE.search(line): + tmp.append(lines[linenum-1]) + elif hangingBraces != emptyHangingBraces: + tmp.append(lines[linenum-1]) + elif hangingComments: + tmp.append(lines[linenum-1]) + else: + tmp.append(lines[linenum-1]) + src="".join(tmp) + c.src=src + c.endline=linenum + decal=len(line)-line.rindex(')') + c.lastParen=len(src)-decal + if debug:print ("logical line %s %s:" % (c.lineno,c.endline),src) + break + line=iterlines.__next__() + linenum=linenum+1 + + return root + + +#----------------- +def lastParen(src): +#----------------- + """Retourne la position de la derniere parenthese fermante dans src a partir du debut de la string + + La string doit contenir la premiere parenthese ouvrante + """ + + src=maskStringsAndComments(src) + level=0 + i,n=0,len(src) + while i < n: + ch=src[i] + i=i+1 + if ch in ('(','['): + level=level+1 + if ch in (')',']'): + if level == 0: + raise UnbalancedBracesException() + level=level-1 + if level == 0: + #derniere parenthese fermante + return i + +#------------------- +def lastParen2(src): +#------------------- + """Retourne la position de la derniere parenthese fermante dans src a partir du debut de la string + + La string ne contient pas la premiere parenthese ouvrante + """ + src=maskStringsAndComments(src) + level=1 + i,n=0,len(src) + while i < n: + ch=src[i] + i=i+1 + if ch in ('(','['): + level=level+1 + if ch in (')',']'): + if level == 0: + raise UnbalancedBracesException() + level=level-1 + if level == 0: + #derniere parenthese fermante + return i diff --git a/Traducteur/regles.py b/Traducteur/regles.py new file mode 100644 index 00000000..a8f78215 --- /dev/null +++ b/Traducteur/regles.py @@ -0,0 +1,524 @@ +# -*- coding: utf-8 -*- +# Copyright (C) 2007-2017 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 +# +""" +Définition des règles +""" + +debug = 0 + +#-------------------- +class ensembleRegles : +#-------------------- + """ + Ensemble des règles + """ + def __init__(self, liste_regles): + self.liste = [] + for item in liste_regles : + args, clefRegle = item + r = regle(clefRegle, args) + self.liste.append(r) + + def verif(self, commande) : + """ + Vérification + """ + bool = 1 + for regle in self.liste : + result = regle.verif(commande) + bool = bool*result + return bool + +#-------------------------------- +class pasDeRegle(ensembleRegles): +#-------------------------------- + """ + Pas de règle + """ + def __init__(self) : + pass + + def verif (self, commande) : + """ + Vérification + """ + return 1 + + +#------------ +class regle : +#------------ + """ + Règle + """ + def __init__(self, clef_regle, args): + self.fonction = dictionnaire_regle[clef_regle] + self.list_args = args + self.bool = 0 + + def verif(self, commande): + """ + Vérification + """ + f = self.fonction(self.list_args) + return f.verif(commande) + +#--------------------- +class existeMCFParmi : +#--------------------- + """ + Existence du mot-clé facteur parmi la liste + """ + def __init__(self, list_arg): + self.listeMCF = list_arg + + def verif(self, commande) : + """ + Vérification + """ + bool = 0 + for c in commande.childNodes : + if c.name in self.listeMCF : + bool = 1 + break + return bool + +#--------------------- +class nexistepasMCFParmi(existeMCFParmi) : +#--------------------- + """ + Existence du mot-clé facteur parmi la liste + """ + def __init__(self, list_arg): + self.listeMCF = list_arg + + def verif(self, commande) : + """ + Vérification + """ + bool = existeMCFParmi.verif(self, commande) + if bool : return 0 + return 1 + +#---------------------- +class existeMCsousMCF : +#---------------------- + """ + Existence du mot-clé simple sous le mot-clé facteur + """ + def __init__(self, list_arg): + self.liste = list_arg + self.MCF = self.liste[0] + self.MC = self.liste[1] + + def verif(self, commande): + """ + Vérification + """ + bool = 0 + for mcf in commande.childNodes : + if mcf.name != self.MCF : continue + l = mcf.childNodes[:] + l.reverse() + for ll in l: + for mc in ll.childNodes: + if mc.name != self.MC : continue + bool = 1 + return bool + +#---------------------- +class existeMCsousMCFcourant : +#---------------------- + """ + Existence du mot-clé simple sous le mot-clé facteur courant + """ + def __init__(self, list_arg): + self.liste = list_arg + self.MC = self.liste[0] + + def verif(self, mcf): + """ + Vérification + """ + bool = 0 + l = mcf.childNodes[:] + l.reverse() + for mc in l: + if mc.name != self.MC : continue + bool = 1 + return bool + +#----------------------------------------- +class nexistepasMCsousMCF(existeMCsousMCF): +#----------------------------------------- + """ + Absence du mot-clé simple sous le mot-clé facteur + """ + def __init__(self, list_arg): + existeMCsousMCF.__init__(self, list_arg) + + + def verif(self, commande): + """ + Vérification + """ + bool = existeMCsousMCF.verif(self, commande) + if bool : return 0 + return 1 + +#----------------------------------------- +class nexistepasMCsousMCFcourant(existeMCsousMCFcourant): +#----------------------------------------- + """ + Absence du mot-clé simple sous le mot-clé facteur courant + """ + def __init__(self, list_arg): + existeMCsousMCFcourant.__init__(self, list_arg) + + + def verif(self, commande): + """ + Vérification + """ + bool = existeMCsousMCFcourant.verif(self, commande) + if bool : return 0 + return 1 + +#------------- +class existe : +#-------------- + """ + Existence du mot-clé simple + """ + def __init__(self, list_arg): + self.genea = list_arg + + def chercheMot(self, niveau, commande): + """ + Recherche du mot + """ + if commande == None : return 0 + if niveau == len(self.genea) : return 1 + texte = self.genea[niveau] + for c in commande.childNodes : + if c.name == texte : + niveau = niveau+1 + return self.chercheMot(niveau, c) + return None + + def verif(self, commande): + """ + Vérification + """ + bool = self.chercheMot(0, commande) + if bool == None : bool = 0 + return bool + +#------------- +class nexistepas : +#-------------- + """ + Absence du mot-clé simple + """ + def __init__(self, list_arg): + self.genea = list_arg + + def chercheMot(self, niveau, commande): + """ + Recherche du mot + """ + if commande == None : return 0 + if niveau == len(self.genea) : return 1 + texte = self.genea[niveau] + for c in commande.childNodes : + if c.name == texte : + niveau = niveau+1 + return self.chercheMot(niveau, c) + return None + + def verif(self, commande): + """ + Vérification + """ + bool = self.chercheMot(0, commande) + if bool : return 0 + return 1 + +#------------------------------- +class MCsousMCFaPourValeur : +#------------------------------ + """ + Égalité du mot-clé simple à une valeur sous le mot-clé facteur + """ + def __init__(self, list_arg): + assert (len(list_arg)==4) + self.genea = list_arg[0:-2] + self.MCF = list_arg[0] + self.MC = list_arg[1] + self.Val = list_arg[2] + self.Jdc = list_arg[3] + + def verif(self, commande): + """ + Vérification + """ + bool = 0 + for mcf in commande.childNodes : + if mcf.name != self.MCF : continue + l = mcf.childNodes[:] + l.reverse() + for ll in l: + for mc in ll.childNodes: + if mc.name != self.MC : continue + TexteMC = mc.getText(self.Jdc) + if (TexteMC.find(self.Val) < 0 ): continue + bool = 1 + return bool + +#------------------------------- +class MCsousMCFcourantaPourValeur : +#------------------------------ + """ + Égalité du mot-clé simple à une valeur sous le mot-clé facteur courant + """ + def __init__(self, list_arg): + assert (len(list_arg)==3) + self.genea = list_arg[0:-1] + self.MC = list_arg[0] + self.Val = list_arg[1] + self.Jdc = list_arg[2] + + def verif(self, mcf): + """ + Vérification + """ + bool = 0 + l = mcf.childNodes[:] + l.reverse() + for mc in l: + if mc.name != self.MC : continue + TexteMC = mc.getText(self.Jdc) + if (TexteMC.find(self.Val) < 0 ): continue + bool = 1 + return bool + + +#----------------------------- +class MCsousMCFaPourValeurDansListe : +#---------------------------- + """ + Égalité du mot-clé simple à une valeur dans une liste + sous le mot-clé facteur + """ + def __init__(self, list_arg): + assert (len(list_arg)==4) + self.genea = list_arg[0:-2] + self.MCF = list_arg[0] + self.MC = list_arg[1] + self.LVal = list_arg[2] + self.Jdc = list_arg[3] + + def verif(self, commande): + """ + Vérification + """ + bool = 0 + for mcf in commande.childNodes : + if mcf.name != self.MCF : continue + l = mcf.childNodes[:] + l.reverse() + for ll in l: + for mc in ll.childNodes: + if mc.name != self.MC : continue + TexteMC = mc.getText(self.Jdc) + for Val in self.LVal: + if (TexteMC.find(Val) < 0 ): continue + bool = 1 + return bool + +#----------------------------- +class MCsousMCFcourantaPourValeurDansListe : +#---------------------------- + """ + Égalité du mot-clé simple à une valeur dans une liste + sous le mot-clé facteur + """ + def __init__(self, list_arg): + assert (len(list_arg)==3) + self.genea = list_arg[0:-1] + self.MC = list_arg[0] + self.LVal = list_arg[1] + self.Jdc = list_arg[2] + + def verif(self, mcf): + """ + Vérification + """ + bool = 0 + l = mcf.childNodes[:] + l.reverse() + for mc in l: + if mc.name != self.MC : continue + TexteMC = mc.getText(self.Jdc) + for Val in self.LVal: + if (TexteMC.find(Val) < 0 ): continue + bool = 1 + return bool + +#----------------------------------------- +class MCsousMCFcourantnaPasPourValeurDansListe(MCsousMCFcourantaPourValeurDansListe) : +#----------------------------------------- + """ + Non égalité du mot-clé simple à une valeur dans une liste + sous le mot-clé facteur + """ + def __init__(self, list_arg): + MCsousMCFcourantaPourValeurDansListe.__init__(self, list_arg) + + + def verif(self, commande): + bool = MCsousMCFcourantaPourValeurDansListe.verif(self, commande) + if bool : return 0 + return 1 + +#----------------------------------------- +class MCsousMCFnaPasPourValeurDansListe(MCsousMCFaPourValeurDansListe) : +#----------------------------------------- + """ + Non égalité du mot-clé simple à une valeur dans une liste + sous le mot-clé facteur + """ + def __init__(self, list_arg): + MCsousMCFaPourValeurDansListe.__init__(self, list_arg) + + + def verif(self, commande): + bool = MCsousMCFaPourValeurDansListe.verif(self, commande) + if bool : return 0 + return 1 + +#------------------------------ +class MCaPourValeur : +#------------------------------ + """ + Égalité du mot-clé à une valeur + """ + def __init__(self, list_arg): + assert (len(list_arg)==3) + self.MC = list_arg[0] + self.Val = list_arg[1] + self.Jdc = list_arg[2] + + def verif(self, commande): + """ + Vérification + """ + bool = 0 + for mc in commande.childNodes : + if mc.name != self.MC : continue + TexteMC = mc.getText(self.Jdc) + if (TexteMC.find(self.Val) < 0 ): continue + bool = 1 + return bool + +#----------------------------------------- +class MCnaPasPourValeur(MCaPourValeur) : +#----------------------------------------- + """ + Non égalité du mot-clé à une valeur + """ + def __init__(self, list_arg): + MCaPourValeur.__init__(self, list_arg) + + def verif(self, commande): + """ + Vérification + """ + bool = MCaPourValeur.verif(self, commande) + if bool : return 0 + return 1 + +#------------------------------ +class MCaPourValeurDansListe : +#------------------------------ + """ + Égalité du mot-clé à une valeur dans une liste + """ + def __init__(self, list_arg): + assert (len(list_arg)==3) + self.MC = list_arg[0] + self.LVal = list_arg[1] + self.Jdc = list_arg[2] + + def verif(self, commande): + """ + Vérification + """ + bool = 0 + for mc in commande.childNodes : + if mc.name != self.MC : continue + TexteMC = mc.getText(self.Jdc) + #print "TexteMC=",type(TexteMC),TexteMC + #print "LVal=",type(self.LVal),self.LVal + for Val in self.LVal: + #print "Val=",type(Val),Val + #print "Find",TexteMC.find(Val) + if (TexteMC.find(Val) < 0 ): continue + bool = 1 + return bool + +#----------------------------------------- +class MCnaPasPourValeurDansListe(MCaPourValeurDansListe) : +#----------------------------------------- + """ + Non égalité du mot-clé à une valeur dans une liste + """ + def __init__(self, list_arg): + MCaPourValeurDansListe.__init__(self, list_arg) + + def verif(self, commande): + """ + Vérification + """ + bool = MCaPourValeurDansListe.verif(self, commande) + if bool : return 0 + return 1 + +dictionnaire_regle = {"existe":existe, + "nexistepas":nexistepas, + "existeMCFParmi":existeMCFParmi, + "nexistepasMCFParmi":nexistepasMCFParmi, + "existeMCsousMCF":existeMCsousMCF, + "nexistepasMCsousMCF":nexistepasMCsousMCF, + "MCsousMCFaPourValeur":MCsousMCFaPourValeur, + "MCsousMCFaPourValeurDansListe":MCsousMCFaPourValeurDansListe, + "MCaPourValeur":MCaPourValeur, + "MCnaPasPourValeur":MCnaPasPourValeur, + "existeMCsousMCFcourant":existeMCsousMCFcourant, + "nexistepasMCsousMCFcourant":nexistepasMCsousMCFcourant, + "MCsousMCFcourantaPourValeur":MCsousMCFcourantaPourValeur, + "MCsousMCFcourantaPourValeurDansListe":MCsousMCFcourantaPourValeurDansListe, + "MCsousMCFcourantnaPasPourValeurDansListe":MCsousMCFcourantnaPasPourValeurDansListe, + "MCsousMCFnaPasPourValeurDansListe":MCsousMCFnaPasPourValeurDansListe, + "MCaPourValeurDansListe":MCaPourValeurDansListe, + "MCnaPasPourValeurDansListe":MCnaPasPourValeurDansListe} + + +SansRegle = pasDeRegle() diff --git a/Traducteur/removemocle.py b/Traducteur/removemocle.py new file mode 100644 index 00000000..ee1eab7a --- /dev/null +++ b/Traducteur/removemocle.py @@ -0,0 +1,215 @@ +# -*- coding: utf-8 -*- +# Copyright (C) 2007-2017 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 +from Traducteur import regles +from Traducteur.parseur import FactNode +from Traducteur.dictErreurs import ecritErreur +from Traducteur.load import jdcSet + +debug=0 +#debug=1 +#on n'a qu'un mocle par commande. On peut donc supprimer le mocle sans trop de precautions (a part iterer a l'envers sur les commandes) +#avant de supprimer un autre mocle, on remet a jour l'arbre syntaxique (lineno,colno,etc.) + + +#----------------------------------------------------------------------- +def removeMotCle(jdc,command,mocle,ensemble=regles.SansRegle,erreur = 0): +#----------------------------------------------------------------------- + #on itere sur les commandes a l'envers pour ne pas polluer les numeros de ligne avec les modifications + if command not in jdcSet : return + boolChange=0 + commands= jdc.root.childNodes[:] + commands.reverse() + for c in commands: + if c.name != command:continue + for mc in c.childNodes: + if mc.name != mocle:continue + if ensemble.verif(c) == 0 : continue + if erreur : ecritErreur((command,mocle),c.lineno) + boolChange=1 + removeMC(jdc,c,mc) + + if boolChange : jdc.reset(jdc.getSource()) + +#------------------------------------------------------- +def removeMotCleSiRegle(jdc,command,mocle,liste_regles) : +#------------------------------------------------------- + if command not in jdcSet : return + mesRegles=regles.ensembleRegles(liste_regles) + removeMotCle(jdc,command,mocle,mesRegles,erreur=0) + +#---------------------------------------------------------------- +def removeMotCleSiRegleAvecErreur(jdc,command,mocle,liste_regles) : +#-------------------------------------------------------------- + if command not in jdcSet : return + mesRegles=regles.ensembleRegles(liste_regles) + removeMotCle(jdc,command,mocle,mesRegles,erreur=1) + +#---------------------------------------------------------------- +def removeMotCleAvecErreur(jdc,command,mocle) : +#-------------------------------------------------------------- + if command not in jdcSet : return + removeMotCle(jdc,command,mocle,erreur=1) + + +#-------------------------------------------------------------------- +def removeCommande(jdc,command,ensemble=regles.SansRegle,erreur=0): +#-------------------------------------------------------------------- + if command not in jdcSet : return + boolChange=0 + commands= jdc.root.childNodes[:] + commands.reverse() + for c in commands: + if c.name != command:continue + if ensemble.verif(c) == 0 : continue + boolChange=1 + if erreur : ecritErreur((command,),c.lineno) + jdc.supLignes(c.lineno,c.endline) + logging.warning("Suppression de %s ligne %s",c.name,c.lineno) + if boolChange : jdc.reset(jdc.getSource()) + +#------------------------------------------------------------- +def removeCommandeSiRegle(jdc,command,liste_regles): +#------------------------------------------------------------- + if command not in jdcSet : return + mesRegles=regles.ensembleRegles(liste_regles) + removeCommande(jdc,command,mesRegles,0) + +#------------------------------------------------------------- +def removeCommandeSiRegleAvecErreur(jdc,command,liste_regles): +#------------------------------------------------------------- + if command not in jdcSet : return + mesRegles=regles.ensembleRegles(liste_regles) + removeCommande(jdc,command,mesRegles,1) + +#--------------------------------- +def removeMC(jdc,c,mc): +#--------------------------------- + if debug : print ("Suppression de:",c.name,mc.name,mc.lineno,mc.colno,mc.endline,mc.endcol) + logging.info("Suppression de %s dans %s ligne %d",mc.name,c.name,mc.lineno) + + if mc.endline > mc.lineno: + if debug: print ("mocle sur plusieurs lignes--%s--" % jdc.getLines()[mc.lineno-1][mc.colno:]) + jdc.getLines()[mc.lineno-1]=jdc.getLines()[mc.lineno-1][:mc.colno] + jdc.getLines()[mc.endline-1]=jdc.getLines()[mc.endline-1][mc.endcol:] + + #attention : supprimer les lignes a la fin + jdc.getLines()[mc.lineno:mc.endline-1]=[] + else: + if debug: print( "mocle sur une ligne--%s--" % jdc.getLines()[mc.lineno-1][mc.colno:mc.endcol]) + s=jdc.getLines()[mc.lineno-1] + jdc.getLines()[mc.lineno-1]=s[:mc.colno]+s[mc.endcol:] + fusionne(jdc,mc.lineno-1) + +#--------------------------------------------------------------------------------- +def removeMotCleInFact(jdc,command,fact,mocle,ensemble=regles.SansRegle,erreur=0): +#---------------------------------------------------------------------------------- + # on itere sur les commandes a l'envers pour ne pas polluer + # les numeros de ligne avec les modifications + if command not in jdcSet : return + commands= jdc.root.childNodes[:] + commands.reverse() + boolChange=0 + for c in commands: + if c.name != command:continue + for mc in c.childNodes: + if mc.name != fact:continue + l=mc.childNodes[:] + l.reverse() + for ll in l: + for n in ll.childNodes: + if n.name != mocle:continue + if ensemble.verif(c) == 0 : continue + if erreur : ecritErreur((command,fact,mocle),c.lineno) + boolChange=1 + removeMC(jdc,c,n) + + if boolChange : jdc.reset(jdc.getSource()) + +#------------------------------------------------------------------ +def removeMotCleInFactSiRegle(jdc,command,fact,mocle,liste_regles): +#------------------------------------------------------------------ + if command not in jdcSet : return + erreur=0 + mesRegles=regles.ensembleRegles(liste_regles) + removeMotCleInFact(jdc,command,fact,mocle,mesRegles,erreur) + +#---------------------------------------------------------------------- +def removeMotCleInFactSiRegleAvecErreur(jdc,command,fact,mocle,liste_regles): +#---------------------------------------------------------------------- + if command not in jdcSet : return + erreur=1 + mesRegles=regles.ensembleRegles(liste_regles) + removeMotCleInFact(jdc,command,fact,mocle,mesRegles,erreur) + + +#---------------------------------------------------------------------- +def removeMotCleInFactCourantSiRegle(jdc,command,fact,mocle,liste_regles,erreur=0): +#---------------------------------------------------------------------- + if command not in jdcSet : return + ensemble=regles.ensembleRegles(liste_regles) + commands= jdc.root.childNodes[:] + commands.reverse() + boolChange=0 + for c in commands: + if c.name != command:continue + for mc in c.childNodes: + if mc.name != fact:continue + l=mc.childNodes[:] + l.reverse() + for ll in l: + if ensemble.verif(ll) == 0 : continue + for n in ll.childNodes: + if n.name != mocle:continue + if erreur : ecritErreur((command,fact,mocle),c.lineno) + boolChange=1 + removeMC(jdc,c,n) + + if boolChange : jdc.reset(jdc.getSource()) + +#------------------------------------------ +def fusionne(jdc,numLigne): +#------------------------------------------ +# fusionne la ligne numLigne et numLigne+1 +# si la ligne numLigne+1 ne contient que des parentheses +# fermantes +# et si la ligne numLigne ne contient pas par un "#" +# Attention a la difference de numerotation +# jdc.getLines()[numLigne] donne la ligne numLigne + 1 +# alors que joinLineandNext(numLigne) travaille sur le tableau + index=0 + texte=jdc.getLines()[numLigne] + fusion=1 + while (index < len(texte)) : + if texte[index] not in (" ",",",")",";","\n") : + fusion=0 + break + index=index+1 + + if fusion == 0 : return; + + texte=jdc.getLines()[numLigne -1] + if texte.find("#") < 0 : + fusion=1 + else : + fusion=0 + + if fusion : + jdc.joinLineandNext(numLigne) diff --git a/Traducteur/renamemocle.py b/Traducteur/renamemocle.py new file mode 100644 index 00000000..e246abf2 --- /dev/null +++ b/Traducteur/renamemocle.py @@ -0,0 +1,188 @@ +# -*- coding: utf-8 -*- +# Copyright (C) 2007-2017 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 sys +from Traducteur.parseur import FactNode +from Traducteur.load import jdcSet +from Traducteur import regles +from Traducteur.dictErreurs import ecritErreur +#debug=1 +debug=0 + +#on n'a qu'un mocle par commande. +#en fin de traitement, on remet a jour l'arbre syntaxique (lineno,colno,etc.) + +#-------------------------------------------------------------------------------- +def renameMotCle(jdc,command,mocle,new_name, erreur=0,ensemble=regles.SansRegle): +#-------------------------------------------------------------------------------- + if command not in jdcSet : return + boolChange=0 + for c in jdc.root.childNodes: + if c.name != command:continue + for mc in c.childNodes: + if mc.name != mocle:continue + if ensemble.verif(c) == 0 : continue + boolChange=1 + if debug: print ("Renommage de:",c.name,mc.name,mc.lineno,mc.colno) + if erreur : + ecritErreur((command,mocle),c.lineno) + else : + logging.info("Renommage de: %s %s ligne %d en %s",c.name,mc.name,mc.lineno,new_name) + s=jdc.getLines()[mc.lineno-1] + jdc.getLines()[mc.lineno-1]=s[:mc.colno]+new_name+s[mc.colno+len(mocle):] + diff=len(new_name) - len(mocle) + decaleLignesdeNBlancs(jdc,mc.lineno,mc.endline-1,diff) + + if boolChange : jdc.reset(jdc.getSource()) + +#------------------------------------------------------ +def renameMotCleAvecErreur(jdc,command,mocle,new_name): +#------------------------------------------------------ + if command not in jdcSet : return + renameMotCle(jdc,command,mocle,new_name,1,regles.SansRegle) + +#-------------------------------------------------------------------------- +def renameMotCleSiRegle(jdc,command,mocle,new_name,liste_regles, erreur=0): +#-------------------------------------------------------------------------- + if command not in jdcSet : return + mesRegles=regles.ensembleRegles(liste_regles) + renameMotCle(jdc,command,mocle,new_name, erreur,mesRegles) + +#------------------------------------------- +def renameOper(jdc,command,new_name): +#------------------------------------------- + if command not in jdcSet : return + jdcSet.add(new_name) + boolChange=0 + for c in jdc.root.childNodes: + if c.name != command:continue + if debug: print ("Renommage de:",c.name,c.lineno,c.colno) + logging.info("Renommage de: %s ligne %d en %s",c.name,c.lineno,new_name) + boolChange=1 + s=jdc.getLines()[c.lineno-1] + jdc.getLines()[c.lineno-1]=s[:c.colno]+new_name+s[c.colno+len(command):] + diff=len(new_name) - len(command) + decaleLignesdeNBlancs(jdc,c.lineno,c.endline,diff) + if boolChange : jdc.reset(jdc.getSource()) + +#---------------------------------------------------------- +def decaleLignesdeNBlancs(jdc,premiere,derniere,nbBlanc): +#---------------------------------------------------------- + ligne = premiere + 1 + while ligne < derniere : + s=jdc.getLines()[ligne] + if nbBlanc > 0 : + jdc.getLines()[ligne] = nbBlanc*" " + s + else : + toutblancs=-1*nbBlanc*" " + if jdc.getLines()[ligne][0:-1*nbBlanc] == toutblancs: + jdc.getLines()[ligne] = s[-1*nbBlanc:] + ligne=ligne+1 + +#--------------------------------------------------------------------------------------------- +def renameMotCleInFact(jdc,command,fact,mocle,new_name, ensemble=regles.SansRegle, erreur=0): +#--------------------------------------------------------------------------------------------- + if command not in jdcSet : return + boolChange=0 + for c in jdc.root.childNodes: + if c.name != command:continue + for mc in c.childNodes: + if mc.name != fact:continue + l=mc.childNodes[:] + #on itere a l'envers + l.reverse() + for ll in l: + for n in ll.childNodes: + if n.name != mocle:continue + if ensemble.verif(c) == 0 : continue + s=jdc.getLines()[n.lineno-1] + jdc.getLines()[n.lineno-1]=s[:n.colno]+new_name+s[n.colno+len(mocle):] + boolChange=1 + if erreur : + ecritErreur((command,fact,mocle),c.lineno) + else : + logging.info("Renommage de: %s, ligne %s, en %s",n.name,n.lineno,new_name) + + if boolChange : jdc.reset(jdc.getSource()) + +#-------------------------------------------------------------------------- +def renameMotCleInFactSiRegle(jdc,command,fact,mocle,new_name,liste_regles): +#-------------------------------------------------------------------------- + if command not in jdcSet : return + mesRegles=regles.ensembleRegles(liste_regles) + renameMotCleInFact(jdc,command,fact,mocle,new_name,mesRegles) + +def renameMotCleInFactCourantSiRegle(jdc,command,fact,mocle,new_name,liste_regles,erreur=0): +#-------------------------------------------------------------------------- + if command not in jdcSet : return + ensemble=regles.ensembleRegles(liste_regles) + boolChange=0 + for c in jdc.root.childNodes: + if c.name != command:continue + for mc in c.childNodes: + if mc.name != fact:continue + l=mc.childNodes[:] + #on itere a l'envers + l.reverse() + for ll in l: + if ensemble.verif(ll) == 0 : continue + for n in ll.childNodes: + 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):] + boolChange=1 + if erreur : + ecritErreur((command,fact,mocle),c.lineno) + else : + logging.info("Renommage de: %s, ligne %s, en %s",n.name,n.lineno,new_name) + + if boolChange : jdc.reset(jdc.getSource()) + + +#----------------------------------------------------------------- +def renameCommande(jdc,command,new_name,ensemble=regles.SansRegle): +#----------------------------------------------------------------- +# nom de la commande "ancien format" , nom de la commande " nouveau format " + if command not in jdcSet : return + jdcSet.add(new_name) + boolChange=0 + if debug : + 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) + for c in jdc.root.childNodes: + if c.name != command:continue + if ensemble.verif(c) == 0 : continue + boolChange=1 + if debug: print ("Renommage de:",c.name,new_name ,c.lineno,c.colno) + logging.info("Renommage de: %s ligne %d en %s",c.name,c.lineno,new_name) + s=jdc.getLines()[c.lineno-1] + jdc.getLines()[c.lineno-1]=s[:c.colno]+new_name+s[c.colno+len(command):] + + if boolChange : jdc.reset(jdc.getSource()) + +#----------------------------------------------------------- +def renameCommandeSiRegle(jdc,command,new_name,liste_regles): +#----------------------------------------------------------- + + if command not in jdcSet : return + mesRegles=regles.ensembleRegles(liste_regles) + renameCommande(jdc,command,new_name,mesRegles) diff --git a/Traducteur/toto.comm b/Traducteur/toto.comm new file mode 100755 index 00000000..0701e84e --- /dev/null +++ b/Traducteur/toto.comm @@ -0,0 +1,161 @@ +# + +REF=Assembly(assembly_type='REF',); + + +U1=Assembly(assembly_type='UOX', + assembly_width=0.21504, + fuel_density=0.95, + radial_description=_F(clad_outer_radius=0.00475, + guide_tube_outer_radius=0.006025, + fuel_rod_pitch=0.0126, + nfuel_rods=264,), + axial_description=_F(active_length_start=0.21, + active_length_end=4.4772,), + grids=_F(mixing=_F(positions=(0.69216,1.19766,1.70316,2.20866,2.71416,3.20416,3.69416,4.18416,), + size=0.033,), + non_mixing=_F(positions=(0.026,4.2412,), + size=0.033,),),); + +UGD=Assembly(assembly_type='UOX', + assembly_width=0.21504, + fuel_density=0.95, + radial_description=_F(clad_outer_radius=0.00475, + guide_tube_outer_radius=0.006025, + fuel_rod_pitch=0.0126, + nfuel_rods=264,), + axial_description=_F(active_length_start=0.21, + active_length_end=4.4772,), + grids=_F(mixing=_F(positions=(0.69216,1.19766,1.70316,2.20866,2.71416,3.20416,3.69416,4.18416,), + size=0.033,), + non_mixing=_F(positions=(0.026,), + size=0.033,),),); + +RB=RodBank(rod_type='heterogeneous', + bottom_composition='AIC', + splitting_heigh=1.4224, + upper_composition='B4C', + step_height=0.016, + nsteps=260,); + +N1=RodBank(rod_type='heterogeneous', + bottom_composition='AIC', + splitting_heigh=1.4224, + upper_composition='B4C', + step_height=0.016, + nsteps=260,); + +N2=RodBank(rod_type='heterogeneous', + bottom_composition='AIC', + splitting_heigh=1.4226, + upper_composition='B4C', + step_height=0.016, + nsteps=260,); + +G1=RodBank(rod_type='homogeneous', + rod_composition='Grey', + step_height=0.016, + nsteps=260,); + +G2=RodBank(rod_type='homogeneous', + rod_composition='Grey', + step_height=0.016, + nsteps=260,); + +techno_data=Techno_data(assembly_list=(REF,U1,UGD,), + rodbank_list=(RB,G1,G2,N1,N2,), + radial_description=_F(nb_assembly=15, + xaxis=('RW','S','R','P','N','L','K','J','H','G','F','E','D','C','B','A','RE',), + yaxis= + ('RS','15','14','13','12','11', + '10','09','08','07','06','05','04','03','02','01','RN',), + assembly_map=((REF,REF,REF,REF,REF,REF,REF,REF,REF,REF,REF,REF,REF,REF,REF,REF,REF,),(REF,REF,REF,REF,REF,U1,U1,U1,U1,U1,U1,U1,REF,REF,REF,REF,REF,),(REF,REF,REF,UGD,U1,UGD,UGD,U1,U1,U1,UGD,UGD,U1,UGD,REF,REF,REF,),(REF,REF,UGD,U1,U1,U1,U1,UGD,U1,UGD,U1,U1,U1,U1,UGD,REF,REF,),(REF,REF,U1,U1,U1,UGD,U1,UGD,U1,UGD,U1,UGD,U1,U1,U1,REF,REF,),(REF,U1,UGD,U1,UGD,U1,U1,UGD,U1,UGD,U1,U1,UGD,U1,UGD,U1,REF,),(REF,U1,UGD,U1,U1,U1,UGD,UGD,U1,UGD,UGD,U1,U1,U1,UGD,U1,REF,),(REF,U1,U1,UGD,UGD,UGD,UGD,U1,UGD,U1,UGD,UGD,UGD,UGD,U1,U1,REF,),(REF,U1,U1,U1,U1,U1,U1,UGD,UGD,UGD,U1,U1,U1,U1,U1,U1,REF,),(REF,U1,U1,UGD,UGD,UGD,UGD,U1,UGD,U1,UGD,UGD,UGD,UGD,U1,U1,REF,),(REF,U1,UGD,U1,U1,U1,UGD,UGD,U1,UGD,UGD,U1,U1,U1,UGD,U1,REF,),(REF,U1,UGD,U1,UGD,U1,U1,UGD,U1,UGD,U1,U1,UGD,U1,UGD,U1,REF,),(REF,REF,U1,U1,U1,UGD,U1,UGD,U1,UGD,U1,UGD,U1,U1,U1,REF,REF,),(REF,REF,UGD,U1,U1,U1,U1,UGD,U1,UGD,U1,U1,U1,U1,UGD,REF,REF,),(REF,REF,REF,UGD,U1,UGD,UGD,U1,U1,U1,UGD,UGD,U1,UGD,REF,REF,REF,),(REF,REF,REF,REF,REF,U1,U1,U1,U1,U1,U1,U1,REF,REF,REF,REF,REF,),(REF,REF,REF,REF,REF,REF,REF,REF,REF,REF,REF,REF,REF,REF,REF,REF,REF,),), + rod_map= + (['#','#','#','#','#','#','#', + '#','#','#','#','#','#','#','#','#','#'],['#','#','#','#','#','.', + '.','.','.','.','.','.','#','#','#','#','#'],['#','#','#','.','.', + '.','.','.','RB','.','.','.','.','.','#','#','#'],['#','#','.','.', + '.','G2','.','N2','.','N2','.','G2','.','.','.','#','#'],['#','#', + '.','.','N1','.','.','.','G1','.','.','.','N1','.','.','#','#'], + ['#','.','.','G2','.','RB','.','.','.','.','.','RB','.','G2','.', + '.','#'],['#','.','.','.','.','.','.','.','N1','.','.','.','.','.', + '.','.','#'],['#','.','.','N2','.','.','.','.','.','.','.','.','.', + 'N2','.','.','#'],['#','.','RB','.','G1','.','N1','.','RB','.','N1', + '.','G1','.','RB','.','#'],['#','.','.','N2','.','.','.','.','.', + '.','.','.','.','N2','.','.','#'],['#','.','.','.','.','.','.','.', + 'N1','.','.','.','.','.','.','.','#'],['#','.','.','G2','.','RB', + '.','.','.','.','.','RB','.','G2','.','.','#'],['#','#','.','.', + 'N1','.','.','.','G1','.','.','.','N1','.','.','#','#'],['#','#', + '.','.','.','G2','.','N2','.','N2','.','G2','.','.','.','#','#'], + ['#','#','#','.','.','.','.','.','RB','.','.','.','.','.','#','#', + '#'],['#','#','#','#','#','.','.','.','.','.','.','.','#','#','#', + '#','#'],['#','#','#','#','#','#','#','#','#','#','#','#','#','#', + '#','#','#'],), + BU_map= + ([0.0,0.0,0.0,0.0,0.0,0.0,0.0, + 0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],[0.0,0.0,0.0,0.0,0.0,0.0,0.0, + 0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],[0.0,0.0,0.0,40.0,0.0,0.0, + 40.0,40.0,20.0,40.0,40.0,0.0,0.0,40.0,0.0,0.0,0.0],[0.0,0.0,40.0,0.0, + 40.0,20.0,40.0,0.0,40.0,0.0,40.0,20.0,40.0,0.0,40.0,0.0,0.0],[0.0,0.0, + 0.0,40.0,20.0,20.0,20.0,40.0,20.0,40.0,20.0,20.0,20.0,40.0,0.0,0.0, + 0.0],[0.0,0.0,0.0,20.0,20.0,20.0,40.0,0.0,40.0,0.0,40.0,20.0,20.0, + 20.0,0.0,0.0,0.0],[0.0,0.0,40.0,40.0,20.0,40.0,20.0,40.0,20.0,40.0, + 20.0,40.0,20.0,40.0,40.0,0.0,0.0],[0.0,0.0,40.0,0.0,40.0,0.0,40.0, + 20.0,20.0,20.0,40.0,0.0,40.0,0.0,40.0,0.0,0.0],[0.0,0.0,20.0,40.0, + 20.0,40.0,20.0,20.0,60.0,20.0,20.0,40.0,20.0,40.0,20.0,0.0,0.0],[0.0, + 0.0,40.0,0.0,40.0,0.0,40.0,20.0,20.0,20.0,40.0,0.0,40.0,0.0,40.0,0.0, + 0.0],[0.0,0.0,40.0,40.0,20.0,40.0,20.0,40.0,20.0,40.0,20.0,40.0,20.0, + 40.0,40.0,0.0,0.0],[0.0,0.0,0.0,20.0,20.0,20.0,40.0,0.0,40.0,0.0,40.0, + 20.0,20.0,20.0,0.0,0.0,0.0],[0.0,0.0,0.0,40.0,20.0,20.0,20.0,40.0, + 20.0,40.0,20.0,20.0,20.0,40.0,0.0,0.0,0.0],[0.0,0.0,40.0,0.0,40.0, + 20.0,40.0,0.0,40.0,0.0,40.0,20.0,40.0,0.0,40.0,0.0,0.0],[0.0,0.0,0.0, + 40.0,0.0,0.0,40.0,40.0,20.0,40.0,40.0,0.0,0.0,40.0,0.0,0.0,0.0],[0.0, + 0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],[0.0, + 0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],),), + axial_description=_F(lower_refl_size=0.21, + upper_refl_size=0.21,), + nominal_power=4000000000.0, + Fuel_power_fraction=0.974, + by_pass=0.07, + core_volumic_flowrate=90940.0,); + +neutro_model=Model_data(physics='Neutronics', + scale='component', + code='APOLLO3', + radial_meshing=_F(flux_solver='subdivision', + flux_subdivision=2, + feedback_solver='subdivision', + feedback_subdivision=1,), + axial_meshing=_F(lower_refl=2, + fuel=42, + upper_refl=2,),); + +thermo_model=Model_data(physics='Thermalhydraulics', + scale='component', + code='FLICA4', + radial_meshing=_F(fluid='subdivision', + fluid_subdivision=1, + pellet=8, + clad=2,), + axial_meshing=_F(lower_refl=1, + fuel=40, + upper_refl=1,),); + +scenario_data=Scenario_data(initial_power=0.1, + initial_power_unit='% Nominal power', + initial_core_inlet_temperature=290.0, + initial_boron_concentration=1300.0, + initial_inlet_pressure=160.2, + initial_outlet_pressure=157.2, + initial_rod_positions=(('Rodbank@RB',201),('Rodbank@N1',96),('Rodbank@N2',260),('Rodbank@G1',260),('Rodbank@G2',260),('Rodcluster@H08',260)), + scenario_type='RIA', + ejected_rod='H02', + rod_position_program=((0.0,0),(0.1,260)), + SCRAM='YES', + SCRAM_power=1130.0, + complete_SCRAM_time=1.0, + post_processing=(('Fuel temperature@Thermalhydraulics','MAX'),('Neutronic power@Neutronics','SUM'),('Fuel temperature@Thermalhydraulics','MED'),('Neutronic power@Neutronics','MED')),); + +Genere_Une_Erreur_Traduction(essai='3',); +#VERSION_CATALOGUE:V_0:FIN VERSION_CATALOGUE +#CHECKSUM:f62a6f71fcde9f983479fc749f7e334c -:FIN CHECKSUM diff --git a/Traducteur/tutu.comm b/Traducteur/tutu.comm new file mode 100644 index 00000000..0701e84e --- /dev/null +++ b/Traducteur/tutu.comm @@ -0,0 +1,161 @@ +# + +REF=Assembly(assembly_type='REF',); + + +U1=Assembly(assembly_type='UOX', + assembly_width=0.21504, + fuel_density=0.95, + radial_description=_F(clad_outer_radius=0.00475, + guide_tube_outer_radius=0.006025, + fuel_rod_pitch=0.0126, + nfuel_rods=264,), + axial_description=_F(active_length_start=0.21, + active_length_end=4.4772,), + grids=_F(mixing=_F(positions=(0.69216,1.19766,1.70316,2.20866,2.71416,3.20416,3.69416,4.18416,), + size=0.033,), + non_mixing=_F(positions=(0.026,4.2412,), + size=0.033,),),); + +UGD=Assembly(assembly_type='UOX', + assembly_width=0.21504, + fuel_density=0.95, + radial_description=_F(clad_outer_radius=0.00475, + guide_tube_outer_radius=0.006025, + fuel_rod_pitch=0.0126, + nfuel_rods=264,), + axial_description=_F(active_length_start=0.21, + active_length_end=4.4772,), + grids=_F(mixing=_F(positions=(0.69216,1.19766,1.70316,2.20866,2.71416,3.20416,3.69416,4.18416,), + size=0.033,), + non_mixing=_F(positions=(0.026,), + size=0.033,),),); + +RB=RodBank(rod_type='heterogeneous', + bottom_composition='AIC', + splitting_heigh=1.4224, + upper_composition='B4C', + step_height=0.016, + nsteps=260,); + +N1=RodBank(rod_type='heterogeneous', + bottom_composition='AIC', + splitting_heigh=1.4224, + upper_composition='B4C', + step_height=0.016, + nsteps=260,); + +N2=RodBank(rod_type='heterogeneous', + bottom_composition='AIC', + splitting_heigh=1.4226, + upper_composition='B4C', + step_height=0.016, + nsteps=260,); + +G1=RodBank(rod_type='homogeneous', + rod_composition='Grey', + step_height=0.016, + nsteps=260,); + +G2=RodBank(rod_type='homogeneous', + rod_composition='Grey', + step_height=0.016, + nsteps=260,); + +techno_data=Techno_data(assembly_list=(REF,U1,UGD,), + rodbank_list=(RB,G1,G2,N1,N2,), + radial_description=_F(nb_assembly=15, + xaxis=('RW','S','R','P','N','L','K','J','H','G','F','E','D','C','B','A','RE',), + yaxis= + ('RS','15','14','13','12','11', + '10','09','08','07','06','05','04','03','02','01','RN',), + assembly_map=((REF,REF,REF,REF,REF,REF,REF,REF,REF,REF,REF,REF,REF,REF,REF,REF,REF,),(REF,REF,REF,REF,REF,U1,U1,U1,U1,U1,U1,U1,REF,REF,REF,REF,REF,),(REF,REF,REF,UGD,U1,UGD,UGD,U1,U1,U1,UGD,UGD,U1,UGD,REF,REF,REF,),(REF,REF,UGD,U1,U1,U1,U1,UGD,U1,UGD,U1,U1,U1,U1,UGD,REF,REF,),(REF,REF,U1,U1,U1,UGD,U1,UGD,U1,UGD,U1,UGD,U1,U1,U1,REF,REF,),(REF,U1,UGD,U1,UGD,U1,U1,UGD,U1,UGD,U1,U1,UGD,U1,UGD,U1,REF,),(REF,U1,UGD,U1,U1,U1,UGD,UGD,U1,UGD,UGD,U1,U1,U1,UGD,U1,REF,),(REF,U1,U1,UGD,UGD,UGD,UGD,U1,UGD,U1,UGD,UGD,UGD,UGD,U1,U1,REF,),(REF,U1,U1,U1,U1,U1,U1,UGD,UGD,UGD,U1,U1,U1,U1,U1,U1,REF,),(REF,U1,U1,UGD,UGD,UGD,UGD,U1,UGD,U1,UGD,UGD,UGD,UGD,U1,U1,REF,),(REF,U1,UGD,U1,U1,U1,UGD,UGD,U1,UGD,UGD,U1,U1,U1,UGD,U1,REF,),(REF,U1,UGD,U1,UGD,U1,U1,UGD,U1,UGD,U1,U1,UGD,U1,UGD,U1,REF,),(REF,REF,U1,U1,U1,UGD,U1,UGD,U1,UGD,U1,UGD,U1,U1,U1,REF,REF,),(REF,REF,UGD,U1,U1,U1,U1,UGD,U1,UGD,U1,U1,U1,U1,UGD,REF,REF,),(REF,REF,REF,UGD,U1,UGD,UGD,U1,U1,U1,UGD,UGD,U1,UGD,REF,REF,REF,),(REF,REF,REF,REF,REF,U1,U1,U1,U1,U1,U1,U1,REF,REF,REF,REF,REF,),(REF,REF,REF,REF,REF,REF,REF,REF,REF,REF,REF,REF,REF,REF,REF,REF,REF,),), + rod_map= + (['#','#','#','#','#','#','#', + '#','#','#','#','#','#','#','#','#','#'],['#','#','#','#','#','.', + '.','.','.','.','.','.','#','#','#','#','#'],['#','#','#','.','.', + '.','.','.','RB','.','.','.','.','.','#','#','#'],['#','#','.','.', + '.','G2','.','N2','.','N2','.','G2','.','.','.','#','#'],['#','#', + '.','.','N1','.','.','.','G1','.','.','.','N1','.','.','#','#'], + ['#','.','.','G2','.','RB','.','.','.','.','.','RB','.','G2','.', + '.','#'],['#','.','.','.','.','.','.','.','N1','.','.','.','.','.', + '.','.','#'],['#','.','.','N2','.','.','.','.','.','.','.','.','.', + 'N2','.','.','#'],['#','.','RB','.','G1','.','N1','.','RB','.','N1', + '.','G1','.','RB','.','#'],['#','.','.','N2','.','.','.','.','.', + '.','.','.','.','N2','.','.','#'],['#','.','.','.','.','.','.','.', + 'N1','.','.','.','.','.','.','.','#'],['#','.','.','G2','.','RB', + '.','.','.','.','.','RB','.','G2','.','.','#'],['#','#','.','.', + 'N1','.','.','.','G1','.','.','.','N1','.','.','#','#'],['#','#', + '.','.','.','G2','.','N2','.','N2','.','G2','.','.','.','#','#'], + ['#','#','#','.','.','.','.','.','RB','.','.','.','.','.','#','#', + '#'],['#','#','#','#','#','.','.','.','.','.','.','.','#','#','#', + '#','#'],['#','#','#','#','#','#','#','#','#','#','#','#','#','#', + '#','#','#'],), + BU_map= + ([0.0,0.0,0.0,0.0,0.0,0.0,0.0, + 0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],[0.0,0.0,0.0,0.0,0.0,0.0,0.0, + 0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],[0.0,0.0,0.0,40.0,0.0,0.0, + 40.0,40.0,20.0,40.0,40.0,0.0,0.0,40.0,0.0,0.0,0.0],[0.0,0.0,40.0,0.0, + 40.0,20.0,40.0,0.0,40.0,0.0,40.0,20.0,40.0,0.0,40.0,0.0,0.0],[0.0,0.0, + 0.0,40.0,20.0,20.0,20.0,40.0,20.0,40.0,20.0,20.0,20.0,40.0,0.0,0.0, + 0.0],[0.0,0.0,0.0,20.0,20.0,20.0,40.0,0.0,40.0,0.0,40.0,20.0,20.0, + 20.0,0.0,0.0,0.0],[0.0,0.0,40.0,40.0,20.0,40.0,20.0,40.0,20.0,40.0, + 20.0,40.0,20.0,40.0,40.0,0.0,0.0],[0.0,0.0,40.0,0.0,40.0,0.0,40.0, + 20.0,20.0,20.0,40.0,0.0,40.0,0.0,40.0,0.0,0.0],[0.0,0.0,20.0,40.0, + 20.0,40.0,20.0,20.0,60.0,20.0,20.0,40.0,20.0,40.0,20.0,0.0,0.0],[0.0, + 0.0,40.0,0.0,40.0,0.0,40.0,20.0,20.0,20.0,40.0,0.0,40.0,0.0,40.0,0.0, + 0.0],[0.0,0.0,40.0,40.0,20.0,40.0,20.0,40.0,20.0,40.0,20.0,40.0,20.0, + 40.0,40.0,0.0,0.0],[0.0,0.0,0.0,20.0,20.0,20.0,40.0,0.0,40.0,0.0,40.0, + 20.0,20.0,20.0,0.0,0.0,0.0],[0.0,0.0,0.0,40.0,20.0,20.0,20.0,40.0, + 20.0,40.0,20.0,20.0,20.0,40.0,0.0,0.0,0.0],[0.0,0.0,40.0,0.0,40.0, + 20.0,40.0,0.0,40.0,0.0,40.0,20.0,40.0,0.0,40.0,0.0,0.0],[0.0,0.0,0.0, + 40.0,0.0,0.0,40.0,40.0,20.0,40.0,40.0,0.0,0.0,40.0,0.0,0.0,0.0],[0.0, + 0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],[0.0, + 0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],),), + axial_description=_F(lower_refl_size=0.21, + upper_refl_size=0.21,), + nominal_power=4000000000.0, + Fuel_power_fraction=0.974, + by_pass=0.07, + core_volumic_flowrate=90940.0,); + +neutro_model=Model_data(physics='Neutronics', + scale='component', + code='APOLLO3', + radial_meshing=_F(flux_solver='subdivision', + flux_subdivision=2, + feedback_solver='subdivision', + feedback_subdivision=1,), + axial_meshing=_F(lower_refl=2, + fuel=42, + upper_refl=2,),); + +thermo_model=Model_data(physics='Thermalhydraulics', + scale='component', + code='FLICA4', + radial_meshing=_F(fluid='subdivision', + fluid_subdivision=1, + pellet=8, + clad=2,), + axial_meshing=_F(lower_refl=1, + fuel=40, + upper_refl=1,),); + +scenario_data=Scenario_data(initial_power=0.1, + initial_power_unit='% Nominal power', + initial_core_inlet_temperature=290.0, + initial_boron_concentration=1300.0, + initial_inlet_pressure=160.2, + initial_outlet_pressure=157.2, + initial_rod_positions=(('Rodbank@RB',201),('Rodbank@N1',96),('Rodbank@N2',260),('Rodbank@G1',260),('Rodbank@G2',260),('Rodcluster@H08',260)), + scenario_type='RIA', + ejected_rod='H02', + rod_position_program=((0.0,0),(0.1,260)), + SCRAM='YES', + SCRAM_power=1130.0, + complete_SCRAM_time=1.0, + post_processing=(('Fuel temperature@Thermalhydraulics','MAX'),('Neutronic power@Neutronics','SUM'),('Fuel temperature@Thermalhydraulics','MED'),('Neutronic power@Neutronics','MED')),); + +Genere_Une_Erreur_Traduction(essai='3',); +#VERSION_CATALOGUE:V_0:FIN VERSION_CATALOGUE +#CHECKSUM:f62a6f71fcde9f983479fc749f7e334c -:FIN CHECKSUM diff --git a/Traducteur/utils.py b/Traducteur/utils.py new file mode 100644 index 00000000..31ab5e87 --- /dev/null +++ b/Traducteur/utils.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright (C) 2007-2017 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 re + +def indexToCoordinates(src, index): + """return le numero de la colonne (x) et le numero de la ligne (y) dans src""" + y = src[: index].count("\n") + startOfLineIdx = src.rfind("\n", 0, index)+1 + x = index-startOfLineIdx + return x, y + +def lineToDict(line): + """Transforme une ligne (string) en un dictionnaire de mots + reperes par le numero de la colonne""" + + words = re.split("(\w+)", line) + h = {};i = 0 + for word in words: + h[i] = word + i+=len(word) + return h + +def dictToLine(d): + """Transformation inverse: a partir d'un dictionnaire retourne une ligne""" + cols = d + cols.sort() + return "".join([d[colno]for colno in cols]) diff --git a/Traducteur/visiteur.py b/Traducteur/visiteur.py new file mode 100644 index 00000000..d3584b16 --- /dev/null +++ b/Traducteur/visiteur.py @@ -0,0 +1,98 @@ +# -*- coding: utf-8 -*- +# Copyright (C) 2007-2017 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 re +from ast import NodeVisitor +debug=1 + +class MatchFinder (NodeVisitor): + """Visiteur de base : gestion des matches """ + def reset(self,line): + self.matches=[] + self._matches = [] + self.words = re.split("(\w+)", line) # every other one is a non word + self.positions = [] + i = 0 + for word in self.words: + self.positions.append(i) + i+=len(word) + self.index = 0 + if debug : print ('fin reset', self.words) + + def popWordsUpTo(self, word): + if word == "*": + return # won't be able to find this + posInWords = self.words.index(word) + idx = self.positions[posInWords] + self.words = self.words[posInWords+1:] + self.positions = self.positions[posInWords+1:] + + def appendMatch(self,name): + idx = self.getNextIndexOfWord(name) + self._matches.append((idx, name)) + + def getNextIndexOfWord(self,name): + return self.positions[self.words.index(name)] + + +class KeywordFinder(MatchFinder): + """Visiteur pour les keywords d'une commande """ + + def visit_keyword(self,node): + if debug : print (' visit_keyword', node.arg) + idx = self.getNextIndexOfWord(node.arg) + self.popWordsUpTo(node.arg) + prevmatches=self._matches + self._matches = [] + #for child in node.getChildNodes(): + # self.visit(child) + self.generic_visit(node) + prevmatches.append((idx, node.arg,self._matches)) + self._matches=prevmatches + #on ne garde que les matches du niveau Keyword le plus haut + self.matches=self._matches + + def visit_Tuple(self,node): + matchlist=[] + # Pour eviter les tuples et listes ordinaires, + if not hasattr(node,'getChildNodes') : return + print ('*********************************************************************') + print ("_____________ visit_Tuple", node) + for child in node.getChildNodes(): + self._matches = [] + self.visit(child) + if self._matches: + # Pour eviter les tuples et listes ordinaires, + # on ne garde que les visites fructueuses + matchlist.append(self._matches) + self._matches=matchlist + #self.generic_visit(node) + + visit_List=visit_Tuple + + def visit_Name(self,node): + if debug : print ('visit_Name', node.id) + self.popWordsUpTo(node.id) + self.generic_visit(node) + + def visit_AssName(self,node): + if debug : print ('visit_AssName', node.id) + self.popWordsUpTo(node.id) + self.generic_visit(node) diff --git a/Traducteur3/.mocles.py.swp b/Traducteur3/.mocles.py.swp deleted file mode 100644 index 9a2f5669..00000000 Binary files a/Traducteur3/.mocles.py.swp and /dev/null differ diff --git a/Traducteur3/.toto.comm.swp b/Traducteur3/.toto.comm.swp deleted file mode 100644 index 824366dd..00000000 Binary files a/Traducteur3/.toto.comm.swp and /dev/null differ diff --git a/Traducteur3/.visiteur.py.swp b/Traducteur3/.visiteur.py.swp deleted file mode 100644 index 9ad7b735..00000000 Binary files a/Traducteur3/.visiteur.py.swp and /dev/null differ diff --git a/Traducteur3/CMakeLists.txt b/Traducteur3/CMakeLists.txt deleted file mode 100644 index d1c51c80..00000000 --- a/Traducteur3/CMakeLists.txt +++ /dev/null @@ -1,34 +0,0 @@ -# -*- coding: utf-8 -*- -# CONFIGURATION MANAGEMENT OF EDF VERSION -# ====================================================================== -# COPYRIGHT (C) 1991 - 2002 EDF R&D WWW.CODE-ASTER.ORG -# THIS PROGRAM IS FREE SOFTWARE; YOU CAN REDISTRIBUTE IT AND/OR MODIFY -# IT UNDER THE TERMS OF THE GNU GENERAL PUBLIC LICENSE AS PUBLISHED BY -# THE FREE SOFTWARE FOUNDATION; EITHER VERSION 2 OF THE LICENSE, OR -# (AT YOUR OPTION) ANY LATER VERSION. -# -# THIS PROGRAM 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 -# GENERAL PUBLIC LICENSE FOR MORE DETAILS. -# -# YOU SHOULD HAVE RECEIVED A COPY OF THE GNU GENERAL PUBLIC LICENSE -# ALONG WITH THIS PROGRAM; IF NOT, WRITE TO EDF R&D CODE_ASTER, -# 1 AVENUE DU GENERAL DE GAULLE, 92141 CLAMART CEDEX, FRANCE. -# -# -# ====================================================================== - -# Installation de tous les fichiers Python, texte et images du repertoire et des sous-repertoires (sauf CVS) -install ( - FILES - calcG.py changeValeur.py dictErreurs.py __init__.py inseremocle.py - load.py log.py mocles.py movemocle.py parseur.py regles.py removemocle.py - renamemocle.py traduitV7V8.py traduitV8V9.py traduitV9V10.py utils.py - visiteur.py - DESTINATION ${CMAKE_INSTALL_PREFIX}/Traducteur - ) - -### Local Variables: -### mode: cmake -### End: diff --git a/Traducteur3/__init__.py b/Traducteur3/__init__.py deleted file mode 100644 index e4044aec..00000000 --- a/Traducteur3/__init__.py +++ /dev/null @@ -1,19 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright (C) 2007-2017 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 -# diff --git a/Traducteur3/changeValeur.py b/Traducteur3/changeValeur.py deleted file mode 100644 index 50b0c9c9..00000000 --- a/Traducteur3/changeValeur.py +++ /dev/null @@ -1,317 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright (C) 2007-2017 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 -# -from Traducteur.utils import lineToDict -import logging -from Traducteur.dictErreurs import ecritErreur -from Traducteur.load import jdcSet -from Traducteur.renamemocle import decaleLignesdeNBlancs -from Traducteur.removemocle import removeMotCleInFact -from Traducteur import regles - - -#-------------------------------------------------------------------------- -def changementValeur(jdc,command,motcle,DictNouvVal,liste=(),defaut=0): -#-------------------------------------------------------------------------- - if command not in jdcSet : return - boolChange=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 : - if indexTexteMC > len(liste_ligne_MC)-1 : break - MaLigneGlob=jdc.getLines()[indexLigneGlob] - MaLigneTexte=liste_ligne_MC[indexTexteMC] - for Valeur in DictNouvVal : - MaLigneTexteDict=lineToDict(MaLigneTexte) - trouvecol=MaLigneTexte.find(Valeur) - if trouvecol > -1: - trouve=(Valeur==MaLigneTexteDict[trouvecol]) - else: - trouve=False - if trouve: - debut=MaLigneGlob.find(motcle) - if debut==-1 : debut=0 - Nouveau=MaLigneGlob[debut:].replace(Valeur,DictNouvVal[Valeur]) - Nouveau=MaLigneGlob[0:debut]+Nouveau - jdc.getLines()[indexLigneGlob]=Nouveau - MaLigneTexte=Nouveau # raccourci honteux mais ... - MaLigneGlob=Nouveau - if Valeur in liste : - ecritErreur((command,motcle,Valeur),indexLigneGlob) - else : - logging.info("Changement de %s par %s dans %s ligne %d",Valeur,DictNouvVal[Valeur],command,indexLigneGlob) - boolChange=1 - indexLigneGlob=indexLigneGlob+1 - indexTexteMC=indexTexteMC+1 - if (trouveUnMC == 0) and ( defaut == 1): - ecritErreur((command,motcle,"DEFAUT"),c.lineno) - if boolChange : jdc.reset(jdc.getSource()) - -#-------------------------------------------------------------------------------- -def changementValeurDsMCF(jdc,command,fact,motcle,DictNouvVal,liste=(),ensemble=regles.SansRegle,defaut=0): -#-------------------------------------------------------------------------------- - - if command not in jdcSet : return - boolChange=0 - for c in jdc.root.childNodes: - if c.name != command : continue - for mcF in c.childNodes: - if mcF.name != fact : continue - l=mcF.childNodes[:] - l.reverse() - for ll in l: - trouveUnMC=0 - for mc in ll.childNodes: - if mc.name != motcle:continue - if ensemble.verif(c) == 0 : continue - trouveUnMC=1 - TexteMC=mc.getText(jdc) - liste_ligne_MC=TexteMC.splitlines() - indexLigneGlob=mc.lineno-1 - indexTexteMC=0 - while indexLigneGlob < mc.endline : - if indexTexteMC > len(liste_ligne_MC)-1 : break - MaLigneGlob=jdc.getLines()[indexLigneGlob] - MaLigneTexte=liste_ligne_MC[indexTexteMC] - for Valeur in DictNouvVal : - MaLigneTexteDict=lineToDict(MaLigneTexte) - trouvecol=MaLigneTexte.find(Valeur) - if trouvecol > -1: - trouve=(Valeur==MaLigneTexteDict[trouvecol]) - else: - trouve=False - if trouve: - debut=MaLigneGlob.find(motcle) - if debut==-1 : debut=0 - Nouveau=MaLigneGlob[debut:].replace(Valeur,DictNouvVal[Valeur]) - Nouveau=MaLigneGlob[0:debut]+Nouveau - jdc.getLines()[indexLigneGlob]=Nouveau - MaLigneTexte=Nouveau # raccourci honteux mais ... - MaLigneGlob=Nouveau - if Valeur in liste : - ecritErreur((command,fact,motcle,Valeur),indexLigneGlob) - else : - logging.info("Changement de %s par %s dans %s ligne %d",Valeur,DictNouvVal[Valeur],command,indexLigneGlob) - boolChange=1 - indexLigneGlob=indexLigneGlob+1 - indexTexteMC=indexTexteMC+1 - if (trouveUnMC == 0) and ( defaut == 1): - logging.warning("OPTION (defaut) de CALCG a verifier ligne %s" ,c.lineno ) - ecritErreur((command,fact,motcle,"DEFAUT"),c.lineno) - if boolChange : jdc.reset(jdc.getSource()) - -#-------------------------------------------------------------------------------- -def changementValeurDsMCFSiRegle(jdc,command,fact,motcle,DictNouvVal,liste_regles,defaut=0): -#-------------------------------------------------------------------------------- - if command not in jdcSet : return - mesRegles=regles.ensembleRegles(liste_regles) - liste=() - changementValeurDsMCF(jdc,command,fact,motcle,DictNouvVal,liste,mesRegles,defaut) - -#--------------------------------------------------------------------------------------- -def changementValeurDsMCFAvecAvertissement(jdc, command, fact,motcle,DictNouvVal,liste): -#--------------------------------------------------------------------------------------- - if command not in jdcSet : return - defaut=0 - if liste[-1] == "defaut" : - defaut=1 - changementValeurDsMCF(jdc,command,fact,motcle,DictNouvVal,liste,defaut) - -#-------------------------------------------------------------------------- -def changementValeurAvecAvertissement(jdc, command,motcle,DictNouvVal,liste): -#-------------------------------------------------------------------------- - if command not in jdcSet : return - defaut=0 - if liste[-1] == "defaut" : - defaut=1 - changementValeur(jdc,command,motcle,DictNouvVal,liste,defaut) - -#-------------------------------------------------------------------------- -def suppressionValeurs(jdc, command,motcle,liste): -#-------------------------------------------------------------------------- - - if command not in jdcSet : return - boolChange=0 - for c in jdc.root.childNodes: - if c.name != command : continue - for mc in c.childNodes: - if mc.name != motcle : continue - indexLigneGlob=mc.lineno-1 - while indexLigneGlob < mc.endline-1 : - MaLigneTexte = jdc.getLines()[indexLigneGlob] - MaLigne=MaLigneTexte - for Valeur in liste : - debutMC =MaLigne.find(motcle) - if debutMC ==-1 : debutMC=0 - debut1=MaLigne[0:debutMC] - chercheLigne=MaLigne[debutMC:] - trouve=chercheLigne.find(Valeur) - premier=0 - if trouve > 1 : #on a au moins une quote - debut=debut1 + chercheLigne[0:trouve-1] - index = -1 - while (-1 * index) < len(debut) : - if (debut[index] == "(") : - premier = 1 - if index == -1 : - index=len(debut) - else : - index=index+1 - break - if (debut[index] == "," ) : - break - if (debut[index] != " " ) : - assert(0) - index = index -1 - debLigne = debut[0:index] - fin=trouve+len(Valeur)+1 - if premier == 1 and chercheLigne[fin] == ',': fin = fin + 1 # on supprime la , - finLigne = chercheLigne[fin:] - MaLigne_tmp=debLigne+finLigne - # traitement ligne commancant par , - if len(MaLigne_tmp.strip()) > 0 : - if MaLigne_tmp.strip()[0]==',' : - MaLigne=MaLigne_tmp.strip()[1:] - else : - MaLigne=MaLigne_tmp[0:] - else : - MaLigne=MaLigne_tmp[0:] - boolChange=1 - jdc.getLines()[indexLigneGlob]=MaLigne - indexLigneGlob=indexLigneGlob+1 - if boolChange : jdc.reset(jdc.getSource()) - -#---------------------------------------------- -def appelleMacroSelonValeurConcept(jdc,macro,genea): -#---------------------------------------------- - if macro not in jdcSet : return - boolChange=0 - fact=genea[0] - motcle=genea[1] - chaine="CO" - for c in jdc.root.childNodes: - if c.name != macro : continue - for mcF in c.childNodes: - if mcF.name != fact : continue - l=mcF.childNodes[:] - l.reverse() - for ll in l: - trouveValeur=0 - for mc in ll.childNodes: - if mc.name != motcle:continue - TexteMC=mc.getText(jdc) - liste_ligne_MC=TexteMC.splitlines() - indexLigneGlob=mc.lineno-2 - trouveTexteMC=0 - trouveegal=0 - trouvechaine=0 - trouveparent=0 - trouvequote=0 - while indexLigneGlob < mc.endline : - indexLigneGlob=indexLigneGlob+1 - MaLigneTexte=jdc.getLines()[indexLigneGlob] - - # on commence par chercher TABLE par exemple - # si on ne trouve pas on passe a la ligne suivante - if ( trouveTexteMC == 0 ) : - indice=MaLigneTexte.find(motcle) - if indice < 0 : continue - trouveTexteMC=1 - else : - indice=0 - - # on cherche = - aChercher=MaLigneTexte[indice:] - if (trouveegal == 0 ): - indice=aChercher.find("=") - if indice < 0 : continue - trouveegal = 1 - else : - indice = 0 - - # on cherche CO - aChercher2=aChercher[indice:] - if (trouvechaine == 0 ): - indice=aChercher2.find(chaine) - if indice < 0 : continue - trouvechaine = 1 - else : - indice = 0 - - #on cherche ( - aChercher3=aChercher2[indice:] - if (trouveparent == 0 ): - indice=aChercher3.find('(') - if indice < 0 : continue - trouveparent = 1 - else : - indice = 0 - - #on cherche la ' - aChercher4=aChercher3[indice:] - if (trouvequote == 0 ): - indice=aChercher4.find("'") - indice2=aChercher4.find('"') - if (indice < 0) and (indice2 < 0): continue - if (indice < 0) : indice=indice2 - trouvequote = 1 - else : - indice = 0 - - trouveValeur=1 - aChercher5=aChercher4[indice+1:] - indice=aChercher5.find("'") - if indice < 0 : indice=aChercher5.find('"') - valeur=aChercher5[:indice] - break - - if trouveValeur==0 : - logging.error("Pb de traduction pour MACR_LIGNE_COUPE : Pas de nom de Concept identifiable") - return - - if boolChange : - jdc.reset(jdc.getSource()) - logging.error("Pb du traduction pour MACR_LIGNE_COUPE : Deux noms de Concept possibles") - return - - boolChange=1 - ligneaTraiter=jdc.getLines()[c.lineno-1] - debut=ligneaTraiter[0:c.colno] - suite=valeur+"=" - fin=ligneaTraiter[c.colno:] - ligne=debut+suite+fin - jdc.getLines()[c.lineno-1]=ligne - nbBlanc=len(valeur)+1 - if c.lineno < c.endline: - decaleLignesdeNBlancs(jdc,c.lineno,c.endline-1,nbBlanc) - if boolChange : jdc.reset(jdc.getSource()) - -#---------------------------------------------- -def changeTouteValeur(jdc,command,motcle,DictNouvVal,liste=(),defaut=0): -#---------------------------------------------- - if macro not in jdcSet : return - boolChange=0 diff --git a/Traducteur3/demosRN.py b/Traducteur3/demosRN.py deleted file mode 100755 index 477603f4..00000000 --- a/Traducteur3/demosRN.py +++ /dev/null @@ -1,94 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -# Copyright (C) 2007-2017 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 -# -""" -""" -usage="""usage: %prog [options] -Typical use is: - python traduitV11V12.py --infile=xxxx --outfile=yyyy -""" - -import os, sys -sys.path.append(os.path.join(os.path.abspath(os.path.dirname(__file__)),'..')) - -import optparse - -from Traducteur.load import getJDC -from Traducteur.mocles import parseKeywords -from Traducteur.removemocle import * -from Traducteur.renamemocle import * -from Traducteur.renamemocle import * -from Traducteur.inseremocle import * -from Traducteur.changeValeur import * -from Traducteur.movemocle import * -from Traducteur.dictErreurs import * -from Traducteur.regles import pasDeRegle -from Traducteur import log - - - -atraiter=( - "Genere_Une_Erreur_Traduction", - "RodBank", - "Assembly", - "Techno_data", - "Model_data", - ) - -dict_erreurs={ - "Genere_Une_Erreur_Traduction":"Message pour test de genereErreurpourCommande ", - } - -sys.dict_erreurs=dict_erreurs - -def traduc(infile,outfile,flog=None): - - hdlr=log.initialise(flog) - jdc=getJDC(infile,atraiter) - root=jdc.root - - #Parse les mocles des commandes - parseKeywords(root) - - # genere une erreur si on trouve la commande dans le jdc # - genereErreurPourCommande(jdc,"Genere_Une_Erreur_Traduction") - - f=open(outfile,'w') - f.write(jdc.getSource()) - f.close() - - log.ferme(hdlr) - -def main(): - parser = optparse.OptionParser(usage=usage) - - parser.add_option('-i','--infile', dest="infile", default='toto.comm', - help="Le fichier à traduire") - parser.add_option('-o','--outfile', dest="outfile", default='tutu.comm', - help="Le fichier traduit") - - parser.add_option('-l','--logfile', dest="flog", default='log.txt', - help="fichier de log") - - options, args = parser.parse_args() - traduc(options.infile,options.outfile,options.flog) - -if __name__ == '__main__': - main() diff --git a/Traducteur3/dictErreurs.py b/Traducteur3/dictErreurs.py deleted file mode 100644 index 82fc058f..00000000 --- a/Traducteur3/dictErreurs.py +++ /dev/null @@ -1,110 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright (C) 2007-2017 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 -from Traducteur.load import jdcSet - - -def ecritErreur(listeGena,ligne=None) : - from sys import dict_erreurs - maCle="" - for Mot in listeGena : - maCle=maCle+"_"+Mot - #try : - if ( 1 == 1) : - maClef=maCle[1:] - if maClef in dict_erreurs : - if ligne != None : - logging.warning("ligne %d : %s ",ligne,dict_erreurs[maClef]) - else : - logging.warning("%s",dict_erreurs[maClef]) - else : - maCle="" - for Mot in listeGena[:-1] : - maCle=maCle+"_"+Mot - maClef=maCle[1:] - maClef=maCle+"_"+"VALEUR" - if maClef in dict_erreurs : - if ligne != None : - logging.warning("ligne %d : %s ",ligne,dict_erreurs[maClef]) - else : - logging.warning("%s",dict_erreurs[maClef]) - #except : - # pass - -def genereErreurPourCommande(jdc,listeCommande) : - commands= jdc.root.childNodes[:] - commands.reverse() - for c in commands: - if type(listeCommande)==list: - for Mot in listeCommande : - if c.name != Mot :continue - ecritErreur((Mot,),c.lineno) - else: - if c.name != listeCommande :continue - ecritErreur((listeCommande,),c.lineno) - -def genereErreurMotCleInFact(jdc,command,fact,mocle): - for c in jdc.root.childNodes: - if c.name != command:continue - for mc in c.childNodes: - if mc.name != fact:continue - l=mc.childNodes[:] - for ll in l: - for n in ll.childNodes: - if n.name != mocle: - continue - else : - ecritErreur((command,fact,mocle,),c.lineno) - -def genereErreurMCF(jdc,command,fact): - for c in jdc.root.childNodes: - if c.name != command:continue - for mc in c.childNodes: - if mc.name != fact: - continue - else : - ecritErreur((command,fact,),c.lineno) - -def genereErreurValeur(jdc,command,fact,list_valeur): - for c in jdc.root.childNodes: - if c.name != command:continue - for mc in c.childNodes: - if mc.name != fact:continue - texte=mc.getText(jdc) - for valeur in list_valeur: - trouve=texte.find(valeur) - if trouve > -1 : - logging.warning("%s doit etre supprimee ou modifiee dans %s : ligne %d",valeur,c.name,mc.lineno) - -def genereErreurValeurDsMCF(jdc,command,fact,mocle,list_valeur): - for c in jdc.root.childNodes: - if c.name != command:continue - for mc in c.childNodes: - if mc.name != fact:continue - l=mc.childNodes[:] - for ll in l: - for n in ll.childNodes: - if n.name != mocle:continue - texte=n.getText(jdc) - for valeur in list_valeur: - trouve=texte.find(valeur) - if trouve > -1 : - logging.warning("%s doit etre supprimee ou modifiee dans %s : ligne %d",valeur,c.name,n.lineno) diff --git a/Traducteur3/edg_REP1300_FULL_PN.comm b/Traducteur3/edg_REP1300_FULL_PN.comm deleted file mode 100755 index ee4744a9..00000000 --- a/Traducteur3/edg_REP1300_FULL_PN.comm +++ /dev/null @@ -1,159 +0,0 @@ - -REF=Assembly(assembly_type='REF',); - -U1=Assembly(assembly_type='UOX', - assembly_width=0.21504, - fuel_density=0.95, - radial_description=_F(clad_outer_radius=0.00475, - guide_tube_outer_radius=0.006025, - fuel_rod_pitch=0.0126, - nfuel_rods=264,), - axial_description=_F(active_length_start=0.21, - active_length_end=4.4772,), - grids=_F(mixing=_F(positions=(0.69216,1.19766,1.70316,2.20866,2.71416,3.20416,3.69416,4.18416,), - size=0.033,), - non_mixing=_F(positions=(0.026,4.2412,), - size=0.033,),),); - -UGD=Assembly(assembly_type='UOX', - assembly_width=0.21504, - fuel_density=0.95, - radial_description=_F(clad_outer_radius=0.00475, - guide_tube_outer_radius=0.006025, - fuel_rod_pitch=0.0126, - nfuel_rods=264,), - axial_description=_F(active_length_start=0.21, - active_length_end=4.4772,), - grids=_F(mixing=_F(positions=(0.69216,1.19766,1.70316,2.20866,2.71416,3.20416,3.69416,4.18416,), - size=0.033,), - non_mixing=_F(positions=(0.026,), - size=0.033,),),); - -RB=RodBank(rod_type='heterogeneous', - bottom_composition='AIC', - splitting_heigh=1.4224, - upper_composition='B4C', - step_height=0.016, - nsteps=260,); - -N1=RodBank(rod_type='heterogeneous', - bottom_composition='AIC', - splitting_heigh=1.4224, - upper_composition='B4C', - step_height=0.016, - nsteps=260,); - -N2=RodBank(rod_type='heterogeneous', - bottom_composition='AIC', - splitting_heigh=1.4226, - upper_composition='B4C', - step_height=0.016, - nsteps=260,); - -G1=RodBank(rod_type='homogeneous', - rod_composition='Grey', - step_height=0.016, - nsteps=260,); - -G2=RodBank(rod_type='homogeneous', - rod_composition='Grey', - step_height=0.016, - nsteps=260,); - -techno_data=Techno_data(assembly_list=(REF,U1,UGD,), - rodbank_list=(RB,G1,G2,N1,N2,), - radial_description=_F(nb_assembly=15, - xaxis=('RW','S','R','P','N','L','K','J','H','G','F','E','D','C','B','A','RE',), - yaxis= - ('RS','15','14','13','12','11', - '10','09','08','07','06','05','04','03','02','01','RN',), - assembly_map=((REF,REF,REF,REF,REF,REF,REF,REF,REF,REF,REF,REF,REF,REF,REF,REF,REF,),(REF,REF,REF,REF,REF,U1,U1,U1,U1,U1,U1,U1,REF,REF,REF,REF,REF,),(REF,REF,REF,UGD,U1,UGD,UGD,U1,U1,U1,UGD,UGD,U1,UGD,REF,REF,REF,),(REF,REF,UGD,U1,U1,U1,U1,UGD,U1,UGD,U1,U1,U1,U1,UGD,REF,REF,),(REF,REF,U1,U1,U1,UGD,U1,UGD,U1,UGD,U1,UGD,U1,U1,U1,REF,REF,),(REF,U1,UGD,U1,UGD,U1,U1,UGD,U1,UGD,U1,U1,UGD,U1,UGD,U1,REF,),(REF,U1,UGD,U1,U1,U1,UGD,UGD,U1,UGD,UGD,U1,U1,U1,UGD,U1,REF,),(REF,U1,U1,UGD,UGD,UGD,UGD,U1,UGD,U1,UGD,UGD,UGD,UGD,U1,U1,REF,),(REF,U1,U1,U1,U1,U1,U1,UGD,UGD,UGD,U1,U1,U1,U1,U1,U1,REF,),(REF,U1,U1,UGD,UGD,UGD,UGD,U1,UGD,U1,UGD,UGD,UGD,UGD,U1,U1,REF,),(REF,U1,UGD,U1,U1,U1,UGD,UGD,U1,UGD,UGD,U1,U1,U1,UGD,U1,REF,),(REF,U1,UGD,U1,UGD,U1,U1,UGD,U1,UGD,U1,U1,UGD,U1,UGD,U1,REF,),(REF,REF,U1,U1,U1,UGD,U1,UGD,U1,UGD,U1,UGD,U1,U1,U1,REF,REF,),(REF,REF,UGD,U1,U1,U1,U1,UGD,U1,UGD,U1,U1,U1,U1,UGD,REF,REF,),(REF,REF,REF,UGD,U1,UGD,UGD,U1,U1,U1,UGD,UGD,U1,UGD,REF,REF,REF,),(REF,REF,REF,REF,REF,U1,U1,U1,U1,U1,U1,U1,REF,REF,REF,REF,REF,),(REF,REF,REF,REF,REF,REF,REF,REF,REF,REF,REF,REF,REF,REF,REF,REF,REF,),), - rod_map= - (['#','#','#','#','#','#','#', - '#','#','#','#','#','#','#','#','#','#'],['#','#','#','#','#','.', - '.','.','.','.','.','.','#','#','#','#','#'],['#','#','#','.','.', - '.','.','.','RB','.','.','.','.','.','#','#','#'],['#','#','.','.', - '.','G2','.','N2','.','N2','.','G2','.','.','.','#','#'],['#','#', - '.','.','N1','.','.','.','G1','.','.','.','N1','.','.','#','#'], - ['#','.','.','G2','.','RB','.','.','.','.','.','RB','.','G2','.', - '.','#'],['#','.','.','.','.','.','.','.','N1','.','.','.','.','.', - '.','.','#'],['#','.','.','N2','.','.','.','.','.','.','.','.','.', - 'N2','.','.','#'],['#','.','RB','.','G1','.','N1','.','RB','.','N1', - '.','G1','.','RB','.','#'],['#','.','.','N2','.','.','.','.','.', - '.','.','.','.','N2','.','.','#'],['#','.','.','.','.','.','.','.', - 'N1','.','.','.','.','.','.','.','#'],['#','.','.','G2','.','RB', - '.','.','.','.','.','RB','.','G2','.','.','#'],['#','#','.','.', - 'N1','.','.','.','G1','.','.','.','N1','.','.','#','#'],['#','#', - '.','.','.','G2','.','N2','.','N2','.','G2','.','.','.','#','#'], - ['#','#','#','.','.','.','.','.','RB','.','.','.','.','.','#','#', - '#'],['#','#','#','#','#','.','.','.','.','.','.','.','#','#','#', - '#','#'],['#','#','#','#','#','#','#','#','#','#','#','#','#','#', - '#','#','#'],), - BU_map= - ([0.0,0.0,0.0,0.0,0.0,0.0,0.0, - 0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],[0.0,0.0,0.0,0.0,0.0,0.0,0.0, - 0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],[0.0,0.0,0.0,40.0,0.0,0.0, - 40.0,40.0,20.0,40.0,40.0,0.0,0.0,40.0,0.0,0.0,0.0],[0.0,0.0,40.0,0.0, - 40.0,20.0,40.0,0.0,40.0,0.0,40.0,20.0,40.0,0.0,40.0,0.0,0.0],[0.0,0.0, - 0.0,40.0,20.0,20.0,20.0,40.0,20.0,40.0,20.0,20.0,20.0,40.0,0.0,0.0, - 0.0],[0.0,0.0,0.0,20.0,20.0,20.0,40.0,0.0,40.0,0.0,40.0,20.0,20.0, - 20.0,0.0,0.0,0.0],[0.0,0.0,40.0,40.0,20.0,40.0,20.0,40.0,20.0,40.0, - 20.0,40.0,20.0,40.0,40.0,0.0,0.0],[0.0,0.0,40.0,0.0,40.0,0.0,40.0, - 20.0,20.0,20.0,40.0,0.0,40.0,0.0,40.0,0.0,0.0],[0.0,0.0,20.0,40.0, - 20.0,40.0,20.0,20.0,60.0,20.0,20.0,40.0,20.0,40.0,20.0,0.0,0.0],[0.0, - 0.0,40.0,0.0,40.0,0.0,40.0,20.0,20.0,20.0,40.0,0.0,40.0,0.0,40.0,0.0, - 0.0],[0.0,0.0,40.0,40.0,20.0,40.0,20.0,40.0,20.0,40.0,20.0,40.0,20.0, - 40.0,40.0,0.0,0.0],[0.0,0.0,0.0,20.0,20.0,20.0,40.0,0.0,40.0,0.0,40.0, - 20.0,20.0,20.0,0.0,0.0,0.0],[0.0,0.0,0.0,40.0,20.0,20.0,20.0,40.0, - 20.0,40.0,20.0,20.0,20.0,40.0,0.0,0.0,0.0],[0.0,0.0,40.0,0.0,40.0, - 20.0,40.0,0.0,40.0,0.0,40.0,20.0,40.0,0.0,40.0,0.0,0.0],[0.0,0.0,0.0, - 40.0,0.0,0.0,40.0,40.0,20.0,40.0,40.0,0.0,0.0,40.0,0.0,0.0,0.0],[0.0, - 0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],[0.0, - 0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],),), - axial_description=_F(lower_refl_size=0.21, - upper_refl_size=0.21,), - nominal_power=4000000000.0, - Fuel_power_fraction=0.974, - by_pass=0.07, - core_volumic_flowrate=90940.0,); - -neutro_model=Model_data(physics='Neutronics', - scale='component', - code='APOLLO3', - radial_meshing=_F(flux_solver='subdivision', - flux_subdivision=2, - feedback_solver='subdivision', - feedback_subdivision=1,), - axial_meshing=_F(lower_refl=2, - fuel=42, - upper_refl=2,),); - -thermo_model=Model_data(physics='Thermalhydraulics', - scale='component', - code='FLICA4', - radial_meshing=_F(fluid='subdivision', - fluid_subdivision=1, - pellet=8, - clad=2,), - axial_meshing=_F(lower_refl=1, - fuel=40, - upper_refl=1,),); - -scenario_data=Scenario_data(initial_power=0.1, - initial_power_unit='% Nominal power', - initial_core_inlet_temperature=290.0, - initial_boron_concentration=1300.0, - initial_inlet_pressure=160.2, - initial_outlet_pressure=157.2, - initial_rod_positions=(('Rodbank@RB',201),('Rodbank@N1',96),('Rodbank@N2',260),('Rodbank@G1',260),('Rodbank@G2',260),('Rodcluster@H08',260)), - scenario_type='RIA', - ejected_rod='H02', - rod_position_program=((0.0,0),(0.1,260)), - SCRAM='YES', - SCRAM_power=1130.0, - complete_SCRAM_time=1.0, - post_processing=(('Fuel temperature@Thermalhydraulics','MAX'),('Neutronic power@Neutronics','SUM'),('Fuel temperature@Thermalhydraulics','MED'),('Neutronic power@Neutronics','MED')),); - -Genere_Une_Erreur_Traduction(essai='3',); -#VERSION_CATALOGUE:V_0:FIN VERSION_CATALOGUE -#CHECKSUM:f62a6f71fcde9f983479fc749f7e334c -:FIN CHECKSUM \ No newline at end of file diff --git a/Traducteur3/inseremocle.py b/Traducteur3/inseremocle.py deleted file mode 100644 index 19dc1ceb..00000000 --- a/Traducteur3/inseremocle.py +++ /dev/null @@ -1,289 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright (C) 2007-2017 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 -from Traducteur.parseur import FactNode -from Traducteur.load import jdcSet -from Traducteur.dictErreurs import ecritErreur -from Traducteur import regles -debug=0 - - -#----------------------------------- -def insereMotCle(jdc,recepteur,texte): -#----------------------------------- -# appelle la methode selon la classe -# du recepteur - - if recepteur.name not in jdcSet : return - if recepteur.__class__.__name__ == "Command" : - if debug : print (" Ajout de ", texte, "dans la commande : " ,recepteur.name ) - insereMotCleDansCommande(jdc,recepteur,texte) - return - - -#-------------------------------------------- -def insereMotCleDansCommande(jdc,command,texte): -#--------------------------------------------- -# insere le texte comme 1er mot cle -# de la commande - if command.name not in jdcSet : return - if debug : print ("insereMotCle ", texte , " dans ", command.name) - numcol=chercheDebut1Mot(jdc,command) - if numcol > 0 : - jdc.splitLine(command.lineno,numcol) - indice = -1 - while texte[indice] == " " or texte[indice] == "\n": - indice = indice -1 - if texte[indice] != "," : texte=texte+"," - texteinfo=texte - texte=texte+'\n' - jdc.addLine(texte,command.lineno) - logging.info("Insertion de : %s ligne %d", texteinfo,command.lineno) - if numcol > 0 : # Les mots clefs etaient sur la meme ligne - jdc.joinLineandNext(command.lineno) - -#------------------------------------------------------------- -def insereMotCleDansFacteur(jdc,facteur,texte,plusieursFois=True): -#---------------------------------------------------------------- - if debug : print ("insereMotCle ", texte , " dans ", facteur.name) - - if texte[-1] == "\n" : texte=texte[0:-1] - ancien=jdc.getLine(facteur.lineno) - - # On va chercher la derniere ) pour ajouter avant - # on va verifier s il il y a un , avant - # si le texte ne finit pas par une "," - # on en met une - - indice = -1 - while texte[indice] == " " : - indice = indice -1 - if texte[indice] != "," : - texte=texte+"," - if (texte.find("#") > -1) and (texte.find("#") < texte.find(",")) : - texte=texte+"\n," - - texteinfo=texte - texte=texte+"\n" - - ligneaCouper=facteur.lineno - while ligneaCouper < facteur.endline + 1 : - trouve=0 - trouveF=0 - trouveP=0 - indiceDeCoupe=0 - while ancien.find("_F") > 0 : - longueur=len(ancien) - indice=ancien.find("_F") - indiceParcours=0 - # pour ne pas tenir compte des autres noms - # Attention si 2 MCF sur la meme ligne (la 1ere) - if trouveF == 0 : - if ((ligneaCouper!=facteur.lineno) or ((ancien.find(facteur.name) < indice ) or (ancien.find(facteur.name) < 0))) : - trouveF=1 - indiceParcours=indice + 2 - # attention pour regler DEFI_FONCTION .. - else : - indiceDeCoupe=indiceDeCoupe+indice+2 - ancien=ancien[indice +2:] - continue - if trouveF == 1 : - indiceDeCoupe=indiceDeCoupe+indice - # print "indice de Parcours" ,indiceParcours - # print ancien[indiceParcours] - # print ancien[indiceParcours+1] - # print ancien[indiceParcours+2] - while indiceParcours < longueur : - if ancien[indiceParcours] == "(" : - trouveP=1 - # print ("trouve". - break - if ancien[indiceParcours] != " " : - trouveP=0 - # print ("mouv") - break - indiceParcours = indiceParcours+1 - trouve = trouveP * trouveF - if trouve : break - ancien=ancien[indice+1:] - if trouve : - debut=indiceDeCoupe + 3 - if(jdc.getLine(ligneaCouper)[debut:]!="\n"): - jdc.splitLine(ligneaCouper,debut) - jdc.addLine(texte,ligneaCouper) - jdc.joinLineandNext(ligneaCouper) - logging.info("Insertion de %s ligne %d", texteinfo,ligneaCouper) - - # Gestion du cas particulier du mot clef facteur vide - if facteur.childNodes == []: - jdc.joinLineandNext(facteur.lineno) - - ligneaCouper=ligneaCouper+1 - ancien=jdc.getLine(ligneaCouper) - if not plusieursFois and trouve : break - - -#----------------------------------- -def chercheDebut1Mot(jdc,command): -#----------------------------------- -# Retourne le numero de colonne si le 1er mot clef est -# sur la meme ligne que le mot clef facteur -# -1 sinon - assert (command.childNodes != []) - debut=-1 - node1=command.childNodes[0] - if hasattr(node1,"lineno"): - if node1.lineno == command.lineno : - debut=node1.colno - else: - debut=chercheDebutFacteur(jdc,command) - if debut == -1 and debug : print ("attention!!! pb pour trouver le debut dans ", command) - return debut - -#----------------------------------- -def chercheDebutFacteur(jdc,facteur): -#----------------------------------- - debut=-1 - ligne=jdc.getLines()[facteur.lineno] - debut=ligne.find("_F") - if debut > -1 : debut=debut + 3 - return debut - - -#----------------------------------- -def chercheAlignement(jdc,command): -#----------------------------------- -# Retourne le nb de blanc -# pour aligner sur le 1er mot clef fils - assert (command.childNodes != []) - node1=command.childNodes[0] - nbBlanc=node1.colno - return " "*nbBlanc - -#--------------------------------------------------------------------------------------------------------- -def chercheOperInsereFacteur(jdc,nomcommande,nouveau,ensemble=regles.SansRegle, estunFacteur=1, erreur=0): -#-------------------------------------------------------------------------------------------------------- -# Cherche l oper -# cree le texte -# appelle insereMotCle pour ajouter le texte -# - boolChange=0 - if estunFacteur : - texte=nouveau+"=_F()," - else : - texte=nouveau - if nomcommande not in jdcSet : return - commands= jdc.root.childNodes[:] - commands.reverse() - for c in commands: - if c.name != nomcommande:continue - if ensemble.verif(c) == 0 : continue - if erreur : ecritErreur((nomcommande,nouveau),c.lineno) - boolChange=1 - insereMotCle(jdc,c,texte) - if boolChange : jdc.reset(jdc.getSource()) - -#---------------------------------------------------------------------------------------- -def chercheOperInsereFacteurSiRegle(jdc,nomcommande,nouveau,liste_regles, estunFacteur=1): -#---------------------------------------------------------------------------------------- -# Cherche l oper -# cree le texte -# appelle insereMotCle pour ajouter le texte -# - if nomcommande not in jdcSet : return - mesRegles=regles.ensembleRegles(liste_regles) - chercheOperInsereFacteur(jdc,nomcommande,nouveau,mesRegles,estunFacteur) - -#---------------------------------------------------------------------------------------- -def chercheOperInsereMotCleSiRegle(jdc,nomcommande,nouveau,liste_regles, estunFacteur=0): -#---------------------------------------------------------------------------------------- - if nomcommande not in jdcSet : return - mesRegles=regles.ensembleRegles(liste_regles) - chercheOperInsereFacteur(jdc,nomcommande,nouveau,mesRegles,estunFacteur) - - -#--------------------------------------------------------------------------------------------------------- -def chercheOperInsereFacteurSiRegleAvecAvertissement(jdc,nomcommande,nouveau,liste_regles, estunFacteur=1): -#--------------------------------------------------------------------------------------------------------- - if nomcommande not in jdcSet : return - mesRegles=regles.ensembleRegles(liste_regles) - chercheOperInsereFacteur(jdc,nomcommande,nouveau,mesRegles,estunFacteur,erreur=1) - -#------------------------------------------------------------------------------------------------- -def ajouteMotClefDansFacteur(jdc,commande,fact,nouveau,ensemble=regles.SansRegle, estunFacteur=0): -#------------------------------------------------------------------------------------------------- -# Cherche la commande -# Cherche le MCF -# cree le texte -# appelle insereMotCle pour ajouter le texte -# - if commande not in jdcSet : return - if estunFacteur : - texte=nouveau+"=_F()," - else : - texte=nouveau - commands= jdc.root.childNodes[:] - commands.reverse() - boolChange=0 - for c in commands: - if c.name != commande : continue - for mcF in c.childNodes: - if mcF.name != fact : continue - if ensemble.verif(c) == 0 : continue - boolChange=1 - insereMotCleDansFacteur(jdc,mcF,texte) - if boolChange : jdc.reset(jdc.getSource()) - -#------------------------------------------------------------------------------------------- -def ajouteMotClefDansFacteurSiRegle(jdc,commande,fact,nouveau,liste_regles,estunFacteur=0): -#------------------------------------------------------------------------------------------- -# - if commande not in jdcSet : return - mesRegles=regles.ensembleRegles(liste_regles) - ajouteMotClefDansFacteur(jdc,commande,fact,nouveau,mesRegles,estunFacteur) - -#------------------------------------------------------------------------------------------- -def ajouteMotClefDansFacteurCourantSiRegle(jdc,commande,fact,nouveau,liste_regles): -#------------------------------------------------------------------------------------------- -# - if commande not in jdcSet : return - ensemble=regles.ensembleRegles(liste_regles) - commands= jdc.root.childNodes[:] - commands.reverse() - boolChange=0 - for c in commands: - if c.name != commande : continue - for mcF in c.childNodes: - if mcF.name != fact : continue - l=mcF.childNodes[:] - l.reverse() - for ll in l: - if ensemble.verif(ll) == 0 : continue - boolChange=1 - n=ll.childNodes[0] - ligneaCouper=n.lineno-1 - numcol=n.colno - jdc.splitLine(ligneaCouper+1,numcol) - texte=nouveau+",\n" - jdc.addLine(texte,ligneaCouper+1) - logging.info("Insertion de %s dans %s : ligne %d", nouveau,c.name,ligneaCouper+1) - if numcol > 0 : - jdc.joinLineandNext(ligneaCouper+1) - if boolChange : jdc.reset(jdc.getSource()) diff --git a/Traducteur3/load.py b/Traducteur3/load.py deleted file mode 100644 index f5aa5b52..00000000 --- a/Traducteur3/load.py +++ /dev/null @@ -1,146 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright (C) 2007-2017 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 os -import re -from Traducteur import parseur -from Traducteur.mocles import parseKeywords - -jdcSet=set() - - -class JDCTrad: - """Cet objet conserve toutes les informations relatives a un fichier de commandes .comm""" - - def __init__(self,src,atraiter): - #---------------------------------------- - self.atraiter=atraiter - self.init(src,atraiter) - commands= self.root.childNodes[:] - commands.reverse() - for c in commands: - jdcSet.add(c.name) - - def init(self,src,atraiter): - #--------------------------- - # construction de self.lines - self.root=parseur.parser(src,atraiter) - self.lines=src.splitlines(1) - - def parseKeywords(self): - #----------------------- - # construction de fils (cf mocles.py) - parseKeywords(self.root) - - def reset(self,src): - #----------------------- - # reconstruction - self.init(src,self.atraiter) - self.parseKeywords() - - def getSource(self): - #----------------------- - # retourne la concatenation de - # toutes les lignes - return "".join(self.getLines()) - - def getLine(self,linenum): - #----------------------- - # retourne la linenumieme ligne - return self.getLines()[linenum-1] - - def getLines(self): - #---------------------------- - # retourne toutes les lignes - return self.lines - - def addLine(self,ligne,numero) : - #---------------------------- - # insere le texte contenu dans ligne - # dans la liste self.lines au rang numero - Ldebut=self.lines[0:numero] - Lmilieu=[ligne,] - Lfin=self.lines[numero:] - self.lines=Ldebut+Lmilieu+Lfin - - - def splitLine(self,numeroLigne,numeroColonne) : - #---------------------------------------------- - # coupe la ligne numeroLigne en 2 a numeroColonne - # ajoute des blancs en debut de 2nde Ligne pour - # aligner - numeroLigne = numeroLigne -1 - Ldebut=self.lines[0:numeroLigne] - if len(self.lines) > numeroLigne : - Lfin=self.lines[numeroLigne+1:] - else : - Lfin=[] - Lsplit=self.lines[numeroLigne] - LigneSplitDebut=Lsplit[0:numeroColonne]+"\n" - LigneSplitFin=" "*numeroColonne+Lsplit[numeroColonne:] - Lmilieu=[LigneSplitDebut,LigneSplitFin] - - self.lines=Ldebut+Lmilieu+Lfin - - def joinLineandNext(self,numeroLigne) : - #-------------------------------------- - # concatene les lignes numeroLigne et numeroLigne +1 - # enleve les blancs de debut de la ligne (numeroLigne +1) - Ldebut=self.lines[0:numeroLigne-1] - if len(self.lines) > numeroLigne : - Lfin=self.lines[numeroLigne+1:] - else : - Lfin=[] - - ligneMilieuDeb=self.lines[numeroLigne - 1 ] - ligneMilieuDeb=ligneMilieuDeb[0:-1] - ligneMilieuFin=self.lines[numeroLigne] - for i in range(len(ligneMilieuFin)): - if ligneMilieuFin[i] != " " : - ligneMilieuFin=ligneMilieuFin[i:] - break - Lmilieu=[ligneMilieuDeb+ligneMilieuFin,] - - self.lines=Ldebut+Lmilieu+Lfin - - def supLignes(self,debut,fin): - #------------------------ - Ldebut=self.lines[0:debut-1] - Lfin=self.lines[fin:] - self.lines=Ldebut+Lfin - - def remplaceLine(self,numeroLigne,nouveauTexte) : - #------------------------------------------------ - self.lines[numeroLigne]=nouveauTexte - -def getJDC(filename,atraiter): -#---------------------------- -# lit le JDC - f=open(filename) - src=f.read() - f.close() - jdc=JDCTrad(src,atraiter) - return jdc - -def getJDCFromTexte(texte,atraiter): -#----------------------------------- -# lit le JDC - jdc=JDCTrad(texte,atraiter) - return jdc diff --git a/Traducteur3/log.py b/Traducteur3/log.py deleted file mode 100644 index 21c4ab61..00000000 --- a/Traducteur3/log.py +++ /dev/null @@ -1,48 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright (C) 2007-2017 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 os -logger=logging.getLogger() - -def initialise(flog=None): - if flog == None : - MonHome=os.environ['HOME'] - MaDir=MonHome+"/Eficas_install" - try : - os.mkdir(MaDir) - except : - pass - try : - os.listdir(MaDir) - flog=MaDir+"/convert.log" - except : - flog='/tmp/convert.log' - - hdlr=logging.FileHandler(flog,'w') - formatter = logging.Formatter('%(levelname)s: %(message)s') - hdlr.setFormatter(formatter) - logger.addHandler(hdlr) - logger.setLevel(logging.INFO) - return hdlr - - -def ferme (hdlr) : - logger.removeHandler(hdlr) diff --git a/Traducteur3/log.txt b/Traducteur3/log.txt deleted file mode 100644 index 85f57675..00000000 --- a/Traducteur3/log.txt +++ /dev/null @@ -1 +0,0 @@ -WARNING: ligne 159 : Message pour test de genereErreurpourCommande diff --git a/Traducteur3/mocles.py b/Traducteur3/mocles.py deleted file mode 100644 index 0c890f8b..00000000 --- a/Traducteur3/mocles.py +++ /dev/null @@ -1,168 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright (C) 2007-2017 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 compiler -import ast -import types -from Traducteur.parseur import Keyword, FactNode, lastParen, lastParen2,maskStringsAndComments -from Traducteur.visiteur import KeywordFinder, NodeVisitor -from Traducteur.utils import indexToCoordinates, lineToDict, dictToLine - -debug=0 - -#------------------------ -def parseFact(match,c,kw): -#------------------------ - submatch=match[2] - lastpar=match[0]+lastParen(c.src[match[0]:]) - #if type(submatch[0][0]) ==types.IntType: - if isinstance(submatch[0][0], int) : - #mot cle facteur isole - no=FactNode() - kw.addChild(no) - for ii in range(len(submatch)-1): - e=submatch[ii] - x,y=indexToCoordinates(c.src,e[0]) - lineno=y+c.lineno - colno=x - x,y=indexToCoordinates(c.src,submatch[ii+1][0]) - endline=y+c.lineno - endcol=x - no.addChild(Keyword(e[1],lineno,colno,endline,endcol)) - #last one - e=submatch[-1] - x,y=indexToCoordinates(c.src,e[0]) - lineno=y+c.lineno - colno=x - x,y=indexToCoordinates(c.src,lastpar-1) - endline=y+c.lineno - endcol=x - no.addChild(Keyword(e[1],lineno,colno,endline,endcol)) - else: - #mot cle facteur multiple - ii=0 - for l in submatch: - lastpar=l[0][0]+lastParen2(c.src[l[0][0]:]) - ii=ii+1 - no=FactNode() - kw.addChild(no) - for j in range(len(l)-1): - e=l[j] - x,y=indexToCoordinates(c.src,e[0]) - lineno=y+c.lineno - colno=x - x,y=indexToCoordinates(c.src,l[j+1][0]) - endline=y+c.lineno - endcol=x - no.addChild(Keyword(e[1],lineno,colno,endline,endcol)) - #last one - e=l[-1] - x,y=indexToCoordinates(c.src,e[0]) - lineno=y+c.lineno - colno=x - x,y=indexToCoordinates(c.src,lastpar-1) - endline=y+c.lineno - endcol=x - no.addChild(Keyword(e[1],lineno,colno,endline,endcol)) - - -#----------------------- -def parseKeywords(root): -#----------------------- - """A partir d'un arbre contenant des commandes, ajoute les noeuds - fils correspondant aux mocles de la commande - """ - debug=1 - #traceback.print_stack(limit=5) - - matchFinder=KeywordFinder() - - for c in root.childNodes: - if debug : print ('parse -------------- ', c.name) - maskedsrc=maskStringsAndComments(c.src) - #on supprime seulement les blancs du debut pour pouvoir compiler - #meme si la commande est sur plusieurs lignes seul le debut compte - #ast=compiler.parse(c.src.lstrip()) - #print ast - monAst=ast.parse(c.src.lstrip()) - if debug : print (ast.dump(monAst)) - #Ne pas supprimer les blancs du debut pour avoir les bons numeros de colonne - matchFinder.reset(maskedsrc) - matchFinder.visit(monAst) - if debug : print ("matchFinder.matches", matchFinder.matches) - if len(matchFinder.matches) > 1: - # plusieurs mocles trouves : - # un mocle commence au debut du keyword (matchFinder.matches[i][0]) - # et finit juste avant le keyword suivant - # (matchFinder.matches[i+1][0]]) - for i in range(len(matchFinder.matches)-1): - if debug:print ("texte:",c.src[matchFinder.matches[i][0]:matchFinder.matches[i+1][0]]) - x,y=indexToCoordinates(c.src,matchFinder.matches[i][0]) - lineno=y+c.lineno - colno=x - x,y=indexToCoordinates(c.src,matchFinder.matches[i+1][0]) - endline=y+c.lineno - endcol=x - if debug:print (matchFinder.matches[i][0],matchFinder.matches[i][1],lineno,colno,endline,endcol) - kw=Keyword(matchFinder.matches[i][1],lineno,colno,endline,endcol) - c.addChild(kw) - submatch= matchFinder.matches[i][2] - if submatch: - parseFact(matchFinder.matches[i],c,kw) - - # dernier mocle : - # il commence au debut du dernier keyword - # (matchFinder.matches[i+1][0]) et - # finit avant la parenthese fermante de la commande (c.lastParen) - - if debug:print ("texte:",c.src[matchFinder.matches[i+1][0]:c.lastParen]) - x,y=indexToCoordinates(c.src,matchFinder.matches[i+1][0]) - lineno=y+c.lineno - colno=x - x,y=indexToCoordinates(c.src,c.lastParen) - endline=y+c.lineno - endcol=x - if debug:print (matchFinder.matches[i+1][0],matchFinder.matches[i+1][1],lineno,colno,endline,endcol) - kw=Keyword(matchFinder.matches[i+1][1],lineno,colno,endline,endcol) - c.addChild(kw) - submatch= matchFinder.matches[i+1][2] - if submatch: - parseFact(matchFinder.matches[i+1],c,kw) - - elif len(matchFinder.matches) == 1: - #un seul mocle trouve : - # il commence au debut du keyword (matchFinder.matches[0][0]) et - # finit juste avant la parenthese fermante de la - # commande (c.lastParen) - if debug:print ("texte:",c.src[matchFinder.matches[0][0]:c.lastParen]) - x,y=indexToCoordinates(c.src,matchFinder.matches[0][0]) - lineno=y+c.lineno - colno=x - x,y=indexToCoordinates(c.src,c.lastParen) - endline=y+c.lineno - endcol=x - if debug:print ( matchFinder.matches[0][0],matchFinder.matches[0][1],lineno,colno,endline,endcol) - kw=Keyword(matchFinder.matches[0][1],lineno,colno,endline,endcol) - c.addChild(kw) - submatch= matchFinder.matches[0][2] - if submatch: - parseFact(matchFinder.matches[0],c,kw) - else: - pass diff --git a/Traducteur3/movemocle.py b/Traducteur3/movemocle.py deleted file mode 100644 index 4a43752f..00000000 --- a/Traducteur3/movemocle.py +++ /dev/null @@ -1,346 +0,0 @@ -# -*- coding: iso-8859-1 -*- -# Copyright (C) 2007-2017 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 -from Traducteur import removemocle -from Traducteur import inseremocle -from Traducteur.parseur import lastParen -from Traducteur.load import jdcSet -debug=0 - -#----------------------------------------------------- -def moveMotCleFromFactToFather(jdc,command,fact,mocle): -#----------------------------------------------------- -# exemple type : IMPR_GENE - - if command not in jdcSet : return - boolChange=0 - commands= jdc.root.childNodes[:] - commands.reverse() - for c in commands: - if c.name != command:continue - boolchange_c=0 - for mc in c.childNodes: - if mc.name != fact:continue - l=mc.childNodes[:] - for ll in l: - for n in ll.childNodes: - if n.name != mocle:continue - # test boolchange_c :il faut le faire une seule fois par commande sinon duplication du mot clé - if boolchange_c != 0 :continue - if debug : print ("Changement de place :", n.name, n.lineno, n.colno) - MonTexte=n.getText(jdc); - boolChange=1 - boolchange_c=1 - inseremocle.insereMotCle(jdc,c,MonTexte) - logging.info("Changement de place %s ligne %s ",n.name, n.lineno) - - if boolChange : jdc.reset(jdc.getSource()) - removemocle.removeMotCleInFact(jdc,command,fact,mocle) - - -#---------------------------------------------------------------------------- -def moveMotCleFromFactToFactMulti(jdc,oper,factsource,mocle,liste_factcible): -#---------------------------------------------------------------------------- -# exemple type STAT_NON_LINE et RESI_INTER_RELA - for factcible in liste_factcible : - moveMotCleFromFactToFact(jdc,oper,factsource,mocle,factcible) - removemocle.removeMotCleInFact(jdc,oper,factsource,mocle) - - -#---------------------------------------------------------------------------- -def moveMotCleFromFactToFact(jdc,oper,factsource,mocle,factcible): -#---------------------------------------------------------------------------- - if oper not in jdcSet : return - if debug : print ("moveMotCleFromFactToFact pour " ,oper,factsource,mocle,factcible) - boolChange=0 - commands= jdc.root.childNodes[:] - commands.reverse() - for c in commands: - if c.name != oper : continue - cible=None - for mc in c.childNodes: - if mc.name != factcible : - continue - else : - cible=mc - break - if cible==None : - if debug : print ("Pas de changement pour ", oper, " ", factsource, " ",mocle, "cible non trouvée") - continue - - for mc in c.childNodes: - source=None - if mc.name != factsource: - continue - else : - source=mc - break - if source==None : - if debug : print ("Pas de changement pour ", oper, " ", factsource, " ",mocle, "source non trouvée") - continue - - if debug : print ("Changement pour ", oper, " ", factsource, " ",mocle, "cible et source trouvées") - l=source.childNodes[:] - for ll in l: - for n in ll.childNodes: - if n.name != mocle:continue - MonTexte=n.getText(jdc); - inseremocle.insereMotCleDansFacteur(jdc,cible,MonTexte) - 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,plusieursFois=True): -#----------------------------------------------------------------------- -# Attention le cas type est THETA_OLD dans calc_G - - if oper not in jdcSet : return - if debug : print ( "movemocleinoper pour " ,oper,mocle,factcible) - boolChange=9 - commands= jdc.root.childNodes[:] - commands.reverse() - for c in commands: - if c.name != oper : continue - cible=None - for mc in c.childNodes: - if mc.name != factcible : - continue - else : - cible=mc - break - if cible==None : - if debug : print ("Pas de changement pour ", oper, " ", factcible, " ", "cible non trouvée") - continue - - source=None - for mc in c.childNodes: - if mc.name != mocle: - continue - else : - source=mc - break - if source==None : - if debug : print ("Pas de changement pour ", oper, " ", mocle, " source non trouvée") - continue - MonTexte=source.getText(jdc); - boolChange=1 - inseremocle.insereMotCleDansFacteur(jdc,cible,MonTexte,plusieursFois) - if boolChange : jdc.reset(jdc.getSource()) - removemocle.removeMotCle(jdc,oper,mocle) - -#------------------------------------------------------ -def copyMotClefInOperToFact(jdc,oper,mocle,factcible): -#------------------------------------------------------ - - if oper not in jdcSet : return - if debug : print ("movemocleinoper pour " ,oper,mocle,factcible) - boolChange=9 - commands= jdc.root.childNodes[:] - commands.reverse() - for c in commands: - if c.name != oper : continue - cible=None - for mc in c.childNodes: - if mc.name != factcible : - continue - else : - cible=mc - break - if cible==None : - if debug : print ("Pas de changement pour ", oper, " ", factcible, " ", "cible non trouvée") - continue - - source=None - for mc in c.childNodes: - if mc.name != mocle: - continue - else : - source=mc - break - if source==None : - if debug : print ("Pas de changement pour ", oper, " ", mocle, " source non trouvée") - continue - MonTexte=source.getText(jdc); - boolChange=1 - inseremocle.insereMotCleDansFacteur(jdc,cible,MonTexte) - if boolChange : jdc.reset(jdc.getSource()) - -#---------------------------------------------------------------------- -def moveMCFToCommand(jdc,command,factsource,commandcible,factcible): -#---------------------------------------------------------------------- -# exemple CONTACT en 10 -# CONTACT devient commande DEFI_CONTACT/ZONE -# - if command not in jdcSet : return - boolChange=0 - commands= jdc.root.childNodes[:] - commands.reverse() - for c in commands: - if c.name != command : continue - for mcF in c.childNodes: - if mcF.name != factsource : continue - l=mcF.getText(jdc) - texte=l.replace(factsource,factcible) - texte='xxxx='+commandcible+'('+texte+')\n' - jdc.splitLine(c.lineno,0) - jdc.addLine(texte,c.lineno) - logging.info("Deplacement de %s dans %s ligne %s",factsource,commandcible,c.lineno) - boolChange=1 - if boolChange : - jdc.reset(jdc.getSource()) - jdcSet.add(commandcible) - -#----------------------------------------------------- -def fusionMotCleToFact(jdc,command,listeMc,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 listeMc : 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 listeMc : - removemocle.removeMotCle(jdc,command,mc) - jdc.reset(jdc.getSource()) - -#----------------------------------------------------- -def fusionMotCleInFact(jdc,command,fact,listeMc,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 listeMc : 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 listeMc : - removemocle.removeMotCleInFact(jdc,command,fact,mc) - jdc.reset(jdc.getSource()) - -#----------------------------------------------------- -def fusionMCFToMCF(jdc,command,listeMcF,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 listeMcF : 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 listeMcF : - removemocle.removeMotCle(jdc,command,mcF) - jdc.reset(jdc.getSource()) - - - -#-------------------------------------------------------------------- -def eclaMotCleToFact(jdc,command,motcle,mot1,mot2,defaut=0): -#-------------------------------------------------------------------------- -# exemple STA10 pesanteur devient MCF avec eclatement des valeurs dans les MC -# On suppose que le MC est sur une seule ligne - if command not in jdcSet : return - boolChange=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) - indexLigneGlob=mc.lineno-1 - MaLigneGlob=jdc.getLines()[indexLigneGlob] - Ligne=TexteMC.split('(')[1].split(')')[0].split(',') - motcle1=mot1+"="+Ligne[0] - motcle2=mot2+"=("+Ligne[1]+','+Ligne[2]+','+Ligne[3]+')' - texte=motcle+'=_F('+motcle1+','+motcle2+')' - num=lastParen(TexteMC) - Nouveau=MaLigneGlob.replace(TexteMC[0:num],texte) - jdc.getLines()[indexLigneGlob]=Nouveau - logging.info("Transformation de %s dans %s ligne %s",motcle,command,c.lineno) - boolChange=1 - if boolChange : jdc.reset(jdc.getSource()) diff --git a/Traducteur3/parseur.py b/Traducteur3/parseur.py deleted file mode 100644 index 2635b9ab..00000000 --- a/Traducteur3/parseur.py +++ /dev/null @@ -1,280 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright (C) 2007-2017 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 re,string - -debug=0 - -escapedQuotesRE = re.compile(r"(\\\\|\\\"|\\\')") -stringsAndCommentsRE = \ - re.compile("(\"\"\".*?\"\"\"|'''.*?'''|\"[^\"]*\"|\'[^\']*\'|#.*?\n)", re.DOTALL) - -import six -if six.PY2 : - allchars = string.maketrans(u"", "") - allcharsExceptNewline = allchars[: allchars.index('\n')]+allchars[allchars.index('\n')+1:] - allcharsExceptNewlineTranstable = string.maketrans(allcharsExceptNewline, '*'*len(allcharsExceptNewline)) -else : - allchars=bytes.maketrans(b"",b"") - allcharsExceptNewline = allchars[: allchars.index(b'\n')]+allchars[allchars.index(b'\n')+1:] - allcharsExceptNewlineTranstable = bytes.maketrans(allcharsExceptNewline, b'*'*len(allcharsExceptNewline)) - - -#------------------------------ -def maskStringsAndComments(src): -#------------------------------ - """Remplace tous les caracteres dans commentaires et strings par des * """ - - src = escapedQuotesRE.sub("**", src) - allstrings = stringsAndCommentsRE.split(src) - # every odd element is a string or comment - for i in range(1, len(allstrings), 2): - if allstrings[i].startswith("'''")or allstrings[i].startswith('"""'): - allstrings[i] = allstrings[i][:3]+ \ - allstrings[i][3:-3].translate(allcharsExceptNewlineTranstable)+ \ - allstrings[i][-3:] - else: - allstrings[i] = allstrings[i][0]+ \ - allstrings[i][1:-1].translate(allcharsExceptNewlineTranstable)+ \ - allstrings[i][-1] - - return "".join(allstrings) - -#un nombre queconque de blancs,un nom,des blancs -pattern_oper = re.compile(r"^\s*(.*?=\s*)?([a-zA-Z_]\w*)(\s*)(\()(.*)",re.DOTALL) -pattern_proc = re.compile(r"^\s*([a-zA-Z_]\w*)(\s*)(\()(.*)",re.DOTALL) - -implicitContinuationChars = (('(', ')'), ('[', ']'), ('{', '}')) -linecontinueRE = re.compile(r"\\\s*(#.*)?$") -emptyHangingBraces = [0,0,0,0,0] - -#-------------------------------------- -class UnbalancedBracesException: pass -#-------------------------------------- - -#----------- -class Node: -#----------- - def __init__(self): - self.childNodes=[] - - def addChild(self,node): - self.childNodes.append(node) - - -#------------------- -class FactNode(Node): -#------------------- - pass - - -#------------------- -class JDCNode(Node): -#------------------- - def __init__(self,src): - Node.__init__(self) - self.src=src - -#------------------- -class Command(Node): -#------------------- - def __init__(self,name,lineno,colno,firstparen): - Node.__init__(self) - self.name=name - self.lineno=lineno - self.colno=colno - self.firstparen=firstparen - -#------------------- -class Keyword(Node): -#------------------- - def __init__(self,name,lineno,colno,endline,endcol): - Node.__init__(self) - self.name=name - self.lineno=lineno - self.colno=colno - self.endline=endline - self.endcol=endcol - - def getText(self,jdc): - if self.endline > self.lineno: - debut=jdc.getLines()[self.lineno-1][self.colno:] - fin = jdc.getLines()[self.endline-1][:self.endcol] - texte=debut - lignecourante=self.lineno - while lignecourante < self.endline -1 : - texte = texte + jdc.getLines()[lignecourante] - lignecourante = lignecourante + 1 - if chaineBlanche(fin) == 0 : - texte=texte + fin - if texte[-1] == "\n" : - texte=texte[0:-1] - else: - texte = jdc.getLines()[self.lineno-1][self.colno:self.endcol] - return texte - -#------------------------- -def chaineBlanche(texte) : -#------------------------- -# retourne 1 si la chaine est composee de " " -# retourne 0 sinon - bool = 1 ; - for i in range(len(texte)) : - if texte[i] != " " : bool = 0 - return bool - -#------------------- -def printNode(node): -#------------------- - if hasattr(node,'name'): - print (node.name) - else: - print ("pas de nom pour:",node) - for c in node.childNodes: - printNode(c) - -#------------------------ -def parser(src,atraiter): -#------------------------ - """Parse le texte src et retourne un arbre syntaxique (root). - - Cet arbre syntaxique a comme noeuds (childNodes) les commandes a traiter (liste atraiter) - """ - lines=src.splitlines(1) - maskedSrc=maskStringsAndComments(src) - maskedLines=maskedSrc.splitlines(1) - - root=JDCNode(src) - - # (a) dans un premier temps on extrait les commandes et on les insere - # dans un arbre (root) les noeuds fils sont stockes dans - # root.childNodes (liste) - lineno=0 - for line in maskedLines: - lineno=lineno+1 - if debug:print ("line",lineno,":",line) - m=pattern_proc.match(line) - if m and (m.group(1) in atraiter): - if debug:print (m.start(3),m.end(3),m.start(4)) - root.addChild(Command(m.group(1),lineno,m.start(1),m.end(3))) - else: - m=pattern_oper.match(line) - if m and (m.group(2) in atraiter): - root.addChild(Command(m.group(2),lineno,m.start(2),m.end(4))) - - #(b) dans un deuxieme temps , on recupere le texte complet de la commande - # jusqu'a la derniere parenthese fermante - - # iterateur sur les lignes physiques masquees - iterlines=iter(maskedLines) - - linenum=0 - for c in root.childNodes: - lineno=c.lineno - colno=c.colno # debut de la commande - while linenum < lineno: - line=iterlines.__next__() - linenum=linenum+1 - if linenum != lineno: - if debug:print ("line %s:"%linenum, line) - tmp = [] - hangingBraces = list(emptyHangingBraces) - hangingComments = 0 - while 1: - # update hanging braces - for i in range(len(implicitContinuationChars)): - contchar = implicitContinuationChars[i] - numHanging = hangingBraces[i] - - hangingBraces[i] = numHanging+line.count(contchar[0]) - \ - line.count(contchar[1]) - - hangingComments ^= line.count('"""') % 2 - hangingComments ^= line.count("'''") % 2 - - if hangingBraces[0] < 0 or hangingBraces[1] < 0 or hangingBraces[2] < 0: - raise UnbalancedBracesException() - - if linecontinueRE.search(line): - tmp.append(lines[linenum-1]) - elif hangingBraces != emptyHangingBraces: - tmp.append(lines[linenum-1]) - elif hangingComments: - tmp.append(lines[linenum-1]) - else: - tmp.append(lines[linenum-1]) - src="".join(tmp) - c.src=src - c.endline=linenum - decal=len(line)-line.rindex(')') - c.lastParen=len(src)-decal - if debug:print ("logical line %s %s:" % (c.lineno,c.endline),src) - break - line=iterlines.__next__() - linenum=linenum+1 - - return root - - -#----------------- -def lastParen(src): -#----------------- - """Retourne la position de la derniere parenthese fermante dans src a partir du debut de la string - - La string doit contenir la premiere parenthese ouvrante - """ - - src=maskStringsAndComments(src) - level=0 - i,n=0,len(src) - while i < n: - ch=src[i] - i=i+1 - if ch in ('(','['): - level=level+1 - if ch in (')',']'): - if level == 0: - raise UnbalancedBracesException() - level=level-1 - if level == 0: - #derniere parenthese fermante - return i - -#------------------- -def lastParen2(src): -#------------------- - """Retourne la position de la derniere parenthese fermante dans src a partir du debut de la string - - La string ne contient pas la premiere parenthese ouvrante - """ - src=maskStringsAndComments(src) - level=1 - i,n=0,len(src) - while i < n: - ch=src[i] - i=i+1 - if ch in ('(','['): - level=level+1 - if ch in (')',']'): - if level == 0: - raise UnbalancedBracesException() - level=level-1 - if level == 0: - #derniere parenthese fermante - return i diff --git a/Traducteur3/regles.py b/Traducteur3/regles.py deleted file mode 100644 index a8f78215..00000000 --- a/Traducteur3/regles.py +++ /dev/null @@ -1,524 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright (C) 2007-2017 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 -# -""" -Définition des règles -""" - -debug = 0 - -#-------------------- -class ensembleRegles : -#-------------------- - """ - Ensemble des règles - """ - def __init__(self, liste_regles): - self.liste = [] - for item in liste_regles : - args, clefRegle = item - r = regle(clefRegle, args) - self.liste.append(r) - - def verif(self, commande) : - """ - Vérification - """ - bool = 1 - for regle in self.liste : - result = regle.verif(commande) - bool = bool*result - return bool - -#-------------------------------- -class pasDeRegle(ensembleRegles): -#-------------------------------- - """ - Pas de règle - """ - def __init__(self) : - pass - - def verif (self, commande) : - """ - Vérification - """ - return 1 - - -#------------ -class regle : -#------------ - """ - Règle - """ - def __init__(self, clef_regle, args): - self.fonction = dictionnaire_regle[clef_regle] - self.list_args = args - self.bool = 0 - - def verif(self, commande): - """ - Vérification - """ - f = self.fonction(self.list_args) - return f.verif(commande) - -#--------------------- -class existeMCFParmi : -#--------------------- - """ - Existence du mot-clé facteur parmi la liste - """ - def __init__(self, list_arg): - self.listeMCF = list_arg - - def verif(self, commande) : - """ - Vérification - """ - bool = 0 - for c in commande.childNodes : - if c.name in self.listeMCF : - bool = 1 - break - return bool - -#--------------------- -class nexistepasMCFParmi(existeMCFParmi) : -#--------------------- - """ - Existence du mot-clé facteur parmi la liste - """ - def __init__(self, list_arg): - self.listeMCF = list_arg - - def verif(self, commande) : - """ - Vérification - """ - bool = existeMCFParmi.verif(self, commande) - if bool : return 0 - return 1 - -#---------------------- -class existeMCsousMCF : -#---------------------- - """ - Existence du mot-clé simple sous le mot-clé facteur - """ - def __init__(self, list_arg): - self.liste = list_arg - self.MCF = self.liste[0] - self.MC = self.liste[1] - - def verif(self, commande): - """ - Vérification - """ - bool = 0 - for mcf in commande.childNodes : - if mcf.name != self.MCF : continue - l = mcf.childNodes[:] - l.reverse() - for ll in l: - for mc in ll.childNodes: - if mc.name != self.MC : continue - bool = 1 - return bool - -#---------------------- -class existeMCsousMCFcourant : -#---------------------- - """ - Existence du mot-clé simple sous le mot-clé facteur courant - """ - def __init__(self, list_arg): - self.liste = list_arg - self.MC = self.liste[0] - - def verif(self, mcf): - """ - Vérification - """ - bool = 0 - l = mcf.childNodes[:] - l.reverse() - for mc in l: - if mc.name != self.MC : continue - bool = 1 - return bool - -#----------------------------------------- -class nexistepasMCsousMCF(existeMCsousMCF): -#----------------------------------------- - """ - Absence du mot-clé simple sous le mot-clé facteur - """ - def __init__(self, list_arg): - existeMCsousMCF.__init__(self, list_arg) - - - def verif(self, commande): - """ - Vérification - """ - bool = existeMCsousMCF.verif(self, commande) - if bool : return 0 - return 1 - -#----------------------------------------- -class nexistepasMCsousMCFcourant(existeMCsousMCFcourant): -#----------------------------------------- - """ - Absence du mot-clé simple sous le mot-clé facteur courant - """ - def __init__(self, list_arg): - existeMCsousMCFcourant.__init__(self, list_arg) - - - def verif(self, commande): - """ - Vérification - """ - bool = existeMCsousMCFcourant.verif(self, commande) - if bool : return 0 - return 1 - -#------------- -class existe : -#-------------- - """ - Existence du mot-clé simple - """ - def __init__(self, list_arg): - self.genea = list_arg - - def chercheMot(self, niveau, commande): - """ - Recherche du mot - """ - if commande == None : return 0 - if niveau == len(self.genea) : return 1 - texte = self.genea[niveau] - for c in commande.childNodes : - if c.name == texte : - niveau = niveau+1 - return self.chercheMot(niveau, c) - return None - - def verif(self, commande): - """ - Vérification - """ - bool = self.chercheMot(0, commande) - if bool == None : bool = 0 - return bool - -#------------- -class nexistepas : -#-------------- - """ - Absence du mot-clé simple - """ - def __init__(self, list_arg): - self.genea = list_arg - - def chercheMot(self, niveau, commande): - """ - Recherche du mot - """ - if commande == None : return 0 - if niveau == len(self.genea) : return 1 - texte = self.genea[niveau] - for c in commande.childNodes : - if c.name == texte : - niveau = niveau+1 - return self.chercheMot(niveau, c) - return None - - def verif(self, commande): - """ - Vérification - """ - bool = self.chercheMot(0, commande) - if bool : return 0 - return 1 - -#------------------------------- -class MCsousMCFaPourValeur : -#------------------------------ - """ - Égalité du mot-clé simple à une valeur sous le mot-clé facteur - """ - def __init__(self, list_arg): - assert (len(list_arg)==4) - self.genea = list_arg[0:-2] - self.MCF = list_arg[0] - self.MC = list_arg[1] - self.Val = list_arg[2] - self.Jdc = list_arg[3] - - def verif(self, commande): - """ - Vérification - """ - bool = 0 - for mcf in commande.childNodes : - if mcf.name != self.MCF : continue - l = mcf.childNodes[:] - l.reverse() - for ll in l: - for mc in ll.childNodes: - if mc.name != self.MC : continue - TexteMC = mc.getText(self.Jdc) - if (TexteMC.find(self.Val) < 0 ): continue - bool = 1 - return bool - -#------------------------------- -class MCsousMCFcourantaPourValeur : -#------------------------------ - """ - Égalité du mot-clé simple à une valeur sous le mot-clé facteur courant - """ - def __init__(self, list_arg): - assert (len(list_arg)==3) - self.genea = list_arg[0:-1] - self.MC = list_arg[0] - self.Val = list_arg[1] - self.Jdc = list_arg[2] - - def verif(self, mcf): - """ - Vérification - """ - bool = 0 - l = mcf.childNodes[:] - l.reverse() - for mc in l: - if mc.name != self.MC : continue - TexteMC = mc.getText(self.Jdc) - if (TexteMC.find(self.Val) < 0 ): continue - bool = 1 - return bool - - -#----------------------------- -class MCsousMCFaPourValeurDansListe : -#---------------------------- - """ - Égalité du mot-clé simple à une valeur dans une liste - sous le mot-clé facteur - """ - def __init__(self, list_arg): - assert (len(list_arg)==4) - self.genea = list_arg[0:-2] - self.MCF = list_arg[0] - self.MC = list_arg[1] - self.LVal = list_arg[2] - self.Jdc = list_arg[3] - - def verif(self, commande): - """ - Vérification - """ - bool = 0 - for mcf in commande.childNodes : - if mcf.name != self.MCF : continue - l = mcf.childNodes[:] - l.reverse() - for ll in l: - for mc in ll.childNodes: - if mc.name != self.MC : continue - TexteMC = mc.getText(self.Jdc) - for Val in self.LVal: - if (TexteMC.find(Val) < 0 ): continue - bool = 1 - return bool - -#----------------------------- -class MCsousMCFcourantaPourValeurDansListe : -#---------------------------- - """ - Égalité du mot-clé simple à une valeur dans une liste - sous le mot-clé facteur - """ - def __init__(self, list_arg): - assert (len(list_arg)==3) - self.genea = list_arg[0:-1] - self.MC = list_arg[0] - self.LVal = list_arg[1] - self.Jdc = list_arg[2] - - def verif(self, mcf): - """ - Vérification - """ - bool = 0 - l = mcf.childNodes[:] - l.reverse() - for mc in l: - if mc.name != self.MC : continue - TexteMC = mc.getText(self.Jdc) - for Val in self.LVal: - if (TexteMC.find(Val) < 0 ): continue - bool = 1 - return bool - -#----------------------------------------- -class MCsousMCFcourantnaPasPourValeurDansListe(MCsousMCFcourantaPourValeurDansListe) : -#----------------------------------------- - """ - Non égalité du mot-clé simple à une valeur dans une liste - sous le mot-clé facteur - """ - def __init__(self, list_arg): - MCsousMCFcourantaPourValeurDansListe.__init__(self, list_arg) - - - def verif(self, commande): - bool = MCsousMCFcourantaPourValeurDansListe.verif(self, commande) - if bool : return 0 - return 1 - -#----------------------------------------- -class MCsousMCFnaPasPourValeurDansListe(MCsousMCFaPourValeurDansListe) : -#----------------------------------------- - """ - Non égalité du mot-clé simple à une valeur dans une liste - sous le mot-clé facteur - """ - def __init__(self, list_arg): - MCsousMCFaPourValeurDansListe.__init__(self, list_arg) - - - def verif(self, commande): - bool = MCsousMCFaPourValeurDansListe.verif(self, commande) - if bool : return 0 - return 1 - -#------------------------------ -class MCaPourValeur : -#------------------------------ - """ - Égalité du mot-clé à une valeur - """ - def __init__(self, list_arg): - assert (len(list_arg)==3) - self.MC = list_arg[0] - self.Val = list_arg[1] - self.Jdc = list_arg[2] - - def verif(self, commande): - """ - Vérification - """ - bool = 0 - for mc in commande.childNodes : - if mc.name != self.MC : continue - TexteMC = mc.getText(self.Jdc) - if (TexteMC.find(self.Val) < 0 ): continue - bool = 1 - return bool - -#----------------------------------------- -class MCnaPasPourValeur(MCaPourValeur) : -#----------------------------------------- - """ - Non égalité du mot-clé à une valeur - """ - def __init__(self, list_arg): - MCaPourValeur.__init__(self, list_arg) - - def verif(self, commande): - """ - Vérification - """ - bool = MCaPourValeur.verif(self, commande) - if bool : return 0 - return 1 - -#------------------------------ -class MCaPourValeurDansListe : -#------------------------------ - """ - Égalité du mot-clé à une valeur dans une liste - """ - def __init__(self, list_arg): - assert (len(list_arg)==3) - self.MC = list_arg[0] - self.LVal = list_arg[1] - self.Jdc = list_arg[2] - - def verif(self, commande): - """ - Vérification - """ - bool = 0 - for mc in commande.childNodes : - if mc.name != self.MC : continue - TexteMC = mc.getText(self.Jdc) - #print "TexteMC=",type(TexteMC),TexteMC - #print "LVal=",type(self.LVal),self.LVal - for Val in self.LVal: - #print "Val=",type(Val),Val - #print "Find",TexteMC.find(Val) - if (TexteMC.find(Val) < 0 ): continue - bool = 1 - return bool - -#----------------------------------------- -class MCnaPasPourValeurDansListe(MCaPourValeurDansListe) : -#----------------------------------------- - """ - Non égalité du mot-clé à une valeur dans une liste - """ - def __init__(self, list_arg): - MCaPourValeurDansListe.__init__(self, list_arg) - - def verif(self, commande): - """ - Vérification - """ - bool = MCaPourValeurDansListe.verif(self, commande) - if bool : return 0 - return 1 - -dictionnaire_regle = {"existe":existe, - "nexistepas":nexistepas, - "existeMCFParmi":existeMCFParmi, - "nexistepasMCFParmi":nexistepasMCFParmi, - "existeMCsousMCF":existeMCsousMCF, - "nexistepasMCsousMCF":nexistepasMCsousMCF, - "MCsousMCFaPourValeur":MCsousMCFaPourValeur, - "MCsousMCFaPourValeurDansListe":MCsousMCFaPourValeurDansListe, - "MCaPourValeur":MCaPourValeur, - "MCnaPasPourValeur":MCnaPasPourValeur, - "existeMCsousMCFcourant":existeMCsousMCFcourant, - "nexistepasMCsousMCFcourant":nexistepasMCsousMCFcourant, - "MCsousMCFcourantaPourValeur":MCsousMCFcourantaPourValeur, - "MCsousMCFcourantaPourValeurDansListe":MCsousMCFcourantaPourValeurDansListe, - "MCsousMCFcourantnaPasPourValeurDansListe":MCsousMCFcourantnaPasPourValeurDansListe, - "MCsousMCFnaPasPourValeurDansListe":MCsousMCFnaPasPourValeurDansListe, - "MCaPourValeurDansListe":MCaPourValeurDansListe, - "MCnaPasPourValeurDansListe":MCnaPasPourValeurDansListe} - - -SansRegle = pasDeRegle() diff --git a/Traducteur3/removemocle.py b/Traducteur3/removemocle.py deleted file mode 100644 index ee1eab7a..00000000 --- a/Traducteur3/removemocle.py +++ /dev/null @@ -1,215 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright (C) 2007-2017 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 -from Traducteur import regles -from Traducteur.parseur import FactNode -from Traducteur.dictErreurs import ecritErreur -from Traducteur.load import jdcSet - -debug=0 -#debug=1 -#on n'a qu'un mocle par commande. On peut donc supprimer le mocle sans trop de precautions (a part iterer a l'envers sur les commandes) -#avant de supprimer un autre mocle, on remet a jour l'arbre syntaxique (lineno,colno,etc.) - - -#----------------------------------------------------------------------- -def removeMotCle(jdc,command,mocle,ensemble=regles.SansRegle,erreur = 0): -#----------------------------------------------------------------------- - #on itere sur les commandes a l'envers pour ne pas polluer les numeros de ligne avec les modifications - if command not in jdcSet : return - boolChange=0 - commands= jdc.root.childNodes[:] - commands.reverse() - for c in commands: - if c.name != command:continue - for mc in c.childNodes: - if mc.name != mocle:continue - if ensemble.verif(c) == 0 : continue - if erreur : ecritErreur((command,mocle),c.lineno) - boolChange=1 - removeMC(jdc,c,mc) - - if boolChange : jdc.reset(jdc.getSource()) - -#------------------------------------------------------- -def removeMotCleSiRegle(jdc,command,mocle,liste_regles) : -#------------------------------------------------------- - if command not in jdcSet : return - mesRegles=regles.ensembleRegles(liste_regles) - removeMotCle(jdc,command,mocle,mesRegles,erreur=0) - -#---------------------------------------------------------------- -def removeMotCleSiRegleAvecErreur(jdc,command,mocle,liste_regles) : -#-------------------------------------------------------------- - if command not in jdcSet : return - mesRegles=regles.ensembleRegles(liste_regles) - removeMotCle(jdc,command,mocle,mesRegles,erreur=1) - -#---------------------------------------------------------------- -def removeMotCleAvecErreur(jdc,command,mocle) : -#-------------------------------------------------------------- - if command not in jdcSet : return - removeMotCle(jdc,command,mocle,erreur=1) - - -#-------------------------------------------------------------------- -def removeCommande(jdc,command,ensemble=regles.SansRegle,erreur=0): -#-------------------------------------------------------------------- - if command not in jdcSet : return - boolChange=0 - commands= jdc.root.childNodes[:] - commands.reverse() - for c in commands: - if c.name != command:continue - if ensemble.verif(c) == 0 : continue - boolChange=1 - if erreur : ecritErreur((command,),c.lineno) - jdc.supLignes(c.lineno,c.endline) - logging.warning("Suppression de %s ligne %s",c.name,c.lineno) - if boolChange : jdc.reset(jdc.getSource()) - -#------------------------------------------------------------- -def removeCommandeSiRegle(jdc,command,liste_regles): -#------------------------------------------------------------- - if command not in jdcSet : return - mesRegles=regles.ensembleRegles(liste_regles) - removeCommande(jdc,command,mesRegles,0) - -#------------------------------------------------------------- -def removeCommandeSiRegleAvecErreur(jdc,command,liste_regles): -#------------------------------------------------------------- - if command not in jdcSet : return - mesRegles=regles.ensembleRegles(liste_regles) - removeCommande(jdc,command,mesRegles,1) - -#--------------------------------- -def removeMC(jdc,c,mc): -#--------------------------------- - if debug : print ("Suppression de:",c.name,mc.name,mc.lineno,mc.colno,mc.endline,mc.endcol) - logging.info("Suppression de %s dans %s ligne %d",mc.name,c.name,mc.lineno) - - if mc.endline > mc.lineno: - if debug: print ("mocle sur plusieurs lignes--%s--" % jdc.getLines()[mc.lineno-1][mc.colno:]) - jdc.getLines()[mc.lineno-1]=jdc.getLines()[mc.lineno-1][:mc.colno] - jdc.getLines()[mc.endline-1]=jdc.getLines()[mc.endline-1][mc.endcol:] - - #attention : supprimer les lignes a la fin - jdc.getLines()[mc.lineno:mc.endline-1]=[] - else: - if debug: print( "mocle sur une ligne--%s--" % jdc.getLines()[mc.lineno-1][mc.colno:mc.endcol]) - s=jdc.getLines()[mc.lineno-1] - jdc.getLines()[mc.lineno-1]=s[:mc.colno]+s[mc.endcol:] - fusionne(jdc,mc.lineno-1) - -#--------------------------------------------------------------------------------- -def removeMotCleInFact(jdc,command,fact,mocle,ensemble=regles.SansRegle,erreur=0): -#---------------------------------------------------------------------------------- - # on itere sur les commandes a l'envers pour ne pas polluer - # les numeros de ligne avec les modifications - if command not in jdcSet : return - commands= jdc.root.childNodes[:] - commands.reverse() - boolChange=0 - for c in commands: - if c.name != command:continue - for mc in c.childNodes: - if mc.name != fact:continue - l=mc.childNodes[:] - l.reverse() - for ll in l: - for n in ll.childNodes: - if n.name != mocle:continue - if ensemble.verif(c) == 0 : continue - if erreur : ecritErreur((command,fact,mocle),c.lineno) - boolChange=1 - removeMC(jdc,c,n) - - if boolChange : jdc.reset(jdc.getSource()) - -#------------------------------------------------------------------ -def removeMotCleInFactSiRegle(jdc,command,fact,mocle,liste_regles): -#------------------------------------------------------------------ - if command not in jdcSet : return - erreur=0 - mesRegles=regles.ensembleRegles(liste_regles) - removeMotCleInFact(jdc,command,fact,mocle,mesRegles,erreur) - -#---------------------------------------------------------------------- -def removeMotCleInFactSiRegleAvecErreur(jdc,command,fact,mocle,liste_regles): -#---------------------------------------------------------------------- - if command not in jdcSet : return - erreur=1 - mesRegles=regles.ensembleRegles(liste_regles) - removeMotCleInFact(jdc,command,fact,mocle,mesRegles,erreur) - - -#---------------------------------------------------------------------- -def removeMotCleInFactCourantSiRegle(jdc,command,fact,mocle,liste_regles,erreur=0): -#---------------------------------------------------------------------- - if command not in jdcSet : return - ensemble=regles.ensembleRegles(liste_regles) - commands= jdc.root.childNodes[:] - commands.reverse() - boolChange=0 - for c in commands: - if c.name != command:continue - for mc in c.childNodes: - if mc.name != fact:continue - l=mc.childNodes[:] - l.reverse() - for ll in l: - if ensemble.verif(ll) == 0 : continue - for n in ll.childNodes: - if n.name != mocle:continue - if erreur : ecritErreur((command,fact,mocle),c.lineno) - boolChange=1 - removeMC(jdc,c,n) - - if boolChange : jdc.reset(jdc.getSource()) - -#------------------------------------------ -def fusionne(jdc,numLigne): -#------------------------------------------ -# fusionne la ligne numLigne et numLigne+1 -# si la ligne numLigne+1 ne contient que des parentheses -# fermantes -# et si la ligne numLigne ne contient pas par un "#" -# Attention a la difference de numerotation -# jdc.getLines()[numLigne] donne la ligne numLigne + 1 -# alors que joinLineandNext(numLigne) travaille sur le tableau - index=0 - texte=jdc.getLines()[numLigne] - fusion=1 - while (index < len(texte)) : - if texte[index] not in (" ",",",")",";","\n") : - fusion=0 - break - index=index+1 - - if fusion == 0 : return; - - texte=jdc.getLines()[numLigne -1] - if texte.find("#") < 0 : - fusion=1 - else : - fusion=0 - - if fusion : - jdc.joinLineandNext(numLigne) diff --git a/Traducteur3/renamemocle.py b/Traducteur3/renamemocle.py deleted file mode 100644 index e246abf2..00000000 --- a/Traducteur3/renamemocle.py +++ /dev/null @@ -1,188 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright (C) 2007-2017 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 sys -from Traducteur.parseur import FactNode -from Traducteur.load import jdcSet -from Traducteur import regles -from Traducteur.dictErreurs import ecritErreur -#debug=1 -debug=0 - -#on n'a qu'un mocle par commande. -#en fin de traitement, on remet a jour l'arbre syntaxique (lineno,colno,etc.) - -#-------------------------------------------------------------------------------- -def renameMotCle(jdc,command,mocle,new_name, erreur=0,ensemble=regles.SansRegle): -#-------------------------------------------------------------------------------- - if command not in jdcSet : return - boolChange=0 - for c in jdc.root.childNodes: - if c.name != command:continue - for mc in c.childNodes: - if mc.name != mocle:continue - if ensemble.verif(c) == 0 : continue - boolChange=1 - if debug: print ("Renommage de:",c.name,mc.name,mc.lineno,mc.colno) - if erreur : - ecritErreur((command,mocle),c.lineno) - else : - logging.info("Renommage de: %s %s ligne %d en %s",c.name,mc.name,mc.lineno,new_name) - s=jdc.getLines()[mc.lineno-1] - jdc.getLines()[mc.lineno-1]=s[:mc.colno]+new_name+s[mc.colno+len(mocle):] - diff=len(new_name) - len(mocle) - decaleLignesdeNBlancs(jdc,mc.lineno,mc.endline-1,diff) - - if boolChange : jdc.reset(jdc.getSource()) - -#------------------------------------------------------ -def renameMotCleAvecErreur(jdc,command,mocle,new_name): -#------------------------------------------------------ - if command not in jdcSet : return - renameMotCle(jdc,command,mocle,new_name,1,regles.SansRegle) - -#-------------------------------------------------------------------------- -def renameMotCleSiRegle(jdc,command,mocle,new_name,liste_regles, erreur=0): -#-------------------------------------------------------------------------- - if command not in jdcSet : return - mesRegles=regles.ensembleRegles(liste_regles) - renameMotCle(jdc,command,mocle,new_name, erreur,mesRegles) - -#------------------------------------------- -def renameOper(jdc,command,new_name): -#------------------------------------------- - if command not in jdcSet : return - jdcSet.add(new_name) - boolChange=0 - for c in jdc.root.childNodes: - if c.name != command:continue - if debug: print ("Renommage de:",c.name,c.lineno,c.colno) - logging.info("Renommage de: %s ligne %d en %s",c.name,c.lineno,new_name) - boolChange=1 - s=jdc.getLines()[c.lineno-1] - jdc.getLines()[c.lineno-1]=s[:c.colno]+new_name+s[c.colno+len(command):] - diff=len(new_name) - len(command) - decaleLignesdeNBlancs(jdc,c.lineno,c.endline,diff) - if boolChange : jdc.reset(jdc.getSource()) - -#---------------------------------------------------------- -def decaleLignesdeNBlancs(jdc,premiere,derniere,nbBlanc): -#---------------------------------------------------------- - ligne = premiere + 1 - while ligne < derniere : - s=jdc.getLines()[ligne] - if nbBlanc > 0 : - jdc.getLines()[ligne] = nbBlanc*" " + s - else : - toutblancs=-1*nbBlanc*" " - if jdc.getLines()[ligne][0:-1*nbBlanc] == toutblancs: - jdc.getLines()[ligne] = s[-1*nbBlanc:] - ligne=ligne+1 - -#--------------------------------------------------------------------------------------------- -def renameMotCleInFact(jdc,command,fact,mocle,new_name, ensemble=regles.SansRegle, erreur=0): -#--------------------------------------------------------------------------------------------- - if command not in jdcSet : return - boolChange=0 - for c in jdc.root.childNodes: - if c.name != command:continue - for mc in c.childNodes: - if mc.name != fact:continue - l=mc.childNodes[:] - #on itere a l'envers - l.reverse() - for ll in l: - for n in ll.childNodes: - if n.name != mocle:continue - if ensemble.verif(c) == 0 : continue - s=jdc.getLines()[n.lineno-1] - jdc.getLines()[n.lineno-1]=s[:n.colno]+new_name+s[n.colno+len(mocle):] - boolChange=1 - if erreur : - ecritErreur((command,fact,mocle),c.lineno) - else : - logging.info("Renommage de: %s, ligne %s, en %s",n.name,n.lineno,new_name) - - if boolChange : jdc.reset(jdc.getSource()) - -#-------------------------------------------------------------------------- -def renameMotCleInFactSiRegle(jdc,command,fact,mocle,new_name,liste_regles): -#-------------------------------------------------------------------------- - if command not in jdcSet : return - mesRegles=regles.ensembleRegles(liste_regles) - renameMotCleInFact(jdc,command,fact,mocle,new_name,mesRegles) - -def renameMotCleInFactCourantSiRegle(jdc,command,fact,mocle,new_name,liste_regles,erreur=0): -#-------------------------------------------------------------------------- - if command not in jdcSet : return - ensemble=regles.ensembleRegles(liste_regles) - boolChange=0 - for c in jdc.root.childNodes: - if c.name != command:continue - for mc in c.childNodes: - if mc.name != fact:continue - l=mc.childNodes[:] - #on itere a l'envers - l.reverse() - for ll in l: - if ensemble.verif(ll) == 0 : continue - for n in ll.childNodes: - 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):] - boolChange=1 - if erreur : - ecritErreur((command,fact,mocle),c.lineno) - else : - logging.info("Renommage de: %s, ligne %s, en %s",n.name,n.lineno,new_name) - - if boolChange : jdc.reset(jdc.getSource()) - - -#----------------------------------------------------------------- -def renameCommande(jdc,command,new_name,ensemble=regles.SansRegle): -#----------------------------------------------------------------- -# nom de la commande "ancien format" , nom de la commande " nouveau format " - if command not in jdcSet : return - jdcSet.add(new_name) - boolChange=0 - if debug : - 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) - for c in jdc.root.childNodes: - if c.name != command:continue - if ensemble.verif(c) == 0 : continue - boolChange=1 - if debug: print ("Renommage de:",c.name,new_name ,c.lineno,c.colno) - logging.info("Renommage de: %s ligne %d en %s",c.name,c.lineno,new_name) - s=jdc.getLines()[c.lineno-1] - jdc.getLines()[c.lineno-1]=s[:c.colno]+new_name+s[c.colno+len(command):] - - if boolChange : jdc.reset(jdc.getSource()) - -#----------------------------------------------------------- -def renameCommandeSiRegle(jdc,command,new_name,liste_regles): -#----------------------------------------------------------- - - if command not in jdcSet : return - mesRegles=regles.ensembleRegles(liste_regles) - renameCommande(jdc,command,new_name,mesRegles) diff --git a/Traducteur3/toto.comm b/Traducteur3/toto.comm deleted file mode 100755 index 0701e84e..00000000 --- a/Traducteur3/toto.comm +++ /dev/null @@ -1,161 +0,0 @@ -# - -REF=Assembly(assembly_type='REF',); - - -U1=Assembly(assembly_type='UOX', - assembly_width=0.21504, - fuel_density=0.95, - radial_description=_F(clad_outer_radius=0.00475, - guide_tube_outer_radius=0.006025, - fuel_rod_pitch=0.0126, - nfuel_rods=264,), - axial_description=_F(active_length_start=0.21, - active_length_end=4.4772,), - grids=_F(mixing=_F(positions=(0.69216,1.19766,1.70316,2.20866,2.71416,3.20416,3.69416,4.18416,), - size=0.033,), - non_mixing=_F(positions=(0.026,4.2412,), - size=0.033,),),); - -UGD=Assembly(assembly_type='UOX', - assembly_width=0.21504, - fuel_density=0.95, - radial_description=_F(clad_outer_radius=0.00475, - guide_tube_outer_radius=0.006025, - fuel_rod_pitch=0.0126, - nfuel_rods=264,), - axial_description=_F(active_length_start=0.21, - active_length_end=4.4772,), - grids=_F(mixing=_F(positions=(0.69216,1.19766,1.70316,2.20866,2.71416,3.20416,3.69416,4.18416,), - size=0.033,), - non_mixing=_F(positions=(0.026,), - size=0.033,),),); - -RB=RodBank(rod_type='heterogeneous', - bottom_composition='AIC', - splitting_heigh=1.4224, - upper_composition='B4C', - step_height=0.016, - nsteps=260,); - -N1=RodBank(rod_type='heterogeneous', - bottom_composition='AIC', - splitting_heigh=1.4224, - upper_composition='B4C', - step_height=0.016, - nsteps=260,); - -N2=RodBank(rod_type='heterogeneous', - bottom_composition='AIC', - splitting_heigh=1.4226, - upper_composition='B4C', - step_height=0.016, - nsteps=260,); - -G1=RodBank(rod_type='homogeneous', - rod_composition='Grey', - step_height=0.016, - nsteps=260,); - -G2=RodBank(rod_type='homogeneous', - rod_composition='Grey', - step_height=0.016, - nsteps=260,); - -techno_data=Techno_data(assembly_list=(REF,U1,UGD,), - rodbank_list=(RB,G1,G2,N1,N2,), - radial_description=_F(nb_assembly=15, - xaxis=('RW','S','R','P','N','L','K','J','H','G','F','E','D','C','B','A','RE',), - yaxis= - ('RS','15','14','13','12','11', - '10','09','08','07','06','05','04','03','02','01','RN',), - assembly_map=((REF,REF,REF,REF,REF,REF,REF,REF,REF,REF,REF,REF,REF,REF,REF,REF,REF,),(REF,REF,REF,REF,REF,U1,U1,U1,U1,U1,U1,U1,REF,REF,REF,REF,REF,),(REF,REF,REF,UGD,U1,UGD,UGD,U1,U1,U1,UGD,UGD,U1,UGD,REF,REF,REF,),(REF,REF,UGD,U1,U1,U1,U1,UGD,U1,UGD,U1,U1,U1,U1,UGD,REF,REF,),(REF,REF,U1,U1,U1,UGD,U1,UGD,U1,UGD,U1,UGD,U1,U1,U1,REF,REF,),(REF,U1,UGD,U1,UGD,U1,U1,UGD,U1,UGD,U1,U1,UGD,U1,UGD,U1,REF,),(REF,U1,UGD,U1,U1,U1,UGD,UGD,U1,UGD,UGD,U1,U1,U1,UGD,U1,REF,),(REF,U1,U1,UGD,UGD,UGD,UGD,U1,UGD,U1,UGD,UGD,UGD,UGD,U1,U1,REF,),(REF,U1,U1,U1,U1,U1,U1,UGD,UGD,UGD,U1,U1,U1,U1,U1,U1,REF,),(REF,U1,U1,UGD,UGD,UGD,UGD,U1,UGD,U1,UGD,UGD,UGD,UGD,U1,U1,REF,),(REF,U1,UGD,U1,U1,U1,UGD,UGD,U1,UGD,UGD,U1,U1,U1,UGD,U1,REF,),(REF,U1,UGD,U1,UGD,U1,U1,UGD,U1,UGD,U1,U1,UGD,U1,UGD,U1,REF,),(REF,REF,U1,U1,U1,UGD,U1,UGD,U1,UGD,U1,UGD,U1,U1,U1,REF,REF,),(REF,REF,UGD,U1,U1,U1,U1,UGD,U1,UGD,U1,U1,U1,U1,UGD,REF,REF,),(REF,REF,REF,UGD,U1,UGD,UGD,U1,U1,U1,UGD,UGD,U1,UGD,REF,REF,REF,),(REF,REF,REF,REF,REF,U1,U1,U1,U1,U1,U1,U1,REF,REF,REF,REF,REF,),(REF,REF,REF,REF,REF,REF,REF,REF,REF,REF,REF,REF,REF,REF,REF,REF,REF,),), - rod_map= - (['#','#','#','#','#','#','#', - '#','#','#','#','#','#','#','#','#','#'],['#','#','#','#','#','.', - '.','.','.','.','.','.','#','#','#','#','#'],['#','#','#','.','.', - '.','.','.','RB','.','.','.','.','.','#','#','#'],['#','#','.','.', - '.','G2','.','N2','.','N2','.','G2','.','.','.','#','#'],['#','#', - '.','.','N1','.','.','.','G1','.','.','.','N1','.','.','#','#'], - ['#','.','.','G2','.','RB','.','.','.','.','.','RB','.','G2','.', - '.','#'],['#','.','.','.','.','.','.','.','N1','.','.','.','.','.', - '.','.','#'],['#','.','.','N2','.','.','.','.','.','.','.','.','.', - 'N2','.','.','#'],['#','.','RB','.','G1','.','N1','.','RB','.','N1', - '.','G1','.','RB','.','#'],['#','.','.','N2','.','.','.','.','.', - '.','.','.','.','N2','.','.','#'],['#','.','.','.','.','.','.','.', - 'N1','.','.','.','.','.','.','.','#'],['#','.','.','G2','.','RB', - '.','.','.','.','.','RB','.','G2','.','.','#'],['#','#','.','.', - 'N1','.','.','.','G1','.','.','.','N1','.','.','#','#'],['#','#', - '.','.','.','G2','.','N2','.','N2','.','G2','.','.','.','#','#'], - ['#','#','#','.','.','.','.','.','RB','.','.','.','.','.','#','#', - '#'],['#','#','#','#','#','.','.','.','.','.','.','.','#','#','#', - '#','#'],['#','#','#','#','#','#','#','#','#','#','#','#','#','#', - '#','#','#'],), - BU_map= - ([0.0,0.0,0.0,0.0,0.0,0.0,0.0, - 0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],[0.0,0.0,0.0,0.0,0.0,0.0,0.0, - 0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],[0.0,0.0,0.0,40.0,0.0,0.0, - 40.0,40.0,20.0,40.0,40.0,0.0,0.0,40.0,0.0,0.0,0.0],[0.0,0.0,40.0,0.0, - 40.0,20.0,40.0,0.0,40.0,0.0,40.0,20.0,40.0,0.0,40.0,0.0,0.0],[0.0,0.0, - 0.0,40.0,20.0,20.0,20.0,40.0,20.0,40.0,20.0,20.0,20.0,40.0,0.0,0.0, - 0.0],[0.0,0.0,0.0,20.0,20.0,20.0,40.0,0.0,40.0,0.0,40.0,20.0,20.0, - 20.0,0.0,0.0,0.0],[0.0,0.0,40.0,40.0,20.0,40.0,20.0,40.0,20.0,40.0, - 20.0,40.0,20.0,40.0,40.0,0.0,0.0],[0.0,0.0,40.0,0.0,40.0,0.0,40.0, - 20.0,20.0,20.0,40.0,0.0,40.0,0.0,40.0,0.0,0.0],[0.0,0.0,20.0,40.0, - 20.0,40.0,20.0,20.0,60.0,20.0,20.0,40.0,20.0,40.0,20.0,0.0,0.0],[0.0, - 0.0,40.0,0.0,40.0,0.0,40.0,20.0,20.0,20.0,40.0,0.0,40.0,0.0,40.0,0.0, - 0.0],[0.0,0.0,40.0,40.0,20.0,40.0,20.0,40.0,20.0,40.0,20.0,40.0,20.0, - 40.0,40.0,0.0,0.0],[0.0,0.0,0.0,20.0,20.0,20.0,40.0,0.0,40.0,0.0,40.0, - 20.0,20.0,20.0,0.0,0.0,0.0],[0.0,0.0,0.0,40.0,20.0,20.0,20.0,40.0, - 20.0,40.0,20.0,20.0,20.0,40.0,0.0,0.0,0.0],[0.0,0.0,40.0,0.0,40.0, - 20.0,40.0,0.0,40.0,0.0,40.0,20.0,40.0,0.0,40.0,0.0,0.0],[0.0,0.0,0.0, - 40.0,0.0,0.0,40.0,40.0,20.0,40.0,40.0,0.0,0.0,40.0,0.0,0.0,0.0],[0.0, - 0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],[0.0, - 0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],),), - axial_description=_F(lower_refl_size=0.21, - upper_refl_size=0.21,), - nominal_power=4000000000.0, - Fuel_power_fraction=0.974, - by_pass=0.07, - core_volumic_flowrate=90940.0,); - -neutro_model=Model_data(physics='Neutronics', - scale='component', - code='APOLLO3', - radial_meshing=_F(flux_solver='subdivision', - flux_subdivision=2, - feedback_solver='subdivision', - feedback_subdivision=1,), - axial_meshing=_F(lower_refl=2, - fuel=42, - upper_refl=2,),); - -thermo_model=Model_data(physics='Thermalhydraulics', - scale='component', - code='FLICA4', - radial_meshing=_F(fluid='subdivision', - fluid_subdivision=1, - pellet=8, - clad=2,), - axial_meshing=_F(lower_refl=1, - fuel=40, - upper_refl=1,),); - -scenario_data=Scenario_data(initial_power=0.1, - initial_power_unit='% Nominal power', - initial_core_inlet_temperature=290.0, - initial_boron_concentration=1300.0, - initial_inlet_pressure=160.2, - initial_outlet_pressure=157.2, - initial_rod_positions=(('Rodbank@RB',201),('Rodbank@N1',96),('Rodbank@N2',260),('Rodbank@G1',260),('Rodbank@G2',260),('Rodcluster@H08',260)), - scenario_type='RIA', - ejected_rod='H02', - rod_position_program=((0.0,0),(0.1,260)), - SCRAM='YES', - SCRAM_power=1130.0, - complete_SCRAM_time=1.0, - post_processing=(('Fuel temperature@Thermalhydraulics','MAX'),('Neutronic power@Neutronics','SUM'),('Fuel temperature@Thermalhydraulics','MED'),('Neutronic power@Neutronics','MED')),); - -Genere_Une_Erreur_Traduction(essai='3',); -#VERSION_CATALOGUE:V_0:FIN VERSION_CATALOGUE -#CHECKSUM:f62a6f71fcde9f983479fc749f7e334c -:FIN CHECKSUM diff --git a/Traducteur3/tutu.comm b/Traducteur3/tutu.comm deleted file mode 100644 index 0701e84e..00000000 --- a/Traducteur3/tutu.comm +++ /dev/null @@ -1,161 +0,0 @@ -# - -REF=Assembly(assembly_type='REF',); - - -U1=Assembly(assembly_type='UOX', - assembly_width=0.21504, - fuel_density=0.95, - radial_description=_F(clad_outer_radius=0.00475, - guide_tube_outer_radius=0.006025, - fuel_rod_pitch=0.0126, - nfuel_rods=264,), - axial_description=_F(active_length_start=0.21, - active_length_end=4.4772,), - grids=_F(mixing=_F(positions=(0.69216,1.19766,1.70316,2.20866,2.71416,3.20416,3.69416,4.18416,), - size=0.033,), - non_mixing=_F(positions=(0.026,4.2412,), - size=0.033,),),); - -UGD=Assembly(assembly_type='UOX', - assembly_width=0.21504, - fuel_density=0.95, - radial_description=_F(clad_outer_radius=0.00475, - guide_tube_outer_radius=0.006025, - fuel_rod_pitch=0.0126, - nfuel_rods=264,), - axial_description=_F(active_length_start=0.21, - active_length_end=4.4772,), - grids=_F(mixing=_F(positions=(0.69216,1.19766,1.70316,2.20866,2.71416,3.20416,3.69416,4.18416,), - size=0.033,), - non_mixing=_F(positions=(0.026,), - size=0.033,),),); - -RB=RodBank(rod_type='heterogeneous', - bottom_composition='AIC', - splitting_heigh=1.4224, - upper_composition='B4C', - step_height=0.016, - nsteps=260,); - -N1=RodBank(rod_type='heterogeneous', - bottom_composition='AIC', - splitting_heigh=1.4224, - upper_composition='B4C', - step_height=0.016, - nsteps=260,); - -N2=RodBank(rod_type='heterogeneous', - bottom_composition='AIC', - splitting_heigh=1.4226, - upper_composition='B4C', - step_height=0.016, - nsteps=260,); - -G1=RodBank(rod_type='homogeneous', - rod_composition='Grey', - step_height=0.016, - nsteps=260,); - -G2=RodBank(rod_type='homogeneous', - rod_composition='Grey', - step_height=0.016, - nsteps=260,); - -techno_data=Techno_data(assembly_list=(REF,U1,UGD,), - rodbank_list=(RB,G1,G2,N1,N2,), - radial_description=_F(nb_assembly=15, - xaxis=('RW','S','R','P','N','L','K','J','H','G','F','E','D','C','B','A','RE',), - yaxis= - ('RS','15','14','13','12','11', - '10','09','08','07','06','05','04','03','02','01','RN',), - assembly_map=((REF,REF,REF,REF,REF,REF,REF,REF,REF,REF,REF,REF,REF,REF,REF,REF,REF,),(REF,REF,REF,REF,REF,U1,U1,U1,U1,U1,U1,U1,REF,REF,REF,REF,REF,),(REF,REF,REF,UGD,U1,UGD,UGD,U1,U1,U1,UGD,UGD,U1,UGD,REF,REF,REF,),(REF,REF,UGD,U1,U1,U1,U1,UGD,U1,UGD,U1,U1,U1,U1,UGD,REF,REF,),(REF,REF,U1,U1,U1,UGD,U1,UGD,U1,UGD,U1,UGD,U1,U1,U1,REF,REF,),(REF,U1,UGD,U1,UGD,U1,U1,UGD,U1,UGD,U1,U1,UGD,U1,UGD,U1,REF,),(REF,U1,UGD,U1,U1,U1,UGD,UGD,U1,UGD,UGD,U1,U1,U1,UGD,U1,REF,),(REF,U1,U1,UGD,UGD,UGD,UGD,U1,UGD,U1,UGD,UGD,UGD,UGD,U1,U1,REF,),(REF,U1,U1,U1,U1,U1,U1,UGD,UGD,UGD,U1,U1,U1,U1,U1,U1,REF,),(REF,U1,U1,UGD,UGD,UGD,UGD,U1,UGD,U1,UGD,UGD,UGD,UGD,U1,U1,REF,),(REF,U1,UGD,U1,U1,U1,UGD,UGD,U1,UGD,UGD,U1,U1,U1,UGD,U1,REF,),(REF,U1,UGD,U1,UGD,U1,U1,UGD,U1,UGD,U1,U1,UGD,U1,UGD,U1,REF,),(REF,REF,U1,U1,U1,UGD,U1,UGD,U1,UGD,U1,UGD,U1,U1,U1,REF,REF,),(REF,REF,UGD,U1,U1,U1,U1,UGD,U1,UGD,U1,U1,U1,U1,UGD,REF,REF,),(REF,REF,REF,UGD,U1,UGD,UGD,U1,U1,U1,UGD,UGD,U1,UGD,REF,REF,REF,),(REF,REF,REF,REF,REF,U1,U1,U1,U1,U1,U1,U1,REF,REF,REF,REF,REF,),(REF,REF,REF,REF,REF,REF,REF,REF,REF,REF,REF,REF,REF,REF,REF,REF,REF,),), - rod_map= - (['#','#','#','#','#','#','#', - '#','#','#','#','#','#','#','#','#','#'],['#','#','#','#','#','.', - '.','.','.','.','.','.','#','#','#','#','#'],['#','#','#','.','.', - '.','.','.','RB','.','.','.','.','.','#','#','#'],['#','#','.','.', - '.','G2','.','N2','.','N2','.','G2','.','.','.','#','#'],['#','#', - '.','.','N1','.','.','.','G1','.','.','.','N1','.','.','#','#'], - ['#','.','.','G2','.','RB','.','.','.','.','.','RB','.','G2','.', - '.','#'],['#','.','.','.','.','.','.','.','N1','.','.','.','.','.', - '.','.','#'],['#','.','.','N2','.','.','.','.','.','.','.','.','.', - 'N2','.','.','#'],['#','.','RB','.','G1','.','N1','.','RB','.','N1', - '.','G1','.','RB','.','#'],['#','.','.','N2','.','.','.','.','.', - '.','.','.','.','N2','.','.','#'],['#','.','.','.','.','.','.','.', - 'N1','.','.','.','.','.','.','.','#'],['#','.','.','G2','.','RB', - '.','.','.','.','.','RB','.','G2','.','.','#'],['#','#','.','.', - 'N1','.','.','.','G1','.','.','.','N1','.','.','#','#'],['#','#', - '.','.','.','G2','.','N2','.','N2','.','G2','.','.','.','#','#'], - ['#','#','#','.','.','.','.','.','RB','.','.','.','.','.','#','#', - '#'],['#','#','#','#','#','.','.','.','.','.','.','.','#','#','#', - '#','#'],['#','#','#','#','#','#','#','#','#','#','#','#','#','#', - '#','#','#'],), - BU_map= - ([0.0,0.0,0.0,0.0,0.0,0.0,0.0, - 0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],[0.0,0.0,0.0,0.0,0.0,0.0,0.0, - 0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],[0.0,0.0,0.0,40.0,0.0,0.0, - 40.0,40.0,20.0,40.0,40.0,0.0,0.0,40.0,0.0,0.0,0.0],[0.0,0.0,40.0,0.0, - 40.0,20.0,40.0,0.0,40.0,0.0,40.0,20.0,40.0,0.0,40.0,0.0,0.0],[0.0,0.0, - 0.0,40.0,20.0,20.0,20.0,40.0,20.0,40.0,20.0,20.0,20.0,40.0,0.0,0.0, - 0.0],[0.0,0.0,0.0,20.0,20.0,20.0,40.0,0.0,40.0,0.0,40.0,20.0,20.0, - 20.0,0.0,0.0,0.0],[0.0,0.0,40.0,40.0,20.0,40.0,20.0,40.0,20.0,40.0, - 20.0,40.0,20.0,40.0,40.0,0.0,0.0],[0.0,0.0,40.0,0.0,40.0,0.0,40.0, - 20.0,20.0,20.0,40.0,0.0,40.0,0.0,40.0,0.0,0.0],[0.0,0.0,20.0,40.0, - 20.0,40.0,20.0,20.0,60.0,20.0,20.0,40.0,20.0,40.0,20.0,0.0,0.0],[0.0, - 0.0,40.0,0.0,40.0,0.0,40.0,20.0,20.0,20.0,40.0,0.0,40.0,0.0,40.0,0.0, - 0.0],[0.0,0.0,40.0,40.0,20.0,40.0,20.0,40.0,20.0,40.0,20.0,40.0,20.0, - 40.0,40.0,0.0,0.0],[0.0,0.0,0.0,20.0,20.0,20.0,40.0,0.0,40.0,0.0,40.0, - 20.0,20.0,20.0,0.0,0.0,0.0],[0.0,0.0,0.0,40.0,20.0,20.0,20.0,40.0, - 20.0,40.0,20.0,20.0,20.0,40.0,0.0,0.0,0.0],[0.0,0.0,40.0,0.0,40.0, - 20.0,40.0,0.0,40.0,0.0,40.0,20.0,40.0,0.0,40.0,0.0,0.0],[0.0,0.0,0.0, - 40.0,0.0,0.0,40.0,40.0,20.0,40.0,40.0,0.0,0.0,40.0,0.0,0.0,0.0],[0.0, - 0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],[0.0, - 0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],),), - axial_description=_F(lower_refl_size=0.21, - upper_refl_size=0.21,), - nominal_power=4000000000.0, - Fuel_power_fraction=0.974, - by_pass=0.07, - core_volumic_flowrate=90940.0,); - -neutro_model=Model_data(physics='Neutronics', - scale='component', - code='APOLLO3', - radial_meshing=_F(flux_solver='subdivision', - flux_subdivision=2, - feedback_solver='subdivision', - feedback_subdivision=1,), - axial_meshing=_F(lower_refl=2, - fuel=42, - upper_refl=2,),); - -thermo_model=Model_data(physics='Thermalhydraulics', - scale='component', - code='FLICA4', - radial_meshing=_F(fluid='subdivision', - fluid_subdivision=1, - pellet=8, - clad=2,), - axial_meshing=_F(lower_refl=1, - fuel=40, - upper_refl=1,),); - -scenario_data=Scenario_data(initial_power=0.1, - initial_power_unit='% Nominal power', - initial_core_inlet_temperature=290.0, - initial_boron_concentration=1300.0, - initial_inlet_pressure=160.2, - initial_outlet_pressure=157.2, - initial_rod_positions=(('Rodbank@RB',201),('Rodbank@N1',96),('Rodbank@N2',260),('Rodbank@G1',260),('Rodbank@G2',260),('Rodcluster@H08',260)), - scenario_type='RIA', - ejected_rod='H02', - rod_position_program=((0.0,0),(0.1,260)), - SCRAM='YES', - SCRAM_power=1130.0, - complete_SCRAM_time=1.0, - post_processing=(('Fuel temperature@Thermalhydraulics','MAX'),('Neutronic power@Neutronics','SUM'),('Fuel temperature@Thermalhydraulics','MED'),('Neutronic power@Neutronics','MED')),); - -Genere_Une_Erreur_Traduction(essai='3',); -#VERSION_CATALOGUE:V_0:FIN VERSION_CATALOGUE -#CHECKSUM:f62a6f71fcde9f983479fc749f7e334c -:FIN CHECKSUM diff --git a/Traducteur3/utils.py b/Traducteur3/utils.py deleted file mode 100644 index 31ab5e87..00000000 --- a/Traducteur3/utils.py +++ /dev/null @@ -1,45 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright (C) 2007-2017 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 re - -def indexToCoordinates(src, index): - """return le numero de la colonne (x) et le numero de la ligne (y) dans src""" - y = src[: index].count("\n") - startOfLineIdx = src.rfind("\n", 0, index)+1 - x = index-startOfLineIdx - return x, y - -def lineToDict(line): - """Transforme une ligne (string) en un dictionnaire de mots - reperes par le numero de la colonne""" - - words = re.split("(\w+)", line) - h = {};i = 0 - for word in words: - h[i] = word - i+=len(word) - return h - -def dictToLine(d): - """Transformation inverse: a partir d'un dictionnaire retourne une ligne""" - cols = d - cols.sort() - return "".join([d[colno]for colno in cols]) diff --git a/Traducteur3/visiteur.py b/Traducteur3/visiteur.py deleted file mode 100644 index d3584b16..00000000 --- a/Traducteur3/visiteur.py +++ /dev/null @@ -1,98 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright (C) 2007-2017 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 re -from ast import NodeVisitor -debug=1 - -class MatchFinder (NodeVisitor): - """Visiteur de base : gestion des matches """ - def reset(self,line): - self.matches=[] - self._matches = [] - self.words = re.split("(\w+)", line) # every other one is a non word - self.positions = [] - i = 0 - for word in self.words: - self.positions.append(i) - i+=len(word) - self.index = 0 - if debug : print ('fin reset', self.words) - - def popWordsUpTo(self, word): - if word == "*": - return # won't be able to find this - posInWords = self.words.index(word) - idx = self.positions[posInWords] - self.words = self.words[posInWords+1:] - self.positions = self.positions[posInWords+1:] - - def appendMatch(self,name): - idx = self.getNextIndexOfWord(name) - self._matches.append((idx, name)) - - def getNextIndexOfWord(self,name): - return self.positions[self.words.index(name)] - - -class KeywordFinder(MatchFinder): - """Visiteur pour les keywords d'une commande """ - - def visit_keyword(self,node): - if debug : print (' visit_keyword', node.arg) - idx = self.getNextIndexOfWord(node.arg) - self.popWordsUpTo(node.arg) - prevmatches=self._matches - self._matches = [] - #for child in node.getChildNodes(): - # self.visit(child) - self.generic_visit(node) - prevmatches.append((idx, node.arg,self._matches)) - self._matches=prevmatches - #on ne garde que les matches du niveau Keyword le plus haut - self.matches=self._matches - - def visit_Tuple(self,node): - matchlist=[] - # Pour eviter les tuples et listes ordinaires, - if not hasattr(node,'getChildNodes') : return - print ('*********************************************************************') - print ("_____________ visit_Tuple", node) - for child in node.getChildNodes(): - self._matches = [] - self.visit(child) - if self._matches: - # Pour eviter les tuples et listes ordinaires, - # on ne garde que les visites fructueuses - matchlist.append(self._matches) - self._matches=matchlist - #self.generic_visit(node) - - visit_List=visit_Tuple - - def visit_Name(self,node): - if debug : print ('visit_Name', node.id) - self.popWordsUpTo(node.id) - self.generic_visit(node) - - def visit_AssName(self,node): - if debug : print ('visit_AssName', node.id) - self.popWordsUpTo(node.id) - self.generic_visit(node)