Salome HOME
Added support of python high level API addons proposed by DBC as test of this approach.
[modules/shaper.git] / src / PythonAPI / modeler / 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 from ModelAPI import *
7
8
9 class Feature(ModelAPI_Feature):
10   """Base class of user-defined Python features."""
11
12   def __init__(self):
13     ModelAPI_Feature.__init__(self)
14
15   def addRealInput (self, inputid):
16     self.data().addAttribute(inputid, ModelAPI_AttributeDouble_typeId())
17
18   def getRealInput (self, inputid):
19     return self.data().real(inputid).value()
20
21   def addResult (self, result):
22     shape = result.shape()
23     body  = self.document().createBody( self.data() )
24     body.store(shape)
25     self.setResult(body)
26
27
28 class Interface():
29   """Base class of hight level Python interfaces to features."""
30
31   def __init__(self, container, fid):
32     self.my = container.addFeature(fid)
33
34   def setRealInput (self, inputid, value):
35     self.my.data().real(inputid).setValue(value)
36
37   def areInputValid (self):
38     return ModelAPI_Session.get().validators().validate(self.my)
39
40   def execute (self):
41     self.my.execute()