Salome HOME
Improve PythonAPI documentation
[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     .. function:: addParameter(part, variable, expression)
13
14     Args:
15         part (ModelAPI_Document): part document
16         variable (string): variable name
17         expression (string): Python expression
18
19     Returns:
20         Parameter: parameter object
21
22     Pass all args to Parameter __init__ function.
23     """
24     assert(args)
25     feature = part.addFeature("Parameter")
26     return Parameter(feature, *args)
27
28
29 class Parameter(Interface):
30     """Interface class for Parameter feature.
31
32     .. function:: Point(feature)
33
34         Create interface for the feature without initialization.
35
36     .. function:: Point(feature, variable, expression)
37
38         Create interface for the feature and initialize the feature with arguments.
39     """
40
41     def __init__(self, feature, *args):
42         """x.__init__(...) initializes x; see x.__class__.__doc__ for signature"""
43         Interface.__init__(self, feature)
44         assert(self._feature.getKind() == "Parameter")
45
46         self._variable = self._feature.data().string("variable")
47         self._expression = self._feature.data().string("expression")
48
49         assert(self._variable)
50         assert(self._expression)
51
52         if not args:
53             return
54
55         assert(len(args) == 2)
56         self.setName(args[0])
57         self.setExpression(args[1])
58
59         self.execute()
60         pass
61
62     def setName(self, name):
63         """Modify variable name attribute of the feature.
64
65         See __init__.
66         """
67         self._fillAttribute(self._name, name)
68         pass
69
70     def setExpression(self, expression):
71         """Modify expression attribute of the feature.
72
73         See __init__.
74         """
75         self._fillAttribute(self._expression, expression)
76         pass