2 Authors: Renaud Nedelec - Daniel Brunier-Coulin
3 Copyright (C) 2014-20xx CEA/DEN, EDF R&D
6 from salome.shaper import model
7 from salome.shaper import geom
10 class BoxFeature(model.Feature):
11 """An example of Box feature implementation.
19 """x.__init__(...) initializes x; see x.__class__.__doc__ for signature"""
20 model.Feature.__init__(self)
24 """Return Id of the feature."""
29 """Returns ID of Width parameter."""
34 """Returns ID of Length parameter."""
39 """Returns ID of Height parameter."""
43 """Override Feature.getKind()"""
44 return BoxFeature.ID()
47 # Creation of the box at default size
49 def initAttributes(self):
50 """Override Feature.initAttributes()"""
51 # Creating the input arguments of the feature
52 self.addRealInput(self.WIDTH_ID())
53 self.addRealInput(self.LENGTH_ID())
54 self.addRealInput(self.HEIGHT_ID())
56 # Creating the base of the box with unit values
57 mypart = model.activeDocument()
58 xoy = model.defaultPlane("XOY")
60 # A base of the geometry
61 self.base = model.addSketch(mypart, xoy)
68 line = model.addPolygon(self.base, p1, p2, p3, p4)
70 self.base.setFixed(line[0].startPoint())
71 self.base.setVertical(line[0])
73 # Setting the size of the base with default values
75 self.width = self.base.setLength(line[3], 50) # Keeps the constraint for edition
77 self.length = self.base.setLength(line[0], 50) # Keeps the constraint for edition
79 # Keeping the rectangle
80 self.base.setParallel(line[0], line[2])
81 self.base.setParallel(line[1], line[3])
82 self.base.setPerpendicular(line[0], line[3])
85 mypart.setCurrentFeature(self.base.feature(), False)
86 model.updateFeatures()
88 # Creating the extrusion (the box) at default size
90 self.box = model.addExtrusion(mypart, self.base.selectFace(), 50)
92 # Edition of the box at user size
95 """F.execute() -- execute the feature"""
96 # Retrieving the user inputs
97 width = self.real(self.WIDTH_ID())
98 length = self.real(self.LENGTH_ID())
99 height = self.real(self.HEIGHT_ID())
102 if width.text() == "":
103 self.base.setValue(self.width, width.value())
105 self.base.setValue(self.width, width.text())
107 if length.text() == "":
108 self.base.setValue(self.length, length.value())
110 self.base.setValue(self.length, length.text())
112 if (height.text() == ""):
113 self.box.setSize(height.value())
115 self.box.setSize(height.text())
117 # Publishing the result: not needed for Macro feature
118 # self.addResult( self.box.result() )
121 """Override Feature.initAttributes().
124 Box feature is macro: removes itself on the creation transaction