Salome HOME
Improve extrusion feature.
[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
30     def __init__(self, feature, *args):
31         CompositeBoolean.__init__(self, feature, *args)
32
33         self._CreationMethod = self._feature.string("CreationMethod")
34         self._to_size = self._feature.data().real("to_size")
35         self._from_size = self._feature.data().real("from_size")
36         self._to_object = self._feature.data().selection("to_object")
37         self._to_offset = self._feature.data().real("to_offset")
38         self._from_object = self._feature.data().selection("from_object")
39         self._from_offset = self._feature.data().real("from_offset")
40
41         assert(self._CreationMethod)
42         assert(self._to_size)
43         assert(self._from_size)
44         assert(self._to_object)
45         assert(self._to_offset)
46         assert(self._from_object)
47         assert(self._from_offset)
48
49         if not args:
50             return
51
52         assert(len(args) == 4 or len(args) == 2)
53         if len(args) == 4:
54             self.setPlanesAndOffsets(*args)
55         elif len(args) == 2:
56             self.setSizes(*args)
57         pass
58
59     def __clear(self):
60         self._CreationMethod.setValue("BySizes")
61         self._fill_attribute(self._to_size, 0)
62         self._fill_attribute(self._from_size, 0)
63         self._fill_attribute(self._to_object, None)
64         self._fill_attribute(self._to_offset, 0)
65         self._fill_attribute(self._from_object, None)
66         self._fill_attribute(self._from_offset, 0)
67         pass
68
69     def setSizes(self, to_size, from_size):
70         """Modify the to_size, from_size attributes of the feature.
71
72         See __init__.
73         """
74         self.__clear()
75         self._CreationMethod.setValue("BySizes")
76         self._fill_attribute(self._to_size, to_size)
77         self._fill_attribute(self._from_size, from_size)
78         pass
79
80     def setPlanesAndOffsets(self, to_object, to_offset,
81                             from_object, from_offset):
82         """Modify planes and offsets attributes of the feature.
83
84         See __init__.
85         """
86         self.__clear()
87         self._CreationMethod.setValue("ByPlanesAndOffsets")
88         self._fill_attribute(self._to_object, to_object)
89         self._fill_attribute(self._to_offset, to_offset)
90         self._fill_attribute(self._from_object, from_object)
91         self._fill_attribute(self._from_offset, from_offset)
92         pass
93