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