Salome HOME
sauve0206
[tools/eficas.git] / Ihm / I_AVANT.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 import types
22
23
24 class I_AVANT:
25    """
26       La règle I_AVANT vérifie que l'on trouve l ordre  des mots-clés
27       de la règle parmi les arguments d'un JDC.
28
29       Ces arguments sont transmis à la règle pour validation sous la forme 
30       d'une liste de noms de mots-clés ou d'un dictionnaire dont 
31       les clés sont des noms de mots-clés.
32    """
33
34    def __init__(self,*args):
35       if len(args) > 2 :
36         print "Erreur à la création de la règle A_CLASSER(",args,")"
37         return
38       if type(args[0]) == types.TupleType:
39          self.listeAvant=args[0]
40       else :
41          self.listeAvant=(args[0],)
42       if type(args[1]) == types.TupleType:
43          self.listeApres=args[1]
44       else :
45          self.listeApres=(args[1],)
46
47    def verif(self,args):
48       """
49           args peut etre un dictionnaire ou une liste. Les éléments de args
50           sont soit les éléments de la liste soit les clés du dictionnaire.
51       """
52       #  on compte le nombre de mots cles presents
53       text =''
54       boolListeAvant=0
55       boolListeApres=0
56       boolOK=1
57       for nom in args:
58           if nom in self.listeAvant :
59              boolListeAvant=1
60              if boolListeApres == 1 :
61                 boolOK = 0
62           if nom in self.listeApres :
63              boolListeApres=1
64       if boolListeAvant == 0 and boolListeApres == 1 : boolOK = 0
65       return text,boolOK
66
67
68    def gettext(self):
69        text = "Regle de classement "' :\n'
70        for mc in self.listeAvant : 
71            text = text + mc + ', '
72        text = text  + " \nAvant : \n" 
73        for mc in self.listeApres : 
74            text = text + mc + ','
75        return text
76