Salome HOME
Documenting of Python code
[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     """Constructor"""
14     ModelAPI_Feature.__init__(self)
15
16   def addRealInput (self, inputid):
17     """Add double input"""
18     self.data().addAttribute(inputid, ModelAPI_AttributeDouble_typeId())
19
20   def getRealInput (self, inputid):
21     """Returns double input"""
22     return self.data().real(inputid).value()
23
24   def addResult (self, result):
25     """Add result"""
26     shape = result.shape()
27     body  = self.document().createBody( self.data() )
28     body.store(shape)
29     self.setResult(body)
30
31
32 class Interface():
33   """Base class of hight level Python interfaces to features."""
34
35   def __init__(self, container, fid):
36     """Constructor"""
37     ### Create the feature
38     self.my = container.addFeature(fid)
39
40   def setRealInput (self, inputid, value):
41     """Set real value"""
42     self.my.data().real(inputid).setValue(value)
43
44   def areInputValid (self):
45     """Returns True if the input is valid"""
46     return ModelAPI_Session.get().validators().validate(self.my)
47
48   def execute (self):
49     """Build the feature result"""
50     self.my.execute()