1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2007-2021 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
24 def numberEntite(entite):
26 Fonction qui attribue un numero unique a tous les objets du catalogue
27 Ce numero permet de conserver l'ordre des objets
38 if hasattr(self,'docu') :
39 if self.docu != "" : return self.docu
41 if hasattr(self,'pere'):
42 return self.pere.getDocu()
49 if hasattr(self,'sug') :
50 if self.sug != "" : return self.sug
53 def checkDefinition(self, parent):
54 """Verifie la definition d'un objet composite (commande, fact, bloc)."""
55 args = self.entites.copy()
57 for nom, val in args.items():
58 if val.label == 'SIMP':
61 #if val.max != 1 and val.type == 'TXM':
62 #print "#CMD", parent, nom
63 elif val.label == 'FACT':
64 val.checkDefinition(parent)
67 #assert self.label != 'FACT', \
68 # 'Commande %s : Mot-clef facteur present sous un mot-clef facteur : interdit !' \
73 # seuls les blocs peuvent entrer en conflit avec les mcs du plus haut niveau
74 for nom, val in args.items():
75 if val.label == 'BLOC':
76 mcbloc = val.checkDefinition(parent)
78 #print "#BLOC", parent, re.sub('\s+', ' ', val.condition)
79 #assert mcs.isdisjoint(mcbloc), "Commande %s : Mot(s)-clef(s) vu(s) plusieurs fois : %s" \
80 # % (parent, tuple(mcs.intersection(mcbloc)))
83 # def enregistreXML(self,root,catalogueXml):
84 # import xml.etree.ElementTree as ET
86 # moi=ET.SubElement(root,str(self.__class__))
87 # nom=ET.SubElement(moi,'nom')
90 # if hasattr(self,'validators') and (self.validators != () and self.validators != None):
91 # valid=ET.SubElement(moi,'validators')
92 # valid.text= str(self.validators.__class__)
93 # catalogueXml.validatorsUtilises.append(self.validators)
95 # if hasattr(self,'regles') and (self.regles !=() and self.regles != None):
96 # for regle in self.regles:
97 # regle.enregistreXML(moi,catalogueXml)
98 # catalogueXml.reglesUtilisees.append(self.regles)
100 # if ((self.getDocu() !="" and self.getDocu() !=None) or \
101 # (self.fr != "" and self.fr != None) or \
102 # (self.ang != "" and self.ang != None) ):
104 # if self.getDocu() !=None : dico["docu"]=self.getDocu()
105 # if self.fr != None : dico["fr"]=six.text_type(self.fr,"iso-8859-1")
106 # if self.ang != None : dico["ang"]=self.ang
107 # doc=ET.SubElement(moi,'doc')
110 # if ((self.getSug() !=None) or \
111 # (hasattr(self,'defaut') and (self.defaut != None) and (self.defaut != 'None'))) :
112 # # il faut ajouter des sug dans le catalogue
113 # # les attributs sont toujours du texte
115 # if (self.defaut != None) and (self.defaut != 'None') :
116 # if isinstance(self.defaut,str ) : dico["defaut"]=six.text_type(self.defaut,"iso-8859-1")
117 # else :dico["defaut"]=str(self.defaut)
118 # if self.getSug() !=None:
119 # if isinstance(self.getSug(),str ) : dico["sug"]=six.text_type(self.getSug(),"iso-8859-1")
120 # else :dico["sug"]=str(self.getSug())
122 # doc=ET.SubElement(moi,'ValeurDef')
126 # if hasattr(self,'into') and self.into!=None: dico['into']=str(self.into)
127 # if hasattr(self,'val_max') and self.val_max != "**" : dico['max']=str(self.val_max)
128 # if hasattr(self,'val_min') and self.val_min != "**" : dico['min']=str(self.val_min)
130 # PV=ET.SubElement(moi,'PlageValeur')
134 # if hasattr(self,'max') and self.max != 1 : dico['max']=str(self.max)
135 # if hasattr(self,'min') and self.min != 1 : dico['max']=str(self.min)
137 # Card=ET.SubElement(moi,'Cardinalite')
141 # if hasattr(self,'reentrant') and self.reentrant not in ('f','n') : dico['reentrant']=str(self.reentrant)
142 # if hasattr(self,'position') and self.position != "local": dico['position']=str(self.position)
143 # if hasattr(self,'homo') and self.homo != 1 : dico['homogene']=str(self.homo)
144 # if hasattr(self,'statut') : dico['statut']=str(self.statut)
145 # if hasattr(self,'repetable') : dico['repetable']=str(self.repetable)
147 # pos=ET.SubElement(moi,'situation')
150 # if hasattr(self,'type') and self.type != ():
151 # typeAttendu=ET.SubElement(moi,'typeAttendu')
153 # for t in self.type:
154 # if type(t) == type : l.append(t.__name__)
156 # typeAttendu.text=str(l)
158 # if hasattr(self,'sd_prod') and self.sd_prod != () and self.sd_prod !=None:
159 # typeCree=ET.SubElement(moi,'typeCree')
160 # typeCree.text=str(self.sd_prod.__name__)
162 # if hasattr(self,'op') and self.op !=None :
163 # subRoutine=ET.SubElement(moi,'subRoutine')
164 # subRoutine.text=str(self.op)
166 # if hasattr(self,'proc') and self.proc != None :
167 # construction=ET.SubElement(moi,'Construction')
168 # construction.text=self.proc.uri
170 # for nomFils, fils in self.entites.items() :
171 # fils.enregistreXML(moi,catalogueXml)
173 # def enregistreXMLStructure(self,root,catalogueXml):
174 # import xml.etree.ElementTree as ET
176 # moi=ET.SubElement(root,str(self.__class__))
178 # if hasattr(self,'into') and self.into!=None:
179 # INTO=ET.SubElement(moi,'into')
183 # if hasattr(self,'val_max') and self.val_max != "**" : dico['max']=str(self.val_max)
184 # if hasattr(self,'val_min') and self.val_min != "**" : dico['min']=str(self.val_min)
186 # PV=ET.SubElement(moi,'maxOrMin')
190 # if hasattr(self,'max') and self.max != 1 : dico['max']=str(self.max)
191 # if hasattr(self,'min') and self.min != 1 : dico['max']=str(self.min)
193 # Card=ET.SubElement(moi,'liste')
197 # if hasattr(self,'statut') and self.statut=="f" :
198 # statut=ET.SubElement(moi,'facultatif')
199 # statut.text='facultatif'
200 # if hasattr(self,'statut') and self.statut !="f" :
201 # statut=ET.SubElement(moi,'obligatoire')
202 # statut.text='obligatoire'
204 # if hasattr(self,'type') and self.type != ():
206 # if 'Fichier' in self.type : ty=ET.SubElement(moi,'Fichier')
210 # if 'Repertoire' in self.type : ty=ET.SubElement(moi,'Repertoire')
213 # for t in self.type:
214 # if t == "I" : ty=ET.SubElement(moi,'typeEntier')
215 # elif t == "R" : ty=ET.SubElement(moi,'typeReel')
216 # elif t == "TXM" : ty=ET.SubElement(moi,'typeTXM')
219 # ty=ET.SubElement(moi,t.__name__)
221 # ty=ET.SubElement(moi,'autre')
224 # if hasattr(self,'sd_prod') and self.sd_prod != () and self.sd_prod !=None:
225 # typeCree=ET.SubElement(moi,'typeCree')
226 # typeCree.text='sd_prod'
228 # if hasattr(self,'op') and self.op !=None :
229 # subRoutine=ET.SubElement(moi,'subRoutine')
230 # subRoutine.text='op'
232 # if hasattr(self,'proc') and self.proc != None :
233 # construction=ET.SubElement(moi,'Construction')
234 # construction.text='proc'
236 # for nomFils, fils in self.entites.items() :
237 # fils.enregistreXMLStructure(moi,catalogueXml)