X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=InterfaceQT4%2Freadercata.py;h=b3def9c2fc85f2ccc3c01d8698de248f0778a272;hb=96176d0080e0d4efbd29d98c0df700a64a82acdc;hp=faa27690b999415537c763f55d8a66b22f4e66b9;hpb=cdd358f4041f957701ac10d86766a85baaef4f78;p=tools%2Feficas.git diff --git a/InterfaceQT4/readercata.py b/InterfaceQT4/readercata.py index faa27690..b3def9c2 100644 --- a/InterfaceQT4/readercata.py +++ b/InterfaceQT4/readercata.py @@ -1,53 +1,59 @@ # -*- 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. +# Copyright (C) 2007-2013 EDF R&D # -# 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. +# 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. # -# 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. +# 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 sert a lire un catalogue et a construire un objet CataItem pour Eficas. Il s'appuie sur la classe READERCATA """ # Modules Python +from __future__ import absolute_import +from __future__ import print_function +try : + from builtins import str + from builtins import object +except : pass + import time import os,sys,py_compile import traceback -import cPickle +import six.moves.cPickle import re import types # Modules Eficas from Noyau.N_CR import CR from Editeur.catadesc import CatalogDescription -from Editeur.utils import init_rep_cata_dev import analyse_catalogue import analyse_catalogue_initial import autre_analyse_cata import uiinfo -from monChoixCata import MonChoixCata +from .monChoixCata import MonChoixCata +from Extensions.i18n import tr +from Extensions.eficas_exception import EficasException + +from PyQt5.QtWidgets import QMessageBox, QApplication, QDialog -from PyQt4 import * -from PyQt4.QtGui import * -from PyQt4.QtCore import * -class READERCATA: +class READERCATA(object): def __init__(self,QWParent, appliEficas): self.QWParent=QWParent @@ -56,20 +62,25 @@ class READERCATA: self.code=self.QWParent.code self.ssCode=self.appliEficas.ssCode self.appliEficas.format_fichier='python' - if hasattr(self.appliEficas,'mode_nouv_commande'): - self.mode_nouv_commande=self.appliEficas.mode_nouv_commande - else : - self.mode_nouv_commande='alpha' + self.mode_nouv_commande=self.appliEficas.CONFIGURATION.mode_nouv_commande self.version_code=self.QWParent.version_code self.version_cata=None self.fic_cata=None self.OpenCata() self.cataitem=None + self.cree_dico_inverse() + if self.code=="TELEMAC": self.cree_dico_CasToCata() + #for k in self.dicoInverse: + # genea= self.dicoInverse[k] + # for t in genea : + # print t[0] + # print "\n" + def OpenCata(self): """ - Ouvre le catalogue standard du code courant, cad le catalogue présent - dans le répertoire Cata + Ouvre le catalogue standard du code courant, cad le catalogue present + dans le repertoire Cata """ liste_cata_possibles=[] @@ -79,10 +90,10 @@ class READERCATA: for catalogue in self.appliEficas.CONFIGURATION.catalogues: if isinstance(catalogue, CatalogDescription): all_cata_list.append(catalogue) - elif isinstance(catalogue, types.TupleType): + elif isinstance(catalogue, tuple): all_cata_list.append(CatalogDescription.create_from_tuple(catalogue)) else: - print "Catalog description cannot be interpreted: ", catalogue + print(("Catalog description cannot be interpreted: ", catalogue)) # This filter is only useful for codes that have subcodes (like MAP). # Otherwise, the "code" attribute of the catalog description can (should) be None. @@ -90,17 +101,12 @@ class READERCATA: liste_cata_possibles = all_cata_list else: for catalogue in all_cata_list: - #print catalogue.code - #print catalogue.file_format if catalogue.code == self.code and catalogue.file_format == self.ssCode: liste_cata_possibles.append(catalogue) - #print "___________" - #print self.ssCode - #print self.code if len(liste_cata_possibles)==0: - QMessageBox.critical(self.QWParent, "Import du catalogue", - u"Pas de catalogue défini pour le code %s" % self.code) + QMessageBox.critical(self.QWParent, tr("Import du catalogue"), + tr("Pas de catalogue defini pour le code ") + self.code) self.appliEficas.close() if self.appliEficas.salome == 0 : sys.exit(1) @@ -123,8 +129,8 @@ class READERCATA: else : cata_choice_list.append(cata) if len(cata_choice_list) == 0: - QMessageBox.critical(self.QWParent, "Import du catalogue", - QString.fromUtf8("Aucun catalogue trouvé")) + QMessageBox.critical(self.QWParent, tr("Import du catalogue"), + tr("Aucun catalogue trouve")) self.appliEficas.close() if self.appliEficas.salome == 0 : sys.exit(1) @@ -133,68 +139,60 @@ class READERCATA: self.version_code = cata_choice_list[0].identifier self.appliEficas.format_fichier = cata_choice_list[0].file_format self.appliEficas.format_fichier_in = cata_choice_list[0].file_format_in - lab=QString("Eficas ") - lab+=QString(self.VERSION_EFICAS) - lab+=QString(" pour ") - lab+=QString(self.code) - lab+=QString(" avec le catalogue ") - lab+=self.version_code - try : - # souci pour les includes et sans Ihm - self.appliEficas.setWindowTitle(lab) - except : - pass else: # plusieurs catalogues sont disponibles : il faut demander a l'utilisateur # lequel il veut utiliser ... self.ask_choix_catalogue(cata_choice_list) - # On est dans Salome et il faut sortir proprement if self.fic_cata == None : if self.appliEficas.salome == 0 : - print "Pas de catalogue pour code %s, version %s" %(self.code,self.version_code) + print(("Pas de catalogue pour code %s, version %s" %(self.code,self.version_code))) sys.exit(1) else : self.appliEficas.close() return - self.determineMater() - # détermination de fic_cata_c et fic_cata_p - self.fic_cata_c = self.fic_cata + 'c' - self.fic_cata_p = os.path.splitext(self.fic_cata)[0]+'_pickled.py' + if self.code == "ASTER" : self.determineMater() # import du catalogue self.cata = self.import_cata(self.fic_cata) if not self.cata : - QMessageBox.critical( self.QWParent, "Import du catalogue","Impossible d'importer le catalogue %s" %self.fic_cata) - self.appliEficas.close() + QMessageBox.critical( self.QWParent, tr("Import du catalogue"),tr("Impossible d'importer le catalogue ")+ self.fic_cata) + self.appliEficas.close() if self.appliEficas.salome == 0 : sys.exit(1) # - # analyse du catalogue (ordre des mots-clés) + # analyse du catalogue (ordre des mots-cles) # # Retrouve_Ordre_Cata_Standard fait une analyse textuelle du catalogue - # remplacé par Retrouve_Ordre_Cata_Standard_autre qui utilise une numerotation - # des mots clés a la création + # remplace par Retrouve_Ordre_Cata_Standard_autre qui utilise une numerotation + # des mots cles a la creation self.Retrouve_Ordre_Cata_Standard_autre() - if self.mode_nouv_commande== "initial" : - self.Retrouve_Ordre_Cata_Standard() + if self.mode_nouv_commande== "initial" : self.Retrouve_Ordre_Cata_Standard() + if hasattr(self.cata, 'Ordre_Des_Commandes') : self.Ordre_Des_Commandes=self.cata.Ordre_Des_Commandes + else : self.Ordre_Des_Commandes=None + + if hasattr(self.cata, 'Classement_Commandes_Ds_Arbre') : + self.Classement_Commandes_Ds_Arbre=self.cata.Classement_Commandes_Ds_Arbre + else : self.Classement_Commandes_Ds_Arbre=() + #print self.cata.Ordre_Des_Commandes # - # analyse des données liées a  l'IHM : UIinfo + # analyse des donnees liees l'IHM : UIinfo # uiinfo.traite_UIinfo(self.cata) # # traitement des clefs documentaires # - self.traite_clefs_documentaires() + if self.code == "ASTER" : self.traite_clefs_documentaires() self.cata=(self.cata,) - titre=self.VERSION_EFICAS + " avec le catalogue " + os.path.basename(self.fic_cata) + + self.titre=self.VERSION_EFICAS+" "+tr( " avec le catalogue ") + os.path.basename(self.fic_cata) if self.appliEficas.top: - self.appliEficas.setWindowTitle(titre) - self.appliEficas.titre=titre - self.QWParent.titre=titre + self.appliEficas.setWindowTitle(self.titre) + self.appliEficas.titre=self.titre + self.QWParent.titre=self.titre def determineMater(self) : # Determinination du repertoire materiau @@ -209,67 +207,87 @@ class READERCATA: a=self.appliEficas.CONFIGURATION.dRepMat[self.version_code] except : if self.code == "ASTER" : - print "Probleme avec le repertoire materiau" + print ("Probleme avec le repertoire materiau") a='.' self.appliEficas.CONFIGURATION.rep_mat=a def import_cata(self,cata): """ - Réalise l'import du catalogue dont le chemin d'acces est donné par cata + Realise l'import du catalogue dont le chemin d'acces est donne par cata """ nom_cata = os.path.splitext(os.path.basename(cata))[0] rep_cata = os.path.dirname(cata) sys.path[:0] = [rep_cata] + self.appliEficas.listeAEnlever.append(rep_cata) + - if sys.modules.has_key(nom_cata): + if nom_cata in list(sys.modules.keys()) : del sys.modules[nom_cata] - for k in sys.modules.keys(): + for k in sys.modules: if k[0:len(nom_cata)+1] == nom_cata+'.': del sys.modules[k] + mesScriptsNomFichier='mesScripts_'+self.code.upper() + if self.code == "ASTER" : + self.appliEficas.rep_scripts=os.path.join(rep_cata,nom_cata) + sys.path[:0] = [self.appliEficas.rep_scripts] + try : + self.appliEficas.mesScripts[self.code]=__import__(mesScriptsNomFichier) + except: + pass + sys.path=sys.path[1:] + else : + try : + self.appliEficas.mesScripts[self.code]=__import__(mesScriptsNomFichier) + except: + pass + try : o=__import__(nom_cata) return o - except Exception,e: + except Exception as e: traceback.print_exc() return 0 + + def Retrouve_Ordre_Cata_Standard_autre(self): """ - Construit une structure de données dans le catalogue qui permet - a  EFICAS de retrouver l'ordre des mots-clés dans le texte du catalogue. - Pour chaque entité du catlogue on crée une liste de nom ordre_mc qui - contient le nom des mots clés dans le bon ordre + Construit une structure de donnees dans le catalogue qui permet + a EFICAS de retrouver l'ordre des mots-cles dans le texte du catalogue. + Pour chaque entite du catlogue on cree une liste de nom ordre_mc qui + contient le nom des mots cles dans le bon ordre """ self.cata_ordonne_dico,self.appliEficas.liste_simp_reel=autre_analyse_cata.analyse_catalogue(self.cata) def Retrouve_Ordre_Cata_Standard(self): """ - Retrouve l'ordre des mots-clés dans le catalogue, cad : + Retrouve l'ordre des mots-cles dans le catalogue, cad : Attention s appuie sur les commentaires """ nom_cata = os.path.splitext(os.path.basename(self.fic_cata))[0] rep_cata = os.path.dirname(self.fic_cata) self.Commandes_Ordre_Catalogue = analyse_catalogue_initial.analyse_catalogue(self.fic_cata) + #print self.Commandes_Ordre_Catalogue def ask_choix_catalogue(self, cata_choice_list): """ - Ouvre une fenetre de sélection du catalogue dans le cas où plusieurs - ont été définis dans Accas/editeur.ini + Ouvre une fenetre de selection du catalogue dans le cas où plusieurs + ont ete definis dans Accas/editeur.ini """ code = getattr(self.appliEficas.CONFIGURATION, "code", None) if code != None : - title="Choix d une version du code "+str(code) + title=tr("Choix d une version du code ")+str(code) else : - title="Choix d une version " + title=tr("Choix d une version ") widgetChoix = MonChoixCata(self.appliEficas, [cata.user_name for cata in cata_choice_list], title) ret=widgetChoix.exec_() - lab=QString(self.VERSION_EFICAS) - lab+=QString(" pour ") - lab+=QString(self.code) - lab+=QString(" avec le catalogue ") + lab=str(self.VERSION_EFICAS)+" " + lab+=tr(" pour ") + lab+=str(self.code) + lab+=tr(" avec le catalogue ") if ret == QDialog.Accepted: cata = cata_choice_list[widgetChoix.CBChoixCata.currentIndex()] self.version_cata = cata.identifier @@ -281,25 +299,82 @@ class READERCATA: self.appliEficas.setWindowTitle(lab) #qApp.mainWidget().setCaption(lab) else: - self.appliEficas.close() - if self.appliEficas.salome == 0 : - sys.exit(0) + raise EficasException() + def traite_clefs_documentaires(self): try: - self.fic_cata_clef=os.path.splitext(self.fic_cata_c)[0]+'_clefs_docu' - #print self.fic_cata_clef - f=open(self.fic_cata_clef) + fic_doc='rep_doc_'+str(self.version_code) + self.fic_doc=getattr(self.appliEficas.CONFIGURATION,fic_doc ) + f=open(self.fic_doc) except: - #print "Pas de fichier associe contenant des clefs documentaires" + print ("Pas de fichier associe contenant des clefs documentaires") return dict_clef_docu={} for l in f.readlines(): clef=l.split(':')[0] - docu=l.split(':')[1] - docu=docu[0:-1] + deb=l.find(':')+1 + docu=l[deb:-1] dict_clef_docu[clef]=docu for oper in self.cata.JdC.commandes: - if dict_clef_docu.has_key(oper.nom): + if oper.nom in dict_clef_docu : oper.docu=dict_clef_docu[oper.nom] + + def cree_dico_inverse(self): + self.dicoInverse={} + self.dicoMC={} + listeEtapes=self.cata[0].JdC.commandes + for e in self.cata[0].JdC.commandes: + self.traite_entite(e) + + #self.dicoFrancaisAnglais={} + #self.dicoAnglaisFrancais={} + #for k in self.dicoInverse: + # listefr=[] + # for nom, obj in self.dicoInverse[k] : + # listefr.append((tr(nom),obj)) + # self.dicoFrancaisAnglais[tr(nom)]=nom + # self.dicoAnglaisFrancais[nom]=tr(nom) + # self.dicoInverseFrancais[tr(k)]=listefr + # #print tr(k),listefr + + + def cree_dico_CasToCata(self): + if self.appliEficas.langue=="ang" : + from dicoCasEnToCata import dicoCasEnToCata as dicoCasToCata + else : + from dicoCasFrToCata import dicoCasFrToCata as dicoCasToCata + self.dicoCasToCata=dicoCasToCata + + + + + def traite_entite(self,e): + boolIn=0 + for (nomFils, fils) in list(e.entites.items()) : + self.dicoMC[nomFils]=fils + self.traite_entite(fils) + boolIn=1 + if boolIn==0 : + liste=[] + moi=e + while hasattr(moi,'pere') : + liste.append((moi.nom,moi)) + moi=moi.pere + liste.append((moi.nom,moi)) + self.dicoInverse[e.nom]=liste + self.dicoInverse[tr(e.nom)]=liste + + def cree_rubrique(self,e,dico, niveau): + from Accas import A_BLOC + decale=niveau*" " + #if niveau != 0 : + # if isinstance(e,A_BLOC.BLOC): print decale, e.condition + # else : print decale, e. nom + for (nom, fils) in list(e.entites.items()) : + if list(fils.entites.items()) != [] : self.cree_rubrique(fils,dico,niveau+1) + #else : print (niveau+1)*" ", nom + + +