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 class Feature(ModelAPI.ModelAPI_Feature):
9 """Base class of user-defined Python features."""
12 """x.__init__(...) initializes x; see x.__class__.__doc__ for signature"""
13 ModelAPI.ModelAPI_Feature.__init__(self)
15 def addRealInput(self, inputid):
16 """F.addRealInput(str) -- add real attribute"""
17 self.data().addAttribute(inputid,
18 ModelAPI.ModelAPI_AttributeDouble_typeId())
20 def getRealInput(self, inputid):
21 """F.getRealInput(str) -- get real value of the attribute"""
22 return self.data().real(inputid).value()
24 def getTextInput(self, inputid):
25 """F.getTextInput(str) -- get text value of the attribute"""
26 return self.data().real(inputid).text()
28 def addResult(self, result):
29 """F.addResult(ModelAPI_Result) -- add ModelAPI_Result shape as a result"""
30 shape = result.shape()
31 body = self.document().createBody(self.data())
37 """Base class of high level Python interfaces to features."""
39 def __init__(self, feature):
40 """x.__init__(...) initializes x; see x.__class__.__doc__ for signature"""
41 self._feature = feature
44 """Return ModelAPI_Feature."""
48 """Return the unique kind of the feature"""
49 return self._feature.getKind()
52 """Return current results of the feature"""
53 return self._feature.results()
55 def firstResult(self):
56 """Return the first result in the list of results"""
57 return self._feature.firstResult()
60 """Return the last result in the list of results"""
61 return self._feature.lastResult()
63 def setRealInput(self, inputid, value):
64 """I.setRealInput(str, float) -- set real value to the attribute"""
65 self._feature.data().real(inputid).setValue(value)
67 def areInputValid(self):
68 """I.areInputValid() -> True or False validation result"""
69 validators = ModelAPI.ModelAPI_Session.get().validators()
70 return validators.validate(self._feature)
73 """I.execute() -- validate and execute the feature.
75 Raises RuntimeError if validation fails.
77 if self.areInputValid():
78 self._feature.execute()
80 raise RuntimeError("Can not execute %s: %s" %
81 (self._feature.getKind(), self._feature.error())