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 Pass all args to Extrusion __init__ function.
16 feature = part.addFeature("Extrusion")
17 return Extrusion(feature, *args)
20 class Extrusion(Interface):
21 """Interface on an Extrusion feature."""
23 def __init__(self, feature, *args):
24 """Initialize an Extrusion feature with given parameters.
26 Expected arguments for all modes:
27 feature -- an Extrusion feature
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.
33 For BySize mode (expect 2 arguments):
35 from_size -- lower size
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
43 Interface.__init__(self, feature)
44 assert(self._feature.getKind() == "Extrusion")
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")
56 assert(self._CreationMethod)
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)
70 assert(len(args) in (1, 2, 4))
73 self.setPlanesAndOffsets(*args)
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)
90 def setBase(self, base):
91 """Modify base attribute of the feature.
95 self._fill_attribute(self._base, base)
98 def setSizes(self, to_size, from_size):
99 """Modify the to_size, from_size attributes of the feature.
104 self._CreationMethod.setValue("BySizes")
105 self._fill_attribute(self._to_size, to_size)
106 self._fill_attribute(self._from_size, from_size)
109 def setSize(self, size):
110 """Modify the size of the feature.
112 If size is positive then initialize to_size with size.
113 If size is negative then initialize from_size with -size.
115 to_size, from_size = 0, 0
121 self.setSizes(to_size, from_size)
124 def setPlanesAndOffsets(self, to_object, to_offset,
125 from_object, from_offset):
126 """Modify planes and offsets attributes of the feature.
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)
139 return [Selection(result, result.shape()) for result in (self.firstResult(),)]