]> SALOME platform Git repositories - modules/shaper.git/blob - src/PythonAPI/model/features/extrusion.py
Salome HOME
0f1cbea8341df448cd2e503c94598d843d66e81e
[modules/shaper.git] / src / PythonAPI / model / features / extrusion.py
1 """Extrusion Interface
2 Author: Daniel Brunier-Coulin with contribution by Mikhail Ponikarov
3         and Sergey Pokhodenko
4 Copyright (C) 2014-20xx CEA/DEN, EDF R&D
5 """
6
7 from model.roots import Interface
8 from model import Selection
9
10 def addExtrusion(part, *args):
11     """Add an Extrusion feature to the Part and return Extrusion.
12
13     Pass all args to Extrusion __init__ function.
14     """
15     assert(args)
16     feature = part.addFeature("Extrusion")
17     return Extrusion(feature, *args)
18
19
20 class Extrusion(Interface):
21     """Interface on an Extrusion feature."""
22
23     def __init__(self, feature, *args):
24         """Initialize an Extrusion feature with given parameters.
25
26         Expected arguments for all modes:
27         feature -- an Extrusion feature
28
29         Expected arguments for initializing the feature:
30         base -- name, sketch or list of names and sketches.
31         If base is None then don't change the feature.
32
33         For BySize mode (expect 2 arguments):
34         to_size -- upper size
35         from_size -- lower size
36
37         For ByPlanesAndOffsets mode (expect 4 arguments):
38         to_object -- upper object (plane)
39         to_offset -- offset from upper object
40         from_object -- lower object (plane)
41         from_offset -- offset from lower object
42         """
43         Interface.__init__(self, feature)
44         assert(self._feature.getKind() == "Extrusion")
45
46         self._base = self._feature.data().selectionList("base")
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._base)
56         assert(self._CreationMethod)
57         assert(self._to_size)
58         assert(self._from_size)
59         assert(self._to_object)
60         assert(self._to_offset)
61         assert(self._from_object)
62         assert(self._from_offset)
63
64         if not args:
65             return
66
67         assert(len(args) in (2, 3, 5))
68         base = args[0]
69         args = args[1:]
70
71         self.setBase(base)
72
73         if len(args) == 4:
74             self.setPlanesAndOffsets(*args)
75         elif len(args) == 2:
76             self.setSizes(*args)
77         elif len(args) == 1:
78             self.setSize(args[0])
79
80         self._execute()
81         pass
82
83     def __clear(self):
84         self._CreationMethod.setValue("BySizes")
85         self._fill_attribute(self._to_size, 0)
86         self._fill_attribute(self._from_size, 0)
87         self._fill_attribute(self._to_object, None)
88         self._fill_attribute(self._to_offset, 0)
89         self._fill_attribute(self._from_object, None)
90         self._fill_attribute(self._from_offset, 0)
91         pass
92
93     def setBase(self, base):
94         """Modify base attribute of the feature.
95
96         See __init__.
97         """
98         self._fill_attribute(self._base, base)
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 setSize(self, size):
113         """Modify the size of the feature.
114
115         If size is positive then initialize to_size with size.
116         If size is negative then initialize from_size with -size.
117         """
118         to_size, from_size = 0, 0
119         if size >= 0:
120             to_size = size
121         else:
122             from_size = -size
123
124         self.setSizes(to_size, from_size)
125         pass
126
127     def setPlanesAndOffsets(self, to_object, to_offset,
128                             from_object, from_offset):
129         """Modify planes and offsets attributes of the feature.
130
131         See __init__.
132         """
133         self.__clear()
134         self._CreationMethod.setValue("ByPlanesAndOffsets")
135         self._fill_attribute(self._to_object, to_object)
136         self._fill_attribute(self._to_offset, to_offset)
137         self._fill_attribute(self._from_object, from_object)
138         self._fill_attribute(self._from_offset, from_offset)
139         pass
140
141     def result(self):
142         return [Selection(result, result.shape()) for result in (self.firstResult(),)]