Salome HOME
Improve PythonAPI documentstion.
[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 and return ExtrusionBoolean.
11
12     Pass all args to Extrusion __init__ function.
13     """
14     assert(args)
15     feature = part.addFeature("ExtrusionCut")
16     return ExtrusionBoolean(feature, *args)
17
18 def addExtrusionFuse(part, *args):
19     """Add an ExtrusionFuse feature to the Part and return ExtrusionBoolean.
20
21     Pass all args to Extrusion __init__ function.
22     """
23     assert(args)
24     feature = part.addFeature("ExtrusionFuse")
25     return ExtrusionBoolean(feature, *args)
26
27
28 class ExtrusionBoolean(CompositeBoolean):
29     """Interface class for ExtrusionBoolean features.
30
31     Supported features:
32     - ExtrusionCut
33     - ExtrusionFuse
34
35     ExtrusionBoolean(feature) -> feature interface without initialization
36     ExtrusionBoolean(feature,
37                      sketch, sketch_selection, boolean_objects,
38                      to_size, from_size) ->
39         feature interface initialized from arguments:
40         - sketch
41         - sketch_selection
42         - boolean_objects
43         - to_size
44         - from_size
45     ExtrusionBoolean(feature,
46                      sketch, sketch_selection, boolean_objects,
47                      to_object, to_offset, from_object, from_offset) ->
48         feature interface initialized from arguments:
49         - sketch
50         - sketch_selection
51         - boolean_objects
52         - to_object
53         - to_offset
54         - from_object
55         - from_offset
56     """
57
58     def __init__(self, feature, *args):
59         """x.__init__(...) initializes x; see x.__class__.__doc__ for signature"""
60         CompositeBoolean.__init__(self, feature, *args[:3])
61         args = args[3:]
62
63         self._CreationMethod = self._feature.string("CreationMethod")
64         self._to_size = self._feature.data().real("to_size")
65         self._from_size = self._feature.data().real("from_size")
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._CreationMethod)
72         assert(self._to_size)
73         assert(self._from_size)
74         assert(self._to_object)
75         assert(self._to_offset)
76         assert(self._from_object)
77         assert(self._from_offset)
78
79         if not args:
80             return
81
82         assert(len(args) in (2, 4))
83         if len(args) == 4:
84             self.setPlanesAndOffsets(*args)
85         elif len(args) == 2:
86             self.setSizes(*args)
87
88         self._execute()
89         pass
90
91     def __clear(self):
92         self._CreationMethod.setValue("BySizes")
93         self._fill_attribute(self._to_size, 0)
94         self._fill_attribute(self._from_size, 0)
95         self._fill_attribute(self._to_object, None)
96         self._fill_attribute(self._to_offset, 0)
97         self._fill_attribute(self._from_object, None)
98         self._fill_attribute(self._from_offset, 0)
99         pass
100
101     def setSizes(self, to_size, from_size):
102         """Modify the to_size, from_size attributes of the feature.
103
104         See __init__.
105         """
106         self.__clear()
107         self._CreationMethod.setValue("BySizes")
108         self._fill_attribute(self._to_size, to_size)
109         self._fill_attribute(self._from_size, from_size)
110         pass
111
112     def setPlanesAndOffsets(self, to_object, to_offset,
113                             from_object, from_offset):
114         """Modify planes and offsets attributes of the feature.
115
116         See __init__.
117         """
118         self.__clear()
119         self._CreationMethod.setValue("ByPlanesAndOffsets")
120         self._fill_attribute(self._to_object, to_object)
121         self._fill_attribute(self._to_offset, to_offset)
122         self._fill_attribute(self._from_object, from_object)
123         self._fill_attribute(self._from_offset, from_offset)
124         pass
125