1 ## Copyright (C) 2014-20xx OPEN CASCADE
7 from salome.shaper import model
8 from salome.shaper import geom
11 class BoxFeature(model.Feature):
12 """An example of feature implementation.
18 """x.__init__(...) initializes x; see x.__class__.__doc__ for signature"""
19 model.Feature.__init__(self)
23 """Return Id of the feature."""
28 """Returns ID of Width parameter."""
33 """Returns ID of Length parameter."""
38 """Returns ID of Height parameter."""
42 """Override Feature.getKind()"""
43 return BoxFeature.ID()
46 # Creation of the box at default size
48 def initAttributes(self):
49 """Override Feature.initAttributes()"""
50 # Creating the input arguments of the feature
51 self.addRealInput(self.WIDTH_ID())
52 self.addRealInput(self.LENGTH_ID())
53 self.addRealInput(self.HEIGHT_ID())
55 # Creating the base of the box with unit values
56 mypart = model.activeDocument()
57 xoy = model.defaultPlane("XOY")
59 # A base of the geometry
60 self.base = model.addSketch(mypart, xoy)
67 line = model.addPolygon(self.base, p1, p2, p3, p4)
69 self.base.setFixed(line[0].startPoint())
70 self.base.setVertical(line[0])
72 # Setting the size of the base with default values
74 self.width = self.base.setLength(line[3], 50) # Keeps the constraint for edition
76 self.length = self.base.setLength(line[0], 50) # Keeps the constraint for edition
78 # Keeping the rectangle
79 self.base.setParallel(line[0], line[2])
80 self.base.setParallel(line[1], line[3])
81 self.base.setPerpendicular(line[0], line[3])
84 mypart.setCurrentFeature(self.base.feature(), False)
85 model.updateFeatures()
87 # Creating the extrusion (the box) at default size
89 self.box = model.addExtrusion(mypart, self.base.selectFace(), 50)
90 self.box.setNestedSketch(self.base)
91 # self.box.setName(self.name())
93 # Edition of the box at user size
96 """F.execute() -- execute the feature"""
97 # Retrieving the user inputs
98 width = self.real(self.WIDTH_ID())
99 length = self.real(self.LENGTH_ID())
100 height = self.real(self.HEIGHT_ID())
103 if width.text() == "":
104 self.base.setValue(self.width, width.value())
106 self.base.setValue(self.width, width.text())
108 if length.text() == "":
109 self.base.setValue(self.length, length.value())
111 self.base.setValue(self.length, length.text())
113 if (height.text() == ""):
114 self.box.setSize(height.value())
116 self.box.setSize(height.text())
118 # Publishing the result: not needed for Macro feature
119 # self.addResult( self.box.result() )
122 """Override Feature.initAttributes().
125 Box feature is macro: removes itself on the creation transaction