]> SALOME platform Git repositories - tools/eficas.git/blob - Ihm/I_ENTITE.py
Salome HOME
chgt Copyrigth
[tools/eficas.git] / Ihm / I_ENTITE.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 _no=0
22
23 import Accas
24 def numberEntite(entite):
25    """
26       Fonction qui attribue un numero unique a tous les objets du catalogue
27       Ce numero permet de conserver l'ordre des objets
28    """
29    global _no
30    _no=_no+1
31    entite._no=_no
32
33 class ENTITE:
34   def __init__(self):
35      numberEntite(self)
36     
37   def getDocu(self):
38     if hasattr(self,'docu') :
39       if self.docu != "" : return self.docu
40       else:
41         if hasattr(self,'pere'):
42           return self.pere.getDocu()
43         else:
44           return None
45     else:
46       return None
47
48   def getSug(self):
49     if hasattr(self,'sug') :
50       if self.sug != "" : return self.sug
51     return None
52
53   def checkDefinition(self, parent):
54       """Verifie la definition d'un objet composite (commande, fact, bloc)."""
55       args = self.entites.copy()
56       mcs = set()
57       for nom, val in args.items():
58          if val.label == 'SIMP':
59             mcs.add(nom)
60             #XXX
61             #if val.max != 1 and val.type == 'TXM':
62                 #print "#CMD", parent, nom
63          elif val.label == 'FACT':
64             val.checkDefinition(parent)
65             #PNPNPN surcharge
66             # CALC_SPEC !
67             #assert self.label != 'FACT', \
68             #   'Commande %s : Mot-clef facteur present sous un mot-clef facteur : interdit !' \
69             #   % parent
70          else:
71             continue
72          del args[nom]
73       # seuls les blocs peuvent entrer en conflit avec les mcs du plus haut niveau
74       for nom, val in args.items():
75          if val.label == 'BLOC':
76             mcbloc = val.checkDefinition(parent)
77             #XXX
78             #print "#BLOC", parent, re.sub('\s+', ' ', val.condition)
79             #assert mcs.isdisjoint(mcbloc), "Commande %s : Mot(s)-clef(s) vu(s) plusieurs fois : %s" \
80             #   % (parent, tuple(mcs.intersection(mcbloc)))
81       return mcs
82
83 #  def enregistreXML(self,root,catalogueXml):
84 #      import xml.etree.ElementTree as ET
85 #      import types
86 #      moi=ET.SubElement(root,str(self.__class__))
87 #      nom=ET.SubElement(moi,'nom')
88 #      nom.text=self.nom
89 #
90 #      if hasattr(self,'validators') and (self.validators != () and self.validators != None):
91 #         valid=ET.SubElement(moi,'validators')
92 #         valid.text= str(self.validators.__class__)
93 #         catalogueXml.validatorsUtilises.append(self.validators)
94 #
95 #      if hasattr(self,'regles') and (self.regles !=() and self.regles != None):
96 #         for regle in self.regles:
97 #             regle.enregistreXML(moi,catalogueXml)
98 #         catalogueXml.reglesUtilisees.append(self.regles)
99 #
100 #      if ((self.getDocu() !="" and self.getDocu() !=None) or  \
101 #          (self.fr != "" and self.fr != None) or \
102 #          (self.ang != "" and self.ang != None) ):
103 #                dico={}
104 #                if self.getDocu() !=None : dico["docu"]=self.getDocu()
105 #                if self.fr != None        : dico["fr"]=six.text_type(self.fr,"iso-8859-1")
106 #                if self.ang != None       : dico["ang"]=self.ang
107 #                doc=ET.SubElement(moi,'doc')
108 #                doc.attrib=dico
109 #
110 #      if ((self.getSug() !=None) or  \
111 #          (hasattr(self,'defaut') and (self.defaut != None) and (self.defaut != 'None'))) :
112 #                # il faut ajouter des sug dans le catalogue
113 #                # les attributs sont  toujours du texte 
114 #                dico={}
115 #                if (self.defaut != None) and (self.defaut != 'None') :
116 #                    if isinstance(self.defaut,str ) : dico["defaut"]=six.text_type(self.defaut,"iso-8859-1")
117 #                    else :dico["defaut"]=str(self.defaut)
118 #                if self.getSug() !=None:
119 #                    if isinstance(self.getSug(),str ) : dico["sug"]=six.text_type(self.getSug(),"iso-8859-1")
120 #                    else :dico["sug"]=str(self.getSug())
121 #                
122 #                doc=ET.SubElement(moi,'ValeurDef')
123 #                doc.attrib=dico
124 #
125 #      dico={}
126 #      if hasattr(self,'into') and self.into!=None: dico['into']=str(self.into)
127 #      if hasattr(self,'val_max') and self.val_max != "**" : dico['max']=str(self.val_max)
128 #      if hasattr(self,'val_min') and self.val_min != "**" : dico['min']=str(self.val_min)
129 #      if dico != {} :
130 #           PV=ET.SubElement(moi,'PlageValeur')
131 #           PV.attrib=dico
132 #
133 #      dico={}
134 #      if hasattr(self,'max')  and self.max != 1 : dico['max']=str(self.max)
135 #      if hasattr(self,'min')  and self.min != 1 : dico['max']=str(self.min)
136 #      if dico != {} :
137 #           Card=ET.SubElement(moi,'Cardinalite')
138 #           Card.attrib=dico
139 #
140 #      dico={}
141 #      if hasattr(self,'reentrant') and self.reentrant not in ('f','n') : dico['reentrant']=str(self.reentrant)
142 #      if hasattr(self,'position') and self.position != "local": dico['position']=str(self.position)
143 #      if hasattr(self,'homo') and self.homo != 1 : dico['homogene']=str(self.homo)
144 #      if hasattr(self,'statut') : dico['statut']=str(self.statut)
145 #      if hasattr(self,'repetable') : dico['repetable']=str(self.repetable)
146 #      if dico != {} :
147 #           pos=ET.SubElement(moi,'situation')
148 #           pos.attrib=dico
149 #
150 #      if hasattr(self,'type') and self.type != ():
151 #         typeAttendu=ET.SubElement(moi,'typeAttendu')
152 #         l=[]
153 #         for t in self.type:
154 #             if type(t) == type : l.append(t.__name__)
155 #             else : l.append(t)
156 #         typeAttendu.text=str(l)
157 #
158 #      if hasattr(self,'sd_prod') and self.sd_prod != () and self.sd_prod !=None:
159 #         typeCree=ET.SubElement(moi,'typeCree')
160 #         typeCree.text=str(self.sd_prod.__name__) 
161
162 #      if hasattr(self,'op') and self.op !=None  : 
163 #         subRoutine=ET.SubElement(moi,'subRoutine')
164 #         subRoutine.text=str(self.op)
165 #
166 #      if hasattr(self,'proc') and self.proc != None : 
167 #         construction=ET.SubElement(moi,'Construction')
168 #         construction.text=self.proc.uri
169 #
170 #      for nomFils, fils in self.entites.items() :
171 #          fils.enregistreXML(moi,catalogueXml)
172 #      
173 #  def enregistreXMLStructure(self,root,catalogueXml):
174 #      import xml.etree.ElementTree as ET
175 #      import types
176 #      moi=ET.SubElement(root,str(self.__class__))
177 #
178 #      if hasattr(self,'into') and self.into!=None: 
179 #          INTO=ET.SubElement(moi,'into')
180 #          INTO.text='into'
181 #
182 #      dico={}
183 #      if hasattr(self,'val_max') and self.val_max != "**" : dico['max']=str(self.val_max)
184 #      if hasattr(self,'val_min') and self.val_min != "**" : dico['min']=str(self.val_min)
185 #      if dico != {} :
186 #           PV=ET.SubElement(moi,'maxOrMin')
187 #           PV.text='maxOrMin'
188 #
189 #      dico={}
190 #      if hasattr(self,'max')  and self.max != 1 : dico['max']=str(self.max)
191 #      if hasattr(self,'min')  and self.min != 1 : dico['max']=str(self.min)
192 #      if dico != {} :
193 #           Card=ET.SubElement(moi,'liste')
194 #           Card.text="liste"
195 #
196 #      dico={}
197 #      if hasattr(self,'statut') and self.statut=="f" :
198 #         statut=ET.SubElement(moi,'facultatif')
199 #         statut.text='facultatif'
200 #      if hasattr(self,'statut') and self.statut !="f" :
201 #         statut=ET.SubElement(moi,'obligatoire')
202 #         statut.text='obligatoire'
203 #
204 #      if hasattr(self,'type') and self.type != ():
205 #        try :
206 #           if 'Fichier' in self.type : ty=ET.SubElement(moi,'Fichier')
207 #           ty.text='type'
208 #        except :
209 #           try :
210 #             if 'Repertoire' in self.type : ty=ET.SubElement(moi,'Repertoire')
211 #             ty.text='type'
212 #           except :
213 #              for t in self.type:
214 #                if t == "I" : ty=ET.SubElement(moi,'typeEntier')
215 #                elif t == "R" : ty=ET.SubElement(moi,'typeReel')
216 #                elif t == "TXM" : ty=ET.SubElement(moi,'typeTXM')
217 #                else :
218 #                  try :
219 #                    ty=ET.SubElement(moi,t.__name__) 
220 #                  except :
221 #                    ty=ET.SubElement(moi,'autre') 
222 #                ty.text='type'
223 #
224 #      if hasattr(self,'sd_prod') and self.sd_prod != () and self.sd_prod !=None:
225 #         typeCree=ET.SubElement(moi,'typeCree')
226 #         typeCree.text='sd_prod'
227
228 #      if hasattr(self,'op') and self.op !=None  : 
229 #         subRoutine=ET.SubElement(moi,'subRoutine')
230 #         subRoutine.text='op'
231 #
232 #      if hasattr(self,'proc') and self.proc != None : 
233 #         construction=ET.SubElement(moi,'Construction')
234 #         construction.text='proc'
235 #
236 #      for nomFils, fils in self.entites.items() :
237 #          fils.enregistreXMLStructure(moi,catalogueXml)
238 #