def poles_from_bsplinecurve_edge(occedge):
    """
    This function fetches the poles of a bspline OCCedge.
 
    Parameters
    ----------
    occedge : OCCedge
        The OCCedge to be examined. The OCCedge needs to contain a bspline curve
        
    Returns
    -------
    List of poles : pyptlist
        List of poles of the bspline curve
    """
    adaptor = BRepAdaptor_Curve(occedge)
    adaptor_handle = BRepAdaptor_HCurve(adaptor)
    bspline = adaptor.BSpline()
    #handle_bspline = Handle_Geom_BSplineCurve_Create()
    #bspline = Geom_BSplineCurve(adaptor.Curve())
    #print(bspline)
    #bspline = handle_bspline.DownCast(adaptor.Curve().Curve()).GetObject()
    npoles = bspline.NbPoles()
    polelist = []
    for np in range(npoles):
        pole = bspline.Pole(np + 1)
        pypole = (pole.X(), pole.Y(), pole.Z())
        polelist.append(pypole)

    if topods_Edge(occedge).Orientation() == TopAbs_REVERSED:
        polelist.reverse()

    return polelist
Esempio n. 2
0
 def curve(self):
     """
     :return: The curve formed by concatenating all the underlying curves
         of the edges.
     :rtype: afem.geometry.entities.NurbsCurve
     """
     geom_convert = GeomConvert_CompCurveToBSplineCurve()
     exp = BRepTools_WireExplorer(self.object)
     tol = self.tol_max
     while exp.More():
         e = TopoDS.Edge_(exp.Current())
         exp.Next()
         adp_crv = BRepAdaptor_Curve(e)
         geom_convert.Add(adp_crv.BSpline(), tol)
     geom_curve = geom_convert.BSplineCurve()
     return Curve.wrap(geom_curve)
Esempio n. 3
0
 def FindGeometry(self, object: AIS_InteractiveObject):
     if object.Type() == AIS_KOI_Shape:
         shape = self.myContext.SelectedShape()
         if shape.ShapeType() == TopAbs_VERTEX:
             pass
         elif shape.ShapeType() == TopAbs_EDGE:
             curve = BRepAdaptor_Curve(shape)
             curve_type = curve.GetType()
             if curve_type == GeomAbs_BezierCurve:
                 return curve.Bezier()
             elif curve_type == GeomAbs_BSplineCurve:
                 return curve.BSpline()
             elif curve_type == GeomAbs_Circle:
                 return Geom_Circle(curve.Circle())
             elif curve_type == GeomAbs_Line:
                 return Geom_Line(curve.Line())
         elif shape.ShapeType() == TopAbs_FACE:
             pass
Esempio n. 4
0
 def recognize_edge(self, a_edge):
     """ Takes a TopoDS shape and tries to identify its nature
     whether it is a plane a cylinder a torus etc.
     if a plane, returns the normal
     if a cylinder, returns the radius
     """
     curve = BRepAdaptor_Curve(a_edge)
     curve_type = curve.GetType()
     if curve_type == GeomAbs_BezierCurve:
         print("--> Bezier")
         self._selectedShape = curve.Bezier()
     elif curve_type == GeomAbs_BSplineCurve:
         print("--> BSpline")
         self._selectedShape = curve.BSpline()
     elif curve_type == GeomAbs_Circle:
         print("--> Circle")
         self._selectedShape = Geom_Circle(curve.Circle())
     else:
         # TODO there are plenty other type that can be checked
         # see documentation for the BRepAdaptor class
         # https://www.opencascade.com/doc/occt-6.9.1/refman/html/class_b_rep_adaptor___surface.html
         print("not implemented")
Esempio n. 5
0
def on_select(shapes):
    if len(shapes) < 1:
        return
    s = shapes[0]

    if s.ShapeType() == TopAbs_EDGE:
        if s.Orientation() == TopAbs_FORWARD:
            print('FORWARD')
        else:
            print('REVERSED')

        tmp = BRepAdaptor_Curve(s)

        # display start and endpoints of curve
        start_point = tmp.Value(tmp.FirstParameter())
        end_point = tmp.Value(tmp.LastParameter())

        if s.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")

        if tmp.GetType() == GeomAbs_Line:
            t = tmp.Line()
            gcode = f'G01 X{end_point.X():.6f} Y{end_point.Y():.6f}'
            print(
                f'line: ({start_point.X():.6f}, {start_point.Y():.6f}) → ({end_point.X():.6f}, {end_point.Y():.6f})'
            )
            # print(gcode)
            print(
                f'line parameters: {tmp.FirstParameter():.6f}, {tmp.LastParameter():.6f}'
            )

        elif tmp.GetType() == GeomAbs_Circle:
            t = tmp.Circle()
            center_point = t.Location()

            # make two line segments, both from the centerpoint, and one to each of the endpoints
            # the cross product of the lines determines the direction. positive = CCW, negative = CW
            # assume for now the arc is in the XY plane, so only check the sign of z
            # assume clockwise for now
            # center format arc
            v1 = gp_Vec(center_point, start_point)
            v2 = gp_Vec(center_point, end_point)

            # angle > 0 if acute, < 0 if obtuse
            angle = v1.AngleWithRef(v2, gp_Vec(0, 0, 1))
            # use cross product to determine direction
            v1.Cross(v2)
            v1 *= angle
            # TODO: verify
            CCW = True if v1.Z() > 0 else False

            gcode = "G0{0} X{1:.6f} Y{2:.6f} I{3:.6f} J{4:.6f}".format(
                2 if CCW else 3, end_point.X(), end_point.Y(),
                center_point.X() - start_point.X(),
                center_point.Y() - start_point.Y())
            print(
                "circle: start (%.6f, %.6f), end (%.6f, %.6f), center (%.6f, %.6f), radius %.6f"
                % (start_point.X(), start_point.Y(), end_point.X(),
                   end_point.Y(), center_point.X(), center_point.Y(),
                   t.Radius()))
            print("circle parameters: %.6f, %.6f" %
                  (tmp.FirstParameter() / math.pi,
                   tmp.LastParameter() / math.pi))

            # print(gcode)
        elif tmp.GetType() == GeomAbs_Ellipse:
            t = tmp.Ellipse()
            x = t.XAxis()
            y = t.YAxis()
            print("ellipse")
        elif tmp.GetType() == GeomAbs_Hyperbola:
            t = tmp.Hyperbola()
            print("hyperbola")
        elif tmp.GetType() == GeomAbs_Parabola:
            t = tmp.Parabola()
            print("parabola")
        elif tmp.GetType() == GeomAbs_BezierCurve:
            t = tmp.Bezier()
            print("bezier")
        elif tmp.GetType() == GeomAbs_BSplineCurve:
            t = tmp.BSpline()
            print("bspline")
        elif tmp.GetType() == GeomAbs_OffsetCurve:
            t = tmp.OffsetCurve()
            print("offset")
        elif tmp.GetType() == GeomAbs_OtherCurve:
            print("other")