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
21 Description des OJB jeveux
23 from basetype import Type
24 from asnom import SDNom
25 from ascheckers import CheckLog
29 # pour utilisation dans eficas
32 from Utilitai.Utmess import UTMESS
36 # -----------------------------------------------------------------------------
43 def __init__(self, nomj=None, *args, **kwargs):
44 super(AsBase, self).__init__(nomj, *args, **kwargs)
45 assert self.nomj is not self.__class__.nomj
46 if isinstance(nomj, str):
48 elif isinstance(nomj, SDNom):
49 self.nomj.update(nomj.__getstate__())
51 def set_name(self, nomj):
52 """Positionne le nomj de self
54 assert isinstance(self.nomj.nomj, str), "uniquement pour les concepts"
57 def check(self, checker=None):
61 # vérif déjà faite ? (en tenant compte du type)
62 if checker.checkedAsBase(self):
64 checker.visitAsBase(self)
66 # vérifie les enfants :
67 optional = checker.optional
68 checker.optional = checker.optional or self.optional
69 for name in self._subtypes:
70 v = getattr(self, name)
71 if isinstance(v, (OJB, AsBase)):
73 for name in dir(self):
74 if name.startswith('check_'):
75 v = getattr(self, name)
80 mess = 60 * '-' + '\n'
82 'Erreur SDVERI (Attention : vérification incomplète)' + \
85 traceback.format_tb(sys.exc_traceback))
86 checker.err(self, mess)
88 checker.optional = optional
91 def dump(self, indent=""):
100 l.append(f + " " + nomj)
101 for name in self._subtypes:
102 obj = getattr(self, name)
103 if isinstance(obj, (AsBase, OJB)):
104 l.append(obj.dump(indent))
105 for name in dir(self):
106 if name.startswith('check_'):
107 obj = getattr(self, name)
108 if callable(obj) and name.startswith("check_"):
111 indent = " " * len(nomj)
112 for checker in checkers:
113 doc = pydoc.text.document(checker)
114 for line in doc.splitlines():
115 l.append(indent + line)
118 def short_repr(self):
119 return "<%s(%x,%r)>" % (self.__class__.__name__, id(self), self.nomj())
122 if not hasattr(self, "accessible") or not self.accessible():
123 # hors Aster ou en par_lot='oui'
124 return self.short_repr()
126 from Cata.cata import IMPR_CO, _F
127 IMPR_CO(CONCEPT=_F(NOM=self.nom), UNITE=6)
131 # par défaut, on fait court !
132 return self.short_repr()
135 # -----------------------------------------------------------------------------
136 class JeveuxAttr(object):
138 """Un attribut jeveux"""
140 def __init__(self, name):
143 def __get__(self, obj, klass):
144 raise NotImplementedError
146 def check(self, attrname, obj, log):
147 checker = getattr(obj, "_" + attrname, None)
150 val = self.__get__(obj, obj.__class__)
151 if callable(checker):
152 return checker(obj, attrname, val, log)
156 log.err(obj, "Attribut incorrect %s %r!=%r" %
157 (self.name, val, checker))
160 # -----------------------------------------------------------------------------
163 class JeveuxExists(JeveuxAttr):
168 def __get__(self, obj, klass):
173 raise AssertionError(repr(nomj))
174 return aster.jeveux_exists(nomj.ljust(24))
176 # -----------------------------------------------------------------------------
179 class JeveuxIntAttr(JeveuxAttr):
181 def __get__(self, obj, klass):
185 if aster.jeveux_exists(nomj):
186 return aster.jeveux_getattr(nomj, self.name)[0]
190 # -----------------------------------------------------------------------------
193 class JeveuxStrAttr(JeveuxAttr):
195 def __get__(self, obj, klass):
199 if aster.jeveux_exists(nomj):
200 return aster.jeveux_getattr(nomj, self.name)[1].strip()
204 # -----------------------------------------------------------------------------
216 clas = JeveuxStrAttr("CLAS")
217 genr = JeveuxStrAttr("GENR")
218 type = JeveuxStrAttr("TYPE")
219 ltyp = JeveuxIntAttr("LTYP")
220 xous = JeveuxStrAttr("XOUS")
221 docu = JeveuxStrAttr("DOCU")
222 exists = JeveuxExists()
225 def __init__(self, nomj=None, **attrs):
226 super(OJB, self).__init__(nomj, **attrs)
227 self.foreachattr(self.setattribute, attrs)
228 self.optional = attrs.get('optional', False)
230 def setattribute(self, name, prop, attrs):
233 setattr(self, _name, attrs[name])
237 if aster.jeveux_exists(nomj):
238 obj_simple = aster.jeveux_getattr(nomj, 'XOUS')[1].strip() == 'S'
240 return aster.getvectjev(nomj)
242 return aster.getcolljev(nomj)
246 def get_stripped(self):
247 """Fonction utilitaire, renvoie une liste de chaines 'strippées'"""
250 return [x.strip() for x in data]
254 def foreachattr(self, callback, *args, **kwargs):
255 klass = self.__class__
257 v = getattr(klass, k)
258 if isinstance(v, JeveuxAttr):
259 callback(k, v, *args, **kwargs)
261 def check(self, checker=None):
264 # l'objet a déjà été vérifié, on ne fait rien
265 if checker.checkedOJB(self):
267 checker.visitOJB(self)
269 self.foreachattr(lambda k, v, obj, c: v.check(k, obj, c),
272 if not self.optional and not checker.optional:
273 checker.err(self, "n'existe pas (%r)" % self._parent)
276 def dump(self, indent=""):
281 return f + " " + self.nomj() + " " + str(self.exists)
283 # -----------------------------------------------------------------------------
290 # -----------------------------------------------------------------------------
294 lonmax = JeveuxIntAttr("LONMAX")
295 lonuti = JeveuxIntAttr("LONUTI")
299 # -----------------------------------------------------------------------------
303 nommax = JeveuxIntAttr("NOMMAX")
304 nomuti = JeveuxIntAttr("NOMUTI")
309 # -----------------------------------------------------------------------------
312 class OJBCollec(OJB):
313 stockage = JeveuxStrAttr("STOCKAGE")
314 nutioc = JeveuxIntAttr("NUTIOC")
315 acces = JeveuxStrAttr("ACCES")
316 modelong = JeveuxStrAttr("MODELONG")
317 nmaxoc = JeveuxIntAttr("NMAXOC")
319 # -----------------------------------------------------------------------------
325 # -----------------------------------------------------------------------------
331 # -----------------------------------------------------------------------------
337 # -----------------------------------------------------------------------------
343 # -----------------------------------------------------------------------------
349 # -----------------------------------------------------------------------------
352 class AsVK8(OJBVect):
356 # -----------------------------------------------------------------------------
359 class AsVK16(OJBVect):
363 # -----------------------------------------------------------------------------
366 class AsVK24(OJBVect):
370 # -----------------------------------------------------------------------------
373 class AsVK32(OJBVect):
377 # -----------------------------------------------------------------------------
380 class AsVK80(OJBVect):