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