2 Author: Daniel Brunier-Coulin with contribution by Mikhail Ponikarov
4 Copyright (C) 2014-20xx CEA/DEN, EDF R&D
7 from .roots import Interface
8 from .sketcher.sketch import Sketch
11 def addExtrusion(part, *args):
12 """Add an Extrusion feature to the Part and return Extrusion.
14 Pass all args to Extrusion __init__ function.
16 assert(len(args) > 0 and args[0] is not None)
17 feature = part.addFeature("Extrusion")
18 return Extrusion(feature, *args)
21 class Extrusion(Interface):
22 """Interface on an Extrusion feature."""
24 def __init__(self, feature, base=None, *args):
25 """Initialize an Extrusion feature with given parameters.
27 Expected arguments for all modes:
28 feature -- an Extrusion feature
30 Expected arguments for initializing the feature:
31 base -- name, sketch or list of names and sketches.
32 If base is None then don't change the feature.
34 For BySize mode (expect 2 arguments):
36 from_size -- lower size
38 For ByPlanesAndOffsets mode (expect 4 arguments):
39 to_object -- upper object (plane)
40 to_offset -- offset from upper object
41 from_object -- lower object (plane)
42 from_offset -- offset from lower object
44 Interface.__init__(self, feature)
45 assert(self._feature.getKind() == "Extrusion")
47 self._base = self._feature.data().selectionList("base")
48 self._CreationMethod = self._feature.string("CreationMethod")
49 self._to_size = self._feature.data().real("to_size")
50 self._from_size = self._feature.data().real("from_size")
51 self._to_object = self._feature.data().selection("to_object")
52 self._to_offset = self._feature.data().real("to_offset")
53 self._from_object = self._feature.data().selection("from_object")
54 self._from_offset = self._feature.data().real("from_offset")
62 self.__createByPlanesAndOffsets(*args)
64 self.__createBySize(*args)
66 raise Exception("cannot create the Extrusion")
71 def __setBase(self, base):
72 """Initialize base attribute of the feature.
75 base -- could be object of this types:
76 - string - topology name of object
77 - Sketch - sketch object
78 - iterable - list or tuple with string and/or Sketch objects
81 if isinstance(base, basestring):
82 self._base.append(base)
83 elif isinstance(base, Sketch):
84 self._base.append(base.result(), base.buildShape())
87 if isinstance(item, basestring):
88 self._base.append(item)
90 self._base.append(item.result(), item.buildShape())
94 self._CreationMethod.setValue("BySizes")
95 self._to_size.setValue(0)
96 self._from_size.setValue(0)
97 self._to_object.setValue(None, None)
98 self._to_offset.setValue(0)
99 self._from_object.setValue(None, None)
100 self._from_offset.setValue(0)
103 def __createBySize(self, to_size, from_size):
105 self._CreationMethod.setValue("BySizes")
106 self._to_size.setValue(to_size)
107 self._from_size.setValue(from_size)
110 def __createByPlanesAndOffsets(self, to_object, to_offset,
111 from_object, from_offset):
113 self._CreationMethod.setValue("ByPlanesAndOffsets")
114 self._to_object.setValue(to_object.result(), to_object.buildShape())
115 self._to_offset.setValue(to_offset)
116 self._from_object.setValue(from_object.result(), from_object.buildShape())
117 self._from_offset.setValue(from_offset)
121 if self.areInputValid():
124 raise Exception("cannot execute Extrusion")
126 def setBase(self, base):
127 """Modify base attribute of the feature.
135 def setSize(self, *args):
136 """Modify the to_size, from_size attributes of the feature.
140 self.__createBySize(*args)
144 def setPlanesAndOffsets(self, *args):
145 """Modify planes and offsets attributes of the feature.
149 self.__createByPlanesAndOffsets(*args)