2 # Copyright (C) 2007-2021 EDF R&D
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.
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.
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
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 """ Ce module contient la classe de definition SIMP
22 qui permet de spécifier les caractéristiques des mots clés simples
25 from __future__ import absolute_import
29 from Noyau import N_ENTITE
30 from Noyau import N_MCSIMP
33 class SIMP(N_ENTITE.ENTITE):
36 Classe pour definir un mot cle simple
38 Cette classe a deux attributs de classe
40 - class_instance qui indique la classe qui devra etre utilisée
41 pour créer l'objet qui servira à controler la conformité d'un
42 mot-clé simple avec sa définition
44 - label qui indique la nature de l'objet de définition (ici, SIMP)
47 class_instance = N_MCSIMP.MCSIMP
50 def __init__(self, typ,ang="", fr="", statut='f', into=None, intoSug = None,siValide = None, defaut=None,
51 min=1, max=1, homo=1, position='local',filtre=None,
52 val_min=float('-inf'), val_max=float('inf'), docu="", validators=None, nomXML=None,
53 sug=None,fenetreIhm=None, attribut=False, sortie='n', intoXML=None, metAJour=None,
54 avecBlancs=False, unite=None):
56 Un mot-clé simple est caractérisé par les attributs suivants :
57 - type : cet attribut est obligatoire et indique le type de valeur attendue
58 - fr : chaîne documentaire en français
59 - statut : obligatoire ou facultatif ou caché
60 - into : valeurs autorisées
61 - intoSug : valeurs possibles mais des valeurs autres du bon type peuvent etre entrees par l utilsateur
62 - defaut : valeur par défaut
63 - min : nombre minimal de valeurs
64 - max : nombre maximal de valeurs
65 - homo : un certatin nb de choses qui il faut redispacher ailleurs (information, constant)
67 - position : si global, le mot-clé peut-être lu n'importe où dans la commande
68 - val_min : valeur minimale autorisée
69 - val_max : valeur maximale autorisée
70 - docu : clef sur de la documentation utilisateur
71 - sug : valeur suggere
72 - fenetreIhm : si widget particulier
73 - attribut : si projection XSD sur attribut
74 - creeDesObjetsDeType : type des UserASSD si siValide en cree
75 - nomXML : se projette en XSD avec un autre nom pour accepter les tirets
76 - sortie : force l ecriture dans le fichier de sortie (utile pour Telemac)
80 #traceback.print_stack()
82 N_ENTITE.ENTITE.__init__(self, validators)
83 # Initialisation des attributs
84 self.creeDesObjets = False
85 self.utiliseUneReference = False
86 self.creeDesObjetsDeType = None
87 self.utiliseDesObjetsDeType = None
88 if type(typ) == tuple:
92 for t in (self.type) :
94 if issubclass(t,Accas.UserASSDMultiple) :
95 creeDesObjetsDeType = t
96 self.utiliseUneReference = True
97 elif issubclass(t,Accas.UserASSD) :
98 creeDesObjetsDeType = t
99 self.utiliseUneReference = True
101 if t == 'createObject' : self.creeDesObjets=True
102 if self.utiliseUneReference :
103 if self.creeDesObjets :
104 self.utiliseUneReference = False
105 self.creeDesObjetsDeType = creeDesObjetsDeType
106 else : self.utiliseDesObjetsDeType = creeDesObjetsDeType
110 self.intoSug = intoSug
111 self.siValide = siValide
116 self.position = position
117 self.val_min = val_min
118 self.val_max = val_max
122 if self.max == '**' : self.max = float('inf')
123 if self.val_max == '**' : self.val_max = float('inf')
124 if self.min == '**' : self.min = float('-inf')
125 if self.val_min == '**' : self.val_min = float('-inf')
126 self.fenetreIhm = fenetreIhm
127 self.attribut = attribut
129 self.intoXML = intoXML
132 self.avecBlancs = avecBlancs
134 if not(self.avecBlancs) and self.max > 1 and 'TXM' in self.type and self.into != None :
135 for val in self.into :
136 if val.find(' ') > -1:
137 self.avecBlancs = True
139 if not(self.avecBlancs) and self.max > 1 and 'TXM' in self.type and self.intoXML != None :
140 for val in self.intoXML :
141 if val.find(' ') > -1:
142 self.avecBlancs = True
144 if self.avecBlancs and not ('TXM' in self.type) :
145 print ('definition incoherente avecBlanc et non texte pour ', self)
148 self.filtreExpression = self.filtre[0]
149 self.filtreVariables = self.filtre[1]
151 self.filtreExpression = []
152 self.filtreVariables = []
153 self.metAJour=metAJour
157 Cette methode sert à valider les attributs de l'objet de définition
166 self.checkValidators()
169 def __call__(self, val, nom, parent=None, objPyxbDeConstruction = None):
171 Construit un objet mot cle simple (MCSIMP) a partir de sa definition (self)
172 de sa valeur (val), de son nom (nom) et de son parent dans l arboresence (parent)
174 return self.class_instance(nom=nom, definition=self, val=val, parent=parent, objPyxbDeConstruction=objPyxbDeConstruction)