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