diff --git a/cadquery/occ_impl/shapes.py b/cadquery/occ_impl/shapes.py index 68c4e911b..d208eb8a5 100644 --- a/cadquery/occ_impl/shapes.py +++ b/cadquery/occ_impl/shapes.py @@ -103,6 +103,7 @@ TopoDS_Vertex, TopoDS_Solid, TopoDS_Shell, + TopoDS_CompSolid, ) from OCP.GC import GC_MakeArcOfCircle, GC_MakeArcOfEllipse # geometry construction @@ -219,6 +220,7 @@ ta.TopAbs_FACE: "Face", ta.TopAbs_SHELL: "Shell", ta.TopAbs_SOLID: "Solid", + ta.TopAbs_COMPSOLID: "CompSolid", ta.TopAbs_COMPOUND: "Compound", } @@ -241,6 +243,7 @@ ta.TopAbs_FACE: TopoDS.Face_s, ta.TopAbs_SHELL: TopoDS.Shell_s, ta.TopAbs_SOLID: TopoDS.Solid_s, + ta.TopAbs_COMPSOLID: TopoDS.CompSolid_s, ta.TopAbs_COMPOUND: TopoDS.Compound_s, } @@ -251,6 +254,7 @@ ta.TopAbs_FACE: BRepAdaptor_Surface, ta.TopAbs_SHELL: "Shell", ta.TopAbs_SOLID: "Solid", + ta.TopAbs_SOLID: "CompSolid", ta.TopAbs_COMPOUND: "Compound", } @@ -280,7 +284,9 @@ ga.GeomAbs_OtherCurve: "OTHER", } -Shapes = Literal["Vertex", "Edge", "Wire", "Face", "Shell", "Solid", "Compound"] +Shapes = Literal[ + "Vertex", "Edge", "Wire", "Face", "Shell", "Solid", "CompSolid", "Compound" +] Geoms = Literal[ "Vertex", "Wire", @@ -386,6 +392,7 @@ def cast( ta.TopAbs_FACE: Face, ta.TopAbs_SHELL: Shell, ta.TopAbs_SOLID: Solid, + ta.TopAbs_COMPSOLID: CompSolid, ta.TopAbs_COMPOUND: Compound, } @@ -726,6 +733,13 @@ def Solids(self) -> List["Solid"]: return [Solid(i) for i in self._entities("Solid")] + def CompSolids(self) -> List["CompSolid"]: + """ + :returns: All the compsolids in this Shape + """ + + return [CompSolid(i) for i in self._entities("CompSolid")] + def Area(self) -> float: """ :returns: The surface area of all faces in this Shape @@ -2746,6 +2760,14 @@ def dprism( return Solid(shape) +class CompSolid(Shape, Mixin3D): + """ + a single compsolid + """ + + wrapped: TopoDS_CompSolid + + class Compound(Shape, Mixin3D): """ a collection of disconnected solids diff --git a/tests/test_cadquery.py b/tests/test_cadquery.py index f54a4938f..ba2b43af2 100644 --- a/tests/test_cadquery.py +++ b/tests/test_cadquery.py @@ -4255,3 +4255,17 @@ def testFindFace(self): self.assertTrue(isinstance(w2.findFace(searchParents=True), Face)) with raises(ValueError): w2.findFace(searchParents=False) + + def testCompSolid(self): + + from OCP.BRepPrimAPI import BRepPrimAPI_MakePrism + + tool = Solid.makeSphere(1, angleDegrees3=120) + shell = tool.Shells()[0] + v = Vector(0, 0, 1) + + builder = BRepPrimAPI_MakePrism(shell.wrapped, v.wrapped) + result = Shape.cast(builder.Shape()) + + self.assertEqual(len(result.CompSolids()), 1) + self.assertEqual(len(result.Solids()), 4)