Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cutThruAll fix for non-planar faces #604

Merged
merged 2 commits into from
Jan 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 1 addition & 12 deletions cadquery/cq.py
Original file line number Diff line number Diff line change
Expand Up @@ -3084,20 +3084,9 @@ def cutThruAll(self, clean: bool = True, taper: float = 0) -> "Workplane":
self.ctx.pendingWires = []

solidRef = self.findSolid()
faceRef = self.findFace()

# if no faces on the stack take the nearest face parallel to the plane zDir
if not faceRef:
# first select all with faces with good orietation
sel1 = PerpendicularDirSelector(self.plane.zDir)
faces = sel1.filter(solidRef.Faces())
# then select the closest
sel2 = NearestToPointSelector(self.plane.origin.toTuple())
faceRef = sel2.filter(faces)[0]

rv = []
for solid in solidRef.Solids():
s = solid.dprism(faceRef, wires, thruAll=True, additive=False, taper=-taper)
s = solid.dprism(None, wires, thruAll=True, additive=False, taper=-taper)

if clean:
s = s.clean()
Expand Down
9 changes: 7 additions & 2 deletions cadquery/occ_impl/shapes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2637,7 +2637,7 @@ def sweep_multi(

def dprism(
self,
basis: Face,
basis: Optional[Face],
profiles: List[Wire],
depth: Optional[float] = None,
taper: float = 0,
Expand All @@ -2659,7 +2659,12 @@ def dprism(
for p in sorted_profiles:
face = Face.makeFromWires(p[0], p[1:])
feat = BRepFeat_MakeDPrism(
shape, face.wrapped, basis.wrapped, taper * DEG2RAD, additive, False
shape,
face.wrapped,
basis.wrapped if basis else TopoDS_Face(),
taper * DEG2RAD,
additive,
False,
)

if thruAll or depth is None:
Expand Down
22 changes: 22 additions & 0 deletions tests/test_cadquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -1409,6 +1409,28 @@ def testCutThroughAll(self):
self.saveModel(t)
self.assertEqual(13, t.faces().size())

# no planar faces
sphere_r = 10.0

r = (
Workplane()
.sphere(sphere_r)
.workplane()
.circle(sphere_r / 2.0)
.cutThruAll()
.workplane()
.transformed(rotate=(90, 0, 0))
.circle(sphere_r / 2.0)
.cutThruAll()
.workplane()
.transformed(rotate=(0, 90, 0))
.circle(sphere_r / 2.0)
.cutThruAll()
)

self.assertTrue(r.val().isValid())
self.assertEqual(r.faces().size(), 7)

def testCutToFaceOffsetNOTIMPLEMENTEDYET(self):
"""
Tests cutting up to a given face, or an offset from a face
Expand Down