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