Salome HOME
.gitignore: test hook.
[tools/eficas.git] / Ihm / I_MCFACT.py
1 # -*- coding: utf-8 -*-
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 from __future__ import absolute_import
21 from Extensions.i18n import tr
22 from . import CONNECTOR
23 from . import I_MCCOMPO
24 import Noyau
25
26 class MCFACT(I_MCCOMPO.MCCOMPO):
27   def isRepetable(self):
28      """ 
29          Indique si l'objet est repetable.
30          Retourne 1 si le mot-cle facteur self peut etre repete
31          Retourne 0 dans le cas contraire
32      """
33      if self.definition.max > 1:
34        # marche avec '**'
35        return 1
36      else :
37        return 0
38
39   def isOblig(self):
40     if self.definition.statut != 'o' : return 0
41     objet = self.parent.getChild(self.nom)
42     if len(objet) > 1 : return 0
43     else : return 1
44
45   def getMinMax(self):
46      """
47      Retourne les valeurs min et max admissibles pour la valeur de self
48      """
49      return self.definition.min,self.definition.max
50
51
52   def getLabelText(self):
53     """
54        Retourne le label de self suivant qu'il s'agit d'un MCFACT
55        isole ou d'un MCFACT appartenant a une MCList :
56        utilisee pour l'affichage dans l'arbre
57     """
58     objet = self.parent.getChild(self.nom, restreint='oui')
59     # objet peut-etre self ou une MCList qui contient self ...
60     if objet is None or objet is self:
61      return tr("Erreur - mclist inexistante : %s", self.nom)
62
63     try:
64       if len(objet) > 1 :
65         index = objet.getIndex(self)+1 # + 1 a cause de la numerotation qui commence a 0
66         return tr(self.nom) +'_'+repr(index)+':'
67       else:
68         return tr(self.nom)
69     except:
70       return tr("Erreur - mot cle facteur de nom : %s", self.nom)
71
72   def getGenealogiePrecise(self):
73     nom=self.getLabelText() 
74     if nom[-1]==':' : nom=nom[0:-1]
75     if self.parent:
76        l=self.parent.getGenealogiePrecise()
77        l.append(nom.strip())
78        return l
79     else:
80        return [nom.strip()]
81
82
83   def initModif(self):
84     """
85        Met l'etat de l'objet a modified et propage au parent
86        qui vaut None s'il n'existe pas
87     """
88     self.state = 'modified'
89     parent= hasattr(self,"alt_parent") and self.alt_parent or self.parent
90     if parent:
91        parent.initModif()
92
93   def finModif(self):
94     """
95       Methode appelee apres qu'une modification a ete faite afin de declencher
96       d'eventuels traitements post-modification
97     """
98     #print "finModif",self
99     # pour les objets autres que les commandes, aucun traitement specifique
100     # on remonte l'info de fin de modif au parent
101     CONNECTOR.Emit(self,"valid")
102     parent= hasattr(self,"alt_parent") and self.alt_parent or self.parent
103     if parent:
104        parent.finModif()
105
106   def normalize(self):
107     """ Retourne le MCFACT normalise. Pour un MCFACT isole, l'objet normalise
108         est une MCLIST de longueur 1 qui contient ce MCFACT
109     """
110     new_obj = self.definition.list_instance()
111     new_obj.init(nom=self.nom,parent=None)
112     new_obj.append(self)
113     return new_obj
114
115   def supprime(self):
116     self.alt_parent=None
117     Noyau.N_MCFACT.MCFACT.supprime(self)