Salome HOME
Improve PythonAPI documentstion.
[modules/shaper.git] / src / PythonAPI / model / parameter / parameter.py
1 """Parameter Interface
2 Author: Sergey Pokhodenko
3 Copyright (C) 2014-20xx CEA/DEN, EDF R&D
4 """
5
6 from model.roots import Interface
7
8
9 def addParameter(part, *args):
10     """Add a Parameter feature to the Part and return Parameter.
11
12     Pass all args to Parameter __init__ function.
13     """
14     feature = part.addFeature("Parameter")
15     return Parameter(feature, *args)
16
17
18 class Parameter(Interface):
19     """Interface class for Parameter feature.
20
21     Parameter(feature) -> feature interface without initialization
22     Parameter(feature, variable, expression) ->
23         feature interface initialized from arguments:
24         - variable -- variable name
25         - expression -- Python expression
26     """
27
28     def __init__(self, feature, *args):
29         """x.__init__(...) initializes x; see x.__class__.__doc__ for signature"""
30         Interface.__init__(self, feature)
31         assert(self._feature.getKind() == "Parameter")
32
33         self._variable = self._feature.data().selection("variable")
34         self._expression = self._feature.data().real("expression")
35
36         assert(self._variable)
37         assert(self._expression)
38
39         if not args:
40             return
41
42         assert(len(args) == 2)
43         self.setName(args[0])
44         self.setExpression(args[1])
45
46         self._execute()
47         pass
48
49     def setName(self, name):
50         """Modify variable name attribute of the feature.
51
52         See __init__.
53         """
54         self._fill_attribute(self._name, name)
55         pass
56
57     def setExpression(self, expression):
58         """Modify expression attribute of the feature.
59
60         See __init__.
61         """
62         self._fill_attribute(self._expression, expression)
63         pass