Skip to content

Commit 48deb19

Browse files
adam-urbanczykmarcus7070
authored andcommitted
Initial implementation of CompSolid
1 parent 0325474 commit 48deb19

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
@@ -4255,3 +4255,17 @@ def testFindFace(self):
42554255
self.assertTrue(isinstance(w2.findFace(searchParents=True), Face))
42564256
with raises(ValueError):
42574257
w2.findFace(searchParents=False)
4258+
4259+
def testCompSolid(self):
4260+
4261+
from OCP.BRepPrimAPI import BRepPrimAPI_MakePrism
4262+
4263+
tool = Solid.makeSphere(1, angleDegrees3=120)
4264+
shell = tool.Shells()[0]
4265+
v = Vector(0, 0, 1)
4266+
4267+
builder = BRepPrimAPI_MakePrism(shell.wrapped, v.wrapped)
4268+
result = Shape.cast(builder.Shape())
4269+
4270+
self.assertEqual(len(result.CompSolids()), 1)
4271+
self.assertEqual(len(result.Solids()), 4)

0 commit comments

Comments
 (0)