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 .tools import get_value, convert_to_underscore
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 hight level Python interfaces to features."""
34 def __init__(self, feature):
35 self._feature = feature
37 def __getattr__(self, name):
38 """Process missing attributes.
40 Add get*() methods for access feature attributes.
41 Redirect missing attributes to the feature.
43 if name.startswith("get"):
46 "_" + convert_to_underscore(name[3:]),
48 for possible_name in possible_names:
49 if hasattr(self, possible_name):
51 return get_value(getattr(self, possible_name))
54 return self._feature.__getattribute__(name)
56 def setRealInput (self, inputid, value):
57 self._feature.data().real(inputid).setValue(value)
59 def areInputValid (self):
60 validators = ModelAPI.ModelAPI_Session.get().validators()
61 return validators.validate(self._feature)
64 self._feature.execute()