]> SALOME platform Git repositories - tools/eficas.git/blob - Ihm/I_MCFACT.py
Salome HOME
update version
[tools/eficas.git] / Ihm / I_MCFACT.py
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2007-2021   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     def getNomDsXML(self):
52         # en xml on a une sequence si max est superieur a 1
53         # sinon non
54         objet = self.parent.getChild(self.nom, restreint='oui')
55         if len(objet) > 1 :
56             index = objet.getIndex(self)
57             nom = self.nom + "[" + str(index) + "]"
58         else :
59             if self.definition.max == 1 : nom = self.nom
60             else :  nom = self.nom+"[0]"
61         nomDsXML=self.parent.getNomDsXML()+"."+nom
62         return nomDsXML
63
64
65     def getLabelText(self):
66         """
67            Retourne le label de self suivant qu'il s'agit d'un MCFACT
68            isole ou d'un MCFACT appartenant a une MCList :
69            utilisee pour l'affichage dans l'arbre
70         """
71         objet = self.parent.getChild(self.nom, restreint='oui')
72         # objet peut-etre self ou une MCList qui contient self ...
73         if objet is None or objet is self:
74             return tr("Erreur - mclist inexistante : %s", self.nom)
75
76         try:
77             if len(objet) > 1 :
78                 index = objet.getIndex(self)+1 # + 1 a cause de la numerotation qui commence a 0
79                 return tr(self.nom) +'_'+repr(index)+':'
80             else:
81                 return tr(self.nom)
82         except:
83             return tr("Erreur - mot cle facteur de nom : %s", self.nom)
84
85     def getGenealogiePrecise(self):
86         nom=self.getLabelText()
87         if nom[-1]==':' : nom=nom[0:-1]
88         if self.parent:
89             l=self.parent.getGenealogiePrecise()
90             l.append(nom.strip())
91             return l
92         else:
93             return [nom.strip()]
94
95
96     def initModif(self):
97         """
98            Met l'etat de l'objet a modified et propage au parent
99            qui vaut None s'il n'existe pas
100         """
101         self.state = 'modified'
102         parent= hasattr(self,"alt_parent") and self.alt_parent or self.parent
103         if parent:
104             parent.initModif()
105
106     def finModif(self):
107         """
108           Methode appelee apres qu'une modification a ete faite afin de declencher
109           d'eventuels traitements post-modification
110         """
111         #print "finModif",self
112         # pour les objets autres que les commandes, aucun traitement specifique
113         # on remonte l'info de fin de modif au parent
114         CONNECTOR.Emit(self,"valid")
115         parent= hasattr(self,"alt_parent") and self.alt_parent or self.parent
116         if parent:
117             parent.finModif()
118
119     def normalize(self):
120         """ Retourne le MCFACT normalise. Pour un MCFACT isole, l'objet normalise
121             est une MCLIST de longueur 1 qui contient ce MCFACT
122         """
123         new_obj = self.definition.list_instance()
124         new_obj.init(nom=self.nom,parent=None)
125         new_obj.append(self)
126         return new_obj
127
128     def supprime(self):
129         self.alt_parent=None
130         Noyau.N_MCFACT.MCFACT.supprime(self)