Example #1
0
def printOffsets(ofs):
    nloop = 0
    for lop in ofs:
        n = 0
        N = len(lop)
        first_point=[]
        previous=[]
        for p in lop:
            # p[0] is the Point
            # p[1] is -1 for lines, and r for arcs
            if n==0: # don't draw anything on the first iteration
                previous=p[0]
                ngc_writer.pen_up()
                ngc_writer.xy_rapid_to( scale*previous.x, scale*previous.y)
                ngc_writer.pen_down()
            else:
                cw=p[3]  # cw or ccw arc
                cen=p[2] # center of arc
                r=p[1]   # radius of arc
                p=p[0]   # target position
                if r==-1: # -1 means line
                    ngc_writer.xy_line_to( scale*p.x, scale*p.y )
                else:
                    ngc_writer.xy_arc_to( scale*p.x, scale*p.y, scale*r, scale*cen.x, scale*cen.y, cw ) 
                previous=p
            n=n+1
        nloop = nloop+1
Example #2
0
def OutputGCode(lev, paths, fn):
    nw.clearance_height = config.top + config.clearance_above_top
    nw.feed_height = config.top + config.engage_above_top
    nw.feed = config.feed
    nw.plunge_feed = config.plunge_feed

    nw.writer = FileWriter(fn)

    nw.comment("============ START G-CODE ===============")
    nw.preamble()
    nw.pen_up()
    pairs = zip(lev, paths)
    for lev, path in sorted(pairs, key = lambda(p): -p[0]):
        nw.comment("level=%s" % lev)
        for curve in path:
            vertices = curve.getVertices()
            current = vertices[0].p
            nw.xy_rapid_to(current.x, current.y)
            nw.pen_down(lev)
            for v in vertices[1:]:
                if v.type == 0:
                    nw.line_to(v.p.x, v.p.y, lev)
                else:
                    r = math.hypot(v.p.x - v.c.x, v.p.y - v.c.y)
                    nw.xy_arc_to(v.p.x, v.p.y, r, v.c.x, v.c.y, v.type != 1)
            nw.pen_up()
    nw.postamble()
    nw.comment("============ END G-CODE ===============")
    
    nw.writer.Close()
def printOffsets(ofs):
    nloop = 0
    for lop in ofs:
        n = 0
        N = len(lop)
        first_point = []
        previous = []
        for p in lop:
            # p[0] is the Point
            # p[1] is -1 for lines, and r for arcs
            if n == 0:  # don't draw anything on the first iteration
                previous = p[0]
                ngc_writer.pen_up()
                ngc_writer.xy_rapid_to(scale * previous.x, scale * previous.y)
                ngc_writer.pen_down()
            else:
                cw = p[3]  # cw or ccw arc
                cen = p[2]  # center of arc
                r = p[1]  # radius of arc
                p = p[0]  # target position
                if r == -1:  # -1 means line
                    ngc_writer.xy_line_to(scale * p.x, scale * p.y)
                else:
                    ngc_writer.xy_arc_to(scale * p.x, scale * p.y, scale * r,
                                         scale * cen.x, scale * cen.y, cw)
                previous = p
            n = n + 1
        nloop = nloop + 1