Salome HOME
Merge V9 dans Master
[tools/eficas.git] / Ihm / I_AVANT.py
1 # -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2017   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 from __future__ import absolute_import
22 from __future__ import print_function
23 import types
24
25
26 class I_AVANT:
27    """
28       La regle I_AVANT verifie que l'on trouve l ordre  des mots-cles
29       de la regle parmi les arguments d'un JDC.
30
31       Ces arguments sont transmis a la regle pour validation sous la forme 
32       d'une liste de noms de mots-cles ou d'un dictionnaire dont 
33       les cles sont des noms de mots-cles.
34    """
35
36    def __init__(self,*args):
37       if len(args) > 2 :
38         print(("Erreur a la creation de la regle A_CLASSER(",args,")"))
39         return
40       if type(args[0]) == tuple:
41         self.listeAvant=args[0]
42       else :
43         self.listeAvant=(args[0],)
44       if type(args[1]) == tuple:
45         self.listeApres=args[1]
46       else :
47         self.listeApres=(args[1],)
48
49    def verif(self,args):
50       """
51           args peut etre un dictionnaire ou une liste. Les elements de args
52           sont soit les elements de la liste soit les cles du dictionnaire.
53       """
54       #  on compte le nombre de mots cles presents
55       text =''
56       boolListeAvant=0
57       boolListeApres=0
58       boolOK=1
59       for nom in args:
60           if nom in self.listeAvant :
61              boolListeAvant=1
62              if boolListeApres == 1 :
63                 boolOK = 0
64           if nom in self.listeApres :
65              boolListeApres=1
66       if boolListeAvant == 0 and boolListeApres == 1 : boolOK = 0
67       return text,boolOK
68
69
70    def getText(self):
71        text = "Regle de classement "' :\n'
72        for mc in self.listeAvant : 
73            text = text + mc + ', '
74        text = text  + " \nAvant : \n" 
75        for mc in self.listeApres : 
76            text = text + mc + ','
77        return text
78