Salome HOME
gitignore V1
[tools/eficas.git] / Validation / V_MCFACT.py
1 # -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2013   EDF R&D
3 #
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.
8 #
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.
13 #
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
17 #
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #
20
21 """
22    Ce module contient la classe mixin MCFACT qui porte les méthodes
23    nécessaires pour réaliser la validation d'un objet de type MCFACT
24    dérivé de OBJECT.
25
26    Une classe mixin porte principalement des traitements et est
27    utilisée par héritage multiple pour composer les traitements.
28 """
29 # Modules EFICAS
30 import V_MCCOMPO
31 from Noyau.strfunc import ufmt
32
33 class MCFACT(V_MCCOMPO.MCCOMPO):
34    """
35       Cette classe a un attribut de classe :
36
37       - txt_nat qui sert pour les comptes-rendus liés à cette classe
38    """
39
40    txt_nat = u"Mot clé Facteur :"
41
42    def isvalid(self,sd='oui',cr='non'):
43       """
44          Methode pour verifier la validité du MCFACT. Cette méthode
45          peut etre appelée selon plusieurs modes en fonction de la valeur
46          de sd et de cr.
47
48          Si cr vaut oui elle crée en plus un compte-rendu
49          sd est présent pour compatibilité de l'interface mais ne sert pas
50       """
51       if self.state == 'unchanged' :
52         return self.valid
53       else:
54         valid = 1
55         if hasattr(self,'valid'):
56           old_valid = self.valid
57         else:
58           old_valid = None
59         for child in self.mc_liste :
60           if not child.isvalid():
61             valid = 0
62             break
63         # Après avoir vérifié la validité de tous les sous-objets, on vérifie
64         # la validité des règles
65         text_erreurs,test_regles = self.verif_regles()
66         if not test_regles :
67           if cr == 'oui' : self.cr.fatal(_(u"Règle(s) non respectée(s) : %s"), text_erreurs)
68           valid = 0
69         #
70         # On verifie les validateurs s'il y en a
71         #
72         if self.definition.validators and not self.definition.validators.verif(self.valeur):
73            if cr == 'oui' :
74               self.cr.fatal(_(u"Mot-clé : %s devrait avoir %s"),
75                                  self.nom, self.definition.validators.info())
76            valid=0
77         # fin des validateurs
78         #
79         if self.reste_val != {}:
80           if cr == 'oui' :
81             self.cr.fatal(_(u"Mots clés inconnus : %s"), ','.join(self.reste_val.keys()))
82           valid=0
83         self.valid = valid
84         self.state = 'unchanged'
85         if not old_valid or old_valid != self.valid :
86            self.init_modif_up()
87         return self.valid
88