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
23 def number_entite(entite):
25 Fonction qui attribue un numero unique a tous les objets du catalogue
26 Ce numero permet de conserver l'ordre des objets
37 if hasattr(self,'docu') :
38 if self.docu != "" : return self.docu
40 if hasattr(self,'pere'):
41 return self.pere.get_docu()
48 if hasattr(self,'sug') :
49 if self.sug != "" : return self.sug
52 def check_definition(self, parent):
53 """Verifie la definition d'un objet composite (commande, fact, bloc)."""
54 args = self.entites.copy()
56 for nom, val in args.items():
57 if val.label == 'SIMP':
60 #if val.max != 1 and val.type == 'TXM':
61 #print "#CMD", parent, nom
62 elif val.label == 'FACT':
63 val.check_definition(parent)
66 #assert self.label != 'FACT', \
67 # 'Commande %s : Mot-clef facteur present sous un mot-clef facteur : interdit !' \
72 # seuls les blocs peuvent entrer en conflit avec les mcs du plus haut niveau
73 for nom, val in args.items():
74 if val.label == 'BLOC':
75 mcbloc = val.check_definition(parent)
77 #print "#BLOC", parent, re.sub('\s+', ' ', val.condition)
78 #assert mcs.isdisjoint(mcbloc), "Commande %s : Mot(s)-clef(s) vu(s) plusieurs fois : %s" \
79 # % (parent, tuple(mcs.intersection(mcbloc)))
82 def enregistreXML(self,root,catalogueXml):
83 import xml.etree.ElementTree as ET
85 moi=ET.SubElement(root,str(self.__class__))
86 nom=ET.SubElement(moi,'nom')
89 if hasattr(self,'validators') and (self.validators != () and self.validators != None):
90 valid=ET.SubElement(moi,'validators')
91 valid.text= str(self.validators.__class__)
92 catalogueXml.validatorsUtilises.append(self.validators)
94 if hasattr(self,'regles') and (self.regles !=() and self.regles != None):
95 for regle in self.regles:
96 regle.enregistreXML(moi,catalogueXml)
97 catalogueXml.reglesUtilisees.append(self.regles)
99 if ((self.get_docu() !="" and self.get_docu() !=None) or \
100 (self.fr != "" and self.fr != None) or \
101 (self.ang != "" and self.ang != None) ):
103 if self.get_docu() !=None : dico["docu"]=self.get_docu()
104 if self.fr != None : dico["fr"]=unicode(self.fr,"iso-8859-1")
105 if self.ang != None : dico["ang"]=self.ang
106 doc=ET.SubElement(moi,'doc')
109 if ((self.get_sug() !=None) or \
110 (hasattr(self,'defaut') and (self.defaut != None) and (self.defaut != 'None'))) :
111 # il faut ajouter des sug dans le catalogue
112 # les attributs sont toujours du texte
114 if (self.defaut != None) and (self.defaut != 'None') :
115 if isinstance(self.defaut,str ) : dico["defaut"]=unicode(self.defaut,"iso-8859-1")
116 else :dico["defaut"]=str(self.defaut)
117 if self.get_sug() !=None:
118 if isinstance(self.get_sug(),str ) : dico["sug"]=unicode(self.get_sug(),"iso-8859-1")
119 else :dico["sug"]=str(self.get_sug())
121 doc=ET.SubElement(moi,'ValeurDef')
125 if hasattr(self,'into') and self.into!=None: dico['into']=str(self.into)
126 if hasattr(self,'val_max') and self.val_max != "**" : dico['max']=str(self.val_max)
127 if hasattr(self,'val_min') and self.val_min != "**" : dico['min']=str(self.val_min)
129 PV=ET.SubElement(moi,'PlageValeur')
133 if hasattr(self,'max') and self.max != 1 : dico['max']=str(self.max)
134 if hasattr(self,'min') and self.min != 1 : dico['max']=str(self.min)
136 Card=ET.SubElement(moi,'Cardinalite')
140 if hasattr(self,'reentrant') and self.reentrant not in ('f','n') : dico['reentrant']=str(self.reentrant)
141 if hasattr(self,'position') and self.position != "local": dico['position']=str(self.position)
142 if hasattr(self,'homo') and self.homo != 1 : dico['homogene']=str(self.homo)
143 if hasattr(self,'statut') : dico['statut']=str(self.statut)
144 if hasattr(self,'repetable') : dico['repetable']=str(self.repetable)
146 pos=ET.SubElement(moi,'situation')
149 if hasattr(self,'type') and self.type != ():
150 typeAttendu=ET.SubElement(moi,'typeAttendu')
153 if type(t) == types.TypeType : l.append(t.__name__)
155 typeAttendu.text=str(l)
157 if hasattr(self,'sd_prod') and self.sd_prod != () and self.sd_prod !=None:
158 typeCree=ET.SubElement(moi,'typeCree')
159 typeCree.text=str(self.sd_prod.__name__)
161 if hasattr(self,'op') and self.op !=None :
162 subRoutine=ET.SubElement(moi,'subRoutine')
163 subRoutine.text=str(self.op)
165 if hasattr(self,'proc') and self.proc != None :
166 construction=ET.SubElement(moi,'Construction')
167 construction.text=self.proc.uri
169 for nomFils, fils in self.entites.items() :
170 fils.enregistreXML(moi,catalogueXml)
172 def enregistreXMLStructure(self,root,catalogueXml):
173 import xml.etree.ElementTree as ET
175 moi=ET.SubElement(root,str(self.__class__))
177 if hasattr(self,'into') and self.into!=None:
178 INTO=ET.SubElement(moi,'into')
182 if hasattr(self,'val_max') and self.val_max != "**" : dico['max']=str(self.val_max)
183 if hasattr(self,'val_min') and self.val_min != "**" : dico['min']=str(self.val_min)
185 PV=ET.SubElement(moi,'maxOrMin')
189 if hasattr(self,'max') and self.max != 1 : dico['max']=str(self.max)
190 if hasattr(self,'min') and self.min != 1 : dico['max']=str(self.min)
192 Card=ET.SubElement(moi,'liste')
196 if hasattr(self,'statut') and self.statut=="f" :
197 statut=ET.SubElement(moi,'facultatif')
198 statut.text='facultatif'
199 if hasattr(self,'statut') and self.statut !="f" :
200 statut=ET.SubElement(moi,'obligatoire')
201 statut.text='obligatoire'
203 if hasattr(self,'type') and self.type != ():
205 if 'Fichier' in self.type : ty=ET.SubElement(moi,'Fichier')
209 if 'Repertoire' in self.type : ty=ET.SubElement(moi,'Repertoire')
213 if t == "I" : ty=ET.SubElement(moi,'typeEntier')
214 elif t == "R" : ty=ET.SubElement(moi,'typeReel')
215 elif t == "TXM" : ty=ET.SubElement(moi,'typeTXM')
218 ty=ET.SubElement(moi,t.__name__)
220 ty=ET.SubElement(moi,'autre')
223 if hasattr(self,'sd_prod') and self.sd_prod != () and self.sd_prod !=None:
224 typeCree=ET.SubElement(moi,'typeCree')
225 typeCree.text='sd_prod'
227 if hasattr(self,'op') and self.op !=None :
228 subRoutine=ET.SubElement(moi,'subRoutine')
231 if hasattr(self,'proc') and self.proc != None :
232 construction=ET.SubElement(moi,'Construction')
233 construction.text='proc'
235 for nomFils, fils in self.entites.items() :
236 fils.enregistreXMLStructure(moi,catalogueXml)