1 """Abstract root classes of user-defined Python features producing a Body
2 Author: Daniel Brunier-Coulin
3 Copyright (C) 2014-20xx CEA/DEN, EDF R&D
8 from model import tools
11 class Feature(ModelAPI.ModelAPI_Feature):
12 """Base class of user-defined Python features."""
15 ModelAPI.ModelAPI_Feature.__init__(self)
17 def addRealInput (self, inputid):
18 self.data().addAttribute(inputid,
19 ModelAPI.ModelAPI_AttributeDouble_typeId())
21 def getRealInput (self, inputid):
22 return self.data().real(inputid).value()
24 def addResult (self, result):
25 shape = result.shape()
26 body = self.document().createBody(self.data())
32 """Base class of high level Python interfaces to features."""
34 def __init__(self, feature):
35 self._feature = feature
36 self._attribute_white_list = [
37 "getKind", "results", "firstResult", "lastResult",
40 def __getattr__(self, name):
41 """Process missing attributes.
43 Add get*() methods for access feature attributes.
44 Redirect some missing attributes to the feature.
46 if name.startswith("get"):
49 "_" + tools.convert_to_underscore(name[3:]),
51 for possible_name in possible_names:
52 if hasattr(self, possible_name):
54 return getattr(self, possible_name)
57 if name in self._attribute_white_list:
58 return getattr(self._feature, name)
60 raise AttributeError()
63 """Return ModelAPI_Feature."""
66 def _fill_attribute(self, attribute, value):
67 """Fill ModelAPI_Attribute* with value."""
68 tools.fill_attribute(attribute, value)
70 def setRealInput(self, inputid, value):
71 self._feature.data().real(inputid).setValue(value)
73 def areInputValid(self):
74 validators = ModelAPI.ModelAPI_Session.get().validators()
75 return validators.validate(self._feature)
78 self._feature.execute()