]> SALOME platform Git repositories - modules/shaper.git/blob - src/PythonAPI/model/features/extrusion.py
Salome HOME
Improve extrusion feature.
[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         self.setBase(args[0])
68
69         args = args[1:]
70         assert(len(args) in (1, 2, 4))
71
72         if len(args) == 4:
73             self.setPlanesAndOffsets(*args)
74         elif len(args) == 2:
75             self.setSizes(*args)
76         elif len(args) == 1:
77             self.setSize(args[0])
78         pass
79
80     def __clear(self):
81         self._CreationMethod.setValue("BySizes")
82         self._fill_attribute(self._to_size, 0)
83         self._fill_attribute(self._from_size, 0)
84         self._fill_attribute(self._to_object, None)
85         self._fill_attribute(self._to_offset, 0)
86         self._fill_attribute(self._from_object, None)
87         self._fill_attribute(self._from_offset, 0)
88         pass
89
90     def setBase(self, base):
91         """Modify base attribute of the feature.
92
93         See __init__.
94         """
95         self._fill_attribute(self._base, base)
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._fill_attribute(self._to_size, to_size)
106         self._fill_attribute(self._from_size, from_size)
107         pass
108
109     def setSize(self, size):
110         """Modify the size of the feature.
111
112         If size is positive then initialize to_size with size.
113         If size is negative then initialize from_size with -size.
114         """
115         to_size, from_size = 0, 0
116         if size >= 0:
117             to_size = size
118         else:
119             from_size = -size
120
121         self.setSizes(to_size, from_size)
122         pass
123
124     def setPlanesAndOffsets(self, to_object, to_offset,
125                             from_object, from_offset):
126         """Modify planes and offsets attributes of the feature.
127
128         See __init__.
129         """
130         self.__clear()
131         self._CreationMethod.setValue("ByPlanesAndOffsets")
132         self._fill_attribute(self._to_object, to_object)
133         self._fill_attribute(self._to_offset, to_offset)
134         self._fill_attribute(self._from_object, from_object)
135         self._fill_attribute(self._from_offset, from_offset)
136         pass
137
138     def result(self):
139         return [Selection(result, result.shape()) for result in (self.firstResult(),)]