Salome HOME
Unit tests:
[modules/shaper.git] / src / PythonAPI / model / features / extrusion_sketch.py
1 """ExtrusionSketch  Interfaces
2 Author: Sergey Pokhodenko
3 Copyright (C) 2014-20xx CEA/DEN, EDF R&D
4 """
5
6 from .roots import CompositeSketch
7
8
9 def addExtrusionSketch(part, *args):
10     """Add an ExtrusionSketch feature to the Part.
11
12     .. function:: addExtrusionSketch(part, sketch, sketch_selection, 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         to_size (double): upper size of the extrusion
19         from_size (double): lower size of the extrusion
20
21     .. function:: addExtrusionSketch(part, sketch, sketch_selection, to_object, to_offset, from_object, from_offset)
22
23     Args:
24         part (ModelAPI_Document): part document
25         sketch (ModelAPI_Object): sketch feature
26         sketch_selection (Selection): sketch objects
27         to_object (Selection): upper plane
28         to_offset (double): offset from upper plane
29         from_object (Selection): lower plane
30         from_offset (double): offset from lower plane
31
32     Returns:
33         ExtrusionSketch: extrusion sketch object
34     """
35     assert(args)
36     feature = part.addFeature("ExtrusionSketch")
37     return ExtrusionSketch(feature, *args)
38
39
40 class ExtrusionSketch(CompositeSketch):
41     """Interface class for ExtrusionSketch feature.
42
43     .. function:: ExtrusionSketch(feature)
44
45     Create interface for the feature without initialization.
46
47     .. function:: ExtrusionSketch(feature, sketch, sketch_selection, to_size, from_size)
48
49     Create interface for the feature and initialize the feature with arguments.
50
51     .. function:: ExtrusionSketch(feature, sketch, sketch_selection, to_object, to_offset, from_object, from_offset)
52
53     Create interface for the feature and initialize the feature with arguments.
54     """
55     def __init__(self, feature, *args):
56         """x.__init__(...) initializes x; see x.__class__.__doc__ for signature"""
57         CompositeSketch.__init__(self, feature, *args[:2])
58         args = args[2:]
59
60         self._CreationMethod = self._feature.string("CreationMethod")
61         self._to_size = self._feature.data().real("to_size")
62         self._from_size = self._feature.data().real("from_size")
63         self._to_object = self._feature.data().selection("to_object")
64         self._to_offset = self._feature.data().real("to_offset")
65         self._from_object = self._feature.data().selection("from_object")
66         self._from_offset = self._feature.data().real("from_offset")
67
68         assert(self._CreationMethod)
69         assert(self._to_size)
70         assert(self._from_size)
71         assert(self._to_object)
72         assert(self._to_offset)
73         assert(self._from_object)
74         assert(self._from_offset)
75
76         if not args:
77             return
78
79         assert(len(args) in (2, 4))
80         if len(args) == 4:
81             self.setPlanesAndOffsets(*args)
82         elif len(args) == 2:
83             self.setSizes(*args)
84
85         self.execute()
86         pass
87
88     def __clear(self):
89         self._CreationMethod.setValue("BySizes")
90         self._fillAttribute(self._to_size, 0)
91         self._fillAttribute(self._from_size, 0)
92         self._fillAttribute(self._to_object, None)
93         self._fillAttribute(self._to_offset, 0)
94         self._fillAttribute(self._from_object, None)
95         self._fillAttribute(self._from_offset, 0)
96         pass
97
98     def setSizes(self, to_size, from_size):
99         """Modify the to_size, from_size attributes of the feature.
100
101         See __init__.
102         """
103         self.__clear()
104         self._CreationMethod.setValue("BySizes")
105         self._fillAttribute(self._to_size, to_size)
106         self._fillAttribute(self._from_size, from_size)
107         pass
108
109     def setPlanesAndOffsets(self, to_object, to_offset,
110                             from_object, from_offset):
111         """Modify planes and offsets attributes of the feature.
112
113         See __init__.
114         """
115         self.__clear()
116         self._CreationMethod.setValue("ByPlanesAndOffsets")
117         self._fillAttribute(self._to_object, to_object)
118         self._fillAttribute(self._to_offset, to_offset)
119         self._fillAttribute(self._from_object, from_object)
120         self._fillAttribute(self._from_offset, from_offset)
121         pass
122