示例#1
0
    def fix_collinear(cls, wire, tol):
        """

        :return:
        """
        if wire.Reversed() is 1:
            wire.Reverse()

        explorer = BRepTools_WireExplorer(wire)
        prev = None

        while explorer.More():

            curr = explorer.Current()

            if prev is None:
                prev = curr
                explorer.Next()
                continue

            v1 = gp.gp_Vec(topexp.FirstVertex(curr), topexp.LastVertex(curr))
            v2 = gp.gp_Vec(topexp.FirstVertex(prev), topexp.LastVertex(prev))

            if v1.Angle(v2) < tol:
                # remove common vertex
                comm = topexp.CommonVertex(curr, prev)

            # if angle between these is close to 0 or pi, remove the vertex ...

        return
示例#2
0
def iter_edges_from_wire(wire):
    """
    Generator / Iterator over the edges of a wire

    Compared to iter_edges, it preserves the order
    of the edges.
    """
    exp = BRepTools_WireExplorer(wire)
    while exp.More():
        yield topods_Edge(exp.Current())
        exp.Next()
示例#3
0
def copy_reversed(wire, edge_dict=None):
    if edge_dict is not None:
        return copy_reversed_params(wire, edge_dict)
    itr = BRepTools_WireExplorer(wire)
    verts = []
    while itr.More():
        current_item = itr.Current()
        out_fst = topexp.FirstVertex(current_item)
        # out_lst = topexp.LastVertex(current_item)
        verts.append(out_fst)
        itr.Next()

    verts.reverse()
    return Wire.create(*verts)
示例#4
0
class WireExplorer(object):
    """
    Wire traversal
    """
    def __init__(self, wire):
        assert isinstance(wire, TopoDS_Wire), 'not a TopoDS_Wire'
        self.wire = wire
        self.wire_explorer = BRepTools_WireExplorer(self.wire)
        self.done = False

    def _reinitialize(self):
        self.wire_explorer = BRepTools_WireExplorer(self.wire)
        self.done = False

    def _loop_topo(self, edges=True):
        if self.done:
            self._reinitialize()
        topologyType = topods_Edge if edges else topods_Vertex
        seq = []
        hashes = set()
        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 current_item_hash not in hashes:
                hashes.add(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 ordered_edges(self):
        return self._loop_topo(edges=True)

    def ordered_vertices(self):
        return self._loop_topo(edges=False)
示例#5
0
def copy_reversed_params(wire, edge_dict):
    itr = BRepTools_WireExplorer(wire)
    verts = []
    while itr.More():
        current_item = itr.Current()
        out_fst = topexp.FirstVertex(current_item)
        out_lst = topexp.LastVertex(current_item)

        new_edge = Construct.make_edge(Construct.copy_vertex(out_lst),
                                       Construct.copy_vertex(out_fst))

        verts.append(new_edge)
        edge_dict[hash(new_edge)] = edge_dict[hash(current_item)]
        itr.Next()

    # verts.reverse()
    return Construct.make_wirex(*verts)
示例#6
0
def follow(wire, face=None):
    if face:
        itr = BRepTools_WireExplorer(wire, face)
    else:
        itr = BRepTools_WireExplorer(wire)
    verts = []
    print('------------')
    while itr.More():
        current_item = itr.Current()

        out_fst = topexp.FirstVertex(current_item)
        out_lst = topexp.LastVertex(current_item)
        v1 = Common.vertex2pnt(out_fst)
        v2 = Common.vertex2pnt(out_lst)

        print(gp.repr3(v1), gp.repr3(v2), current_item.Orientation())

        # verts.append(out_fst)
        itr.Next()
    print('------------')
    return
示例#7
0
    def __call__(
        self,
        outer_wire: TopoDS_Shape,
        support_outer: TopoDS_Edge,
        new_point: gp.gp_Pnt,
        inner_wire: TopoDS_Wire,
        support_inner: TopoDS_Vertex,
    ) -> TopoDS_Shape:
        """
        Im sure theres a builtin command for this, but i cant find it...

        'outer_wire' is a wire which contains a hole defined by the reverse
        of 'inner_wire'

        Remove the hole by replacing the edge 'support_outer' with a loop that
        includes inner_wire

        Produces a single Wire oriented to its interior face.

        :param outer_wire:
        :param support_outer: Edge on the outer wire
        :param new_point:
        :param inner_wire:
        :param support_inner:
        :return:
        """
        new_vert_out2in = Construct.make_vertex(new_point)
        new_vert_in2out = Construct.make_vertex(new_point)

        v1 = topexp.FirstVertex(support_outer)
        v2 = topexp.LastVertex(support_outer)

        new_edge_a = Construct.make_edge(v1, new_vert_in2out)
        new_edge_d = Construct.make_edge(new_vert_out2in, v2)

        self.replaced.append([support_outer, [new_edge_a, new_edge_d]])

        pt = Common.vertex2pnt(support_inner)
        vert_inner = Construct.make_vertex(pt)

        new_edge_b = Construct.make_edge(new_vert_in2out, support_inner)
        new_edge_c = Construct.make_edge(vert_inner, new_vert_out2in)
        self.added.extend([new_edge_b, new_edge_c])

        # get the edges which are on inner support
        edges_before = []
        edges_after = []

        found = False
        itr = BRepTools_WireExplorer(inner_wire)
        while itr.More():

            if itr.CurrentVertex() == support_inner:
                # the edge leaving the selected support
                found = True

            if found is True:
                edges_after.append(itr.Current())
            else:
                edges_before.append(itr.Current())
            itr.Next()

        new_order = edges_after + edges_before
        last = new_order.pop()
        # -------------------------------------------------
        builder = brep.BRepBuilderAPI_MakeWire()

        builder.Add(new_edge_a)
        builder.Add(new_edge_b)
        for edge in new_order:
            builder.Add(edge)

        last_vert = topexp.FirstVertex(last)
        new_last = Construct.make_edge(last_vert, vert_inner)

        self.replaced.append([last, [new_last]])
        builder.Add(new_last)
        builder.Add(new_edge_c)
        builder.Add(new_edge_d)

        builder.Build()
        replacement = builder.Wire()
        reshaper = brep.BRepTools_ReShape()
        reshaper.Replace(support_outer, replacement)
        return reshaper.Apply(outer_wire)