Skip to content
Closed
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
3 changes: 2 additions & 1 deletion cadquery/occ_impl/shapes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1895,7 +1895,8 @@ def __setstate__(self, data: tuple[BytesIO, bool]) -> None:

BinTools.Read_s(wrapped, data[0])

self.wrapped = wrapped
# NB downcast raises on null shapes
self.wrapped = wrapped if wrapped.IsNull() else downcast(wrapped)
self.forConstruction = data[1]

def replace(self, old: Shape, *new: Shape) -> Self:
Expand Down
29 changes: 29 additions & 0 deletions tests/test_pickle.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from copy import copy, deepcopy
from pickle import loads, dumps

from cadquery import (
Expand Down Expand Up @@ -41,6 +42,34 @@ def test_shape():
assert isinstance(loads(dumps(s)), Shape)


@mark.parametrize(
"copier",
[copy, deepcopy, lambda obj: loads(dumps(obj))],
ids=["copy", "deepcopy", "pickle"],
)
def test_shape_type(copier):
"""
Copying or unpickling a shape keeps its specialized TopoDS type
(e.g. TopoDS_Solid), as constructing it does.
"""

s = box(1, 1, 1)

for obj in (s, s.Faces()[0], s.Edges()[0], s.Vertices()[0]):
assert type(copier(obj).wrapped) is type(obj.wrapped)


def test_null_shape():
"""
Unpickling a null shape keeps it null rather than raising.
"""

s = box(1, 1, 1)
s.wrapped.Nullify()

assert loads(dumps(s)).wrapped.IsNull()


def test_assy():

mat_1 = Material(
Expand Down
Loading