def vertex_fillet(cube_shp, vert): # apply a fillet on incident edges on a vertex afillet = BRepFilletAPI_MakeFillet(cube_shp) cnt = 0 # find edges from vertex _map = TopTools_IndexedDataMapOfShapeListOfShape() topexp_MapShapesAndAncestors(cube_shp, TopAbs_VERTEX, TopAbs_EDGE, _map) results = _map.FindFromKey(vert) topology_iterator = TopTools_ListIteratorOfListOfShape(results) while topology_iterator.More(): edge = topods_Edge(topology_iterator.Value()) topology_iterator.Next() first, last = topexp_FirstVertex(edge), topexp_LastVertex(edge) vertex, first_vert, last_vert = BRep_Tool().Pnt(vert), BRep_Tool().Pnt(first), BRep_Tool().Pnt(last) if edge.Orientation(): if not vertex.IsEqual(first_vert, 0.001): afillet.Add(0, 20., edge) else: afillet.Add(20, 0, edge) cnt += 1 afillet.Build() if afillet.IsDone(): return afillet.Shape() else: raise AssertionError('you failed on me you fool!')
def _map_shapes_and_ancestors(self, topoTypeA, topoTypeB, topologicalEntity): ''' using the same method @param topoTypeA: @param topoTypeB: @param topologicalEntity: ''' topo_set = set() _map = TopTools_IndexedDataMapOfShapeListOfShape() topexp_MapShapesAndAncestors(self.myShape, topoTypeA, topoTypeB, _map) results = _map.FindFromKey(topologicalEntity) if results.Size() == 0: yield None topology_iterator = TopTools_ListIteratorOfListOfShape(results) while topology_iterator.More(): topo_entity = self.topoFactory[topoTypeB](topology_iterator.Value()) # return the entity if not in set # to assure we're not returning entities several times if not topo_entity in topo_set: if self.ignore_orientation: unique = True for i in topo_set: if i.IsSame(topo_entity): unique = False break if unique: yield topo_entity else: yield topo_entity topo_set.add(topo_entity) topology_iterator.Next()
def _map_shapes_and_ancestors(self, topology_type_1, topology_type_2, topological_entity): """ using the same method @param topoTypeA: @param topoTypeB: @param topological_entity: """ topo_set = set() topo_set_hash_codes = {} _map = TopTools_IndexedDataMapOfShapeListOfShape() topexp_MapShapesAndAncestors(self.my_shape, topology_type_1, topology_type_2, _map) results = _map.FindFromKey(topological_entity) if results.Size() == 0: yield None topology_iterator = TopTools_ListIteratorOfListOfShape(results) while topology_iterator.More(): topo_entity = self.topology_factory[topology_type_2]( topology_iterator.Value()) topo_entity_hash_code = topo_entity.HashCode(MAX_32_BIT_INT) # return the entity if not in set # to assure we're not returning entities several times if not topo_entity in topo_set: if self.ignore_orientation: if not topo_entity_hash_code in topo_set_hash_codes: topo_set_hash_codes[topo_entity_hash_code] = [ topo_entity ] yield topo_entity else: unique = True for i in topo_set_hash_codes[topo_entity_hash_code]: if i.IsSame(topo_entity): unique = False break if unique: topo_set_hash_codes[topo_entity_hash_code].append( topo_entity) yield topo_entity else: yield topo_entity topo_set.add(topo_entity) topology_iterator.Next()
def face_adjacent(shape, face, edge): efmap = TopTools_IndexedDataMapOfShapeListOfShape() topexp_MapShapesAndAncestors(shape, TopAbs_EDGE, TopAbs_FACE, efmap) adjface = TopoDS_Face() if TopOpeBRepBuild_Tools.GetAdjacentFace(face, edge, efmap, adjface): return adjface else: return None
def _number_shapes_ancestors(self, topoTypeA, topoTypeB, topologicalEntity): '''returns the number of shape ancestors If you want to know how many edges a faces has: _number_shapes_ancestors(self, TopAbs_EDGE, TopAbs_FACE, edg) will return the number of edges a faces has @param topoTypeA: @param topoTypeB: @param topologicalEntity: ''' topo_set = set() _map = TopTools_IndexedDataMapOfShapeListOfShape() topexp_MapShapesAndAncestors(self.myShape, topoTypeA, topoTypeB, _map) results = _map.FindFromKey(topologicalEntity) if results.IsEmpty(): return None topology_iterator = TopTools_ListIteratorOfListOfShape(results) while topology_iterator.More(): topo_set.add(topology_iterator.Value()) topology_iterator.Next() return len(topo_set)