Salome HOME
Make redirect missing attributes to the feature.
[modules/shaper.git] / src / PythonAPI / model / roots.py
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
4 """
5
6 import ModelAPI
7
8
9
10 class Feature(ModelAPI.ModelAPI_Feature):
11     """Base class of user-defined Python features."""
12
13     def __init__(self):
14         ModelAPI.ModelAPI_Feature.__init__(self)
15
16     def addRealInput (self, inputid):
17         self.data().addAttribute(inputid,
18                                  ModelAPI.ModelAPI_AttributeDouble_typeId())
19
20     def getRealInput (self, inputid):
21         return self.data().real(inputid).value()
22
23     def addResult (self, result):
24         shape = result.shape()
25         body = self.document().createBody(self.data())
26         body.store(shape)
27         self.setResult(body)
28
29
30 class Interface():
31     """Base class of hight level Python interfaces to features."""
32
33     def __init__(self, feature):
34         self._feature = feature
35
36     def __getattr__(self, name):
37         """Process missing attributes.
38
39         Redirect missing attributes to the feature.
40         """
41         return self._feature.__getattribute__(name)
42
43     def setRealInput (self, inputid, value):
44         self._feature.data().real(inputid).setValue(value)
45
46     def areInputValid (self):
47         validators = ModelAPI.ModelAPI_Session.get().validators()
48         return validators.validate(self._feature)
49
50     def execute (self):
51         self._feature.execute()