diff --git a/src/build123d/build_enums.py b/src/build123d/build_enums.py index 9d890fe..8f8059a 100644 --- a/src/build123d/build_enums.py +++ b/src/build123d/build_enums.py @@ -179,11 +179,12 @@ class Intrinsic(Enum): class Keep(Enum): """Split options""" - TOP = auto() + ALL = auto() BOTTOM = auto() + BOTH = auto() INSIDE = auto() OUTSIDE = auto() - BOTH = auto() + TOP = auto() def __repr__(self): return f"<{self.__class__.__name__}.{self.name}>" diff --git a/src/build123d/topology/one_d.py b/src/build123d/topology/one_d.py index 62993b7..b5a3acf 100644 --- a/src/build123d/topology/one_d.py +++ b/src/build123d/topology/one_d.py @@ -898,6 +898,10 @@ class Mixin1D(Shape): ) -> Self | list[Self] | None: """split and keep inside or outside""" + @overload + def split(self, tool: TrimmingTool, keep: Literal[Keep.ALL]) -> list[Self]: + """split and return the unordered pieces""" + @overload def split(self, tool: TrimmingTool, keep: Literal[Keep.BOTH]) -> tuple[ Self | list[Self] | None, @@ -958,6 +962,14 @@ class Mixin1D(Shape): if isinstance(split_result, TopoDS_Compound): split_result = unwrap_topods_compound(split_result, True) + # For speed the user may just want all the objects which they + # can sort more efficiently then the generic algoritm below + if keep == Keep.ALL: + return ShapeList( + self.__class__.cast(part) + for part in get_top_level_topods_shapes(split_result) + ) + if not isinstance(tool, Plane): # Get a TopoDS_Face to work with from the tool if isinstance(trim_tool, TopoDS_Shell): diff --git a/tests/test_direct_api.py b/tests/test_direct_api.py index 4c10981..4dcbfaf 100644 --- a/tests/test_direct_api.py +++ b/tests/test_direct_api.py @@ -3248,6 +3248,12 @@ class TestShape(DirectApiTestCase): outer_vol = 5 * 5 self.assertAlmostEqual(split.volume, outer_vol - inner_vol) + def test_split_keep_all(self): + shape = Box(1, 1, 1) + split_shape = shape.split(Plane.XY, keep=Keep.ALL) + self.assertTrue(isinstance(split_shape, ShapeList)) + self.assertEqual(len(split_shape), 2) + def test_split_edge_by_shell(self): edge = Edge.make_line((-5, 0, 0), (5, 0, 0)) tool = Wire.make_rect(4, 4)