2 Author: Daniel Brunier-Coulin with contribution by Mikhail Ponikarov
4 Copyright (C) 2014-20xx CEA/DEN, EDF R&D
7 from model.roots import Interface
8 from model import Selection
10 def addExtrusion(part, *args):
11 """Add an Extrusion feature to the Part and return Extrusion.
13 This function has *3 signatures*:
15 .. function:: addExtrusion(base, size)
18 base(str, Sketch or list): base object(s)
19 size(double): size of the extrusion, the side is decided by the sign
21 .. function:: addExtrusion(base, to_size, from_size)
24 base(str, Sketch or list): base object(s)
25 to_size(double): upper size of the extrusion
26 from_size(double): lower size of the extrusion
28 .. function:: addExtrusion(base, to_object, to_offset, from_object, from_offset)
31 base(str, Sketch or list): base object(s)
32 to_object(plane): upper plane
33 to_offset(double): offset from upper object
34 from_object(plane): lower plane
35 from_offset(double): offset from lower plane
37 In all three cases the function returns an extrusion object
40 Extrusion: extrusion object
43 feature = part.addFeature("Extrusion")
44 return Extrusion(feature, *args)
47 class Extrusion(Interface):
48 """Interface class for Extrusion feature.
51 def __init__(self, feature, *args):
53 Extrusion(feature) -> feature interface without initialization
54 Extrusion(feature, base, size) ->
55 feature interface initialized from arguments:
56 - base -- name, sketch or list of names and sketches
57 - size -- if positive -> to_size, if negative -> from_size
58 Extrusion(feature, base, to_size, from_size) ->
59 feature interface initialized from arguments:
60 - base -- name, sketch or list of names and sketches
61 - to_size -- upper size
62 - from_size -- lower size
63 Extrusion(feature, base, to_object, to_offset, from_object, from_offset) ->
64 feature interface initialized from arguments:
65 - base -- name, sketch or list of names and sketches
66 - to_object -- upper object (plane)
67 - to_offset -- offset from upper object
68 - from_object -- lower object (plane)
69 - from_offset -- offset from lower object
71 Interface.__init__(self, feature)
72 assert(self._feature.getKind() == "Extrusion")
74 self._base = self._feature.data().selectionList("base")
75 self._CreationMethod = self._feature.string("CreationMethod")
76 self._to_size = self._feature.data().real("to_size")
77 self._from_size = self._feature.data().real("from_size")
78 self._to_object = self._feature.data().selection("to_object")
79 self._to_offset = self._feature.data().real("to_offset")
80 self._from_object = self._feature.data().selection("from_object")
81 self._from_offset = self._feature.data().real("from_offset")
84 assert(self._CreationMethod)
86 assert(self._from_size)
87 assert(self._to_object)
88 assert(self._to_offset)
89 assert(self._from_object)
90 assert(self._from_offset)
95 assert(len(args) in (2, 3, 5))
102 self.setPlanesAndOffsets(*args)
106 self.setSize(args[0])
112 self._CreationMethod.setValue("BySizes")
113 self._fillAttribute(self._to_size, 0)
114 self._fillAttribute(self._from_size, 0)
115 self._fillAttribute(self._to_object, None)
116 self._fillAttribute(self._to_offset, 0)
117 self._fillAttribute(self._from_object, None)
118 self._fillAttribute(self._from_offset, 0)
121 def setBase(self, base):
122 """Modify base attribute of the feature.
126 self._fillAttribute(self._base, base)
129 def setSizes(self, to_size, from_size):
130 """Modify the to_size, from_size attributes of the feature.
134 # MPV: with "clear" calling here the extrusion all the time becomes modificed (height is set to
135 # zero and then to actual value, but this function is used in macro Bax, that causes "modified"
136 # values without changes that causes cyclic dependency
138 self._fillAttribute(self._CreationMethod, "BySizes")
139 self._fillAttribute(self._to_size, to_size)
140 self._fillAttribute(self._from_size, from_size)
143 def setSize(self, size):
144 """Modify the size of the feature.
146 If size is positive then initialize to_size with size.
147 If size is negative then initialize from_size with -size.
149 to_size, from_size = 0, 0
155 self.setSizes(to_size, from_size)
158 def setPlanesAndOffsets(self, to_object, to_offset,
159 from_object, from_offset):
160 """Modify planes and offsets attributes of the feature.
165 self._CreationMethod.setValue("ByPlanesAndOffsets")
166 self._fillAttribute(self._to_object, to_object)
167 self._fillAttribute(self._to_offset, to_offset)
168 self._fillAttribute(self._from_object, from_object)
169 self._fillAttribute(self._from_offset, from_offset)
173 """F.result() -> list of Selection objects"""
174 return [Selection(result, result.shape()) for result in (self.firstResult(),)]