예제 #1
0
def wire_gcode(wire):
    print(f'Wire Orientation: {o(wire)}')
    if wire.Orientation() == TopAbs_REVERSED:
        wire.Reverse()

    for edge in WireExplorer(wire).ordered_edges():
        print(f'Edge Orientation: {o(edge)}')
        tmp = BRepAdaptor_Curve(edge)
        # get underlying curve
        c, start, end = BRep_Tool.Curve(edge)
        # display start and endpoints of curve
        start_point = tmp.Value(tmp.FirstParameter())
        end_point = tmp.Value(tmp.LastParameter())

        if edge.Orientation() == TopAbs_FORWARD:
            display.DisplayColoredShape(
                BRepBuilderAPI_MakeVertex(start_point).Vertex(), "BLUE")
            display.DisplayColoredShape(
                BRepBuilderAPI_MakeVertex(end_point).Vertex(), "RED")
        else:
            display.DisplayColoredShape(
                BRepBuilderAPI_MakeVertex(start_point).Vertex(), "RED")
            display.DisplayColoredShape(
                BRepBuilderAPI_MakeVertex(end_point).Vertex(), "BLUE")

        # display individual curve
        display.DisplayShape(edge, update=True)
        time.sleep(1)
예제 #2
0
def getVectorTangentToCurveAtPoint(aEdge, uRatio):
  aCurve, aFP, aLP = BRep_Tool.Curve(aEdge)
  aP = aFP + (aLP - aFP) * uRatio
  v1 = gp_Vec()
  p1 = gp_Pnt()
  aCurve.D1(aP, p1, v1)
  return v1
예제 #3
0
    def write_edge(points_edge, topo_edge):
        """
        Method to recreate an Edge associated to a geometric curve
        after the modification of its points.
        :param points_edge: the deformed points array.
        :param topo_edge: the Edge to be modified
        :return: Edge (Shape)

        :rtype: TopoDS_Edge

        """
        # convert Edge to Geom B-spline Curve
        nurbs_converter = BRepBuilderAPI_NurbsConvert(topo_edge)
        nurbs_converter.Perform(topo_edge)
        nurbs_curve = nurbs_converter.Shape()
        topo_curve = topods_Edge(nurbs_curve)
        h_geomcurve = BRep_Tool.Curve(topo_curve)[0]
        h_bcurve = geomconvert_CurveToBSplineCurve(h_geomcurve)
        bspline_edge_curve = h_bcurve

        # Edge geometric properties
        nb_cpt = bspline_edge_curve.NbPoles()
        # check consistency
        if points_edge.shape[0] != nb_cpt:
            raise ValueError("Input control points do not have not have the "
                             "same number as the geometric edge!")

        else:
            for i in range(1, nb_cpt + 1):
                cpt = points_edge[i - 1]
                bspline_edge_curve.SetPole(i, gp_Pnt(cpt[0], cpt[1], cpt[2]))

        new_edge = BRepBuilderAPI_MakeEdge(bspline_edge_curve)

        return new_edge.Edge()
예제 #4
0
    def face_expand(self, face=TopoDS_Face()):
        plan = self.pln_on_face(face)
        find_edge = LocOpe_FindEdges(self.tmp_face, face)
        find_edge.InitIterator()
        edge_n = 0
        while find_edge.More():
            edge = find_edge.EdgeTo()
            line = self.prop_edge(edge)

            e_curve, u0, u1 = BRep_Tool.Curve(edge)
            p = e_curve.Value((u0 + u1) / 2)
            i = (edge_n + self.tmp_face_n) % len(self.colors)
            self.display.DisplayShape(edge, color=self.colors[i])
            self.display.DisplayMessage(
                p, "Face{:d}-Edge{:d}".format(self.tmp_face_n, edge_n))

            plan_axs = plan.Position()
            line_axs = line.Position()
            line_axs.SetLocation(p)

            print()
            print("Face: {:d}, Edge: {:d}".format(self.tmp_face_n, edge_n))
            print(self.tmp_axis.Axis())
            print(plan.Position().Axis())
            #print(self.cal_len(edge), self.cal_are(face))

            self.face_rotate(face, line_axs)
            #self.face_tranfer(face, plan.Axis())

            plan = self.pln_on_face(face)
            print(face, self.cal_are(face), plan)
            print(plan, plan.Axis())
            find_edge.Next()

            edge_n += 1
예제 #5
0
파일: OCCD_Basic.py 프로젝트: fboussuge/UV
def ask_edge_midPnt(edge):
    """
    """
    result = BRep_Tool.Curve(
        edge
    )  ###result[0] is the handle of curve;result[1] is the umin; result[2] is umax
    tmid = (result[1] + result[2]) / 2
    p = gp_Pnt(0, 0, 0)
    result[0].GetObject().D0(tmid, p)
    return p.Coord()
예제 #6
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)
예제 #7
0
def getPntsEdgesFacesIntersect(edgesShape, facesShape):
    pnts = []
    faces = getShapeItems(facesShape, TopAbs_FACE)
    edges = getShapeItems(edgesShape, TopAbs_EDGE)
    for edge in edges:
        for face in faces:
            curve3 = BRep_Tool.Curve(edge)
            curve = Geom_TrimmedCurve(curve3[0],curve3[1],curve3[2])
            surface = BRep_Tool.Surface(face)
            pntsToAdd = getPntsCurveSurfaceIntersect(curve, surface)
            pnts += pntsToAdd
    return pnts
예제 #8
0
파일: OCCD_Basic.py 프로젝트: fboussuge/UV
def xyz_from_arclength_edge(edge, arclength, tmin):
    """
    Given arclength from the endpoint with parameter tmin, return the xyz on edge
    """
    adaptor3d_Curve = BRepAdaptor_Curve(edge)
    abscissaPoint = GCPnts_AbscissaPoint(adaptor3d_Curve, arclength, tmin)

    result = BRep_Tool.Curve(
        edge
    )  ###result[0] is the handle of curve;result[1] is the umin; result[2] is umax
    aPnt = result[0].GetObject().Value(abscissaPoint.Parameter())

    return aPnt
예제 #9
0
파일: OCCD_Basic.py 프로젝트: fboussuge/UV
def ask_edge_tangent2(edge, unNormParm):
    """
    """
    result = BRep_Tool.Curve(
        edge
    )  ###result[0] is the handle of curve;result[1] is the umin; result[2] is umax

    p = gp_Pnt(0, 0, 0)
    v1 = gp_Vec(0, 0, 0)
    result[0].GetObject().D1(
        unNormParm, p,
        v1)  ###handle.GetObject() gives Geom_Curve type, p:gp_Pnt, v1:gp_Vec
    return v1.Coord()
예제 #10
0
파일: OCCD_Basic.py 프로젝트: fboussuge/UV
def ask_edge_midpnt_tangent(edge):
    """
    Ask the midpoint of an edge and the tangent at the midpoint
    """
    result = BRep_Tool.Curve(
        edge
    )  ###result[0] is the handle of curve;result[1] is the umin; result[2] is umax
    tmid = (result[1] + result[2]) / 2
    p = gp_Pnt(0, 0, 0)
    v1 = gp_Vec(0, 0, 0)
    result[0].GetObject().D1(
        tmid, p,
        v1)  ###handle.GetObject() gives Geom_Curve type, p:gp_Pnt, v1:gp_Vec
    return [p.Coord(), v1.Coord()]
예제 #11
0
파일: OCCD_Basic.py 프로젝트: fboussuge/UV
def ask_edge_tangent(edge, parm):
    """
    parm is normalized parameter
    """
    result = BRep_Tool.Curve(
        edge
    )  ###result[0] is the handle of curve;result[1] is the umin; result[2] is umax
    t = result[1] + (result[2] - result[1]) * parm
    p = gp_Pnt(0, 0, 0)
    v1 = gp_Vec(0, 0, 0)
    result[0].GetObject().D1(
        t, p,
        v1)  ###handle.GetObject() gives Geom_Curve type, p:gp_Pnt, v1:gp_Vec
    return v1.Coord()
예제 #12
0
파일: OCCD_Basic.py 프로젝트: fboussuge/UV
def xyz_from_t_edge(edge, parameter):
    """
    Given an edge and a normalized parameter[0,1], this calculates the point on the edge
    1. First extract the curve from edge and non-normalized parameter range tmin, tmax
    2. Tranlate the input parameter to non-normalized parameter
    3. Calculate the point (return a gpPnt)

    """

    result = BRep_Tool.Curve(
        edge
    )  ###result[0] is the handle of curve;result[1] is the umin; result[2] is umax
    #    print(parameter)
    #    print(result[2])
    #    print(result[1])
    np = result[1] + (result[2] - result[1]) * parameter
    aPnt = result[0].GetObject().Value(
        np)  ###handle_Geom_Curve.GetObject() will give the Geom_Curve
    return aPnt
예제 #13
0
def makeEdgesFacesIntersectPoints(edgesShape, facesShape):
    def findIntersectPoints(curve, surface):
        ps = []
        tool = GeomAPI_IntCS(curve, surface)
        pCount = tool.NbPoints()
        for i in range(1, pCount + 1):
            ps += [tool.Point(i)]
        return ps

    intersectPoints = []
    aEdges = getShapeItems(edgesShape, TopAbs_EDGE)
    aFaces = getShapeItems(facesShape, TopAbs_FACE)
    for aEdge in aEdges:
        for aFace in aFaces:
            # noinspection PyTypeChecker
            edgeCurves = BRep_Tool.Curve(aEdge)
            edgeTrimmedCurve = Geom_TrimmedCurve(edgeCurves[0], edgeCurves[1], edgeCurves[2])
            # noinspection PyTypeChecker
            faceSurface = BRep_Tool.Surface(aFace)
            foundIntersectPoints = findIntersectPoints(edgeTrimmedCurve, faceSurface)
            intersectPoints += foundIntersectPoints
    return intersectPoints
예제 #14
0
 def export_rim_2d(self, rimfile="pln1.rim", name="pln1-rim"):
     rim_2d = dispocc.proj_rim_pln(self, self.rim, self.pln, self.axs)
     fp = open(rimfile, "w")
     fp.write(' {:s}\n'.format(name))
     fp.write('{:12d}{:12d}{:12d}\n'.format(1, 1, 1))
     rim_tmp = gp_Pnt()
     for i, e in enumerate(Topo(rim_2d).edges()):
         e_curve, u0, u1 = BRep_Tool.Curve(e)
         print(i, e, u0, u1)
         if i != 0 and rim_tmp == e_curve.Value(u0):
             u_range = np.linspace(u0, u1, 50)
             rim_tmp = e_curve.Value(u1)
             p = e_curve.Value(u0)
             p.Transform(set_trf(self.axs, gp_Ax3()))
             data = [p.X(), p.Y()]
             print(0, p, u_range[0], u_range[-1])
         elif i != 0 and rim_tmp == e_curve.Value(u1):
             u_range = np.linspace(u1, u0, 50)
             rim_tmp = e_curve.Value(u0)
             p = e_curve.Value(u1)
             p.Transform(set_trf(self.axs, gp_Ax3()))
             data = [p.X(), p.Y()]
             print(1, p, u_range[0], u_range[-1])
         else:
             u_range = np.linspace(u0, u1, 50)
             rim_tmp = e_curve.Value(u1)
             p = e_curve.Value(u0)
             p.Transform(set_trf(self.axs, gp_Ax3()))
             data = [p.X(), p.Y()]
             print(2, p, u_range[0], u_range[-1])
         fp.write(''.join([float_to_string(val) for val in data]) + '\n')
         for u in u_range[1:]:
             p = e_curve.Value(u)
             p.Transform(set_trf(self.axs, gp_Ax3()))
             data = [p.X(), p.Y()]
             fp.write(''.join([float_to_string(val)
                               for val in data]) + '\n')
     fp.close()
 def get_curve(self):
     return BRep_Tool.Curve(self)
예제 #16
0
 def Curve(self):
     aCurve = BRep_Tool.Curve(self.Edge())
     return aCurve[0]
예제 #17
0
 def check_ground(self):
     if len(self.pts) > 2:
         ray = make_edge(self.pts[-2], self.pts[-1])
         h_line = BRep_Tool.Curve(ray)
         h_surf = BRep_Tool.Surface(self.grd)
         print(GeomAPI_IntCS(h_line, h_surf))
예제 #18
0
파일: OCCD_Basic.py 프로젝트: fboussuge/UV
def edge_extreme(edge):
    """
    Get the parameter range of a curve underlying an edge
    """
    (curve, tmin, tmax) = BRep_Tool.Curve(edge)
    return (curve, tmin, tmax)