This commit is contained in:
Jeremy Wright 2015-06-23 15:26:38 -04:00
commit dd789ccfa1
3 changed files with 83 additions and 0 deletions

View File

@ -795,6 +795,44 @@ class CQ(object):
solid.wrapped = s.wrapped
return self.newObject([s])
def chamfer(self, length, length2 = None):
"""
Chamfers a solid on the selected edges.
The edges on the stack are chamfered. The solid to which the
edges belong must be in the parent chain of the selected
edges.
Optional parameter `length2` can be supplied with a different
value than `length` for a chamfer that is shorter on one side
longer on the other side.
:param length: the length of the fillet, must be greater than zero
:param length2: optional parameter for asymmetrical chamfer
:type length: positive float
:type length2: positive float
:raises: ValueError if at least one edge is not selected
:raises: ValueError if the solid containing the edge is not in the chain
:returns: cq object with the resulting solid selected.
This example will create a unit cube, with the top edges chamfered::
s = Workplane("XY").box(1,1,1).faces("+Z").chamfer(0.1)
This example will create chamfers longer on the sides::
s = Workplane("XY").box(1,1,1).faces("+Z").chamfer(0.2, 0.1)
"""
solid = self.findSolid()
edgeList = self.edges().vals()
if len(edgeList) < 1:
raise ValueError("Chamfer requires that edges be selected")
s = solid.chamfer(length, length2, edgeList)
solid.wrapped = s.wrapped
return self.newObject([s])
class Workplane(CQ):
"""

View File

@ -812,6 +812,21 @@ class Solid(Shape):
nativeEdges = [e.wrapped for e in edgeList]
return Shape.cast(self.wrapped.makeFillet(radius, nativeEdges))
def chamfer(self, length, length2, edgeList):
"""
Chamfers the specified edges of this solid.
:param length: length > 0, the length (length) of the chamfer
:param length2: length2 > 0, optional parameter for asymmetrical chamfer. Should be `None` if not required.
:param edgeList: a list of Edge objects, which must belong to this solid
:return: Chamfered solid
"""
nativeEdges = [e.wrapped for e in edgeList]
# note: we prefer 'length' word to 'radius' as opposed to FreeCAD's API
if length2:
return Shape.cast(self.wrapped.makeChamfer(length, length2, nativeEdges))
else:
return Shape.cast(self.wrapped.makeChamfer(length, nativeEdges))
def shell(self, faceList, thickness, tolerance=0.0001):
"""
make a shelled solid of given by removing the list of faces

View File

@ -804,6 +804,36 @@ class TestCadQuery(BaseTest):
self.saveModel(c)
self.assertEqual(12,c.faces().size() )
def testChamfer(self):
"""
Test chamfer API with a box shape
"""
cube = CQ(makeUnitCube()).faces(">Z").chamfer(0.1)
self.saveModel(cube)
self.assertEqual(10, cube.faces().size())
def testChamferAsymmetrical(self):
"""
Test chamfer API with a box shape for asymmetrical lengths
"""
cube = CQ(makeUnitCube()).faces(">Z").chamfer(0.1, 0.2)
self.saveModel(cube)
self.assertEqual(10, cube.faces().size())
# test if edge lengths are different
edge = cube.edges(">Z").vals()[0]
self.assertAlmostEqual(0.6, edge.Length(), 3)
edge = cube.edges("|Z").vals()[0]
self.assertAlmostEqual(0.9, edge.Length(), 3)
def testChamferCylinder(self):
"""
Test chamfer API with a cylinder shape
"""
cylinder = Workplane("XY").circle(1).extrude(1).faces(">Z").chamfer(0.1)
self.saveModel(cylinder)
self.assertEqual(4, cylinder.faces().size())
def testCounterBores(self):
"""
Tests making a set of counterbored holes in a face