Skip to content

Commit e87279d

Browse files
authored
Merge branch 'CadQuery:master' into master
2 parents 2fbb68f + 7afbb37 commit e87279d

File tree

2 files changed

+34
-30
lines changed

2 files changed

+34
-30
lines changed

cadquery/occ_impl/shapes.py

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2351,18 +2351,20 @@ def chamfer(
23512351

23522352
def shell(
23532353
self: Any,
2354-
faceList: Iterable[Face],
2354+
faceList: Optional[Iterable[Face]],
23552355
thickness: float,
23562356
tolerance: float = 0.0001,
23572357
kind: Literal["arc", "intersection"] = "arc",
23582358
) -> Any:
23592359
"""
2360-
make a shelled solid of given by removing the list of faces
2360+
Make a shelled solid of self.
23612361
2362-
:param faceList: list of face objects, which must be part of the solid.
2363-
:param thickness: floating point thickness. positive shells outwards, negative shells inwards
2364-
:param tolerance: modelling tolerance of the method, default=0.0001
2365-
:return: a shelled solid
2362+
:param faceList: List of faces to be removed, which must be part of the solid. Can
2363+
be an empty list.
2364+
:param thickness: Floating point thickness. Positive shells outwards, negative
2365+
shells inwards.
2366+
:param tolerance: Modelling tolerance of the method, default=0.0001.
2367+
:return: A shelled solid.
23662368
"""
23672369

23682370
kind_dict = {
@@ -2371,45 +2373,39 @@ def shell(
23712373
}
23722374

23732375
occ_faces_list = TopTools_ListOfShape()
2376+
shell_builder = BRepOffsetAPI_MakeThickSolid()
23742377

23752378
if faceList:
23762379
for f in faceList:
23772380
occ_faces_list.Append(f.wrapped)
23782381

2379-
shell_builder = BRepOffsetAPI_MakeThickSolid(
2380-
self.wrapped,
2381-
occ_faces_list,
2382-
thickness,
2383-
tolerance,
2384-
Intersection=True,
2385-
Join=kind_dict[kind],
2386-
)
2382+
shell_builder.MakeThickSolidByJoin(
2383+
self.wrapped,
2384+
occ_faces_list,
2385+
thickness,
2386+
tolerance,
2387+
Intersection=True,
2388+
Join=kind_dict[kind],
2389+
)
2390+
shell_builder.Build()
23872391

2388-
shell_builder.Build()
2389-
rv = shell_builder.Shape()
2392+
if faceList:
2393+
rv = self.__class__(shell_builder.Shape())
23902394

23912395
else: # if no faces provided a watertight solid will be constructed
2392-
shell_builder = BRepOffsetAPI_MakeThickSolid(
2393-
self.wrapped,
2394-
occ_faces_list,
2395-
thickness,
2396-
tolerance,
2397-
Intersection=True,
2398-
Join=kind_dict[kind],
2399-
)
2400-
2401-
shell_builder.Build()
24022396
s1 = self.__class__(shell_builder.Shape()).Shells()[0].wrapped
24032397
s2 = self.Shells()[0].wrapped
24042398

24052399
# s1 can be outer or inner shell depending on the thickness sign
24062400
if thickness > 0:
2407-
rv = BRepBuilderAPI_MakeSolid(s1, s2).Shape()
2401+
sol = BRepBuilderAPI_MakeSolid(s1, s2)
24082402
else:
2409-
rv = BRepBuilderAPI_MakeSolid(s2, s1).Shape()
2403+
sol = BRepBuilderAPI_MakeSolid(s2, s1)
24102404

2411-
# fix needed for the orientations
2412-
return self.__class__(rv) if faceList else self.__class__(rv).fix()
2405+
# fix needed for the orientations
2406+
rv = self.__class__(sol.Shape()).fix()
2407+
2408+
return rv
24132409

24142410
def isInside(
24152411
self: ShapeProtocol, point: VectorLike, tolerance: float = 1.0e-6

tests/test_cadquery.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2290,6 +2290,14 @@ def testClosedShell(self):
22902290
s3 = Workplane().polyline(pts).close().extrude(1).shell(-0.05)
22912291
self.assertTrue(s3.val().isValid())
22922292

2293+
s4_shape = Workplane("XY").box(2, 2, 2).val()
2294+
# test that None and empty list both work and are equivalent
2295+
s4_shell_1 = s4_shape.shell(faceList=None, thickness=-0.1)
2296+
s4_shell_2 = s4_shape.shell(faceList=[], thickness=-0.1)
2297+
# this should be the same as the first shape
2298+
self.assertEqual(len(s4_shell_1.Faces()), s1.faces().size())
2299+
self.assertEqual(len(s4_shell_2.Faces()), s1.faces().size())
2300+
22932301
def testOpenCornerShell(self):
22942302
s = Workplane("XY").box(1, 1, 1)
22952303
s1 = s.faces("+Z")

0 commit comments

Comments
 (0)