Salome HOME
fin du menage
[tools/eficas.git] / Extensions / nuplet.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 """
21     Ce module contient la classe de definition pour les nuplets NUPL
22 """
23 # Modules Python
24 from __future__ import absolute_import
25 try : 
26    from builtins import str
27 except : pass
28
29 import types
30
31 # Modules Eficas
32 from Noyau import N_ENTITE,N_MCLIST,N_CR
33 from Ihm import I_ENTITE
34 from Extensions.i18n import tr
35 from . import mcnuplet
36
37 class NUPL(N_ENTITE.ENTITE,I_ENTITE.ENTITE):
38    """
39    """
40    class_instance = mcnuplet.MCNUPLET
41    list_instance = N_MCLIST.MCList
42    label='NUPLET'
43    CR=N_CR.CR
44
45    def __init__(self,fr="",ang="",docu="",statut='f',defaut=None,min=0,max=1,
46                     elements=None):
47       N_ENTITE.ENTITE.__init__(self)
48       I_ENTITE.ENTITE.__init__(self)
49       self.fr=fr
50       self.ang=ang
51       self.docu=docu
52       self.statut=statut
53       self.defaut=defaut
54       self.min=min
55       self.max=max
56       if self.max =='**' : self.max=float('inf')
57       if self.min =='**' : self.min=float('-inf')
58       self.entites=elements
59       self.regles=()
60       # on force le statut des sous entites a obligatoire
61       for e in elements:e.statut='o'
62       self.idracine="NUPLET"
63       self.affecter_parente()
64
65    def verifCata(self):
66       """
67           Cette methode sert a valider les attributs de l'objet de definition
68           de la classe NUPL
69       """
70       if type(self.min) != int :
71         if self.min != '**' and self.min != float('-inf'):
72           self.cr.fatal(tr("L'attribut 'min' doit etre un entier : ")+str(self.min))
73       if type(self.max) != int :
74         if self.max != '**'  and self.max != float('inf'):
75           self.cr.fatal(tr("L'attribut 'max' doit etre un entier : ")+str(self.max))
76       if self.min > self.max :
77          self.cr.fatal(tr("Nombres d'occurrence min et max invalides :") +str(self.min)+","+str(self.max))
78       if type(self.fr) != bytes and type(self.fr) != str  :
79         self.cr.fatal(tr("L'attribut 'fr' doit etre une chaine de caracteres"))
80       if self.statut not in ['o','f','c','d']:
81         self.cr.fatal(tr("L'attribut 'statut' doit valoir 'o','f','c' ou 'd'"))
82       if type(self.docu) != bytes and type(self.docu) != str   :
83         self.cr.fatal(tr("L'attribut 'docu' doit etre une chaine de caracteres"))
84       self.verifCataRegles()
85
86    def __call__(self,val,nom,parent):
87       """
88          Construit la structure de donnees pour un NUPLET a partir de sa definition (self)
89          de sa valeur (val), de son nom (nom) et de son parent dans l arboresence (parent)
90       """
91       if (type(val) == tuple or type(val) == list) and type(val[0]) == tuple:
92         # On est en presence d une liste de nuplets
93         l=self.list_instance()
94         l.init(nom=nom,parent=parent)
95         for v in val:
96           objet=self.class_instance(nom=nom,definition=self,val=v,parent=parent)
97           l.append(objet)
98         return l
99       else:
100         # on est en presence d un seul nuplet
101         return self.class_instance(nom=nom,definition=self,val=val,parent=parent)
102
103    def report(self):
104       """ 
105            Methode qui cree le rapport de verification du catalogue du nuplet 
106       """
107       self.cr = self.CR()
108       self.verifCata()
109       for v in self.entites :
110         cr = v.report()
111         cr.debut =tr("Debut ")+v.__class__.__name__+ ' : '
112         cr.fin =tr("Fin ")+v.__class__.__name__+ ' : '
113         self.cr.add(cr)
114       return self.cr
115
116    def affecter_parente(self):
117       """
118           Cette methode a pour fonction de donner un nom et un pere aux
119           sous entites qui n'ont aucun moyen pour atteindre leur parent 
120           directement
121           Il s'agit principalement des mots cles
122       """
123       k=0
124       for v in self.entites:
125         v.pere = self
126         v.nom = str(k)
127         k=k+1
128