Skip to content

Commit d7e7812

Browse files
Merge branch 'master' into getPending
2 parents 7be6070 + 48deb19 commit d7e7812

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

cadquery/occ_impl/shapes.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@
103103
TopoDS_Vertex,
104104
TopoDS_Solid,
105105
TopoDS_Shell,
106+
TopoDS_CompSolid,
106107
)
107108

108109
from OCP.GC import GC_MakeArcOfCircle, GC_MakeArcOfEllipse # geometry construction
@@ -219,6 +220,7 @@
219220
ta.TopAbs_FACE: "Face",
220221
ta.TopAbs_SHELL: "Shell",
221222
ta.TopAbs_SOLID: "Solid",
223+
ta.TopAbs_COMPSOLID: "CompSolid",
222224
ta.TopAbs_COMPOUND: "Compound",
223225
}
224226

@@ -241,6 +243,7 @@
241243
ta.TopAbs_FACE: TopoDS.Face_s,
242244
ta.TopAbs_SHELL: TopoDS.Shell_s,
243245
ta.TopAbs_SOLID: TopoDS.Solid_s,
246+
ta.TopAbs_COMPSOLID: TopoDS.CompSolid_s,
244247
ta.TopAbs_COMPOUND: TopoDS.Compound_s,
245248
}
246249

@@ -251,6 +254,7 @@
251254
ta.TopAbs_FACE: BRepAdaptor_Surface,
252255
ta.TopAbs_SHELL: "Shell",
253256
ta.TopAbs_SOLID: "Solid",
257+
ta.TopAbs_SOLID: "CompSolid",
254258
ta.TopAbs_COMPOUND: "Compound",
255259
}
256260

@@ -280,7 +284,9 @@
280284
ga.GeomAbs_OtherCurve: "OTHER",
281285
}
282286

283-
Shapes = Literal["Vertex", "Edge", "Wire", "Face", "Shell", "Solid", "Compound"]
287+
Shapes = Literal[
288+
"Vertex", "Edge", "Wire", "Face", "Shell", "Solid", "CompSolid", "Compound"
289+
]
284290
Geoms = Literal[
285291
"Vertex",
286292
"Wire",
@@ -386,6 +392,7 @@ def cast(
386392
ta.TopAbs_FACE: Face,
387393
ta.TopAbs_SHELL: Shell,
388394
ta.TopAbs_SOLID: Solid,
395+
ta.TopAbs_COMPSOLID: CompSolid,
389396
ta.TopAbs_COMPOUND: Compound,
390397
}
391398

@@ -726,6 +733,13 @@ def Solids(self) -> List["Solid"]:
726733

727734
return [Solid(i) for i in self._entities("Solid")]
728735

736+
def CompSolids(self) -> List["CompSolid"]:
737+
"""
738+
:returns: All the compsolids in this Shape
739+
"""
740+
741+
return [CompSolid(i) for i in self._entities("CompSolid")]
742+
729743
def Area(self) -> float:
730744
"""
731745
:returns: The surface area of all faces in this Shape
@@ -2746,6 +2760,14 @@ def dprism(
27462760
return Solid(shape)
27472761

27482762

2763+
class CompSolid(Shape, Mixin3D):
2764+
"""
2765+
a single compsolid
2766+
"""
2767+
2768+
wrapped: TopoDS_CompSolid
2769+
2770+
27492771
class Compound(Shape, Mixin3D):
27502772
"""
27512773
a collection of disconnected solids

tests/test_cadquery.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4313,3 +4313,17 @@ def testPopPending(self):
43134313
w5 = Workplane().circle(1).extrude(1)
43144314
with self.assertRaises(ValueError):
43154315
w5.cutBlind(-1)
4316+
4317+
def testCompSolid(self):
4318+
4319+
from OCP.BRepPrimAPI import BRepPrimAPI_MakePrism
4320+
4321+
tool = Solid.makeSphere(1, angleDegrees3=120)
4322+
shell = tool.Shells()[0]
4323+
v = Vector(0, 0, 1)
4324+
4325+
builder = BRepPrimAPI_MakePrism(shell.wrapped, v.wrapped)
4326+
result = Shape.cast(builder.Shape())
4327+
4328+
self.assertEqual(len(result.CompSolids()), 1)
4329+
self.assertEqual(len(result.Solids()), 4)

0 commit comments

Comments
 (0)