1919
2020from __future__ import print_function
2121
22- __all__ = [' Topo' , ' WireExplorer' , ' dumpTopology' ]
22+ __all__ = [" Topo" , " WireExplorer" , " dumpTopology" ]
2323
2424from OCC .Core .BRep import BRep_Tool
2525
2626from OCC .Core .BRepTools import BRepTools_WireExplorer
27- from OCC .Core .TopAbs import (TopAbs_VERTEX , TopAbs_EDGE , TopAbs_FACE , TopAbs_WIRE ,
28- TopAbs_SHELL , TopAbs_SOLID , TopAbs_COMPOUND ,
29- TopAbs_COMPSOLID )
27+ from OCC .Core .TopAbs import (
28+ TopAbs_VERTEX ,
29+ TopAbs_EDGE ,
30+ TopAbs_FACE ,
31+ TopAbs_WIRE ,
32+ TopAbs_SHELL ,
33+ TopAbs_SOLID ,
34+ TopAbs_COMPOUND ,
35+ TopAbs_COMPSOLID ,
36+ )
3037from OCC .Core .TopExp import TopExp_Explorer , topexp_MapShapesAndAncestors
31- from OCC .Core .TopTools import (TopTools_ListOfShape ,
32- TopTools_ListIteratorOfListOfShape ,
33- TopTools_IndexedDataMapOfShapeListOfShape )
34- from OCC .Core .TopoDS import (topods , TopoDS_Wire , TopoDS_Vertex , TopoDS_Edge ,
35- TopoDS_Face , TopoDS_Shell , TopoDS_Solid ,
36- TopoDS_Compound , TopoDS_CompSolid , topods_Edge ,
37- topods_Vertex , TopoDS_Iterator )
38+ from OCC .Core .TopTools import (
39+ TopTools_ListOfShape ,
40+ TopTools_ListIteratorOfListOfShape ,
41+ TopTools_IndexedDataMapOfShapeListOfShape ,
42+ )
43+ from OCC .Core .TopoDS import (
44+ topods ,
45+ TopoDS_Wire ,
46+ TopoDS_Vertex ,
47+ TopoDS_Edge ,
48+ TopoDS_Face ,
49+ TopoDS_Shell ,
50+ TopoDS_Solid ,
51+ TopoDS_Compound ,
52+ TopoDS_CompSolid ,
53+ topods_Edge ,
54+ topods_Vertex ,
55+ TopoDS_Iterator ,
56+ )
3857
3958
4059class WireExplorer (object ):
41- '''
60+ """
4261 Wire traversal
43- '''
62+ """
63+
4464 def __init__ (self , wire ):
45- assert isinstance (wire , TopoDS_Wire ), ' not a TopoDS_Wire'
65+ assert isinstance (wire , TopoDS_Wire ), " not a TopoDS_Wire"
4666 self .wire = wire
4767 self .wire_explorer = BRepTools_WireExplorer (self .wire )
4868 self .done = False
@@ -88,9 +108,9 @@ def ordered_vertices(self):
88108
89109
90110class Topo (object ):
91- '''
111+ """
92112 Topology traversal
93- '''
113+ """
94114
95115 def __init__ (self , myShape , ignore_orientation = False ):
96116 """
@@ -133,26 +153,33 @@ def __init__(self, myShape, ignore_orientation=False):
133153 TopAbs_SHELL : topods .Shell ,
134154 TopAbs_SOLID : topods .Solid ,
135155 TopAbs_COMPOUND : topods .Compound ,
136- TopAbs_COMPSOLID : topods .CompSolid
156+ TopAbs_COMPSOLID : topods .CompSolid ,
137157 }
138158
139- def _loop_topo (self , topologyType , topologicalEntity = None , topologyTypeToAvoid = None ):
140- '''
159+ def _loop_topo (
160+ self , topologyType , topologicalEntity = None , topologyTypeToAvoid = None
161+ ):
162+ """
141163 this could be a faces generator for a python TopoShape class
142164 that way you can just do:
143165 for face in srf.faces:
144166 processFace(face)
145- '''
146- topoTypes = {TopAbs_VERTEX : TopoDS_Vertex ,
147- TopAbs_EDGE : TopoDS_Edge ,
148- TopAbs_FACE : TopoDS_Face ,
149- TopAbs_WIRE : TopoDS_Wire ,
150- TopAbs_SHELL : TopoDS_Shell ,
151- TopAbs_SOLID : TopoDS_Solid ,
152- TopAbs_COMPOUND : TopoDS_Compound ,
153- TopAbs_COMPSOLID : TopoDS_CompSolid }
154-
155- assert topologyType in topoTypes .keys (), '%s not one of %s' % (topologyType , topoTypes .keys ())
167+ """
168+ topoTypes = {
169+ TopAbs_VERTEX : TopoDS_Vertex ,
170+ TopAbs_EDGE : TopoDS_Edge ,
171+ TopAbs_FACE : TopoDS_Face ,
172+ TopAbs_WIRE : TopoDS_Wire ,
173+ TopAbs_SHELL : TopoDS_Shell ,
174+ TopAbs_SOLID : TopoDS_Solid ,
175+ TopAbs_COMPOUND : TopoDS_Compound ,
176+ TopAbs_COMPSOLID : TopoDS_CompSolid ,
177+ }
178+
179+ assert topologyType in topoTypes .keys (), "%s not one of %s" % (
180+ topologyType ,
181+ topoTypes .keys (),
182+ )
156183 self .topExp = TopExp_Explorer ()
157184 # use self.myShape if nothing is specified
158185 if topologicalEntity is None and topologyTypeToAvoid is None :
@@ -162,9 +189,7 @@ def _loop_topo(self, topologyType, topologicalEntity=None, topologyTypeToAvoid=N
162189 elif topologyTypeToAvoid is None :
163190 self .topExp .Init (topologicalEntity , topologyType )
164191 elif topologyTypeToAvoid :
165- self .topExp .Init (topologicalEntity ,
166- topologyType ,
167- topologyTypeToAvoid )
192+ self .topExp .Init (topologicalEntity , topologyType , topologyTypeToAvoid )
168193 seq = []
169194 hashes = [] # list that stores hashes to avoid redundancy
170195 occ_seq = TopTools_ListOfShape ()
@@ -201,9 +226,9 @@ def _loop_topo(self, topologyType, topologicalEntity=None, topologyTypeToAvoid=N
201226 return iter (seq )
202227
203228 def faces (self ):
204- '''
229+ """
205230 loops over all faces
206- '''
231+ """
207232 return self ._loop_topo (TopAbs_FACE )
208233
209234 def _number_of_topo (self , iterable ):
@@ -216,95 +241,95 @@ def number_of_faces(self):
216241 return self ._number_of_topo (self .faces ())
217242
218243 def vertices (self ):
219- '''
244+ """
220245 loops over all vertices
221- '''
246+ """
222247 return self ._loop_topo (TopAbs_VERTEX )
223248
224249 def number_of_vertices (self ):
225250 return self ._number_of_topo (self .vertices ())
226251
227252 def edges (self ):
228- '''
253+ """
229254 loops over all edges
230- '''
255+ """
231256 return self ._loop_topo (TopAbs_EDGE )
232257
233258 def number_of_edges (self ):
234259 return self ._number_of_topo (self .edges ())
235260
236261 def wires (self ):
237- '''
262+ """
238263 loops over all wires
239- '''
264+ """
240265 return self ._loop_topo (TopAbs_WIRE )
241266
242267 def number_of_wires (self ):
243268 return self ._number_of_topo (self .wires ())
244269
245270 def shells (self ):
246- '''
271+ """
247272 loops over all shells
248- '''
273+ """
249274 return self ._loop_topo (TopAbs_SHELL , None )
250275
251276 def number_of_shells (self ):
252277 return self ._number_of_topo (self .shells ())
253278
254279 def solids (self ):
255- '''
280+ """
256281 loops over all solids
257- '''
282+ """
258283 return self ._loop_topo (TopAbs_SOLID , None )
259284
260285 def number_of_solids (self ):
261286 return self ._number_of_topo (self .solids ())
262287
263288 def comp_solids (self ):
264- '''
289+ """
265290 loops over all compound solids
266- '''
291+ """
267292 return self ._loop_topo (TopAbs_COMPSOLID )
268293
269294 def number_of_comp_solids (self ):
270295 return self ._number_of_topo (self .comp_solids ())
271296
272297 def compounds (self ):
273- '''
298+ """
274299 loops over all compounds
275- '''
300+ """
276301 return self ._loop_topo (TopAbs_COMPOUND )
277302
278303 def number_of_compounds (self ):
279304 return self ._number_of_topo (self .compounds ())
280305
281306 def ordered_vertices_from_wire (self , wire ):
282- '''
307+ """
283308 @param wire: TopoDS_Wire
284- '''
309+ """
285310 we = WireExplorer (wire )
286311 return we .ordered_vertices ()
287312
288313 def number_of_ordered_vertices_from_wire (self , wire ):
289314 return self ._number_of_topo (self .ordered_vertices_from_wire (wire ))
290315
291316 def ordered_edges_from_wire (self , wire ):
292- '''
317+ """
293318 @param wire: TopoDS_Wire
294- '''
319+ """
295320 we = WireExplorer (wire )
296321 return we .ordered_edges ()
297322
298323 def number_of_ordered_edges_from_wire (self , wire ):
299324 return self ._number_of_topo (self .ordered_edges_from_wire (wire ))
300325
301326 def _map_shapes_and_ancestors (self , topoTypeA , topoTypeB , topologicalEntity ):
302- '''
327+ """
303328 using the same method
304329 @param topoTypeA:
305330 @param topoTypeB:
306331 @param topologicalEntity:
307- '''
332+ """
308333 topo_set = set ()
309334 _map = TopTools_IndexedDataMapOfShapeListOfShape ()
310335 topexp_MapShapesAndAncestors (self .myShape , topoTypeA , topoTypeB , _map )
@@ -335,14 +360,14 @@ def _map_shapes_and_ancestors(self, topoTypeA, topoTypeB, topologicalEntity):
335360 topology_iterator .Next ()
336361
337362 def _number_shapes_ancestors (self , topoTypeA , topoTypeB , topologicalEntity ):
338- ''' returns the number of shape ancestors
363+ """ returns the number of shape ancestors
339364 If you want to know how many edges a faces has:
340365 _number_shapes_ancestors(self, TopAbs_EDGE, TopAbs_FACE, edg)
341- will return the number of edges a faces has
366+ will return the number of edges a faces has
342367 @param topoTypeA:
343368 @param topoTypeB:
344369 @param topologicalEntity:
345- '''
370+ """
346371 topo_set = set ()
347372 _map = TopTools_IndexedDataMapOfShapeListOfShape ()
348373 topexp_MapShapesAndAncestors (self .myShape , topoTypeA , topoTypeB , _map )
@@ -484,13 +509,16 @@ def number_of_faces_from_solids(self, solid):
484509
485510def dumpTopology (shape , level = 0 ):
486511 """
487- Print the details of an object from the top down
512+ Print the details of an object from the top down
488513 """
489514 brt = BRep_Tool ()
490515 s = shape .ShapeType ()
491516 if s == TopAbs_VERTEX :
492517 pnt = brt .Pnt (topods_Vertex (shape ))
493- print (".." * level + "<Vertex %i: %s %s %s>" % (hash (shape ), pnt .X (), pnt .Y (), pnt .Z ()))
518+ print (
519+ ".." * level
520+ + "<Vertex %i: %s %s %s>" % (hash (shape ), pnt .X (), pnt .Y (), pnt .Z ())
521+ )
494522 else :
495523 print (".." * level , end = "" )
496524 print (shapeTypeString (shape ))
0 commit comments