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 self.cree_dico_inverse()
69 if self.code=="TELEMAC": self.cree_dico_CasToCata()
70 #for k in self.dicoInverse.keys():
71 # genea= self.dicoInverse[k]
79 Ouvre le catalogue standard du code courant, cad le catalogue present
80 dans le repertoire Cata
83 liste_cata_possibles=[]
84 self.Commandes_Ordre_Catalogue=[]
87 for catalogue in self.appliEficas.CONFIGURATION.catalogues:
88 if isinstance(catalogue, CatalogDescription):
89 all_cata_list.append(catalogue)
90 elif isinstance(catalogue, types.TupleType):
91 all_cata_list.append(CatalogDescription.create_from_tuple(catalogue))
93 print ("Catalog description cannot be interpreted: ", catalogue)
95 # This filter is only useful for codes that have subcodes (like MAP).
96 # Otherwise, the "code" attribute of the catalog description can (should) be None.
97 if self.ssCode is None:
98 liste_cata_possibles = all_cata_list
100 for catalogue in all_cata_list:
101 if catalogue.code == self.code and catalogue.file_format == self.ssCode:
102 liste_cata_possibles.append(catalogue)
104 if len(liste_cata_possibles)==0:
105 QMessageBox.critical(self.QWParent, tr("Import du catalogue"),
106 tr("Pas de catalogue defini pour le code ") + self.code)
107 self.appliEficas.close()
108 if self.appliEficas.salome == 0 :
113 if self.version_code is not None:
114 # La version a ete fixee
115 for cata in liste_cata_possibles:
116 if self.version_code == cata.identifier:
117 self.fic_cata = cata.cata_file_path
118 self.appliEficas.format_fichier = cata.file_format
119 self.appliEficas.format_fichier_in = cata.file_format_in
121 cata_choice_list = []
122 for cata in liste_cata_possibles:
125 cata_choice_list.insert(0, cata)
127 cata_choice_list.append(cata)
128 if len(cata_choice_list) == 0:
129 QMessageBox.critical(self.QWParent, tr("Import du catalogue"),
130 tr("Aucun catalogue trouve"))
131 self.appliEficas.close()
132 if self.appliEficas.salome == 0 :
134 elif len(cata_choice_list) == 1:
135 self.fic_cata = cata_choice_list[0].cata_file_path
136 self.version_code = cata_choice_list[0].identifier
137 self.appliEficas.format_fichier = cata_choice_list[0].file_format
138 self.appliEficas.format_fichier_in = cata_choice_list[0].file_format_in
140 # plusieurs catalogues sont disponibles : il faut demander a l'utilisateur
141 # lequel il veut utiliser ...
142 self.ask_choix_catalogue(cata_choice_list)
144 if self.fic_cata == None :
145 if self.appliEficas.salome == 0 :
146 print ("Pas de catalogue pour code %s, version %s" %(self.code,self.version_code))
149 self.appliEficas.close()
152 if self.code == "ASTER" : self.determineMater()
154 # import du catalogue
155 self.cata = self.import_cata(self.fic_cata)
157 QMessageBox.critical( self.QWParent, tr("Import du catalogue"),tr("Impossible d'importer le catalogue ")+ self.fic_cata)
158 self.appliEficas.close()
159 if self.appliEficas.salome == 0 :
162 # analyse du catalogue (ordre des mots-cles)
164 # Retrouve_Ordre_Cata_Standard fait une analyse textuelle du catalogue
165 # remplace par Retrouve_Ordre_Cata_Standard_autre qui utilise une numerotation
166 # des mots cles a la creation
167 self.Retrouve_Ordre_Cata_Standard_autre()
168 if self.mode_nouv_commande== "initial" : self.Retrouve_Ordre_Cata_Standard()
169 if hasattr(self.cata, 'Ordre_Des_Commandes') : self.Ordre_Des_Commandes=self.cata.Ordre_Des_Commandes
170 else : self.Ordre_Des_Commandes=None
172 if hasattr(self.cata, 'Classement_Commandes_Ds_Arbre') :
173 self.Classement_Commandes_Ds_Arbre=self.cata.Classement_Commandes_Ds_Arbre
174 else : self.Classement_Commandes_Ds_Arbre=()
175 #print self.cata.Ordre_Des_Commandes
178 # analyse des donnees liees l'IHM : UIinfo
180 uiinfo.traite_UIinfo(self.cata)
183 # traitement des clefs documentaires
185 if self.code == "ASTER" : self.traite_clefs_documentaires()
186 self.cata=(self.cata,)
188 self.titre=self.VERSION_EFICAS+" "+tr( " avec le catalogue ") + os.path.basename(self.fic_cata)
189 if self.appliEficas.top:
190 self.appliEficas.setWindowTitle(self.titre)
191 self.appliEficas.titre=self.titre
192 self.QWParent.titre=self.titre
194 def determineMater(self) :
195 # Determinination du repertoire materiau
196 v_codeSansPoint=self.version_code
197 if v_codeSansPoint == None : return
198 v_codeSansPoint=re.sub("\.","",v_codeSansPoint)
199 chaine="rep_mat_"+v_codeSansPoint
200 if hasattr(self.appliEficas.CONFIGURATION,chaine):
201 a=getattr(self.appliEficas.CONFIGURATION,chaine)
204 a=self.appliEficas.CONFIGURATION.dRepMat[self.version_code]
206 if self.code == "ASTER" :
207 print ("Probleme avec le repertoire materiau")
209 self.appliEficas.CONFIGURATION.rep_mat=a
211 def import_cata(self,cata):
213 Realise l'import du catalogue dont le chemin d'acces est donne par cata
215 nom_cata = os.path.splitext(os.path.basename(cata))[0]
216 rep_cata = os.path.dirname(cata)
217 sys.path[:0] = [rep_cata]
218 self.appliEficas.listeAEnlever.append(rep_cata)
221 if sys.modules.has_key(nom_cata):
222 del sys.modules[nom_cata]
223 for k in sys.modules.keys():
224 if k[0:len(nom_cata)+1] == nom_cata+'.':
227 mesScriptsNomFichier='mesScripts_'+self.code.upper()
228 if self.code == "ASTER" :
229 self.appliEficas.rep_scripts=os.path.join(rep_cata,nom_cata)
230 sys.path[:0] = [self.appliEficas.rep_scripts]
232 self.appliEficas.mesScripts[self.code]=__import__(mesScriptsNomFichier)
235 sys.path=sys.path[1:]
238 self.appliEficas.mesScripts[self.code]=__import__(mesScriptsNomFichier)
243 o=__import__(nom_cata)
245 except Exception as e:
246 traceback.print_exc()
251 def Retrouve_Ordre_Cata_Standard_autre(self):
253 Construit une structure de donnees dans le catalogue qui permet
254 a EFICAS de retrouver l'ordre des mots-cles dans le texte du catalogue.
255 Pour chaque entite du catlogue on cree une liste de nom ordre_mc qui
256 contient le nom des mots cles dans le bon ordre
258 self.cata_ordonne_dico,self.appliEficas.liste_simp_reel=autre_analyse_cata.analyse_catalogue(self.cata)
260 def Retrouve_Ordre_Cata_Standard(self):
262 Retrouve l'ordre des mots-cles dans le catalogue, cad :
263 Attention s appuie sur les commentaires
265 nom_cata = os.path.splitext(os.path.basename(self.fic_cata))[0]
266 rep_cata = os.path.dirname(self.fic_cata)
267 self.Commandes_Ordre_Catalogue = analyse_catalogue_initial.analyse_catalogue(self.fic_cata)
268 #print self.Commandes_Ordre_Catalogue
270 def ask_choix_catalogue(self, cata_choice_list):
272 Ouvre une fenetre de selection du catalogue dans le cas où plusieurs
273 ont ete definis dans Accas/editeur.ini
275 code = getattr(self.appliEficas.CONFIGURATION, "code", None)
277 title=tr("Choix d une version du code ")+str(code)
279 title=tr("Choix d une version ")
281 widgetChoix = MonChoixCata(self.appliEficas, [cata.user_name for cata in cata_choice_list], title)
282 ret=widgetChoix.exec_()
284 lab=str(self.VERSION_EFICAS)+" "
287 lab+=tr(" avec le catalogue ")
288 if ret == QDialog.Accepted:
289 cata = cata_choice_list[widgetChoix.CBChoixCata.currentIndex()]
290 self.version_cata = cata.identifier
291 self.fic_cata = cata.cata_file_path
292 self.version_code = self.version_cata
293 self.appliEficas.format_fichier = cata.file_format
294 self.appliEficas.format_fichier_in = cata.file_format_in
295 lab+=self.version_cata
296 self.appliEficas.setWindowTitle(lab)
297 #qApp.mainWidget().setCaption(lab)
299 raise EficasException()
302 def traite_clefs_documentaires(self):
304 fic_doc='rep_doc_'+str(self.version_code)
305 self.fic_doc=getattr(self.appliEficas.CONFIGURATION,fic_doc )
308 print ("Pas de fichier associe contenant des clefs documentaires")
312 for l in f.readlines():
316 dict_clef_docu[clef]=docu
317 for oper in self.cata.JdC.commandes:
318 if dict_clef_docu.has_key(oper.nom):
319 oper.docu=dict_clef_docu[oper.nom]
321 def cree_dico_inverse(self):
324 listeEtapes=self.cata[0].JdC.commandes
325 for e in self.cata[0].JdC.commandes:
326 self.traite_entite(e)
328 #self.dicoFrancaisAnglais={}
329 #self.dicoAnglaisFrancais={}
330 #for k in self.dicoInverse.keys():
332 # for nom, obj in self.dicoInverse[k] :
333 # listefr.append((tr(nom),obj))
334 # self.dicoFrancaisAnglais[tr(nom)]=nom
335 # self.dicoAnglaisFrancais[nom]=tr(nom)
336 # self.dicoInverseFrancais[tr(k)]=listefr
337 # #print tr(k),listefr
340 def cree_dico_CasToCata(self):
341 if self.appliEficas.langue=="ang" :
342 from dicoCasEnToCata import dicoCasEnToCata as dicoCasToCata
344 from dicoCasFrToCata import dicoCasFrToCata as dicoCasToCata
345 self.dicoCasToCata=dicoCasToCata
350 def traite_entite(self,e):
352 for (nomFils, fils) in e.entites.items() :
353 self.dicoMC[nomFils]=fils
354 self.traite_entite(fils)
359 while hasattr(moi,'pere') :
360 liste.append((moi.nom,moi))
362 liste.append((moi.nom,moi))
363 self.dicoInverse[e.nom]=liste
364 self.dicoInverse[tr(e.nom)]=liste
366 def cree_rubrique(self,e,dico, niveau):
367 from Accas import A_BLOC
370 # if isinstance(e,A_BLOC.BLOC): print decale, e.condition
371 # else : print decale, e. nom
372 for (nom, fils) in e.entites.items() :
373 if fils.entites.items() != [] : self.cree_rubrique(fils,dico,niveau+1)
374 #else : print (niveau+1)*" ", nom