Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrap TopoDS_CompSolid #681

Merged
merged 1 commit into from
Mar 10, 2021
Merged
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
24 changes: 23 additions & 1 deletion cadquery/occ_impl/shapes.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
TopoDS_Vertex,
TopoDS_Solid,
TopoDS_Shell,
TopoDS_CompSolid,
)

from OCP.GC import GC_MakeArcOfCircle, GC_MakeArcOfEllipse # geometry construction
Expand Down Expand Up @@ -219,6 +220,7 @@
ta.TopAbs_FACE: "Face",
ta.TopAbs_SHELL: "Shell",
ta.TopAbs_SOLID: "Solid",
ta.TopAbs_COMPSOLID: "CompSolid",
ta.TopAbs_COMPOUND: "Compound",
}

Expand All @@ -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,
}

Expand All @@ -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",
}

Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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,
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions tests/test_cadquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)