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
46 from PyQt4.QtGui import *
47 from PyQt4.QtCore import *
52 def __init__(self,QWParent, appliEficas):
53 self.QWParent=QWParent
54 self.appliEficas=self.QWParent.appliEficas
55 self.VERSION_EFICAS=self.appliEficas.VERSION_EFICAS
56 self.code=self.QWParent.code
57 self.ssCode=self.appliEficas.ssCode
58 self.appliEficas.format_fichier='python'
59 if hasattr(self.appliEficas,'mode_nouv_commande'):
60 self.mode_nouv_commande=self.appliEficas.mode_nouv_commande
62 self.mode_nouv_commande='alpha'
63 self.version_code=self.QWParent.version_code
64 self.version_cata=None
71 Ouvre le catalogue standard du code courant, cad le catalogue present
72 dans le repertoire Cata
75 liste_cata_possibles=[]
76 self.Commandes_Ordre_Catalogue=[]
79 for catalogue in self.appliEficas.CONFIGURATION.catalogues:
80 if isinstance(catalogue, CatalogDescription):
81 all_cata_list.append(catalogue)
82 elif isinstance(catalogue, types.TupleType):
83 all_cata_list.append(CatalogDescription.create_from_tuple(catalogue))
85 print "Catalog description cannot be interpreted: ", catalogue
87 # This filter is only useful for codes that have subcodes (like MAP).
88 # Otherwise, the "code" attribute of the catalog description can (should) be None.
89 if self.ssCode is None:
90 liste_cata_possibles = all_cata_list
92 for catalogue in all_cata_list:
93 if catalogue.code == self.code and catalogue.file_format == self.ssCode:
94 liste_cata_possibles.append(catalogue)
96 if len(liste_cata_possibles)==0:
97 QMessageBox.critical(self.QWParent, tr("Import du catalogue"),
98 tr("Pas de catalogue defini pour le code ") + self.code)
99 self.appliEficas.close()
100 if self.appliEficas.salome == 0 :
105 if self.version_code is not None:
106 # La version a ete fixee
107 for cata in liste_cata_possibles:
108 if self.version_code == cata.identifier:
109 self.fic_cata = cata.cata_file_path
110 self.appliEficas.format_fichier = cata.file_format
111 self.appliEficas.format_fichier_in = cata.file_format_in
113 cata_choice_list = []
114 for cata in liste_cata_possibles:
117 cata_choice_list.insert(0, cata)
119 cata_choice_list.append(cata)
120 if len(cata_choice_list) == 0:
121 QMessageBox.critical(self.QWParent, tr("Import du catalogue"),
122 tr("Aucun catalogue trouve"))
123 self.appliEficas.close()
124 if self.appliEficas.salome == 0 :
126 elif len(cata_choice_list) == 1:
127 self.fic_cata = cata_choice_list[0].cata_file_path
128 self.version_code = cata_choice_list[0].identifier
129 self.appliEficas.format_fichier = cata_choice_list[0].file_format
130 self.appliEficas.format_fichier_in = cata_choice_list[0].file_format_in
132 # plusieurs catalogues sont disponibles : il faut demander a l'utilisateur
133 # lequel il veut utiliser ...
134 self.ask_choix_catalogue(cata_choice_list)
136 if self.fic_cata == None :
137 if self.appliEficas.salome == 0 :
138 print "Pas de catalogue pour code %s, version %s" %(self.code,self.version_code)
141 self.appliEficas.close()
144 if self.code == "ASTER" : self.determineMater()
146 # import du catalogue
147 self.cata = self.import_cata(self.fic_cata)
149 QMessageBox.critical( self.QWParent, tr("Import du catalogue"),tr("Impossible d'importer le catalogue ")+ self.fic_cata)
150 self.appliEficas.close()
151 if self.appliEficas.salome == 0 :
154 # analyse du catalogue (ordre des mots-cles)
156 # Retrouve_Ordre_Cata_Standard fait une analyse textuelle du catalogue
157 # remplace par Retrouve_Ordre_Cata_Standard_autre qui utilise une numerotation
158 # des mots cles a la creation
159 self.Retrouve_Ordre_Cata_Standard_autre()
160 if self.mode_nouv_commande== "initial" :
161 self.Retrouve_Ordre_Cata_Standard()
164 # analyse des donnees liees l'IHM : UIinfo
166 uiinfo.traite_UIinfo(self.cata)
169 # traitement des clefs documentaires
171 if self.code == "ASTER" : self.traite_clefs_documentaires()
172 self.cata=(self.cata,)
174 self.titre=self.VERSION_EFICAS+" "+tr( " avec le catalogue ") + os.path.basename(self.fic_cata)
175 if self.appliEficas.top:
176 self.appliEficas.setWindowTitle(self.titre)
177 self.appliEficas.titre=self.titre
178 self.QWParent.titre=self.titre
180 def determineMater(self) :
181 # Determinination du repertoire materiau
182 v_codeSansPoint=self.version_code
183 if v_codeSansPoint == None : return
184 v_codeSansPoint=re.sub("\.","",v_codeSansPoint)
185 chaine="rep_mat_"+v_codeSansPoint
186 if hasattr(self.appliEficas.CONFIGURATION,chaine):
187 a=getattr(self.appliEficas.CONFIGURATION,chaine)
190 a=self.appliEficas.CONFIGURATION.dRepMat[self.version_code]
192 if self.code == "ASTER" :
193 print "Probleme avec le repertoire materiau"
195 self.appliEficas.CONFIGURATION.rep_mat=a
197 def import_cata(self,cata):
199 Realise l'import du catalogue dont le chemin d'acces est donne par cata
201 nom_cata = os.path.splitext(os.path.basename(cata))[0]
202 rep_cata = os.path.dirname(cata)
203 sys.path[:0] = [rep_cata]
204 self.appliEficas.listeAEnlever.append(rep_cata)
207 if sys.modules.has_key(nom_cata):
208 del sys.modules[nom_cata]
209 for k in sys.modules.keys():
210 if k[0:len(nom_cata)+1] == nom_cata+'.':
213 mesScriptsNomFichier='mesScripts_'+self.code.upper()
214 if self.code == "ASTER" :
215 self.appliEficas.rep_scripts=os.path.join(rep_cata,nom_cata)
216 sys.path[:0] = [self.appliEficas.rep_scripts]
218 self.appliEficas.mesScripts=__import__(mesScriptsNomFichier)
221 sys.path=sys.path[1:]
224 self.appliEficas.mesScripts=__import__(mesScriptsNomFichier)
229 o=__import__(nom_cata)
232 traceback.print_exc()
237 def Retrouve_Ordre_Cata_Standard_autre(self):
239 Construit une structure de donnees dans le catalogue qui permet
240 a EFICAS de retrouver l'ordre des mots-cles dans le texte du catalogue.
241 Pour chaque entite du catlogue on cree une liste de nom ordre_mc qui
242 contient le nom des mots cles dans le bon ordre
244 self.cata_ordonne_dico,self.appliEficas.liste_simp_reel=autre_analyse_cata.analyse_catalogue(self.cata)
246 def Retrouve_Ordre_Cata_Standard(self):
248 Retrouve l'ordre des mots-cles dans le catalogue, cad :
249 Attention s appuie sur les commentaires
251 nom_cata = os.path.splitext(os.path.basename(self.fic_cata))[0]
252 rep_cata = os.path.dirname(self.fic_cata)
253 self.Commandes_Ordre_Catalogue = analyse_catalogue_initial.analyse_catalogue(self.fic_cata)
255 def ask_choix_catalogue(self, cata_choice_list):
257 Ouvre une fenetre de selection du catalogue dans le cas où plusieurs
258 ont ete definis dans Accas/editeur.ini
260 code = getattr(self.appliEficas.CONFIGURATION, "code", None)
262 title=tr("Choix d une version du code ")+str(code)
264 title=tr("Choix d une version ")
266 widgetChoix = MonChoixCata(self.appliEficas, [cata.user_name for cata in cata_choice_list], title)
267 ret=widgetChoix.exec_()
269 lab=QString(self.VERSION_EFICAS)+" "
271 lab+=QString(self.code)
272 lab+=tr(" avec le catalogue ")
273 if ret == QDialog.Accepted:
274 cata = cata_choice_list[widgetChoix.CBChoixCata.currentIndex()]
275 self.version_cata = cata.identifier
276 self.fic_cata = cata.cata_file_path
277 self.version_code = self.version_cata
278 self.appliEficas.format_fichier = cata.file_format
279 self.appliEficas.format_fichier_in = cata.file_format_in
280 lab+=self.version_cata
281 self.appliEficas.setWindowTitle(lab)
282 #qApp.mainWidget().setCaption(lab)
284 raise EficasException()
286 def traite_clefs_documentaires(self):
288 fic_doc='rep_doc_'+str(self.version_code)
289 self.fic_doc=getattr(self.appliEficas.CONFIGURATION,fic_doc )
292 print "Pas de fichier associe contenant des clefs documentaires"
296 for l in f.readlines():
300 dict_clef_docu[clef]=docu
301 for oper in self.cata.JdC.commandes:
302 if dict_clef_docu.has_key(oper.nom):
303 oper.docu=dict_clef_docu[oper.nom]