Salome HOME
199d1e1d990a691e361646e63f3cac7c3f929e54
[modules/shaper.git] / src / PythonAPI / model / features / extrusion_boolean.py
1 """ExtrusionCut and ExtrusionFuse  Interfaces
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 addExtrusionCut(part, *args):
10     """Add an ExtrusionCut feature to the Part.
11
12     .. function:: addExtrusionCut(part, sketch, sketch_selection, boolean_objects, to_size, from_size)
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         to_size (double): upper size of the extrusion
20         from_size (double): lower size of the extrusion
21
22     .. function:: addExtrusionCut(part, sketch, sketch_selection, boolean_objects, to_object, to_offset, from_object, from_offset)
23
24     Args:
25         part (ModelAPI_Document): part document
26         sketch (ModelAPI_Object): sketch feature
27         sketch_selection (Selection): sketch objects
28         boolean_objects (list of Selection): boolean objects
29         to_object (Selection): upper plane
30         to_offset (double): offset from upper plane
31         from_object (Selection): lower plane
32         from_offset (double): offset from lower plane
33
34     Returns:
35         ExtrusionBoolean: extrusion boolean object
36     """
37     assert(args)
38     feature = part.addFeature("ExtrusionCut")
39     return ExtrusionBoolean(feature, *args)
40
41 def addExtrusionFuse(part, *args):
42     """Add an ExtrusionFuse feature to the Part and return ExtrusionBoolean.
43
44     .. function:: addExtrusionFuse(part, sketch, sketch_selection, boolean_objects, to_size, from_size)
45
46     Args:
47         part (ModelAPI_Document): part document
48         sketch (ModelAPI_Object): sketch feature
49         sketch_selection (Selection): sketch objects
50         boolean_objects (list of Selection): boolean objects
51         to_size (double): upper size of the extrusion
52         from_size (double): lower size of the extrusion
53
54     .. function:: addExtrusionFuse(part, sketch, sketch_selection, boolean_objects, to_object, to_offset, from_object, from_offset)
55
56     Args:
57         part (ModelAPI_Document): part document
58         sketch (ModelAPI_Object): sketch feature
59         sketch_selection (Selection): sketch objects
60         boolean_objects (list of Selection): boolean objects
61         to_object (Selection): upper plane
62         to_offset (double): offset from upper plane
63         from_object (Selection): lower plane
64         from_offset (double): offset from lower plane
65
66     Returns:
67         ExtrusionBoolean: extrusion boolean object
68     """
69     assert(args)
70     feature = part.addFeature("ExtrusionFuse")
71     return ExtrusionBoolean(feature, *args)
72
73
74 class ExtrusionBoolean(CompositeBoolean):
75     """Interface class for ExtrusionBoolean features.
76
77     Supported features:
78
79     * ExtrusionCut
80     * ExtrusionFuse
81
82     .. function:: ExtrusionBoolean(feature)
83
84         Create interface for the feature without initialization.
85
86     .. function:: ExtrusionBoolean(feature, sketch, sketch_selection, boolean_objects, to_size, from_size)
87
88         Create interface for the feature and initialize the feature with arguments.
89
90     .. function:: ExtrusionBoolean(feature, sketch, sketch_selection, boolean_objects, to_object, to_offset, from_object, from_offset)
91
92         Create interface for the feature and initialize the feature with arguments.
93     """
94
95     def __init__(self, feature, *args):
96         """x.__init__(...) initializes x; see x.__class__.__doc__ for signature"""
97         CompositeBoolean.__init__(self, feature, *args[:3])
98         args = args[3:]
99
100         self._CreationMethod = self._feature.string("CreationMethod")
101         self._to_size = self._feature.data().real("to_size")
102         self._from_size = self._feature.data().real("from_size")
103         self._to_object = self._feature.data().selection("to_object")
104         self._to_offset = self._feature.data().real("to_offset")
105         self._from_object = self._feature.data().selection("from_object")
106         self._from_offset = self._feature.data().real("from_offset")
107
108         assert(self._CreationMethod)
109         assert(self._to_size)
110         assert(self._from_size)
111         assert(self._to_object)
112         assert(self._to_offset)
113         assert(self._from_object)
114         assert(self._from_offset)
115
116         if not args:
117             return
118
119         assert(len(args) in (2, 4))
120         if len(args) == 4:
121             self.setPlanesAndOffsets(*args)
122         elif len(args) == 2:
123             self.setSizes(*args)
124
125         self.execute()
126         pass
127
128     def __clear(self):
129         self._CreationMethod.setValue("BySizes")
130         self._fillAttribute(self._to_size, 0)
131         self._fillAttribute(self._from_size, 0)
132         self._fillAttribute(self._to_object, None)
133         self._fillAttribute(self._to_offset, 0)
134         self._fillAttribute(self._from_object, None)
135         self._fillAttribute(self._from_offset, 0)
136         pass
137
138     def setSizes(self, to_size, from_size):
139         """Modify the to_size, from_size attributes of the feature.
140
141         See __init__.
142         """
143         self.__clear()
144         self._CreationMethod.setValue("BySizes")
145         self._fillAttribute(self._to_size, to_size)
146         self._fillAttribute(self._from_size, from_size)
147         pass
148
149     def setPlanesAndOffsets(self, to_object, to_offset,
150                             from_object, from_offset):
151         """Modify planes and offsets attributes of the feature.
152
153         See __init__.
154         """
155         self.__clear()
156         self._CreationMethod.setValue("ByPlanesAndOffsets")
157         self._fillAttribute(self._to_object, to_object)
158         self._fillAttribute(self._to_offset, to_offset)
159         self._fillAttribute(self._from_object, from_object)
160         self._fillAttribute(self._from_offset, from_offset)
161         pass
162