1 ## Copyright (C) 2014-2017 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
18 ## email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
22 Authors: Renaud Nedelec - Daniel Brunier-Coulin
23 Copyright (C) 2014-20xx CEA/DEN, EDF R&D
26 from salome.shaper import model
27 from salome.shaper import geom
30 class BoxFeature(model.Feature):
31 """An example of Box feature implementation.
39 """x.__init__(...) initializes x; see x.__class__.__doc__ for signature"""
40 model.Feature.__init__(self)
44 """Return Id of the feature."""
49 """Returns ID of Width parameter."""
54 """Returns ID of Length parameter."""
59 """Returns ID of Height parameter."""
63 """Override Feature.getKind()"""
64 return BoxFeature.ID()
67 # Creation of the box at default size
69 def initAttributes(self):
70 """Override Feature.initAttributes()"""
71 # Creating the input arguments of the feature
72 self.addRealInput(self.WIDTH_ID())
73 self.addRealInput(self.LENGTH_ID())
74 self.addRealInput(self.HEIGHT_ID())
76 # Creating the base of the box with unit values
77 mypart = model.activeDocument()
78 xoy = model.defaultPlane("XOY")
80 # A base of the geometry
81 self.base = model.addSketch(mypart, xoy)
88 line = model.addPolygon(self.base, p1, p2, p3, p4)
90 self.base.setFixed(line[0].startPoint())
91 self.base.setVertical(line[0])
93 # Setting the size of the base with default values
95 self.width = self.base.setLength(line[3], 50) # Keeps the constraint for edition
97 self.length = self.base.setLength(line[0], 50) # Keeps the constraint for edition
99 # Keeping the rectangle
100 self.base.setParallel(line[0], line[2])
101 self.base.setParallel(line[1], line[3])
102 self.base.setPerpendicular(line[0], line[3])
105 mypart.setCurrentFeature(self.base.feature(), False)
106 model.updateFeatures()
108 # Creating the extrusion (the box) at default size
110 self.box = model.addExtrusion(mypart, self.base.selectFace(), 50)
112 # Edition of the box at user size
115 """F.execute() -- execute the feature"""
116 # Retrieving the user inputs
117 width = self.real(self.WIDTH_ID())
118 length = self.real(self.LENGTH_ID())
119 height = self.real(self.HEIGHT_ID())
122 if width.text() == "":
123 self.base.setValue(self.width, width.value())
125 self.base.setValue(self.width, width.text())
127 if length.text() == "":
128 self.base.setValue(self.length, length.value())
130 self.base.setValue(self.length, length.text())
132 if (height.text() == ""):
133 self.box.setSize(height.value())
135 self.box.setSize(height.text())
137 # Publishing the result: not needed for Macro feature
138 # self.addResult( self.box.result() )
141 """Override Feature.initAttributes().
144 Box feature is macro: removes itself on the creation transaction