Skip to content

Commit

Permalink
Initial implementation of CompSolid
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-urbanczyk committed Mar 9, 2021
1 parent 0325474 commit dafb6ac
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
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)

0 comments on commit dafb6ac

Please sign in to comment.