Beispiel #1
0
 def project_curve(self, other):
     # this way Geom_Circle and alike are valid too
     if (isinstance(other, TopoDS_Edge) or
         isinstance(other, Geom_Curve) or
        issubclass(other, Geom_Curve)):
             # convert edge to curve
             first, last = topexp.FirstVertex(other), topexp.LastVertex(other)
             lbound, ubound = BRep_Tool().Parameter(first, other), BRep_Tool().Parameter(last, other)
             other = BRep_Tool.Curve(other, lbound, ubound).GetObject()
             return geomprojlib.Project(other, self.surface_handle)
Beispiel #2
0
    def endpoints(self):
        """Get tuple of start and finish point of current curve object 
           (if it exists)."""

        assert (self.is_wire_or_edge())

        if self.is_wire():
            a, b = TopoDS_Vertex(), TopoDS_Vertex()
            topexp.Vertices(self.Wire(), a, b)
            return point3(a), point3(b)

        elif self.is_edge():
            a = topexp.FirstVertex(self.Edge())
            b = topexp.LastVertex(self.Edge())
            return point3(a), point3(b)
Beispiel #3
0
 def first_vertex(self):
     return topexp.FirstVertex(self)
Beispiel #4
0
def sort_edges_into_order(occedge_list, isclosed=False):
    """
    This function creates a list of ordered OCCedges from a list of loose OCCedges. The edges does not need to form a close face. 
 
    Parameters
    ----------
    occedge_list : list of OCCedges
        The list of OCCedges to be sorted.
    
    isclosed : bool, optional
        True or False, is the resultant wires suppose to be closed or opened, Default = False.
        
    Returns
    -------
    list of sorted edges : list of OCCedges
        A list of ordered OCCedges.
    """
    from OCC.Core.TopoDS import topods
    from OCC.Core.TopExp import topexp
    from OCC.Core.BRep import BRep_Tool
    from OCC.Core.ShapeAnalysis import ShapeAnalysis_WireOrder
    from OCC.Core.Precision import precision

    sawo_statusdict = {
        0: "all edges are direct and in sequence",
        1: "all edges are direct but some are not in sequence",
        2: "unresolved gaps remain",
        -1: "some edges are reversed, but no gaps remain",
        -2: "some edges are reversed and some gaps remain",
        -10: "failure on reorder"
    }

    mode3d = True
    SAWO = ShapeAnalysis_WireOrder(mode3d, precision.PConfusion())

    for occedge in occedge_list:
        V1 = topexp.FirstVertex(topods.Edge(occedge))
        V2 = topexp.LastVertex(topods.Edge(occedge))
        pnt1 = BRep_Tool().Pnt(V1)
        pnt2 = BRep_Tool().Pnt(V2)
        SAWO.Add(pnt1.XYZ(), pnt2.XYZ())
        SAWO.SetKeepLoopsMode(True)

    SAWO.Perform(isclosed)
    #print "SAWO.Status()", SAWO.Status()
    if not SAWO.IsDone():
        raise RuntimeError("build wire: Unable to reorder edges: \n" +
                           sawo_statusdict[SAWO.Status()])
    else:
        if SAWO.Status() not in [0, -1]:
            pass  # not critical, wirebuilder will handle this
        SAWO.SetChains(precision.PConfusion())
        sorted_edge2dlist = []
        #print "Number of chains: ", SAWO.NbChains()
        for i in range(SAWO.NbChains()):
            sorted_edges = []
            estart, eend = SAWO.Chain(i + 1)
            #print "Number of edges in chain", i, ": ", eend - estart + 1
            if (eend - estart + 1) == 0:
                continue
            for j in range(estart, eend + 1):
                idx = abs(SAWO.Ordered(j))
                edge2w = occedge_list[idx - 1]
                if SAWO.Ordered(j) < 0:
                    edge2w.Reverse()
                sorted_edges.append(edge2w)

            sorted_edge2dlist.append(sorted_edges)

    return sorted_edge2dlist