From b2eb1fb1b7ef9b6a603af467ad0a558e0a7b6219 Mon Sep 17 00:00:00 2001 From: gumyr Date: Mon, 11 Dec 2023 11:25:59 -0500 Subject: [PATCH] Fixed workplanes popping problem Issue #399 --- src/build123d/build_common.py | 4 ++-- tests/test_build_common.py | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/build123d/build_common.py b/src/build123d/build_common.py index 0c7dfbd4..1e942bfb 100644 --- a/src/build123d/build_common.py +++ b/src/build123d/build_common.py @@ -204,7 +204,8 @@ def __init__( mode: Mode = Mode.ADD, ): self.mode = mode - self.workplanes = WorkplaneList._convert_to_planes(workplanes) + planes = WorkplaneList._convert_to_planes(workplanes) + self.workplanes = planes if planes else [Plane.XY] self._reset_tok = None current_frame = inspect.currentframe() assert current_frame is not None @@ -234,7 +235,6 @@ def __enter__(self): self.builder_parent = Builder._get_context() else: self.builder_parent = None - self.workplanes = self.workplanes if self.workplanes else [Plane.XY] self._reset_tok = self._current.set(self) diff --git a/tests/test_build_common.py b/tests/test_build_common.py index ef3eb331..3a9b170e 100644 --- a/tests/test_build_common.py +++ b/tests/test_build_common.py @@ -194,6 +194,19 @@ def test_multiple(self): Line((0, 0), (0, 1)) self.assertEqual(len(test.pending_edges), 2) + def test_workplane_popping(self): + # If BuildSketch pushes and pops its workplanes correctly, the order shouldn't matter + with BuildPart(Plane.XZ) as a: + with BuildSketch(): + Circle(1) + Cylinder(1, 5) + + with BuildPart(Plane.XZ) as b: + Cylinder(1, 5) + with BuildSketch(): + Circle(1) + self.assertAlmostEqual(a.part.volume, (a.part & b.part).volume, 4) + class TestCommonOperations(unittest.TestCase): """Test custom operators"""