1+ from OCC .Core import TopAbs
2+ from OCC .Core import TopExp
3+ from OCC .Core import TopoDS
14from OCC .Core .BOPAlgo import BOPAlgo_Splitter
25from OCC .Core .BRepGProp import brepgprop
36from OCC .Core .GProp import GProp_GProps
47from OCC .Core .TopoDS import TopoDS_Compound
58from OCC .Core .TopoDS import TopoDS_Iterator
6- from OCC .Core .TopoDS import TopoDS_Shape
79
810from compas .geometry import Point
911
1012from .conversions import point_to_compas
1113
12- # =============================================================================
13- # Brep ops
14- # =============================================================================
1514
16-
17- def split_shapes (arguments : list [TopoDS_Shape ], tools : list [TopoDS_Shape ]) -> list [TopoDS_Shape ]:
15+ def split_shapes (arguments : list [TopoDS .TopoDS_Shape ], tools : list [TopoDS .TopoDS_Shape ]) -> list [TopoDS .TopoDS_Shape ]:
1816 """Split a group of breps by another group of breps.
1917
2018 Parameters
2119 ----------
22- arguments : list[TopoDS_Shape]
20+ arguments : list[TopoDS. TopoDS_Shape]
2321 The arguments passed to the command.
24- tools : list[TopoDS_Shape]
22+ tools : list[TopoDS. TopoDS_Shape]
2523 The tools passed to the command.
2624
2725 Returns
2826 -------
29- list[TopoDS_Shape]
27+ list[TopoDS. TopoDS_Shape]
3028 The resulting breps.
3129
3230 """
@@ -53,17 +51,12 @@ def split_shapes(arguments: list[TopoDS_Shape], tools: list[TopoDS_Shape]) -> li
5351 return results
5452
5553
56- # =============================================================================
57- # Brep props
58- # =============================================================================
59-
60-
61- def compute_shape_centreofmass (occ_shape : TopoDS_Shape ) -> Point :
54+ def compute_shape_centreofmass (occ_shape : TopoDS .TopoDS_Shape ) -> Point :
6255 """Return a COMPAS Point at the centre of mass of a Brep.
6356
6457 Parameters
6558 ----------
66- occ_shape : TopoDS_Shape
59+ occ_shape : TopoDS. TopoDS_Shape
6760 The brep.
6861
6962 Returns
@@ -76,3 +69,135 @@ def compute_shape_centreofmass(occ_shape: TopoDS_Shape) -> Point:
7669 brepgprop .VolumeProperties (occ_shape , props )
7770 pnt = props .CentreOfMass ()
7871 return point_to_compas (pnt )
72+
73+
74+ def occ_shape_find_vertices (occ_shape : TopoDS .TopoDS_Shape ) -> list [TopoDS .TopoDS_Vertex ]:
75+ """Find all the vertices in an OCC shape.
76+
77+ Parameters
78+ ----------
79+ occ_shape : TopoDS.TopoDS_Shape
80+ The shape to explore.
81+
82+ Returns
83+ -------
84+ list[TopoDS.TopoDS_Vertex]
85+
86+ """
87+ vertices : list [TopoDS .TopoDS_Vertex ] = []
88+ explorer = TopExp .TopExp_Explorer (occ_shape , TopAbs .TopAbs_VERTEX ) # type: ignore
89+ while explorer .More ():
90+ vertex = explorer .Current ()
91+ vertices .append (vertex ) # type: ignore
92+ explorer .Next ()
93+ return vertices
94+
95+
96+ def occ_shape_find_edges (occ_shape : TopoDS .TopoDS_Shape ) -> list [TopoDS .TopoDS_Edge ]:
97+ """Find all the edges in an OCC shape.
98+
99+ Parameters
100+ ----------
101+ occ_shape : TopoDS.TopoDS_Shape
102+ The shape to explore.
103+
104+ Returns
105+ -------
106+ list[TopoDS.TopoDS_Edge]
107+
108+ """
109+ edges : list [TopoDS .TopoDS_Edge ] = []
110+ explorer = TopExp .TopExp_Explorer (occ_shape , TopAbs .TopAbs_EDGE ) # type: ignore
111+ while explorer .More ():
112+ edge = explorer .Current ()
113+ edges .append (edge ) # type: ignore
114+ explorer .Next ()
115+ return edges
116+
117+
118+ def occ_shape_find_loops (occ_shape : TopoDS .TopoDS_Shape ) -> list [TopoDS .TopoDS_Wire ]:
119+ """Find all the loops or wires in an OCC shape.
120+
121+ Parameters
122+ ----------
123+ occ_shape : TopoDS.TopoDS_Shape
124+ The shape to explore.
125+
126+ Returns
127+ -------
128+ list[TopoDS.TopoDS_Wire]
129+
130+ """
131+ wires : list [TopoDS .TopoDS_Wire ] = []
132+ explorer = TopExp .TopExp_Explorer (occ_shape , TopAbs .TopAbs_WIRE ) # type: ignore
133+ while explorer .More ():
134+ wire = explorer .Current ()
135+ wires .append (wire ) # type: ignore
136+ explorer .Next ()
137+ return wires
138+
139+
140+ def occ_shape_find_faces (occ_shape : TopoDS .TopoDS_Shape ) -> list [TopoDS .TopoDS_Face ]:
141+ """Find all the faces in an OCC shape.
142+
143+ Parameters
144+ ----------
145+ occ_shape : TopoDS.TopoDS_Shape
146+ The shape to explore.
147+
148+ Returns
149+ -------
150+ list[TopoDS.TopoDS_Face]
151+
152+ """
153+ faces : list [TopoDS .TopoDS_Face ] = []
154+ explorer = TopExp .TopExp_Explorer (occ_shape , TopAbs .TopAbs_FACE ) # type: ignore
155+ while explorer .More ():
156+ face = explorer .Current ()
157+ faces .append (face ) # type: ignore
158+ explorer .Next ()
159+ return faces
160+
161+
162+ def occ_shape_find_shells (occ_shape : TopoDS .TopoDS_Shape ) -> list [TopoDS .TopoDS_Shell ]:
163+ """Find all the shells in an OCC shape.
164+
165+ Parameters
166+ ----------
167+ occ_shape : TopoDS.TopoDS_Shape
168+ The shape to explore.
169+
170+ Returns
171+ -------
172+ list[TopoDS.TopoDS_Shell]
173+
174+ """
175+ shells : list [TopoDS .TopoDS_Shell ] = []
176+ explorer = TopExp .TopExp_Explorer (occ_shape , TopAbs .TopAbs_SHELL ) # type: ignore
177+ while explorer .More ():
178+ shell = explorer .Current ()
179+ shells .append (shell ) # type: ignore
180+ explorer .Next ()
181+ return shells
182+
183+
184+ def occ_shape_find_solids (occ_shape : TopoDS .TopoDS_Shape ) -> list [TopoDS .TopoDS_Solid ]:
185+ """Find all the solids in an OCC shape.
186+
187+ Parameters
188+ ----------
189+ occ_shape : TopoDS.TopoDS_Shape
190+ The shape to explore.
191+
192+ Returns
193+ -------
194+ list[TopoDS.TopoDS_Solid]
195+
196+ """
197+ solids : list [TopoDS .TopoDS_Solid ] = []
198+ explorer = TopExp .TopExp_Explorer (occ_shape , TopAbs .TopAbs_SOLID ) # type: ignore
199+ while explorer .More ():
200+ solid = explorer .Current ()
201+ solids .append (solid ) # type: ignore
202+ explorer .Next ()
203+ return solids
0 commit comments