1 # -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2013 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
22 Description des OJB jeveux
24 from basetype import Type
25 from asnom import SDNom
26 from ascheckers import CheckLog
29 # pour utilisation dans eficas
32 from Utilitai.Utmess import UTMESS
36 # -----------------------------------------------------------------------------
41 def __init__(self, nomj=None, *args, **kwargs ):
42 super(AsBase,self).__init__( nomj, *args, **kwargs )
43 assert self.nomj is not self.__class__.nomj
44 if isinstance( nomj, str ):
46 elif isinstance( nomj, SDNom ):
47 self.nomj.update( nomj.__getstate__() )
49 def set_name(self, nomj):
50 """Positionne le nomj de self
52 assert isinstance( self.nomj.nomj, str ), "uniquement pour les concepts"
55 def check(self, checker=None):
59 # vérif déjà faite ? (en tenant compte du type)
60 if checker.checkedAsBase(self):
62 checker.visitAsBase( self )
64 # vérifie les enfants :
65 optional = checker.optional
66 checker.optional = checker.optional or self.optional
67 for name in self._subtypes:
68 v = getattr(self, name)
69 if isinstance( v, (OJB,AsBase) ):
71 for name in dir(self):
72 if name.startswith( 'check_' ):
73 v = getattr(self, name)
79 mess=mess+'Erreur SDVERI (Attention : vérification incomplète)'+'\n'
80 mess=mess.join(traceback.format_tb(sys.exc_traceback))
81 checker.err(self,mess)
83 checker.optional = optional
89 def dump(self, indent=""):
98 l.append( f+" "+nomj )
99 #l.append( '-'*(len(nomj)+3) )
100 for name in self._subtypes:
101 obj = getattr(self, name)
102 if isinstance(obj,(AsBase,OJB)):
103 l.append( obj.dump(indent) )
104 for name in dir(self):
105 if name.startswith( 'check_' ):
106 obj = getattr(self, name)
107 if callable(obj) and name.startswith("check_"):
108 checkers.append( obj )
110 indent = " "*len(nomj)
111 for checker in checkers:
112 doc = pydoc.text.document( checker )
113 for line in doc.splitlines():
114 l.append( indent + line )
115 return "\n".join( l )
117 def short_repr(self):
118 return "<%s(%x,%r)>" % (self.__class__.__name__, id(self), self.nomj() )
121 if not hasattr(self, "accessible") or not self.accessible():
122 # hors Aster ou en par_lot='oui'
123 return self.short_repr()
125 from Cata.cata import IMPR_CO, _F
126 IMPR_CO(CONCEPT=_F(NOM=self.nom), UNITE=6)
130 # par défaut, on fait court !
131 return self.short_repr()
134 # -----------------------------------------------------------------------------
135 class JeveuxAttr(object):
136 """Un attribut jeveux"""
137 def __init__(self, name):
140 def __get__(self, obj, klass):
141 raise NotImplementedError
143 def check(self, attrname, obj, log ):
144 checker = getattr(obj, "_"+attrname, None )
147 val = self.__get__( obj, obj.__class__ )
148 if callable( checker ):
149 return checker( obj, attrname, val, log )
151 test = val == checker
153 log.err( obj, "Attribut incorrect %s %r!=%r" % (self.name, val, checker ) )
156 # -----------------------------------------------------------------------------
157 class JeveuxExists(JeveuxAttr):
161 def __get__(self, obj, klass):
166 raise AssertionError(repr(nomj))
167 return aster.jeveux_exists( nomj.ljust(24) )
169 # -----------------------------------------------------------------------------
170 class JeveuxIntAttr(JeveuxAttr):
171 def __get__(self, obj, klass):
175 if aster.jeveux_exists( nomj ):
176 return aster.jeveux_getattr( nomj, self.name )[0]
180 # -----------------------------------------------------------------------------
181 class JeveuxStrAttr(JeveuxAttr):
182 def __get__(self, obj, klass):
186 if aster.jeveux_exists( nomj ):
187 return aster.jeveux_getattr( nomj, self.name )[1].strip()
191 # -----------------------------------------------------------------------------
201 clas = JeveuxStrAttr("CLAS")
202 genr = JeveuxStrAttr("GENR")
203 type = JeveuxStrAttr("TYPE")
204 ltyp = JeveuxIntAttr("LTYP")
205 xous = JeveuxStrAttr("XOUS")
206 docu = JeveuxStrAttr("DOCU")
207 exists = JeveuxExists()
211 def __init__(self, nomj=None, **attrs):
212 super(OJB,self).__init__( nomj, **attrs )
213 self.foreachattr( self.setattribute, attrs )
214 self.optional = attrs.get('optional', False)
216 def setattribute( self, name, prop, attrs ):
219 setattr( self, _name, attrs[name] )
223 if aster.jeveux_exists( nomj ):
224 obj_simple = aster.jeveux_getattr( nomj, 'XOUS')[1].strip() == 'S'
226 return aster.getvectjev( nomj )
228 return aster.getcolljev( nomj )
232 def get_stripped(self):
233 """Fonction utilitaire, renvoie une liste de chaines 'strippées'"""
236 return [ x.strip() for x in data ]
240 def foreachattr(self, callback, *args, **kwargs):
241 klass = self.__class__
243 v = getattr( klass, k )
244 if isinstance(v, JeveuxAttr):
245 callback( k, v, *args, **kwargs )
247 def check(self, checker=None):
250 # l'objet a déjà été vérifié, on ne fait rien
251 if checker.checkedOJB(self):
253 checker.visitOJB( self )
255 self.foreachattr( lambda k,v,obj,c: v.check(k, obj, c),
258 if not self.optional and not checker.optional :
259 checker.err( self, "n'existe pas (%r)" %self._parent )
262 def dump(self, indent=""):
267 return f +" "+ self.nomj() +" "+ str(self.exists)
269 # -----------------------------------------------------------------------------
270 def Facultatif( ojb ):
274 # -----------------------------------------------------------------------------
276 lonmax = JeveuxIntAttr("LONMAX")
277 lonuti = JeveuxIntAttr("LONUTI")
281 # -----------------------------------------------------------------------------
283 nommax = JeveuxIntAttr("NOMMAX")
284 nomuti = JeveuxIntAttr("NOMUTI")
289 # -----------------------------------------------------------------------------
290 class OJBCollec(OJB):
291 stockage = JeveuxStrAttr("STOCKAGE")
292 nutioc = JeveuxIntAttr( "NUTIOC" )
293 acces = JeveuxStrAttr( "ACCES" )
294 modelong = JeveuxStrAttr( "MODELONG" )
295 nmaxoc = JeveuxIntAttr( "NMAXOC" )
297 # -----------------------------------------------------------------------------
301 # -----------------------------------------------------------------------------
305 # -----------------------------------------------------------------------------
309 # -----------------------------------------------------------------------------
313 # -----------------------------------------------------------------------------
317 # -----------------------------------------------------------------------------
318 class AsVK8(OJBVect):
322 # -----------------------------------------------------------------------------
323 class AsVK16(OJBVect):
327 # -----------------------------------------------------------------------------
328 class AsVK24(OJBVect):
332 # -----------------------------------------------------------------------------
333 class AsVK32(OJBVect):
337 # -----------------------------------------------------------------------------
338 class AsVK80(OJBVect):