示例#1
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()
示例#2
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!')
示例#3
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())
示例#4
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()
示例#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)
示例#6
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)
#!/usr/bin/env python
示例#8
0
#!/usr/bin/env python
示例#9
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)
示例#10
0
# -*- coding: iso-8859-1 -*-