Salome HOME
sauvegarde doc
[tools/eficas.git] / Noyau / N_MCFACT.py
1 # coding=utf-8
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 MCFACT qui sert à controler la valeur
23     d'un mot-clé facteur par rapport à sa définition portée par un objet
24     de type ENTITE
25 """
26
27 import N_MCCOMPO
28
29
30 class MCFACT(N_MCCOMPO.MCCOMPO):
31
32     """
33     """
34     nature = "MCFACT"
35
36     def __init__(self, val, definition, nom, parent):
37         """
38            Attributs :
39             - val : valeur du mot clé simple
40             - definition
41             - nom
42             - parent
43         """
44         self.definition = definition
45         self.nom = nom
46         self.val = val
47         self.parent = parent
48         self.valeur = self.GETVAL(self.val)
49         if parent:
50             self.jdc = self.parent.jdc
51             self.niveau = self.parent.niveau
52             self.etape = self.parent.etape
53         else:
54             # Le mot cle a été créé sans parent
55             self.jdc = None
56             self.niveau = None
57             self.etape = None
58         self.mc_liste = self.build_mc()
59
60     def GETVAL(self, val):
61         """
62             Retourne la valeur effective du mot-clé en fonction
63             de la valeur donnée. Defaut si val == None
64         """
65         if (val is None and hasattr(self.definition, 'defaut')):
66             return self.definition.defaut
67         else:
68             return val
69
70     def get_valeur(self):
71         """
72             Retourne la "valeur" d'un mot-clé facteur qui est l'objet lui-meme.
73             Cette valeur est utilisée lors de la création d'un contexte
74             d'évaluation d'expressions à l'aide d'un interpréteur Python
75         """
76         return self
77
78     def get_val(self):
79         """
80             Une autre méthode qui retourne une "autre" valeur du mot clé facteur.
81             Elle est utilisée par la méthode get_mocle
82         """
83         return [self]
84
85     def __getitem__(self, key):
86         """
87             Dans le cas d un mot cle facteur unique on simule une liste de
88             longueur 1
89         """
90         if key == 0:
91             return self
92         return self.get_mocle(key)
93
94     def accept(self, visitor):
95         """
96            Cette methode permet de parcourir l'arborescence des objets
97            en utilisant le pattern VISITEUR
98         """
99         visitor.visitMCFACT(self)
100
101     def makeobjet(self):
102         return self.definition.class_instance(val=None, nom=self.nom,
103                                               definition=self.definition, parent=self.parent)