Beispiel #1
0
def vertex_fillet(cube, vert):
    # apply a fillet on incident edges on a vertex
    afillet = BRepFilletAPI_MakeFillet(cube)
    cnt = 0
    # find edges from vertex
    _map = TopTools_IndexedDataMapOfShapeListOfShape()
    topexp_MapShapesAndAncestors(cube, 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!')
Beispiel #2
0
    def chamfer(self, length, length2, edgeList):
        """
        Chamfers the specified edges of this solid.
        :param length: length > 0, the length (length) of the chamfer
        :param length2: length2 > 0, optional parameter for asymmetrical chamfer. Should be `None` if not required.
        :param edgeList:  a list of Edge objects, which must belong to this solid
        :return: Chamfered solid
        """
        nativeEdges = [e.wrapped for e in edgeList]

        # make a edge --> faces mapping
        edge_face_map = TopTools_IndexedDataMapOfShapeListOfShape()

        topexp_MapShapesAndAncestors(self.wrapped, ta.TopAbs_EDGE,
                                     ta.TopAbs_FACE, edge_face_map)

        # note: we prefer 'length' word to 'radius' as opposed to FreeCAD's API
        chamfer_builder = BRepFilletAPI_MakeChamfer(self.wrapped)

        if length2:
            d1 = length
            d2 = length2
        else:
            d1 = length
            d2 = length

        for e in nativeEdges:
            face = edge_face_map.FindFromKey(e).First()
            chamfer_builder.Add(d1, d2, e, topods_Face(
                face))  # NB: edge_face_map return a generic TopoDS_Shape
        return self.__class__(chamfer_builder.Shape())
Beispiel #3
0
    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()
Beispiel #4
0
class TopoMap(TopoTypeFactory):
    """
    Wrapper for
        - TopTools_IndexedDataMapOfShapeListOfShape: creation, lookup etc

    Topo creates an instance each time which is slow.

    """
    def __init__(self, shape, topo_type1, topo_type2):
        self._map = TopTools_IndexedDataMapOfShapeListOfShape()
        self._target_type = topo_type2
        topexp_MapShapesAndAncestors(shape, topo_type1, topo_type2, self._map)

    def index_of(self, item):
        return self._map.FindIndex(item)

    def __getitem__(self, item: TopoDS_Shape) -> List[TopoDS_Shape]:
        seen = set()
        res = []
        results = self._map.FindFromKey(item)
        if results.IsEmpty():
            return res

        topology_iterator = TopTools_ListIteratorOfListOfShape(results)

        while topology_iterator.More():
            topo_entity = self.topoFactory[self._target_type](topology_iterator.Value())
            # return the entity if not in set
            # to assure we're not returning entities several times
            if not hash(topo_entity) in seen:
                res.append(topo_entity)

            seen.add(hash(topo_entity))
            topology_iterator.Next()
        return res

    def clear(self):
        self._map.Clear()

    @classmethod
    def v2e(cls, shape:TopoDS_Shape):
        return cls(shape, TopAbs_VERTEX, TopAbs_EDGE)

    @classmethod
    def e2v(cls, shape: TopoDS_Shape):
        return cls(shape, TopAbs_EDGE, TopAbs_VERTEX)
Beispiel #5
0
 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)
Beispiel #6
0
#!/usr/bin/env python
Beispiel #7
0
 def __init__(self, shape, topo_type1, topo_type2):
     self._map = TopTools_IndexedDataMapOfShapeListOfShape()
     self._target_type = topo_type2
     topexp_MapShapesAndAncestors(shape, topo_type1, topo_type2, self._map)