Beispiel #1
0
def _dxf_circle(e: Edge, msp: ezdxf.layouts.Modelspace, plane: Plane):

    geom = e._geomAdaptor()
    circ = geom.Circle()

    r = circ.Radius()
    c = circ.Location()

    c_dy = circ.YAxis().Direction()
    c_dz = circ.Axis().Direction()

    dy = gp_Dir(0, 1, 0)

    phi = c_dy.AngleWithRef(dy, c_dz)

    if c_dz.XYZ().Z() > 0:
        a1 = RAD2DEG * (geom.FirstParameter() - phi)
        a2 = RAD2DEG * (geom.LastParameter() - phi)
    else:
        a1 = -RAD2DEG * (geom.LastParameter() + phi)
        a2 = -RAD2DEG * (geom.FirstParameter() + phi)

    if e.IsClosed():
        msp.add_circle((c.X(), c.Y(), c.Z()), r)
    else:
        msp.add_arc((c.X(), c.Y(), c.Z()), r, a1, a2)
Beispiel #2
0
def _dxf_spline(e: Edge, msp: ezdxf.layouts.Modelspace, plane: Plane):

    adaptor = e._geomAdaptor()
    curve = GeomConvert.CurveToBSplineCurve_s(adaptor.Curve().Curve())

    spline = GeomConvert.SplitBSplineCurve_s(curve, adaptor.FirstParameter(),
                                             adaptor.LastParameter(),
                                             CURVE_TOLERANCE)

    # need to apply the transform on the geometry level
    spline.Transform(plane.fG.wrapped.Trsf())

    order = spline.Degree() + 1
    knots = list(spline.KnotSequence())
    poles = [(p.X(), p.Y(), p.Z()) for p in spline.Poles()]
    weights = ([spline.Weight(i)
                for i in range(1,
                               spline.NbPoles() +
                               1)] if spline.IsRational() else None)

    if spline.IsPeriodic():
        pad = spline.NbKnots() - spline.LastUKnotIndex()
        poles += poles[:pad]

    dxf_spline = ezdxf.math.BSpline(poles, order, knots, weights)

    msp.add_spline().apply_construction_tool(dxf_spline)
Beispiel #3
0
def _dxf_ellipse(e: Edge, msp: ezdxf.layouts.Modelspace, plane: Plane):

    geom = e._geomAdaptor()
    ellipse = geom.Ellipse()

    r1 = ellipse.MinorRadius()
    r2 = ellipse.MajorRadius()

    c = ellipse.Location()
    xdir = ellipse.XAxis().Direction()
    xax = r2 * xdir.XYZ()

    msp.add_ellipse(
        (c.X(), c.Y(), c.Z()),
        (xax.X(), xax.Y(), xax.Z()),
        r1 / r2,
        geom.FirstParameter(),
        geom.LastParameter(),
    )
Beispiel #4
0
def _dxf_spline(e: Edge, msp: ezdxf.layouts.Modelspace, plane: Plane):

    adaptor = e._geomAdaptor()
    curve = GeomConvert.CurveToBSplineCurve_s(adaptor.Curve().Curve())

    spline = GeomConvert.SplitBSplineCurve_s(curve, adaptor.FirstParameter(),
                                             adaptor.LastParameter(),
                                             CURVE_TOLERANCE)

    order = spline.Degree() + 1
    knots = list(spline.KnotSequence())
    poles = [(p.X(), p.Y(), p.Z()) for p in spline.Poles()]

    weights = list(spline.Weights()) if spline.IsRational() else None

    if spline.IsClosed():
        dxf_spline = ezdxf.math.BSplineClosed(poles, order, knots, weights)
    else:
        dxf_spline = ezdxf.math.BSpline(poles, order, knots, weights)

    msp.add_spline().apply_construction_tool(dxf_spline)