Skip to content
This repository has been archived by the owner on Feb 9, 2021. It is now read-only.

Commit

Permalink
Merge fd40107 into 3b3176d
Browse files Browse the repository at this point in the history
  • Loading branch information
hyOzd committed Jun 22, 2015
2 parents 3b3176d + fd40107 commit 221e5fa
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 0 deletions.
38 changes: 38 additions & 0 deletions cadquery/CQ.py
Original file line number Diff line number Diff line change
Expand Up @@ -795,6 +795,44 @@ def fillet(self, radius):
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):
"""
Expand Down
15 changes: 15 additions & 0 deletions cadquery/freecad_impl/shapes.py
Original file line number Diff line number Diff line change
Expand Up @@ -812,6 +812,21 @@ def fillet(self, radius, edgeList):
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
Expand Down
30 changes: 30 additions & 0 deletions tests/TestCadQuery.py
Original file line number Diff line number Diff line change
Expand Up @@ -804,6 +804,36 @@ def testFillet(self):
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
Expand Down

0 comments on commit 221e5fa

Please sign in to comment.