1 # -*- coding: iso-8859-1 -*-
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 contient la classe ENTITE qui est la classe de base
22 de toutes les classes de definition d'EFICAS.
30 from strfunc import ufmt
34 Classe de base pour tous les objets de definition : mots cles et commandes
35 Cette classe ne contient que des methodes utilitaires
36 Elle ne peut être instanciee et doit d abord être specialisee
39 factories={'validator':N_VALIDATOR.validatorFactory}
41 def __init__(self,validators=None):
43 Initialise les deux attributs regles et entites d'une classe dérivée
44 à : pas de règles et pas de sous-entités.
46 L'attribut regles doit contenir la liste des regles qui s'appliquent
49 L'attribut entités doit contenir le dictionnaires des sous-entités
50 (clé = nom, valeur=objet)
55 self.validators=self.factories['validator'](validators)
57 self.validators=validators
59 def affecter_parente(self):
61 Cette methode a pour fonction de donner un nom et un pere aux
62 sous entités qui n'ont aucun moyen pour atteindre leur parent
64 Il s'agit principalement des mots cles
66 for k,v in self.entites.items():
72 Cette methode sert à valider les attributs de l'objet de définition
74 raise NotImplementedError("La méthode verif_cata de la classe %s doit être implémentée"
75 % self.__class__.__name__)
79 Cette methode doit retourner un objet dérivé de la classe OBJECT
81 raise NotImplementedError("La méthode __call__ de la classe %s doit être implémentée"
82 % self.__class__.__name__)
86 Cette méthode construit pour tous les objets dérivés de ENTITE un
87 rapport de validation de la définition portée par cet objet
91 for k,v in self.entites.items() :
94 cr.debut = u"Début "+v.__class__.__name__+ ' : ' + k
95 cr.fin = u"Fin "+v.__class__.__name__+ ' : ' + k
98 self.cr.fatal(_(u"Impossible d'obtenir le rapport de %s %s"), k,`v`)
99 print "Impossible d'obtenir le rapport de %s %s" %(k,`v`)
103 def verif_cata_regles(self):
105 Cette méthode vérifie pour tous les objets dérivés de ENTITE que
106 les objets REGLES associés ne portent que sur des sous-entités
109 for regle in self.regles :
111 for mc in regle.mcs :
112 if not self.entites.has_key(mc) :
116 self.cr.fatal(_(u"Argument(s) non permis : %r pour la règle : %s"), l, txt)
118 def check_definition(self, parent):
119 """Verifie la definition d'un objet composite (commande, fact, bloc)."""
120 args = self.entites.copy()
122 for nom, val in args.items():
123 if val.label == 'SIMP':
126 #if val.max != 1 and val.type == 'TXM':
127 #print "#CMD", parent, nom
128 elif val.label == 'FACT':
129 val.check_definition(parent)
131 #assert self.label != 'FACT', \
132 #'Commande %s : Mot-clef facteur present sous un mot-clef facteur : interdit !' \
137 # seuls les blocs peuvent entrer en conflit avec les mcs du plus haut niveau
138 for nom, val in args.items():
139 if val.label == 'BLOC':
140 mcbloc = val.check_definition(parent)
142 #print "#BLOC", parent, re.sub('\s+', ' ', val.condition)
143 #assert mcs.isdisjoint(mcbloc), "Commande %s : Mot(s)-clef(s) vu(s) plusieurs fois : %s" \
144 # % (parent, tuple(mcs.intersection(mcbloc)))
147 def check_op(self, valmin=-9999, valmax=9999):
148 """Vérifie l'attribut op."""
149 if self.op is not None and \
150 (type(self.op) is not int or self.op < valmin or self.op > valmax):
151 self.cr.fatal(_(u"L'attribut 'op' doit être un entier "
152 u"compris entre %d et %d : %r"), valmin, valmax, self.op)
154 def check_proc(self):
155 """Vérifie l'attribut proc."""
156 if self.proc is not None and not isinstance(self.proc, N_OPS.OPS):
157 self.cr.fatal(_(u"L'attribut op doit être une instance d'OPS : %r"), self.proc)
159 def check_regles(self):
160 """Vérifie l'attribut regles."""
161 if type(self.regles) is not tuple:
162 self.cr.fatal(_(u"L'attribut 'regles' doit être un tuple : %r"),
166 """Vérifie l'attribut fr."""
167 if type(self.fr) not in (str, unicode):
168 self.cr.fatal(_(u"L'attribut 'fr' doit être une chaine de caractères : %r"),
171 def check_docu(self):
172 """Vérifie l'attribut docu."""
173 if type(self.docu) not in (str, unicode):
174 self.cr.fatal(_(u"L'attribut 'docu' doit être une chaine de caractères : %r"),
178 """Vérifie l'attribut proc."""
179 if type(self.nom) != types.StringType :
180 self.cr.fatal(_(u"L'attribut 'nom' doit être une chaine de caractères : %r"),
183 def check_reentrant(self):
184 """Vérifie l'attribut reentrant."""
185 if self.reentrant not in ('o', 'n', 'f'):
186 self.cr.fatal(_(u"L'attribut 'reentrant' doit valoir 'o','n' ou 'f' : %r"),
189 def check_statut(self, into=('o', 'f', 'c', 'd')):
190 """Vérifie l'attribut statut."""
191 if self.statut not in into:
192 self.cr.fatal(_(u"L'attribut 'statut' doit être parmi %s : %r"),
195 def check_condition(self):
196 """Vérifie l'attribut condition."""
197 if self.condition != None :
198 if type(self.condition) != types.StringType :
199 self.cr.fatal(_(u"L'attribut 'condition' doit être une chaine de caractères : %r"),
202 self.cr.fatal(_(u"La condition ne doit pas valoir None !"))
204 def check_min_max(self):
205 """Vérifie les attributs min/max."""
206 if type(self.min) != types.IntType :
208 self.cr.fatal(_(u"L'attribut 'min' doit être un entier : %r"), self.min)
209 if type(self.max) != types.IntType :
211 self.cr.fatal(_(u"L'attribut 'max' doit être un entier : %r"), self.max)
212 if self.min > self.max :
213 self.cr.fatal(_(u"Nombres d'occurrence min et max invalides : %r %r"),
216 def check_validators(self):
217 """Vérifie les validateurs supplémentaires"""
218 if self.validators and not self.validators.verif_cata():
219 self.cr.fatal(_(u"Un des validateurs est incorrect. Raison : %s"),
220 self.validators.cata_info)
222 def check_homo(self):
223 """Vérifie l'attribut homo."""
224 if self.homo != 0 and self.homo != 1 :
225 self.cr.fatal(_(u"L'attribut 'homo' doit valoir 0 ou 1 : %r"), self.homo)
227 def check_into(self):
228 """Vérifie l'attribut into."""
229 if self.into != None :
230 if type(self.into) != types.TupleType :
231 self.cr.fatal(_(u"L'attribut 'into' doit être un tuple : %r"), self.into)
233 def check_position(self):
234 """Vérifie l'attribut position."""
235 if self.position not in ('local', 'global', 'global_jdc'):
236 self.cr.fatal(_(u"L'attribut 'position' doit valoir 'local', 'global' "
237 u"ou 'global_jdc' : %r"), self.position)