Salome HOME
version 19 mars
[tools/eficas.git] / Validation / V_JDC.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 JDC qui porte les méthodes
23    nécessaires pour réaliser la validation d'un objet de type JDC
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.N_Exception import AsException
32 from Noyau.N_utils import AsType
33 from Noyau.strfunc import ufmt
34
35
36 try :
37   from Extensions.i18n import tr
38 except :
39   def tr(txt):
40     return txt
41
42
43 class JDC(V_MCCOMPO.MCCOMPO):
44    """
45    """
46
47    def report(self):
48       """
49           Methode pour generation d un rapport de validite
50       """
51       self.cr.purge()
52       self.cr.debut=tr("DEBUT CR validation : ")+self.nom
53       self.cr.fin=tr("FIN CR validation : ")+self.nom
54       for e in self.etapes :
55         if e.isactif():
56           self.cr.add(e.report())
57       self.state = 'modified'
58       self.isvalid(cr='oui')
59       return self.cr
60
61    def isvalid(self,cr='non'):
62       """
63         Méthode booléenne qui retourne 0 si le JDC est invalide, 1 sinon
64       """
65       # FR : on prend en compte l'état du JDC ('unchanged','modified','undetermined')
66       # afin d'accélérer le test de validité du JDC
67       if self.state == 'unchanged':
68         return self.valid
69       else:
70         valid = 1
71         texte,test = self.verif_regles()
72         if test == 0:
73           if cr == 'oui':
74               self.cr.fatal(' '.strip(texte))
75           valid = 0
76         if valid :
77           for e in self.etapes:
78             if not e.isactif() : continue
79             if not e.isvalid():
80               valid = 0
81               break
82         self.state="unchanged"
83         self.valid = valid
84         return self.valid
85
86    def verif_regles(self):
87       """
88       Effectue la vérification de validité des règles du jeu de commandes
89       """
90       noms_etapes = [etape.nom for etape in self.etapes]
91       texte_global = ''
92       test_global = 1
93       for regle in self.regles:
94         texte, test = regle.verif(noms_etapes)
95         texte_global = texte_global + texte
96         test_global = test_global*test
97       return texte_global, test_global
98