1 # Copyright (C) 2014-2019 CEA/DEN, EDF R&D
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License, or (at your option) any later version.
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 # Lesser General Public License for more details.
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 Authors: Renaud Nedelec - Daniel Brunier-Coulin
25 from salome.shaper import model
26 from salome.shaper import geom
29 class BoxFeature(model.Feature):
30 """An example of Box feature implementation.
38 """x.__init__(...) initializes x; see x.__class__.__doc__ for signature"""
39 model.Feature.__init__(self)
43 """Return Id of the feature."""
48 """Returns ID of Width parameter."""
53 """Returns ID of Length parameter."""
58 """Returns ID of Height parameter."""
62 """Override Feature.getKind()"""
63 return BoxFeature.ID()
66 # Creation of the box at default size
68 def initAttributes(self):
69 """Override Feature.initAttributes()"""
70 # Creating the input arguments of the feature
71 self.addRealInput(self.WIDTH_ID())
72 self.addRealInput(self.LENGTH_ID())
73 self.addRealInput(self.HEIGHT_ID())
75 # Creating the base of the box with unit values
76 mypart = model.activeDocument()
77 xoy = model.defaultPlane("XOY")
79 # A base of the geometry
80 self.base = model.addSketch(mypart, xoy)
87 line = model.addPolygon(self.base, p1, p2, p3, p4)
89 self.base.setFixed(line[0].startPoint())
90 self.base.setVertical(line[0])
92 # Setting the size of the base with default values
94 self.width = self.base.setLength(line[3], 50) # Keeps the constraint for edition
96 self.length = self.base.setLength(line[0], 50) # Keeps the constraint for edition
98 # Keeping the rectangle
99 self.base.setParallel(line[0], line[2])
100 self.base.setParallel(line[1], line[3])
101 self.base.setPerpendicular(line[0], line[3])
104 mypart.setCurrentFeature(self.base.feature(), False)
105 model.updateFeatures()
107 # Creating the extrusion (the box) at default size
109 self.box = model.addExtrusion(mypart, self.base.selectFace(), 50)
111 # Edition of the box at user size
114 """F.execute() -- execute the feature"""
115 # Retrieving the user inputs
116 width = self.real(self.WIDTH_ID())
117 length = self.real(self.LENGTH_ID())
118 height = self.real(self.HEIGHT_ID())
121 if width.text() == "":
122 self.base.setValue(self.width, width.value())
124 self.base.setValue(self.width, width.text())
126 if length.text() == "":
127 self.base.setValue(self.length, length.value())
129 self.base.setValue(self.length, length.text())
131 if (height.text() == ""):
132 self.box.setSize(height.value())
134 self.box.setSize(height.text())
136 # Publishing the result: not needed for Macro feature
137 # self.addResult( self.box.result() )
140 """Override Feature.initAttributes().
143 Box feature is macro: removes itself on the creation transaction