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

Fully closed shelling #394

Merged
merged 1 commit into from
Jul 8, 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
2 changes: 0 additions & 2 deletions cadquery/cq.py
Original file line number Diff line number Diff line change
Expand Up @@ -1118,8 +1118,6 @@ def shell(self, thickness: float) -> "Workplane":
solidRef = self.findSolid()

faces = [f for f in self.objects if isinstance(f, Face)]
if len(faces) < len(self.objects):
raise ValueError("Shelling requires that faces are selected")

s = solidRef.shell(faces, thickness)
return self.newObject([s])
Expand Down
38 changes: 28 additions & 10 deletions cadquery/occ_impl/shapes.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
Any,
overload,
TypeVar,
Callable,
cast as tcast,
)
from typing_extensions import Literal, Protocol
Expand Down Expand Up @@ -51,6 +50,7 @@
BRepBuilderAPI_Transformed,
BRepBuilderAPI_RightCorner,
BRepBuilderAPI_RoundCorner,
BRepBuilderAPI_MakeSolid,
)

# properties used to store mass calculation result
Expand Down Expand Up @@ -158,10 +158,9 @@

from OCP.IFSelect import IFSelect_ReturnStatus

from OCP.TopAbs import TopAbs_ShapeEnum
from OCP.TopAbs import TopAbs_ShapeEnum, TopAbs_Orientation

from math import pi, sqrt
from functools import reduce
import warnings

TOLERANCE = 1e-6
Expand Down Expand Up @@ -1563,16 +1562,35 @@ def shell(
"""

occ_faces_list = TopTools_ListOfShape()
for f in faceList:
occ_faces_list.Append(f.wrapped)

shell_builder = BRepOffsetAPI_MakeThickSolid(
self.wrapped, occ_faces_list, thickness, tolerance
)
if faceList:
for f in faceList:
occ_faces_list.Append(f.wrapped)

shell_builder = BRepOffsetAPI_MakeThickSolid(
self.wrapped, occ_faces_list, thickness, tolerance
)

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

shell_builder.Build()
else: # if no faces provided a watertight solid will be constructed
shell_builder = BRepOffsetAPI_MakeThickSolid(
self.wrapped, occ_faces_list, thickness, tolerance
)

shell_builder.Build()
s1 = self.__class__(shell_builder.Shape()).Shells()[0].wrapped
s2 = self.Shells()[0].wrapped

# s1 can be outer or inner shell depending on the thickness sign
if thickness > 0:
rv = BRepBuilderAPI_MakeSolid(s1, s2).Shape()
else:
rv = BRepBuilderAPI_MakeSolid(s2, s1).Shape()

return self.__class__(shell_builder.Shape())
# fix needed for the orientations
return self.__class__(rv) if faceList else self.__class__(rv).fix()

def isInside(
self: ShapeProtocol, point: VectorLike, tolerance: float = 1.0e-6
Expand Down
12 changes: 12 additions & 0 deletions tests/test_cadquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -1816,6 +1816,18 @@ def testSimpleShell(self):
self.saveModel(s)
self.assertEqual(23, s.faces().size())

def testClosedShell(self):
"""
Create a hollow box
"""
s1 = Workplane("XY").box(2, 2, 2).shell(-0.1)
self.assertEqual(12, s1.faces().size())
self.assertTrue(s1.val().isValid())

s2 = Workplane("XY").box(2, 2, 2).shell(0.1)
self.assertEqual(32, s2.faces().size())
self.assertTrue(s2.val().isValid())

def testOpenCornerShell(self):
s = Workplane("XY").box(1, 1, 1)
s1 = s.faces("+Z")
Expand Down