Skip to content

Commit 3348c18

Browse files
cutThruAll fix for non-planar faces (#604)
* reworked cutThruAll to support non-planar faces * Added test
1 parent 8fcfb02 commit 3348c18

File tree

3 files changed

+30
-14
lines changed

3 files changed

+30
-14
lines changed

cadquery/cq.py

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3084,20 +3084,9 @@ def cutThruAll(self, clean: bool = True, taper: float = 0) -> "Workplane":
30843084
self.ctx.pendingWires = []
30853085

30863086
solidRef = self.findSolid()
3087-
faceRef = self.findFace()
3088-
3089-
# if no faces on the stack take the nearest face parallel to the plane zDir
3090-
if not faceRef:
3091-
# first select all with faces with good orietation
3092-
sel1 = PerpendicularDirSelector(self.plane.zDir)
3093-
faces = sel1.filter(solidRef.Faces())
3094-
# then select the closest
3095-
sel2 = NearestToPointSelector(self.plane.origin.toTuple())
3096-
faceRef = sel2.filter(faces)[0]
3097-
30983087
rv = []
30993088
for solid in solidRef.Solids():
3100-
s = solid.dprism(faceRef, wires, thruAll=True, additive=False, taper=-taper)
3089+
s = solid.dprism(None, wires, thruAll=True, additive=False, taper=-taper)
31013090

31023091
if clean:
31033092
s = s.clean()

cadquery/occ_impl/shapes.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2637,7 +2637,7 @@ def sweep_multi(
26372637

26382638
def dprism(
26392639
self,
2640-
basis: Face,
2640+
basis: Optional[Face],
26412641
profiles: List[Wire],
26422642
depth: Optional[float] = None,
26432643
taper: float = 0,
@@ -2659,7 +2659,12 @@ def dprism(
26592659
for p in sorted_profiles:
26602660
face = Face.makeFromWires(p[0], p[1:])
26612661
feat = BRepFeat_MakeDPrism(
2662-
shape, face.wrapped, basis.wrapped, taper * DEG2RAD, additive, False
2662+
shape,
2663+
face.wrapped,
2664+
basis.wrapped if basis else TopoDS_Face(),
2665+
taper * DEG2RAD,
2666+
additive,
2667+
False,
26632668
)
26642669

26652670
if thruAll or depth is None:

tests/test_cadquery.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1409,6 +1409,28 @@ def testCutThroughAll(self):
14091409
self.saveModel(t)
14101410
self.assertEqual(13, t.faces().size())
14111411

1412+
# no planar faces
1413+
sphere_r = 10.0
1414+
1415+
r = (
1416+
Workplane()
1417+
.sphere(sphere_r)
1418+
.workplane()
1419+
.circle(sphere_r / 2.0)
1420+
.cutThruAll()
1421+
.workplane()
1422+
.transformed(rotate=(90, 0, 0))
1423+
.circle(sphere_r / 2.0)
1424+
.cutThruAll()
1425+
.workplane()
1426+
.transformed(rotate=(0, 90, 0))
1427+
.circle(sphere_r / 2.0)
1428+
.cutThruAll()
1429+
)
1430+
1431+
self.assertTrue(r.val().isValid())
1432+
self.assertEqual(r.faces().size(), 7)
1433+
14121434
def testCutToFaceOffsetNOTIMPLEMENTEDYET(self):
14131435
"""
14141436
Tests cutting up to a given face, or an offset from a face

0 commit comments

Comments
 (0)