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 _loop_topo(self, edges=True): if self.done: self._reinitialize() topologyType = topods_Edge if edges else topods_Vertex seq = [] hashes = [] # list that stores hashes to avoid redundancy occ_seq = TopTools_ListOfShape() while self.wire_explorer.More(): # loop edges if edges: current_item = self.wire_explorer.Current() # loop vertices else: current_item = self.wire_explorer.CurrentVertex() current_item_hash = current_item.__hash__() if not current_item_hash in hashes: hashes.append(current_item_hash) occ_seq.Append(current_item) self.wire_explorer.Next() # Convert occ_seq to python list occ_iterator = TopTools_ListIteratorOfListOfShape(occ_seq) while occ_iterator.More(): topo_to_add = topologyType(occ_iterator.Value()) seq.append(topo_to_add) occ_iterator.Next() self.done = True return iter(seq)
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)
def _map_shapes_and_ancestors(self, topo_type_a, topo_type_b, topo_entity): ''' using the same method @param topoTypeA: @param topoTypeB: @param topological_entity: ''' topo_set = set() items = [] topo_map = TopTools_IndexedDataMapOfShapeListOfShape() TopExp.MapShapesAndAncestors_(self.shape, topo_type_a, topo_type_b, topo_map) topo_results = topo_map.FindFromKey(topo_entity) if topo_results.IsEmpty(): return [] topology_iterator = TopTools_ListIteratorOfListOfShape(topo_results) factory = self.topo_factory[topo_type_b] while topology_iterator.More(): topo_entity = factory(topology_iterator.Value()) # return the entity if not in set # to assure we're not returning entities several times if topo_entity not in topo_set: if self.ignore_orientation: unique = True for i in topo_set: if i.IsSame(topo_entity): unique = False break if unique: items.append(topo_entity) else: items.append(topo_entity) topo_set.add(topo_entity) topology_iterator.Next() return items
def _number_shapes_ancestors(self, topo_type_a, topo_type_b, topological_entity): """ Get 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 topo_type_a: @param topo_type_b: @param topological_entity: """ topo_set = set() _map = TopTools_IndexedDataMapOfShapeListOfShape() TopExp.MapShapesAndAncestors_(self.shape, topo_type_a, topo_type_b, _map) results = _map.FindFromKey(topological_entity) 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)
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.IsEmpty(): 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 _loop_topo(self, edges=True): wexp = self.wire_explorer = BRepTools_WireExplorer(self.wire) items = set() # list that stores hashes to avoid redundancy occ_seq = TopTools_ListOfShape() get_current = wexp.Current if edges else wexp.CurrentVertex while wexp.More(): current_item = get_current() if current_item not in items: items.add(current_item) occ_seq.Append(current_item) wexp.Next() # Convert occ_seq to python list seq = [] topology_type = TopoDS.Edge_ if edges else TopoDS.Vertex_ occ_iterator = TopTools_ListIteratorOfListOfShape(occ_seq) while occ_iterator.More(): topo_to_add = topology_type(occ_iterator.Value()) seq.append(topo_to_add) occ_iterator.Next() return seq
def _loop_topo(self, topologyType, topologicalEntity=None, topologyTypeToAvoid=None): ''' this could be a faces generator for a python TopoShape class that way you can just do: for face in srf.faces: processFace(face) ''' topoTypes = { TopAbs_VERTEX: TopoDS_Vertex, TopAbs_EDGE: TopoDS_Edge, TopAbs_FACE: TopoDS_Face, TopAbs_WIRE: TopoDS_Wire, TopAbs_SHELL: TopoDS_Shell, TopAbs_SOLID: TopoDS_Solid, TopAbs_COMPOUND: TopoDS_Compound, TopAbs_COMPSOLID: TopoDS_CompSolid } assert topologyType in topoTypes.keys(), '%s not one of %s' % ( topologyType, topoTypes.keys()) self.topExp = TopExp_Explorer() # use self.myShape if nothing is specified if topologicalEntity is None and topologyTypeToAvoid is None: self.topExp.Init(self.myShape, topologyType) elif topologicalEntity is None and topologyTypeToAvoid is not None: self.topExp.Init(self.myShape, topologyType, topologyTypeToAvoid) elif topologyTypeToAvoid is None: self.topExp.Init(topologicalEntity, topologyType) elif topologyTypeToAvoid: self.topExp.Init(topologicalEntity, topologyType, topologyTypeToAvoid) seq = [] hashes = [] # list that stores hashes to avoid redundancy occ_seq = TopTools_ListOfShape() while self.topExp.More(): current_item = self.topExp.Current() current_item_hash = current_item.__hash__() if not current_item_hash in hashes: hashes.append(current_item_hash) occ_seq.Append(current_item) self.topExp.Next() # Convert occ_seq to python list occ_iterator = TopTools_ListIteratorOfListOfShape(occ_seq) while occ_iterator.More(): topo_to_add = self.topoFactory[topologyType](occ_iterator.Value()) seq.append(topo_to_add) occ_iterator.Next() if self.ignore_orientation: # filter out those entities that share the same TShape # but do *not* share the same orientation filter_orientation_seq = [] for i in seq: _present = False for j in filter_orientation_seq: if i.IsSame(j): _present = True break if _present is False: filter_orientation_seq.append(i) return filter_orientation_seq else: return iter(seq)
def _loop_topo(self, topology_type, topological_entity=None, topology_type_to_avoid=None): """ this could be a faces generator for a python TopoShape class that way you can just do: for face in srf.faces: processFace(face) """ allowed_types = self.topo_types.keys() if topology_type not in allowed_types: raise TypeError('%s not one of %s' % (topology_type, allowed_types)) shape = self.shape if shape is None: return [] topo_exp = TopExp_Explorer() # use self.myShape if nothing is specified if topological_entity is None and topology_type_to_avoid is None: topo_exp.Init(shape, topology_type) elif topological_entity is None and topology_type_to_avoid is not None: topo_exp.Init(shape, topology_type, topology_type_to_avoid) elif topology_type_to_avoid is None: topo_exp.Init(topological_entity, topology_type) elif topology_type_to_avoid: topo_exp.Init(topological_entity, topology_type, topology_type_to_avoid) items = set() # list that stores hashes to avoid redundancy occ_seq = TopTools_ListOfShape() while topo_exp.More(): current_item = topo_exp.Current() if current_item not in items: items.add(current_item) occ_seq.Append(current_item) topo_exp.Next() # Convert occ_seq to python list seq = [] factory = self.topo_factory[topology_type] occ_iterator = TopTools_ListIteratorOfListOfShape(occ_seq) while occ_iterator.More(): topo_to_add = factory(occ_iterator.Value()) seq.append(topo_to_add) occ_iterator.Next() if not self.ignore_orientation: return seq # else filter out those entities that share the same TShape # but do *not* share the same orientation filter_orientation_seq = [] for i in seq: present = False for j in filter_orientation_seq: if i.IsSame(j): present = True break if present is False: filter_orientation_seq.append(i) return filter_orientation_seq