1 # -*- coding: utf-8 -*-
2 # CONFIGURATION MANAGEMENT OF EDF VERSION
3 # ======================================================================
4 # COPYRIGHT (C) 1991 - 2002 EDF R&D WWW.CODE-ASTER.ORG
5 # THIS PROGRAM IS FREE SOFTWARE; YOU CAN REDISTRIBUTE IT AND/OR MODIFY
6 # IT UNDER THE TERMS OF THE GNU GENERAL PUBLIC LICENSE AS PUBLISHED BY
7 # THE FREE SOFTWARE FOUNDATION; EITHER VERSION 2 OF THE LICENSE, OR
8 # (AT YOUR OPTION) ANY LATER VERSION.
10 # THIS PROGRAM IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL, BUT
11 # WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF
12 # MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. SEE THE GNU
13 # GENERAL PUBLIC LICENSE FOR MORE DETAILS.
15 # YOU SHOULD HAVE RECEIVED A COPY OF THE GNU GENERAL PUBLIC LICENSE
16 # ALONG WITH THIS PROGRAM; IF NOT, WRITE TO EDF R&D CODE_ASTER,
17 # 1 AVENUE DU GENERAL DE GAULLE, 92141 CLAMART CEDEX, FRANCE.
20 # ======================================================================
22 Ce module sert a lire un catalogue et a construire
23 un objet CataItem pour Eficas.
24 Il s'appuie sur la classe READERCATA
28 import os,sys,py_compile
34 from Noyau.N_CR import CR
35 from Editeur.utils import init_rep_cata_dev
37 import analyse_catalogue
38 import analyse_catalogue_initial
39 import autre_analyse_cata
41 from monChoixCata import MonChoixCata
44 from PyQt4.QtGui import *
45 from PyQt4.QtCore import *
47 VERSION_EFICAS="Eficas V1.16"
51 def __init__(self,QWParent, appliEficas):
52 self.QWParent=QWParent
53 self.appliEficas=self.QWParent.appliEficas
54 self.code=self.QWParent.code
55 self.appliEficas.format_fichier='python'
56 if hasattr(self.appliEficas,'mode_nouv_commande'):
57 self.mode_nouv_commande=self.appliEficas.mode_nouv_commande
59 self.mode_nouv_commande='alpha'
60 self.version_code=self.QWParent.version_code
61 self.version_cata=None
68 Ouvre le catalogue standard du code courant, cad le catalogue présent
69 dans le répertoire Cata
72 liste_cata_possibles=[]
73 for catalogue in self.appliEficas.CONFIGURATION.catalogues:
74 if catalogue[0] == self.code :
75 liste_cata_possibles.append(catalogue)
77 if len(liste_cata_possibles)==0:
78 QMessageBox.critical( self.QWParent, "Import du catalogue","Pas de catalogue defini pour le code %s" % self.code)
79 self.appliEficas.close()
82 if self.version_code is not None:
83 # La version a ete fixee
84 for cata in liste_cata_possibles:
85 if self.version_code == cata[1]:
86 self.fic_cata = cata[2]
87 self.appliEficas.format_fichier=cata[3]
88 elif len(liste_cata_possibles)==1:
89 self.fic_cata = liste_cata_possibles[0][2]
90 self.version_code = liste_cata_possibles[0][1]
91 self.appliEficas.format_fichier=liste_cata_possibles[0][3]
92 lab=QString("Eficas V1.")
93 lab+=QString(VERSION_EFICAS)
94 lab+=QString(" pour ")
95 lab+=QString(self.code)
96 lab+=QString(" avec le catalogue ")
97 lab+=self.version_code
99 # souci pour les includes et sans Ihm
100 self.appliEficas.setWindowTitle(lab)
104 # plusieurs catalogues sont disponibles : il faut demander a l'utilisateur
105 # lequel il veut utiliser ...
106 self.ask_choix_catalogue()
108 if self.fic_cata == None :
109 print "Pas de catalogue pour code %s, version %s" %(self.code,self.version_code)
112 self.determineMater()
115 # détermination de fic_cata_c et fic_cata_p
116 self.fic_cata_c = self.fic_cata + 'c'
117 self.fic_cata_p = os.path.splitext(self.fic_cata)[0]+'_pickled.py'
119 # import du catalogue
120 self.cata = self.import_cata(self.fic_cata)
122 QMessageBox.critical( self.QWParent, "Import du catalogue","Impossible d'importer le catalogue %s" %self.fic_cata)
123 self.appliEficas.close()
126 # analyse du catalogue (ordre des mots-clés)
128 # Retrouve_Ordre_Cata_Standard fait une analyse textuelle du catalogue
129 # remplacé par Retrouve_Ordre_Cata_Standard_autre qui utilise une numerotation
130 # des mots clés a la création
131 self.Retrouve_Ordre_Cata_Standard_autre()
132 if self.mode_nouv_commande== "initial" :
133 self.Retrouve_Ordre_Cata_Standard()
135 self.Commandes_Ordre_Catalogue=[]
138 # analyse des données liées a l'IHM : UIinfo
140 uiinfo.traite_UIinfo(self.cata)
143 # traitement des clefs documentaires
145 self.traite_clefs_documentaires()
146 self.cata=(self.cata,)
147 titre=VERSION_EFICAS + " avec le catalogue " + os.path.basename(self.fic_cata)
148 if self.appliEficas.top:
149 self.appliEficas.setWindowTitle(titre)
150 self.appliEficas.titre=titre
152 def determineMater(self) :
153 # Determinination du repertoire materiau
154 v_codeSansPoint=self.version_code
155 v_codeSansPoint=re.sub("\.","",v_codeSansPoint)
156 chaine="rep_mat_"+v_codeSansPoint
157 if hasattr(self.appliEficas.CONFIGURATION,chaine):
158 a=getattr(self.appliEficas.CONFIGURATION,chaine)
161 a=self.appliEficas.CONFIGURATION.dRepMat[self.version_code]
163 if self.code == "ASTER" :
164 print "Probleme avec le repertoire materiau"
166 self.appliEficas.CONFIGURATION.rep_mat=a
168 def import_cata(self,cata):
170 Réalise l'import du catalogue dont le chemin d'acces est donné par cata
172 nom_cata = os.path.splitext(os.path.basename(cata))[0]
173 rep_cata = os.path.dirname(cata)
174 sys.path[:0] = [rep_cata]
176 o=__import__(nom_cata)
179 traceback.print_exc()
182 def Retrouve_Ordre_Cata_Standard_autre(self):
184 Construit une structure de données dans le catalogue qui permet
185 a EFICAS de retrouver l'ordre des mots-clés dans le texte du catalogue.
186 Pour chaque entité du catlogue on crée une liste de nom ordre_mc qui
187 contient le nom des mots clés dans le bon ordre
189 self.cata_ordonne_dico,self.appliEficas.liste_simp_reel=autre_analyse_cata.analyse_catalogue(self.cata)
191 def Retrouve_Ordre_Cata_Standard(self):
193 Retrouve l'ordre des mots-clés dans le catalogue, cad :
194 Attention s appuie sur les commentaires
196 nom_cata = os.path.splitext(os.path.basename(self.fic_cata))[0]
197 rep_cata = os.path.dirname(self.fic_cata)
198 self.Commandes_Ordre_Catalogue = analyse_catalogue_initial.analyse_catalogue(self.fic_cata)
200 def ask_choix_catalogue(self):
202 Ouvre une fenetre de sélection du catalogue dans le cas oa¹ plusieurs
203 ont été définis dans Accas/editeur.ini
205 # construction du dictionnaire et de la liste des catalogues
206 self.dico_catalogues = {}
208 for catalogue in self.appliEficas.CONFIGURATION.catalogues:
209 if catalogue[0] == self.code :
210 self.dico_catalogues[catalogue[1]] = catalogue
211 if len(catalogue) == 5 :
212 if catalogue[4]=='defaut' : defaut = catalogue[1]
213 liste_choix = self.dico_catalogues.keys()
216 lab=QString(VERSION_EFICAS)
217 lab+=QString(" pour ")
218 lab+=QString(self.code)
219 lab+=QString(" avec le catalogue ")
221 # teste si plusieurs catalogues ou non
222 if len(liste_choix) == 0:
223 QMessageBox.critical( self.QWParent, "", "Aucun catalogue déclaré pour %s" %self.code)
224 self.appliEficas.close()
227 # création d'une boite de dialogue modale
228 widgetChoix=MonChoixCata(liste_choix,self, self.appliEficas, "", True )
229 ret=widgetChoix.exec_()
231 lab=QString(VERSION_EFICAS)
232 lab+=QString(" pour ")
233 lab+=QString(self.code)
234 lab+=QString(" avec le catalogue ")
235 if ret == QDialog.Accepted:
236 self.version_cata=str(self.version_cata)
237 self.fic_cata = self.dico_catalogues[self.version_cata][2]
238 self.version_code = self.version_cata
239 self.appliEficas.format_fichier = self.dico_catalogues[self.version_cata][3]
240 lab+=self.version_cata
241 self.appliEficas.setWindowTitle(lab)
242 #qApp.mainWidget().setCaption(lab)
248 def traite_clefs_documentaires(self):
250 self.fic_cata_clef=os.path.splitext(self.fic_cata_c)[0]+'_clefs_docu'
251 f=open(self.fic_cata_clef)
253 #print "Pas de fichier associé contenant des clefs documentaires"
257 for l in f.readlines():
261 dict_clef_docu[clef]=docu
262 for oper in self.cata.JdC.commandes:
263 if dict_clef_docu.has_key(oper.nom):
264 oper.docu=dict_clef_docu[oper.nom]