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
22 Ce module contient la classe mixin MCSIMP qui porte les méthodes
23 nécessaires pour réaliser la validation d'un objet de type MCSIMP
26 Une classe mixin porte principalement des traitements et est
27 utilisée par héritage multiple pour composer les traitements.
33 from Noyau import N_CR
34 from Noyau.N_Exception import AsException
35 from Noyau.N_VALIDATOR import ValError,TypeProtocol,CardProtocol,IntoProtocol
36 from Noyau.N_VALIDATOR import listProto
37 from Noyau.strfunc import ufmt
40 from Extensions.i18n import tr
46 print (tr(u"None n'est pas une valeur autorisée"))
51 Cette classe est quasiment identique à la classe originale d'EFICAS
52 a part quelques changements cosmétiques et des chagements pour la
53 faire fonctionner de facon plus autonome par rapport à l'environnement
56 A mon avis, il faudrait aller plus loin et réduire les dépendances
57 amont au strict nécessaire.
59 - Est il indispensable de faire l'évaluation de la valeur dans le contexte
60 du jdc dans cette classe.
62 - Ne pourrait on pas doter les objets en présence des méthodes suffisantes
63 pour éviter les tests un peu particuliers sur GEOM, PARAMETRE et autres. J'ai
64 d'ailleurs modifié la classe pour éviter l'import de GEOM
70 self.state='undetermined'
71 self.typeProto=TypeProtocol("type",typ=self.definition.type)
72 self.intoProto=IntoProtocol("into",into=self.definition.into,val_min=self.definition.val_min,val_max=self.definition.val_max)
73 self.cardProto=CardProtocol("card",min=self.definition.min,max=self.definition.max)
76 if hasattr(self,'valid'):
82 def set_valid(self,valid):
83 old_valid=self.get_valid()
85 self.state = 'unchanged'
86 if not old_valid or old_valid != self.valid :
89 def isvalid(self,cr='non'):
91 Cette méthode retourne un indicateur de validité de l'objet de type MCSIMP
93 - 0 si l'objet est invalide
94 - 1 si l'objet est valide
96 Le paramètre cr permet de paramétrer le traitement. Si cr == 'oui'
97 la méthode construit également un comte-rendu de validation
98 dans self.cr qui doit avoir été créé préalablement.
100 if self.state == 'unchanged':
105 # verification presence
106 if self.isoblig() and v == None :
108 self.cr.fatal(_(tr(u"Mot-clé : %s obligatoire non valorisé")), self.nom)
111 lval=listProto.adapt(v)
112 #Pour tenir compte des Tuples
113 if hasattr(self.definition.type[0],'ntuple') :
115 if not (type(lval[0]) is tuple) : lval=(lval,)
121 self.cr.fatal(_(tr(u"None n'est pas une valeur autorisée")))
124 #typeProto=TypeProtocol("type",typ=self.definition.type)
125 #intoProto=IntoProtocol("into",into=self.definition.into,val_min=self.definition.val_min,val_max=self.definition.val_max)
126 #cardProto=CardProtocol("card",min=self.definition.min,max=self.definition.max)
127 #typeProto=self.definition.typeProto
128 #intoProto=self.definition.intoProto
129 #cardProto=self.definition.cardProto
130 typeProto=self.typeProto
131 intoProto=self.intoProto
132 cardProto=self.cardProto
134 #un cr est demandé : on collecte tous les types d'erreur
147 #self.cr.fatal(unicode(e))
149 cardProto.adapt(lval)
153 #self.cr.fatal(unicode(e))
155 # On verifie les validateurs s'il y en a et si necessaire (valid == 1)
157 if valid and self.definition.validators:
159 self.definition.validators.convert(lval)
161 self.cr.fatal(_(tr(u"Mot-clé %s invalide : %s\nCritère de validité: %s")),
162 self.nom, str(e), self.definition.validators.info())
165 #si pas de cr demande, on sort a la toute premiere erreur
170 cardProto.adapt(lval)
171 if self.definition.validators:
172 if hasattr(self.definition.validators,'set_MCSimp'):
173 self.definition.validators.set_MCSimp(self)
174 self.definition.validators.convert(lval)
178 self.set_valid(valid)
182 """ indique si le mot-clé est obligatoire
184 return self.definition.statut=='o'
186 def init_modif_up(self):
188 Propage l'état modifié au parent s'il existe et n'est l'objet
191 if self.parent and self.parent != self :
192 self.parent.state = 'modified'
195 """ génère le rapport de validation de self """
197 self.cr.debut = tr("Mot-clef simple : ")+tr(self.nom)
198 self.cr.fin = tr(u"Fin Mot-clé simple : ")+tr(self.nom)
199 self.state = 'modified'
201 self.isvalid(cr='oui')
202 except AsException,e:
203 if CONTEXT.debug : traceback.print_exc()
204 self.cr.fatal(_(tr(u"Mot-clé simple : %s %s")), self.nom, e)