]> SALOME platform Git repositories - modules/shaper.git/blob - src/PythonAPI/model/features/revolution_boolean.py
Salome HOME
Fix Platine test
[modules/shaper.git] / src / PythonAPI / model / features / revolution_boolean.py
1 """RevolutionCut and RevolutionFuse Interface
2 Author: Sergey Pokhodenko
3 Copyright (C) 2014-20xx CEA/DEN, EDF R&D
4 """
5
6 from .roots import CompositeBoolean
7
8
9 def addRevolutionCut(part, *args):
10     """Add a RevolutionCut feature to the Part.
11
12     .. function:: addRevolutionCut(part, sketch, sketch_selection, boolean_objects, axis_object, to_angle, from_angle)
13
14     Args:
15         part (ModelAPI_Document): part document
16         sketch (ModelAPI_Object): sketch feature
17         sketch_selection (Selection): sketch objects
18         boolean_objects (list of Selection): boolean objects
19         axis_object (Selection): axis object
20         to_size (double): upper size of the extrusion
21         from_size (double): lower size of the extrusion
22
23     .. function:: addRevolutionCut(part, sketch, sketch_selection, boolean_objects, axis_object, to_object, to_offset, from_object, from_offset)
24
25     Args:
26         part (ModelAPI_Document): part document
27         sketch (ModelAPI_Object): sketch feature
28         sketch_selection (Selection): sketch objects
29         boolean_objects (list of Selection): boolean objects
30         axis_object (Selection): axis object
31         to_object (Selection): upper plane
32         to_offset (double): offset from upper plane
33         from_object (Selection): lower plane
34         from_offset (double): offset from lower plane
35
36     Returns:
37         RevolutionBoolean: revolution boolean object
38     """
39     assert(args)
40     feature = part.addFeature("RevolutionCut")
41     return RevolutionBoolean(feature, *args)
42
43 def addRevolutionFuse(part, *args):
44     """Add a RevolutionFuse feature to the Part.
45
46     .. function:: addRevolutionFuse(part, sketch, sketch_selection, boolean_objects, axis_object, to_angle, from_angle)
47
48     Args:
49         part (ModelAPI_Document): part document
50         sketch (ModelAPI_Object): sketch feature
51         sketch_selection (Selection): sketch objects
52         boolean_objects (list of Selection): boolean objects
53         axis_object (Selection): axis object
54         to_size (double): upper size of the extrusion
55         from_size (double): lower size of the extrusion
56
57     .. function:: addRevolutionFuse(part, sketch, sketch_selection, boolean_objects, axis_object, to_object, to_offset, from_object, from_offset)
58
59     Args:
60         part (ModelAPI_Document): part document
61         sketch (ModelAPI_Object): sketch feature
62         sketch_selection (Selection): sketch objects
63         boolean_objects (list of Selection): boolean objects
64         axis_object (Selection): axis object
65         to_object (Selection): upper plane
66         to_offset (double): offset from upper plane
67         from_object (Selection): lower plane
68         from_offset (double): offset from lower plane
69
70
71     Pass all args to RevolutionFuse __init__ function.
72
73     Returns:
74         RevolutionBoolean: revolution boolean object
75     """
76     assert(args)
77     feature = part.addFeature("RevolutionFuse")
78     return RevolutionBoolean(feature, *args)
79
80
81 class RevolutionBoolean(CompositeBoolean):
82     """Interface class for RevolutionBoolean features.
83
84     Supported features:
85
86     * RevolutionCut
87     * RevolutionFuse
88
89     .. function:: RevolutionBoolean(feature)
90
91         Create interface for the feature without initialization.
92
93     .. function:: RevolutionBoolean(feature, sketch, sketch_selection, boolean_objects, axis_object, to_angle, from_angle)
94
95         Create interface for the feature and initialize the feature with arguments.
96
97     .. function:: RevolutionBoolean(feature, sketch, sketch_selection, boolean_objects, axis_object, to_object, to_offset, from_object, from_offset)
98
99         Create interface for the feature and initialize the feature with arguments.
100     """
101
102     def __init__(self, feature, *args):
103         """x.__init__(...) initializes x; see x.__class__.__doc__ for signature"""
104         CompositeBoolean.__init__(self, feature, *args[:3])
105         args = args[3:]
106
107         self._axis_object = self._feature.data().selection("axis_object")
108         self._CreationMethod = self._feature.string("CreationMethod")
109         self._to_angle = self._feature.data().real("to_angle")
110         self._from_angle = self._feature.data().real("from_angle")
111         self._to_object = self._feature.data().selection("to_object")
112         self._to_offset = self._feature.data().real("to_offset")
113         self._from_object = self._feature.data().selection("from_object")
114         self._from_offset = self._feature.data().real("from_offset")
115
116         assert(self._axis_object)
117         assert(self._CreationMethod)
118         assert(self._to_angle)
119         assert(self._from_angle)
120         assert(self._to_object)
121         assert(self._to_offset)
122         assert(self._from_object)
123         assert(self._from_offset)
124
125         if not args:
126             return
127
128         assert(len(args) in (3, 5))
129         axis_object = args[0]
130         args = args[1:]
131
132         self.setAxisObject(axis_object)
133
134         if len(args) == 4:
135             self.setPlanesAndOffsets(*args)
136         elif len(args) == 2:
137             self.setAngles(*args)
138
139         self.execute()
140         pass
141
142     def __clear(self):
143         self._CreationMethod.setValue("ByAngles")
144         self._fillAttribute(self._to_angle, 0)
145         self._fillAttribute(self._from_angle, 0)
146         self._fillAttribute(self._to_object, None)
147         self._fillAttribute(self._to_offset, 0)
148         self._fillAttribute(self._from_object, None)
149         self._fillAttribute(self._from_offset, 0)
150         pass
151
152     def setAxisObject(self, axis_object):
153         """Modify axis_object attribute of the feature.
154
155         See __init__.
156         """
157         self._fillAttribute(self._axis_object, axis_object)
158         pass
159
160     def setAngles(self, to_angle, from_angle):
161         """Modify the to_angle, from_angle attributes of the feature.
162
163         See __init__.
164         """
165         self.__clear()
166         self._CreationMethod.setValue("ByAngles")
167         self._fillAttribute(self._to_angle, to_angle)
168         self._fillAttribute(self._from_angle, from_angle)
169         pass
170
171     def setPlanesAndOffsets(self, to_object, to_offset,
172                             from_object, from_offset):
173         """Modify planes and offsets attributes of the feature.
174
175         See __init__.
176         """
177         self.__clear()
178         self._CreationMethod.setValue("ByPlanesAndOffsets")
179         self._fillAttribute(self._to_object, to_object)
180         self._fillAttribute(self._to_offset, to_offset)
181         self._fillAttribute(self._from_object, from_object)
182         self._fillAttribute(self._from_offset, from_offset)
183         pass
184