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

Expose intersection joint type for shell #413

Merged
merged 1 commit into from
Jul 24, 2020
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
7 changes: 5 additions & 2 deletions cadquery/cq.py
Original file line number Diff line number Diff line change
Expand Up @@ -1080,14 +1080,17 @@ def translate(self, vec: VectorLike) -> "Workplane":
]
)

def shell(self, thickness: float) -> "Workplane":
def shell(
self, thickness: float, kind: Literal["arc", "intersection"] = "arc"
) -> "Workplane":
"""
Remove the selected faces to create a shell of the specified thickness.

To shell, first create a solid, and *in the same chain* select the faces you wish to remove.

:param thickness: a positive float, representing the thickness of the desired shell.
Negative values shell inwards, positive values shell outwards.
:param kind: kind of joints, intersetion or arc (default: arc).
:raises: ValueError if the current stack contains objects that are not faces of a solid
further up in the chain.
:returns: a CQ object with the resulting shelled solid selected.
Expand Down Expand Up @@ -1120,7 +1123,7 @@ def shell(self, thickness: float) -> "Workplane":

faces = [f for f in self.objects if isinstance(f, Face)]

s = solidRef.shell(faces, thickness)
s = solidRef.shell(faces, thickness, kind=kind)
return self.newObject([s])

def fillet(self, radius: float) -> "Workplane":
Expand Down
20 changes: 18 additions & 2 deletions cadquery/occ_impl/shapes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1665,6 +1665,7 @@ def shell(
faceList: Iterable[Face],
thickness: float,
tolerance: float = 0.0001,
kind: Literal["arc", "intersection"] = "arc",
) -> Any:
"""
make a shelled solid of given by removing the list of faces
Expand All @@ -1675,22 +1676,37 @@ def shell(
:return: a shelled solid
"""

kind_dict = {
"arc": GeomAbs_JoinType.GeomAbs_Arc,
"intersection": GeomAbs_JoinType.GeomAbs_Intersection,
}

occ_faces_list = TopTools_ListOfShape()

if faceList:
for f in faceList:
occ_faces_list.Append(f.wrapped)

shell_builder = BRepOffsetAPI_MakeThickSolid(
self.wrapped, occ_faces_list, thickness, tolerance, Intersection=True
self.wrapped,
occ_faces_list,
thickness,
tolerance,
Intersection=True,
Join=kind_dict[kind],
)

shell_builder.Build()
rv = shell_builder.Shape()

else: # if no faces provided a watertight solid will be constructed
shell_builder = BRepOffsetAPI_MakeThickSolid(
self.wrapped, occ_faces_list, thickness, tolerance, Intersection=True
self.wrapped,
occ_faces_list,
thickness,
tolerance,
Intersection=True,
Join=kind_dict[kind],
)

shell_builder.Build()
Expand Down
18 changes: 15 additions & 3 deletions tests/test_cadquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -1828,9 +1828,21 @@ def testSimpleShell(self):
"""
Create s simple box
"""
s = Workplane("XY").box(2, 2, 2).faces("+Z").shell(0.05)
self.saveModel(s)
self.assertEqual(23, s.faces().size())
s1 = Workplane("XY").box(2, 2, 2).faces("+Z").shell(0.05)
self.saveModel(s1)
self.assertEqual(23, s1.faces().size())

s2 = (
Workplane()
.ellipse(4, 2)
.extrude(4)
.faces(">Z")
.shell(+2, kind="intersection")
)
self.assertEqual(5, s2.faces().size())

s3 = Workplane().ellipse(4, 2).extrude(4).faces(">Z").shell(+2, kind="arc")
self.assertEqual(6, s3.faces().size())

def testClosedShell(self):
"""
Expand Down