Salome HOME
bug 53033
[tools/eficas.git] / Ihm / I_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 from Extensions.i18n import tr
21 import CONNECTOR
22 import I_MCCOMPO
23 import Noyau
24
25 class MCFACT(I_MCCOMPO.MCCOMPO):
26   def isrepetable(self):
27      """ 
28          Indique si l'objet est répétable.
29          Retourne 1 si le mot-clé facteur self peut être répété
30          Retourne 0 dans le cas contraire
31      """
32      if self.definition.max > 1:
33        # marche avec '**'
34        return 1
35      else :
36        return 0
37
38   def isoblig(self):
39     return self.definition.statut=='o'
40
41   def getlabeltext(self):
42     """
43        Retourne le label de self suivant qu'il s'agit d'un MCFACT
44        isole ou d'un MCFACT appartenant a une MCList :
45        utilisee pour l'affichage dans l'arbre
46     """
47     objet = self.parent.get_child(self.nom)
48     # objet peut-etre self ou une MCList qui contient self ...
49     if objet is None or objet is self:
50      return tr("Erreur - mclist inexistante : %s", self.nom)
51
52     try:
53       if len(objet) > 1 :
54         index = objet.get_index(self)+1 # + 1 à cause de la numérotation qui commence à 0
55         return self.nom +'_'+`index`+':'
56       else:
57         return self.nom
58     except:
59       return tr("Erreur - mot cle facteur de nom : %s", self.nom)
60
61   def init_modif(self):
62     """
63        Met l'état de l'objet à modified et propage au parent
64        qui vaut None s'il n'existe pas
65     """
66     self.state = 'modified'
67     parent= hasattr(self,"alt_parent") and self.alt_parent or self.parent
68     if parent:
69        parent.init_modif()
70
71   def fin_modif(self):
72     """
73       Méthode appelée après qu'une modification a été faite afin de déclencher
74       d'éventuels traitements post-modification
75     """
76     #print "fin_modif",self
77     # pour les objets autres que les commandes, aucun traitement spécifique
78     # on remonte l'info de fin de modif au parent
79     CONNECTOR.Emit(self,"valid")
80     parent= hasattr(self,"alt_parent") and self.alt_parent or self.parent
81     if parent:
82        parent.fin_modif()
83
84   def normalize(self):
85     """ Retourne le MCFACT normalisé. Pour un MCFACT isolé, l'objet normalisé
86         est une MCLIST de longueur 1 qui contient ce MCFACT
87     """
88     new_obj = self.definition.list_instance()
89     new_obj.init(nom=self.nom,parent=None)
90     new_obj.append(self)
91     return new_obj
92
93   def supprime(self):
94     self.alt_parent=None
95     Noyau.N_MCFACT.MCFACT.supprime(self)