Salome HOME
3ab420144b67cc05bff14d2c8a40049aed42c12c
[modules/shaper.git] / src / PythonAPI / model / features / revolution.py
1 """Revolution 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 addRevolution(part, *args):
10     """Add a Revolution feature to the Part.
11
12     .. function:: addRevolution(part, base, axis_object, to_angle, from_angle)
13
14     Args:
15         part (ModelAPI_Document): part document
16         base (list of Selection): base objects
17         axis_object (Selection): axis object
18         to_angle (double): to angle
19         from_angle (double): from angle
20
21     .. function:: addRevolution(feature, base, axis_object, to_object, to_offset, from_object, from_offset)
22
23     Args:
24         part (ModelAPI_Document): part document
25         base (list of Selection): base objects
26         axis_object (Selection): axis object
27         to_object (plane): upper plane
28         to_offset (double): offset from upper object
29         from_object (plane): lower plane
30         from_offset (double): offset from lower plane
31
32     Returns:
33         Revolution: revolution object
34     """
35     assert(len(args) > 0 and args[0] is not None)
36     feature = part.addFeature("Revolution")
37     return Revolution(feature, *args)
38
39
40 class Revolution(Interface):
41     """Interface class for Revolution features.
42
43     .. function:: Revolution(feature)
44
45         Create interface for the feature without initialization.
46
47     .. function:: Revolution(feature, base, axis_object, to_angle, from_angle)
48
49         Create interface for the feature and initialize the feature with arguments.
50
51     .. function:: Revolution(feature, base, axis_object, to_object, to_offset, from_object, from_offset)
52
53         Create interface for the feature and initialize the feature with arguments.
54     """
55
56     def __init__(self, feature, *args):
57         """x.__init__(...) initializes x; see x.__class__.__doc__ for signature"""
58         Interface.__init__(self, feature)
59         assert(self._feature.getKind() == "Revolution")
60
61         self._base = self._feature.data().selectionList("base")
62         self._axis_object = self._feature.data().selection("axis_object")
63         self._CreationMethod = self._feature.string("CreationMethod")
64         self._to_angle = self._feature.data().real("to_angle")
65         self._from_angle = self._feature.data().real("from_angle")
66         self._to_object = self._feature.data().selection("to_object")
67         self._to_offset = self._feature.data().real("to_offset")
68         self._from_object = self._feature.data().selection("from_object")
69         self._from_offset = self._feature.data().real("from_offset")
70
71         assert(self._base)
72         assert(self._axis_object)
73         assert(self._CreationMethod)
74         assert(self._to_angle)
75         assert(self._from_angle)
76         assert(self._to_object)
77         assert(self._to_offset)
78         assert(self._from_object)
79         assert(self._from_offset)
80
81         if not args:
82             return
83
84         assert(len(args) in (4, 6))
85
86         base, axis_object = args[:2]
87         args = args[2:]
88
89         self.setBase(base)
90         self.setAxisObject(axis_object)
91
92         if len(args) == 4:
93             self.setPlanesAndOffsets(*args)
94         elif len(args) == 2:
95             self.setAngles(*args)
96
97         self.execute()
98         pass
99
100     def __clear(self):
101         self._CreationMethod.setValue("ByAngles")
102         self._fillAttribute(self._to_angle, 0)
103         self._fillAttribute(self._from_angle, 0)
104         self._fillAttribute(self._to_object, None)
105         self._fillAttribute(self._to_offset, 0)
106         self._fillAttribute(self._from_object, None)
107         self._fillAttribute(self._from_offset, 0)
108         pass
109
110     def setBase(self, base):
111         """Modify base attribute of the feature.
112
113         See __init__.
114         """
115         self._fillAttribute(self._base, base)
116         pass
117
118     def setAxisObject(self, axis_object):
119         """Modify axis_object attribute of the feature.
120
121         See __init__.
122         """
123         self._fillAttribute(self._axis_object, axis_object)
124         pass
125
126     def setAngles(self, to_angle, from_angle):
127         """Modify the to_angle, from_angle attributes of the feature.
128
129         See __init__.
130         """
131         self.__clear()
132         self._CreationMethod.setValue("ByAngles")
133         self._fillAttribute(self._to_angle, to_angle)
134         self._fillAttribute(self._from_angle, from_angle)
135         pass
136
137     def setPlanesAndOffsets(self, to_object, to_offset,
138                             from_object, from_offset):
139         """Modify planes and offsets attributes of the feature.
140
141         See __init__.
142         """
143         self.__clear()
144         self._CreationMethod.setValue("ByPlanesAndOffsets")
145         self._fillAttribute(self._to_object, to_object)
146         self._fillAttribute(self._to_offset, to_offset)
147         self._fillAttribute(self._from_object, from_object)
148         self._fillAttribute(self._from_offset, from_offset)
149         pass