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
20 from __future__ import absolute_import
25 def number_entite(entite):
27 Fonction qui attribue un numero unique a tous les objets du catalogue
28 Ce numero permet de conserver l'ordre des objets
39 if hasattr(self,'docu') :
40 if self.docu != "" : return self.docu
42 if hasattr(self,'pere'):
43 return self.pere.get_docu()
50 if hasattr(self,'sug') :
51 if self.sug != "" : return self.sug
54 def check_definition(self, parent):
55 """Verifie la definition d'un objet composite (commande, fact, bloc)."""
56 args = self.entites.copy()
58 for nom, val in args.items():
59 if val.label == 'SIMP':
62 #if val.max != 1 and val.type == 'TXM':
63 #print "#CMD", parent, nom
64 elif val.label == 'FACT':
65 val.check_definition(parent)
68 #assert self.label != 'FACT', \
69 # 'Commande %s : Mot-clef facteur present sous un mot-clef facteur : interdit !' \
74 # seuls les blocs peuvent entrer en conflit avec les mcs du plus haut niveau
75 for nom, val in args.items():
76 if val.label == 'BLOC':
77 mcbloc = val.check_definition(parent)
79 #print "#BLOC", parent, re.sub('\s+', ' ', val.condition)
80 #assert mcs.isdisjoint(mcbloc), "Commande %s : Mot(s)-clef(s) vu(s) plusieurs fois : %s" \
81 # % (parent, tuple(mcs.intersection(mcbloc)))
84 def enregistreXML(self,root,catalogueXml):
85 import xml.etree.ElementTree as ET
87 moi=ET.SubElement(root,str(self.__class__))
88 nom=ET.SubElement(moi,'nom')
91 if hasattr(self,'validators') and (self.validators != () and self.validators != None):
92 valid=ET.SubElement(moi,'validators')
93 valid.text= str(self.validators.__class__)
94 catalogueXml.validatorsUtilises.append(self.validators)
96 if hasattr(self,'regles') and (self.regles !=() and self.regles != None):
97 for regle in self.regles:
98 regle.enregistreXML(moi,catalogueXml)
99 catalogueXml.reglesUtilisees.append(self.regles)
101 if ((self.get_docu() !="" and self.get_docu() !=None) or \
102 (self.fr != "" and self.fr != None) or \
103 (self.ang != "" and self.ang != None) ):
105 if self.get_docu() !=None : dico["docu"]=self.get_docu()
106 if self.fr != None : dico["fr"]=six.text_type(self.fr,"iso-8859-1")
107 if self.ang != None : dico["ang"]=self.ang
108 doc=ET.SubElement(moi,'doc')
111 if ((self.get_sug() !=None) or \
112 (hasattr(self,'defaut') and (self.defaut != None) and (self.defaut != 'None'))) :
113 # il faut ajouter des sug dans le catalogue
114 # les attributs sont toujours du texte
116 if (self.defaut != None) and (self.defaut != 'None') :
117 if isinstance(self.defaut,str ) : dico["defaut"]=six.text_type(self.defaut,"iso-8859-1")
118 else :dico["defaut"]=str(self.defaut)
119 if self.get_sug() !=None:
120 if isinstance(self.get_sug(),str ) : dico["sug"]=six.text_type(self.get_sug(),"iso-8859-1")
121 else :dico["sug"]=str(self.get_sug())
123 doc=ET.SubElement(moi,'ValeurDef')
127 if hasattr(self,'into') and self.into!=None: dico['into']=str(self.into)
128 if hasattr(self,'val_max') and self.val_max != "**" : dico['max']=str(self.val_max)
129 if hasattr(self,'val_min') and self.val_min != "**" : dico['min']=str(self.val_min)
131 PV=ET.SubElement(moi,'PlageValeur')
135 if hasattr(self,'max') and self.max != 1 : dico['max']=str(self.max)
136 if hasattr(self,'min') and self.min != 1 : dico['max']=str(self.min)
138 Card=ET.SubElement(moi,'Cardinalite')
142 if hasattr(self,'reentrant') and self.reentrant not in ('f','n') : dico['reentrant']=str(self.reentrant)
143 if hasattr(self,'position') and self.position != "local": dico['position']=str(self.position)
144 if hasattr(self,'homo') and self.homo != 1 : dico['homogene']=str(self.homo)
145 if hasattr(self,'statut') : dico['statut']=str(self.statut)
146 if hasattr(self,'repetable') : dico['repetable']=str(self.repetable)
148 pos=ET.SubElement(moi,'situation')
151 if hasattr(self,'type') and self.type != ():
152 typeAttendu=ET.SubElement(moi,'typeAttendu')
155 if type(t) == type : l.append(t.__name__)
157 typeAttendu.text=str(l)
159 if hasattr(self,'sd_prod') and self.sd_prod != () and self.sd_prod !=None:
160 typeCree=ET.SubElement(moi,'typeCree')
161 typeCree.text=str(self.sd_prod.__name__)
163 if hasattr(self,'op') and self.op !=None :
164 subRoutine=ET.SubElement(moi,'subRoutine')
165 subRoutine.text=str(self.op)
167 if hasattr(self,'proc') and self.proc != None :
168 construction=ET.SubElement(moi,'Construction')
169 construction.text=self.proc.uri
171 for nomFils, fils in self.entites.items() :
172 fils.enregistreXML(moi,catalogueXml)
174 def enregistreXMLStructure(self,root,catalogueXml):
175 import xml.etree.ElementTree as ET
177 moi=ET.SubElement(root,str(self.__class__))
179 if hasattr(self,'into') and self.into!=None:
180 INTO=ET.SubElement(moi,'into')
184 if hasattr(self,'val_max') and self.val_max != "**" : dico['max']=str(self.val_max)
185 if hasattr(self,'val_min') and self.val_min != "**" : dico['min']=str(self.val_min)
187 PV=ET.SubElement(moi,'maxOrMin')
191 if hasattr(self,'max') and self.max != 1 : dico['max']=str(self.max)
192 if hasattr(self,'min') and self.min != 1 : dico['max']=str(self.min)
194 Card=ET.SubElement(moi,'liste')
198 if hasattr(self,'statut') and self.statut=="f" :
199 statut=ET.SubElement(moi,'facultatif')
200 statut.text='facultatif'
201 if hasattr(self,'statut') and self.statut !="f" :
202 statut=ET.SubElement(moi,'obligatoire')
203 statut.text='obligatoire'
205 if hasattr(self,'type') and self.type != ():
207 if 'Fichier' in self.type : ty=ET.SubElement(moi,'Fichier')
211 if 'Repertoire' in self.type : ty=ET.SubElement(moi,'Repertoire')
215 if t == "I" : ty=ET.SubElement(moi,'typeEntier')
216 elif t == "R" : ty=ET.SubElement(moi,'typeReel')
217 elif t == "TXM" : ty=ET.SubElement(moi,'typeTXM')
220 ty=ET.SubElement(moi,t.__name__)
222 ty=ET.SubElement(moi,'autre')
225 if hasattr(self,'sd_prod') and self.sd_prod != () and self.sd_prod !=None:
226 typeCree=ET.SubElement(moi,'typeCree')
227 typeCree.text='sd_prod'
229 if hasattr(self,'op') and self.op !=None :
230 subRoutine=ET.SubElement(moi,'subRoutine')
233 if hasattr(self,'proc') and self.proc != None :
234 construction=ET.SubElement(moi,'Construction')
235 construction.text='proc'
237 for nomFils, fils in self.entites.items() :
238 fils.enregistreXMLStructure(moi,catalogueXml)