1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2007-2013 EDF R&D
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License.
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # Lesser General Public License for more details.
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 Ce module sert a lire un catalogue et a construire
22 un objet CataItem pour Eficas.
23 Il s'appuie sur la classe READERCATA
27 import os,sys,py_compile
34 from Noyau.N_CR import CR
35 from Editeur.catadesc import CatalogDescription
37 import analyse_catalogue
38 import analyse_catalogue_initial
39 import autre_analyse_cata
41 from monChoixCata import MonChoixCata
42 from Extensions.i18n import tr
43 from Extensions.eficas_exception import EficasException
45 from determine import monEnvQT5
47 from PyQt5.QtWidgets import QMessageBox, QApplication, QDialog
49 from PyQt4.QtGui import *
55 def __init__(self,QWParent, appliEficas):
56 self.QWParent=QWParent
57 self.appliEficas=self.QWParent.appliEficas
58 self.VERSION_EFICAS=self.appliEficas.VERSION_EFICAS
59 self.code=self.QWParent.code
60 self.ssCode=self.appliEficas.ssCode
61 self.appliEficas.format_fichier='python'
62 self.mode_nouv_commande=self.appliEficas.CONFIGURATION.mode_nouv_commande
63 self.version_code=self.QWParent.version_code
64 self.version_cata=None
68 if self.code=="TELEMAC": self.cree_dico_inverse()
72 Ouvre le catalogue standard du code courant, cad le catalogue present
73 dans le repertoire Cata
76 liste_cata_possibles=[]
77 self.Commandes_Ordre_Catalogue=[]
80 for catalogue in self.appliEficas.CONFIGURATION.catalogues:
81 if isinstance(catalogue, CatalogDescription):
82 all_cata_list.append(catalogue)
83 elif isinstance(catalogue, types.TupleType):
84 all_cata_list.append(CatalogDescription.create_from_tuple(catalogue))
86 print "Catalog description cannot be interpreted: ", catalogue
88 # This filter is only useful for codes that have subcodes (like MAP).
89 # Otherwise, the "code" attribute of the catalog description can (should) be None.
90 if self.ssCode is None:
91 liste_cata_possibles = all_cata_list
93 for catalogue in all_cata_list:
94 if catalogue.code == self.code and catalogue.file_format == self.ssCode:
95 liste_cata_possibles.append(catalogue)
97 if len(liste_cata_possibles)==0:
98 QMessageBox.critical(self.QWParent, tr("Import du catalogue"),
99 tr("Pas de catalogue defini pour le code ") + self.code)
100 self.appliEficas.close()
101 if self.appliEficas.salome == 0 :
106 if self.version_code is not None:
107 # La version a ete fixee
108 for cata in liste_cata_possibles:
109 if self.version_code == cata.identifier:
110 self.fic_cata = cata.cata_file_path
111 self.appliEficas.format_fichier = cata.file_format
112 self.appliEficas.format_fichier_in = cata.file_format_in
114 cata_choice_list = []
115 for cata in liste_cata_possibles:
118 cata_choice_list.insert(0, cata)
120 cata_choice_list.append(cata)
121 if len(cata_choice_list) == 0:
122 QMessageBox.critical(self.QWParent, tr("Import du catalogue"),
123 tr("Aucun catalogue trouve"))
124 self.appliEficas.close()
125 if self.appliEficas.salome == 0 :
127 elif len(cata_choice_list) == 1:
128 self.fic_cata = cata_choice_list[0].cata_file_path
129 self.version_code = cata_choice_list[0].identifier
130 self.appliEficas.format_fichier = cata_choice_list[0].file_format
131 self.appliEficas.format_fichier_in = cata_choice_list[0].file_format_in
133 # plusieurs catalogues sont disponibles : il faut demander a l'utilisateur
134 # lequel il veut utiliser ...
135 self.ask_choix_catalogue(cata_choice_list)
137 if self.fic_cata == None :
138 if self.appliEficas.salome == 0 :
139 print "Pas de catalogue pour code %s, version %s" %(self.code,self.version_code)
142 self.appliEficas.close()
145 if self.code == "ASTER" : self.determineMater()
147 # import du catalogue
148 self.cata = self.import_cata(self.fic_cata)
150 QMessageBox.critical( self.QWParent, tr("Import du catalogue"),tr("Impossible d'importer le catalogue ")+ self.fic_cata)
151 self.appliEficas.close()
152 if self.appliEficas.salome == 0 :
155 # analyse du catalogue (ordre des mots-cles)
157 # Retrouve_Ordre_Cata_Standard fait une analyse textuelle du catalogue
158 # remplace par Retrouve_Ordre_Cata_Standard_autre qui utilise une numerotation
159 # des mots cles a la creation
160 self.Retrouve_Ordre_Cata_Standard_autre()
161 if self.mode_nouv_commande== "initial" : self.Retrouve_Ordre_Cata_Standard()
162 if hasattr(self.cata, 'Ordre_Des_Commandes') : self.Ordre_Des_Commandes=self.cata.Ordre_Des_Commandes
163 else : self.Ordre_Des_Commandes=None
165 if hasattr(self.cata, 'Classement_Commandes_Ds_Arbre') :
166 self.Classement_Commandes_Ds_Arbre=self.cata.Classement_Commandes_Ds_Arbre
167 else : self.Classement_Commandes_Ds_Arbre=()
168 #print self.cata.Ordre_Des_Commandes
171 # analyse des donnees liees l'IHM : UIinfo
173 uiinfo.traite_UIinfo(self.cata)
176 # traitement des clefs documentaires
178 if self.code == "ASTER" : self.traite_clefs_documentaires()
179 self.cata=(self.cata,)
181 self.titre=self.VERSION_EFICAS+" "+tr( " avec le catalogue ") + os.path.basename(self.fic_cata)
182 if self.appliEficas.top:
183 self.appliEficas.setWindowTitle(self.titre)
184 self.appliEficas.titre=self.titre
185 self.QWParent.titre=self.titre
187 def determineMater(self) :
188 # Determinination du repertoire materiau
189 v_codeSansPoint=self.version_code
190 if v_codeSansPoint == None : return
191 v_codeSansPoint=re.sub("\.","",v_codeSansPoint)
192 chaine="rep_mat_"+v_codeSansPoint
193 if hasattr(self.appliEficas.CONFIGURATION,chaine):
194 a=getattr(self.appliEficas.CONFIGURATION,chaine)
197 a=self.appliEficas.CONFIGURATION.dRepMat[self.version_code]
199 if self.code == "ASTER" :
200 print "Probleme avec le repertoire materiau"
202 self.appliEficas.CONFIGURATION.rep_mat=a
204 def import_cata(self,cata):
206 Realise l'import du catalogue dont le chemin d'acces est donne par cata
208 nom_cata = os.path.splitext(os.path.basename(cata))[0]
209 rep_cata = os.path.dirname(cata)
210 sys.path[:0] = [rep_cata]
211 self.appliEficas.listeAEnlever.append(rep_cata)
214 if sys.modules.has_key(nom_cata):
215 del sys.modules[nom_cata]
216 for k in sys.modules.keys():
217 if k[0:len(nom_cata)+1] == nom_cata+'.':
220 mesScriptsNomFichier='mesScripts_'+self.code.upper()
221 if self.code == "ASTER" :
222 self.appliEficas.rep_scripts=os.path.join(rep_cata,nom_cata)
223 sys.path[:0] = [self.appliEficas.rep_scripts]
225 self.appliEficas.mesScripts[self.code]=__import__(mesScriptsNomFichier)
228 sys.path=sys.path[1:]
231 self.appliEficas.mesScripts[self.code]=__import__(mesScriptsNomFichier)
236 o=__import__(nom_cata)
239 traceback.print_exc()
244 def Retrouve_Ordre_Cata_Standard_autre(self):
246 Construit une structure de donnees dans le catalogue qui permet
247 a EFICAS de retrouver l'ordre des mots-cles dans le texte du catalogue.
248 Pour chaque entite du catlogue on cree une liste de nom ordre_mc qui
249 contient le nom des mots cles dans le bon ordre
251 self.cata_ordonne_dico,self.appliEficas.liste_simp_reel=autre_analyse_cata.analyse_catalogue(self.cata)
252 #print self.cata_ordonne_dico,self.appliEficas.liste_simp_reel
254 def Retrouve_Ordre_Cata_Standard(self):
256 Retrouve l'ordre des mots-cles dans le catalogue, cad :
257 Attention s appuie sur les commentaires
259 nom_cata = os.path.splitext(os.path.basename(self.fic_cata))[0]
260 rep_cata = os.path.dirname(self.fic_cata)
261 self.Commandes_Ordre_Catalogue = analyse_catalogue_initial.analyse_catalogue(self.fic_cata)
262 #print self.Commandes_Ordre_Catalogue
264 def ask_choix_catalogue(self, cata_choice_list):
266 Ouvre une fenetre de selection du catalogue dans le cas où plusieurs
267 ont ete definis dans Accas/editeur.ini
269 code = getattr(self.appliEficas.CONFIGURATION, "code", None)
271 title=tr("Choix d une version du code ")+str(code)
273 title=tr("Choix d une version ")
275 widgetChoix = MonChoixCata(self.appliEficas, [cata.user_name for cata in cata_choice_list], title)
276 ret=widgetChoix.exec_()
278 lab=str(self.VERSION_EFICAS)+" "
281 lab+=tr(" avec le catalogue ")
282 if ret == QDialog.Accepted:
283 cata = cata_choice_list[widgetChoix.CBChoixCata.currentIndex()]
284 self.version_cata = cata.identifier
285 self.fic_cata = cata.cata_file_path
286 self.version_code = self.version_cata
287 self.appliEficas.format_fichier = cata.file_format
288 self.appliEficas.format_fichier_in = cata.file_format_in
289 lab+=self.version_cata
290 self.appliEficas.setWindowTitle(lab)
291 #qApp.mainWidget().setCaption(lab)
293 raise EficasException()
296 def traite_clefs_documentaires(self):
298 fic_doc='rep_doc_'+str(self.version_code)
299 self.fic_doc=getattr(self.appliEficas.CONFIGURATION,fic_doc )
302 print "Pas de fichier associe contenant des clefs documentaires"
306 for l in f.readlines():
310 dict_clef_docu[clef]=docu
311 for oper in self.cata.JdC.commandes:
312 if dict_clef_docu.has_key(oper.nom):
313 oper.docu=dict_clef_docu[oper.nom]
315 def cree_dico_inverse(self):
318 listeEtapes=self.cata[0].JdC.commandes
319 for e in self.cata[0].JdC.commandes:
320 #for e in (self.cata[0].JdC.commandes[0],):
322 self.traite_entite(e)
323 #for e in self.cata[0].JdC.commandes:
324 # self.cree_rubrique(e,self.dico,0)
325 #print self.dicoInverse
327 #from Extensions import localisation
329 # tres dommage A Revoir
330 #localisation.localise(app,"fr")
331 self.dicoInverseFrancais={}
332 self.dicoFrancaisAnglais={}
333 self.dicoAnglaisFrancais={}
334 for k in self.dicoInverse.keys():
336 for nom, obj in self.dicoInverse[k] :
337 listefr.append((tr(nom),obj))
338 self.dicoFrancaisAnglais[tr(nom)]=nom
339 self.dicoAnglaisFrancais[nom]=tr(nom)
340 self.dicoInverseFrancais[tr(k)]=listefr
342 if self.appliEficas.langue=="ang" : localisation.localise(app,"en")
346 def traite_entite(self,e):
347 #print "_______________"
351 for (nomFils, fils) in e.entites.items() :
352 self.dicoMC[nomFils]=fils
353 self.traite_entite(fils)
358 while hasattr(moi,'pere') :
359 liste.append((moi.nom,moi))
361 liste.append((moi.nom,moi))
362 self.dicoInverse[e.nom]=liste
364 def cree_rubrique(self,e,dico, niveau):
365 from Accas import A_BLOC
368 # if isinstance(e,A_BLOC.BLOC): print decale, e.condition
369 # else : print decale, e. nom
370 for (nom, fils) in e.entites.items() :
371 if fils.entites.items() != [] : self.cree_rubrique(fils,dico,niveau+1)
372 #else : print (niveau+1)*" ", nom