Ejemplo n.º 1
0
def make_zig_curve(curve, y0, y):
    global test_count

    if rightward_for_zigs:
        curve.Reverse()

    zig = area.Curve()

    zig_started = False
    zag_found = False

    prev_p = None

    for vertex in curve.getVertices():
        if prev_p != None:
            if math.fabs(vertex.p.y - y0) < 0.002:
                if zig_started:
                    zig.append(unrotated_vertex(vertex))
                elif math.fabs(prev_p.y - y0) < 0.002 and vertex.type == 0:
                    zig.append(
                        area.Vertex(0, unrotated_point(prev_p),
                                    area.Point(0, 0)))
                    zig.append(unrotated_vertex(vertex))
                    zig_started = True
            elif zig_started:
                zig.append(unrotated_vertex(vertex))
                if math.fabs(vertex.p.y - y) < 0.002:
                    zag_found = True
                    break
        prev_p = vertex.p

    if zig_started:
        curve_list_for_zigs.append(zig)
Ejemplo n.º 2
0
def make_area_for_roughing(k):
    num_spans = kurve.num_spans(k)

    if num_spans == 0:
        raise "sketch has no spans!"

    d, startx, starty, ex, ey, cx, cy = kurve.get_span(k, 0)
    d, sx, sy, endx, endy, cx, cy = kurve.get_span(k, num_spans - 1)
    a = area.Area()
    c = area.Curve()
    largey = 7

    for span in range(0, num_spans):
        d, sx, sy, ex, ey, cx, cy = kurve.get_span(k, span)
        if span == 0:  # first span
            c.append(
                area.Vertex(0, area.Point(startx, largey), area.Point(0, 0)))

        c.append(area.Vertex(d, area.Point(ex, ey), area.Point(cx, cy)))
    # close the area

    c.append(area.Vertex(0, area.Point(endx, largey), area.Point(0, 0)))
    c.append(area.Vertex(0, area.Point(startx, largey), area.Point(0, 0)))
    a.append(c)
    return a
Ejemplo n.º 3
0
def rotated_area(a):
    an = area.Area()
    for curve in a.getCurves():
        curve_new = area.Curve()
        for v in curve.getVertices():
            curve_new.append(rotated_vertex(v))
        an.append(curve_new)
    return an
Ejemplo n.º 4
0
def make_circle(p, radius):
    circle = area.Area()
    c = area.Curve()
    c.append(p + area.Point(radius, 0))
    c.append(area.Vertex(1, p + area.Point(-radius, 0), p))
    c.append(area.Vertex(1, p + area.Point(radius, 0), p))
    circle.append(c)
    return circle
Ejemplo n.º 5
0
    def feed(self, x=None, y=None, z=None, a=None, b=None, c=None):
        px = self.x
        py = self.y
        pz = self.z
        recreator.Redirector.feed(self, x, y, z, a, b, c)
        if self.x == None or self.y == None or self.z == None:
            return
        if px == self.x and py == self.y:
            return

        # add a line to the path
        if self.path == None: self.path = area.Curve()
        self.path.append(area.Point(self.x, self.y))
Ejemplo n.º 6
0
def make_smaller( curve, start = None, finish = None, end_beyond = False ):
    if start != None:
        curve.ChangeStart(curve.NearestPoint(start))

    if finish != None:
        if end_beyond:
            curve2 = area.Curve(curve)
            curve2.ChangeEnd(curve2.NearestPoint(finish))
            first = True
            for vertex in curve2.getVertices():
                if first == False: curve.append(vertex)
                first = False
        else:
            curve.ChangeEnd(curve.NearestPoint(finish))
Ejemplo n.º 7
0
def zigzag(a, stepover, zig_unidirectional):
    if a.num_curves() == 0:
        return

    global rightward_for_zigs
    global curve_list_for_zigs
    global sin_angle_for_zigs
    global cos_angle_for_zigs
    global sin_minus_angle_for_zigs
    global cos_minus_angle_for_zigs
    global one_over_units

    one_over_units = 1 / area.get_units()

    a = rotated_area(a)

    b = area.Box()
    a.GetBox(b)

    x0 = b.MinX() - 1.0
    x1 = b.MaxX() + 1.0

    height = b.MaxY() - b.MinY()
    num_steps = int(height / stepover + 1)
    y = b.MinY() + 0.1 * one_over_units
    null_point = area.Point(0, 0)
    rightward_for_zigs = True
    curve_list_for_zigs = []

    for i in range(0, num_steps):
        y0 = y
        y = y + stepover
        p0 = area.Point(x0, y0)
        p1 = area.Point(x0, y)
        p2 = area.Point(x1, y)
        p3 = area.Point(x1, y0)
        c = area.Curve()
        c.append(area.Vertex(0, p0, null_point, 0))
        c.append(area.Vertex(0, p1, null_point, 0))
        c.append(area.Vertex(0, p2, null_point, 1))
        c.append(area.Vertex(0, p3, null_point, 0))
        c.append(area.Vertex(0, p0, null_point, 1))
        a2 = area.Area()
        a2.append(c)
        a2.Intersect(a)
        make_zig(a2, y0, y, zig_unidirectional)
        if zig_unidirectional == False:
            rightward_for_zigs = (rightward_for_zigs == False)

    reorder_zigs()
Ejemplo n.º 8
0
    def cut_path(self):
        if self.path == None: return

        print self.drag_distance
        self.path.OffsetForward(self.drag_distance, False)

        nc.creator = nc.creator.original

        if self.path.getNumVertices() > 0:
            v = self.path.FirstVertex()
            nc.creator.feed(v.p.x, v.p.y)

        cut_curve(self.path)
        nc.creator = self

        self.path = area.Curve()
Ejemplo n.º 9
0
    def arc(self,
            x=None,
            y=None,
            z=None,
            i=None,
            j=None,
            k=None,
            r=None,
            ccw=True):
        recreator.Redirector.arc(self, x, y, z, i, j, k, r, ccw)

        # add an arc to the path
        if self.path == None: self.path = area.Curve()
        self.path.append(
            area.Vertex(1 if ccw else -1, area.Point(self.x, self.y),
                        area.Point(i, j)))
Ejemplo n.º 10
0
 def arc(self, dir, x, y, z, i, j, k, r):
     self.rapid_flag = False
     if x == None: x = self.x
     if y == None: y = self.y
     if z == None: z = self.z
     area.set_units(0.05)
     curve = area.Curve()
     curve.append(area.Point(self.x, self.y))
     curve.append(area.Vertex(dir, area.Point(x, y), area.Point(i, j)))
     curve.UnFitArcs()
     for span in curve.GetSpans():
         self.add_line(Point(span.p.x, span.p.y, z),
                       Point(span.v.p.x, span.v.p.y, z))
     self.x = x
     self.y = y
     self.z = z
Ejemplo n.º 11
0
def make_obround(p0, p1, radius):
    dir = p1 - p0
    d = dir.length()
    dir.normalize()
    right = area.Point(dir.y, -dir.x)
    obround = area.Area()
    c = area.Curve()
    vt0 = p0 + right * radius
    vt1 = p1 + right * radius
    vt2 = p1 - right * radius
    vt3 = p0 - right * radius
    c.append(area.Vertex(0, vt0, area.Point(0, 0)))
    c.append(area.Vertex(0, vt1, area.Point(0, 0)))
    c.append(area.Vertex(1, vt2, p1))
    c.append(area.Vertex(0, vt3, area.Point(0, 0)))
    c.append(area.Vertex(1, vt0, p0))
    obround.append(c)
    return obround
Ejemplo n.º 12
0
def profile2(curve,
             direction="on",
             radius=1.0,
             vertfeed=0.0,
             horizfeed=0.0,
             vertrapid=0.0,
             horizrapid=0.0,
             offset_extra=0.0,
             roll_radius=2.0,
             roll_on=None,
             roll_off=None,
             depthparams=None,
             extend_at_start=0.0,
             extend_at_end=0.0,
             lead_in_line_len=0.0,
             lead_out_line_len=0.0):

    # print "direction: " + str(direction)
    # print "radius: " + str(radius)
    # print "vertfeed: " + str(vertfeed)
    # print "horizfeed: " + str(horizfeed)
    # print "offset_extra: " + str(offset_extra)
    # print "roll_radius: " + str(roll_radius)
    # print "roll_on: " + str(roll_on)
    # print "roll_off: " + str(roll_off)
    # print "depthparams: " + str(depthparams)
    # print "extend_at_start: " + str(extend_at_start)
    # print "extend_at_end: " + str(extend_at_end)
    # print "lead_in_line_len: " + str(lead_in_line_len)
    # print "lead_out_line_len: " + str(lead_out_line_len)
    # print "in profile2: 318"

    global tags
    direction = direction.lower()
    offset_curve = area.Curve(curve)
    # print "curve: " , str(curve)
    # print "result curve: ", offset_curve.__dict__

    if direction == "on":
        use_CRC() == False

    if direction != "on":
        if direction != "left" and direction != "right":
            raise ("direction must be left or right", direction)

        # get tool diameter
        offset = radius + offset_extra
        if use_CRC() is False or (use_CRC() is True
                                  and CRC_nominal_path() is True):
            if math.fabs(offset) > 0.00005:
                if direction == "right":
                    offset = -offset
                offset_success = offset_curve.Offset(offset)
                if offset_success is False:
                    global using_area_for_offset
                    if curve.IsClosed() and (using_area_for_offset is False):
                        cw = curve.IsClockwise()
                        using_area_for_offset = True
                        a = area.Area()
                        a.append(curve)
                        print("curve, offset: ", str(curve), str(offset))
                        a.Offset(-offset)
                        for curve in a.getCurves():
                            print("result curve: ", curve)
                            curve_cw = curve.IsClockwise()
                            if cw != curve_cw:
                                curve.Reverse()
                            # once we know how what a good start point is
                            # we might want to set it here
                            #set_good_start_point(curve, False)
                            profile(curve, direction, 0.0, 0.0, roll_radius,
                                    roll_on, roll_off, depthparams,
                                    extend_at_start, extend_at_end,
                                    lead_in_line_len, lead_out_line_len)
                        using_area_for_offset = False
                        return
                    else:
                        raise Exception("couldn't offset kurve " +
                                        str(offset_curve))

    # extend curve
    if extend_at_start > 0.0:
        span = offset_curve.GetFirstSpan()
        new_start = span.p + span.GetVector(0.0) * (-extend_at_start)
        new_curve = area.Curve()
        new_curve.append(new_start)
        for vertex in offset_curve.getVertices():
            new_curve.append(vertex)
        offset_curve = new_curve

    if extend_at_end > 0.0:
        span = offset_curve.GetLastSpan()
        new_end = span.v.p + span.GetVector(1.0) * extend_at_end
        offset_curve.append(new_end)

    # remove tags further than radius from the offset kurve
    new_tags = []
    for tag in tags:
        if tag.dist(offset_curve) <= radius + 0.001:
            new_tags.append(tag)
    tags = new_tags

    if offset_curve.getNumVertices() <= 1:
        raise ("sketch has no spans!")

    # do multiple depths
    depths = depthparams.get_depths()

    # current_start_depth = depthparams.start_depth

    # tags
    if len(tags) > 0:
        # make a copy to restore to after each level
        copy_of_offset_curve = area.Curve(offset_curve)

    prev_depth = depthparams.start_depth

    endpoint = None

    for depth in depths:
        mat_depth = prev_depth

        if len(tags) > 0:
            split_for_tags(offset_curve, radius, depthparams.start_depth,
                           depth, depthparams.final_depth)

        # make the roll on and roll off kurves
        roll_on_curve = area.Curve()
        add_roll_on(offset_curve, roll_on_curve, direction, roll_radius,
                    offset_extra, roll_on)
        roll_off_curve = area.Curve()
        add_roll_off(offset_curve, roll_off_curve, direction, roll_radius,
                     offset_extra, roll_off)
        if use_CRC():
            crc_start_point = area.Point()
            add_CRC_start_line(offset_curve, roll_on_curve, roll_off_curve,
                               radius, direction, crc_start_point,
                               lead_in_line_len)

        # get the tag depth at the start
        start_z = get_tag_z_for_span(0, offset_curve, radius,
                                     depthparams.start_depth, depth,
                                     depthparams.final_depth)
        if start_z > mat_depth:
            mat_depth = start_z

        # rapid across to the start
        s = roll_on_curve.FirstVertex().p

        # start point
        if (endpoint is None) or (endpoint != s):
            if use_CRC():
                rapid(crc_start_point.x,
                      crc_start_point.y) + "F " + horizrapid + "\n"
            else:
                rapid(s.x, s.y)  #+ "F " + str(horizrapid) + "\n"

            # rapid down to just above the material
            if endpoint is None:
                rapid(
                    z=mat_depth +
                    depthparams.rapid_safety_space)  #+ "F " + vertrapid + "\n"

            else:
                rapid(z=mat_depth)  #+ "F " + str(vertrapid) + "\n"

        # feed down to depth
        mat_depth = depth
        if start_z > mat_depth:
            mat_depth = start_z
        feed(s.x, s.y, z=mat_depth)

        if use_CRC():
            start_CRC(direction == "left", radius)
            # move to the startpoint
            feed(s.x, s.y)

        # cut the roll on arc
        cut_curve(roll_on_curve)

        # cut the main kurve
        current_perim = 0.0

        for span in offset_curve.GetSpans():
            # height for tags
            current_perim += span.Length()
            ez = get_tag_z_for_span(current_perim, offset_curve, radius,
                                    depthparams.start_depth, depth,
                                    depthparams.final_depth)
            if ez is None:
                ez = depth
            if span.v.type == 0:  # line
                feed(span.v.p.x, span.v.p.y, ez)
            else:
                if span.v.type == 1:  # anti-clockwise arc
                    arc_ccw(span.v.p.x,
                            span.v.p.y,
                            ez,
                            i=span.v.c.x,
                            j=span.v.c.y)
                else:
                    arc_cw(span.v.p.x,
                           span.v.p.y,
                           ez,
                           i=span.v.c.x,
                           j=span.v.c.y)

        # cut the roll off arc
        cut_curve(roll_off_curve)

        endpoint = offset_curve.LastVertex().p
        if roll_off_curve.getNumVertices() > 0:
            endpoint = roll_off_curve.LastVertex().p

        # add CRC end_line
        if use_CRC():
            crc_end_point = area.Point()
            add_CRC_end_line(offset_curve, roll_on_curve, roll_off_curve,
                             radius, direction, crc_end_point,
                             lead_out_line_len)
            if direction == "on":
                rapid(
                    z=depthparams.clearance_height)  #+ "F " + vertrapid + "\n"
            else:
                feed(crc_end_point.x, crc_end_point.y)

        # restore the unsplit kurve
        if len(tags) > 0:
            offset_curve = area.Curve(copy_of_offset_curve)
        if use_CRC():
            end_CRC()

        if endpoint != s:
            # rapid up to the clearance height
            rapid(z=depthparams.clearance_height)  # + "F " + vertrapid + "\n"

        prev_depth = depth

    rapid(z=depthparams.clearance_height)  # + "F " + vertrapid + "\n"

    del offset_curve

    if len(tags) > 0:
        del copy_of_offset_curve
Ejemplo n.º 13
0
def makeAreaCurve(edges, direction, startpt=None, endpt=None):
    curveobj = area.Curve()

    cleanededges = Part.__sortEdges__(cleanedges(edges, 0.01))

    # for e in cleanededges:
    # print str(e.valueAt(e.FirstParameter)) + "," +
    # str(e.valueAt(e.LastParameter))
    edgelist = []

    if len(cleanededges) == 1:  # user selected a single edge.
        edgelist = cleanededges
    else:
        # edgelist = [] #Multiple edges.  Need to sequence the vetexes.
        # First get the first segment oriented correctly.

        # We first compare the last parameter of the first segment to see if it
        # matches either end of the second segment. If not, it must need
        # flipping.
        p0L = cleanededges[0].valueAt(cleanededges[0].LastParameter)
        if PathGeom.pointsCoincide(
                p0L, cleanededges[1].valueAt(cleanededges[1].FirstParameter)
        ) or PathGeom.pointsCoincide(
                p0L, cleanededges[1].valueAt(cleanededges[1].LastParameter)):
            edge0 = cleanededges[0]
        else:
            edge0 = PathUtils.reverseEdge(cleanededges[0])

        edgelist.append(edge0)

        # Now iterate the rest of the edges matching the last parameter of the
        # previous segment.
        for edge in cleanededges[1:]:
            if PathGeom.pointsCoincide(
                    edge.valueAt(edge.FirstParameter),
                    edgelist[-1].valueAt(edgelist[-1].LastParameter)):
                nextedge = edge
            else:
                nextedge = PathUtils.reverseEdge(edge)
            edgelist.append(nextedge)
    # print "makeareacurve 87: " + "area.Point(" +
    # str(edgelist[0].Vertexes[0].X) + ", " +
    # str(edgelist[0].Vertexes[0].Y)+")"
    curveobj.append(
        area.Point(edgelist[0].Vertexes[0].X, edgelist[0].Vertexes[0].Y))
    #     seglist =[]
    #     if direction=='CW':
    #         edgelist.reverse()
    #         for e in edgelist:
    #             seglist.append(PathUtils.reverseEdge(e)) #swap end points on every segment
    #     else:
    #         for e in edgelist:
    #             seglist.append(e)

    for s in edgelist:
        curveobj.append(makeAreaVertex(s))

    if startpt:
        # future nearest point code yet to be worked out -fixme
        #         v1 = Vector(startpt.X,startpt.Y,startpt.Z)
        #         perppoint1 = DraftGeomUtils.findPerpendicular(v1,firstedge)
        #         perppoint1 = DraftGeomUtils.findDistance(v1,firstedge)
        #         if  perppoint1:
        #             curveobj.ChangeStart(area.Point(perppoint1[0].x,perppoint1[0].y))
        #         else:
        #             curveobj.ChangeStart(area.Point(startpt.X,startpt.Y))
        curveobj.ChangeStart(area.Point(startpt.x, startpt.y))
    if endpt:
        # future nearest point code yet to be worked out -fixme
        #         v2 = Vector(endpt.X,endpt.Y,endpt.Z)
        #         perppoint2 = DraftGeomUtils.findPerpendicular(v2,lastedge)
        #         if perppoint2:
        #             curveobj.ChangeEnd(area.Point(perppoint2[0].x,perppoint2[0].y))
        #         else:
        #             curveobj.ChangeEnd(area.Point(endpt.X,endpt.Y))
        curveobj.ChangeEnd(area.Point(endpt.x, endpt.y))

    if curveobj.IsClockwise() and direction == 'CCW':
        curveobj.Reverse()
    elif not curveobj.IsClockwise() and direction == 'CW':
        curveobj.Reverse()
    return curveobj
Ejemplo n.º 14
0
tool_change(id=4)
spindle(7000)
feedrate_hv(840, 100)
flush_nc()
clearance = float(5)
rapid_safety_space = float(2)
start_depth = float(0)
step_down = float(1)
final_depth = float(-1)
tool_diameter = float(4.7752)
cutting_edge_angle = float(0)
#absolute() mode
roll_radius = float(2)
offset_extra = 0
comment('Sketch')
curve = area.Curve()
#open path
curve.append(area.Point(66.163292, 40.55579))
curve.append(area.Point(66.163292, -37.200397))
curve.append(
    area.Vertex(-1, area.Point(56.163292, -47.200397),
                area.Point(56.163292, -37.200397)))
curve.append(area.Point(-58.730675, -47.200397))
curve.append(
    area.Vertex(-1, area.Point(-68.730675, -37.200397),
                area.Point(-58.730675, -37.200397)))
curve.append(area.Point(-68.730675, 40.55579))

roll_on = 'auto'
roll_off = 'auto'
extend_at_start = 0
Ejemplo n.º 15
0
def zigzag(a, a_firstoffset, stepover):
    if a.num_curves() == 0:
        return

    global rightward_for_zigs
    global curve_list_for_zigs
    global test_count
    global sin_angle_for_zigs
    global cos_angle_for_zigs
    global sin_minus_angle_for_zigs
    global cos_minus_angle_for_zigs

    a = rotated_area(a)

    b = area.Box()
    a.GetBox(b)

    #x0 = b.MinX() - 1.0
    #x1 = b.MaxX() + 1.0
    x1 = b.MinX() - 1.0
    x0 = b.MaxX() + 1.0

    height = b.MaxY() - b.MinY()
    num_steps = int(height / stepover + 1)
    #y = b.MinY() + 0.1
    y = b.MaxY() - 0.1
    null_point = area.Point(0, 0)
    rightward_for_zigs = True
    curve_list_for_zigs = []
    test_count = 0

    for i in range(0, num_steps):
        #collect vertices for a  box shape from X+,Y+ toward the curve
        #then move the tool Y+ and then back toward the X start position
        #   ------->
        #  |
        #   -------<
        test_count = test_count + 1
        y0 = y
        #y = y + stepover
        y = y - stepover
        p0 = area.Point(x0, y0)
        p1 = area.Point(x0, y)
        p2 = area.Point(x1, y)
        p3 = area.Point(x1, y0)
        c = area.Curve()
        c.append(area.Vertex(0, p0, null_point, 0))
        c.append(area.Vertex(0, p1, null_point, 0))
        c.append(area.Vertex(0, p2, null_point, 1))
        c.append(area.Vertex(0, p3, null_point, 0))
        c.append(area.Vertex(0, p0, null_point, 1))

        a2 = area.Area()
        a2.append(c)
        a2.Intersect(a)

        rightward_for_zigs = (rightward_for_zigs == False)

        y10 = y + stepover
        #y = y + stepover
        y2 = y + stepover * 2
        p10 = area.Point(x0, y10)
        p11 = area.Point(x0, y2)
        p12 = area.Point(x1, y2)
        p13 = area.Point(x1, y10)
        c2 = area.Curve()
        c2.append(area.Vertex(0, p10, null_point, 0))
        c2.append(area.Vertex(0, p11, null_point, 0))
        c2.append(area.Vertex(0, p12, null_point, 1))
        c2.append(area.Vertex(0, p13, null_point, 0))
        c2.append(area.Vertex(0, p10, null_point, 1))
        a3 = area.Area()
        a3.append(c2)
        a3.Intersect(a)
        make_zig(a3, y0, y)
        rightward_for_zigs = (rightward_for_zigs == False)

    reorder_zigs()
Ejemplo n.º 16
0
def profile(curve, direction = "on", radius = 1.0, offset_extra = 0.0, roll_radius = 2.0, roll_on = None, roll_off = None, rapid_safety_space = None, clearance = None, start_depth = None, step_down = None, final_depth = None, extend_at_start = 0.0, extend_at_end = 0.0, lead_in_line_len=0.0,lead_out_line_len= 0.0):
    global tags

    offset_curve = area.Curve(curve)
    if direction == "on":
        use_CRC == False 
        
        
    if direction != "on":
        if direction != "left" and direction != "right":
            raise "direction must be left or right", direction

        # get tool diameter
        offset = radius + offset_extra
        if use_CRC == False or (use_CRC==True and CRC_nominal_path==True):
            if direction == "right":
                offset = -offset
            offset_success = offset_curve.Offset(offset)
            if offset_success == False:
                raise Exception, "couldn't offset kurve " + str(offset_curve)
            
    # extend curve
    if extend_at_start > 0.0:
        span = offset_curve.GetFirstSpan()
        new_start = span.p + span.GetVector(0.0) * ( -extend_at_start)
        new_curve = area.Curve()
        new_curve.append(new_start)
        for vertex in offset_curve.getVertices():
            new_curve.append(vertex)
        offset_curve = new_curve
        
    if extend_at_end > 0.0:
        span = offset_curve.GetLastSpan()
        new_end = span.v.p + span.GetVector(1.0) * extend_at_end
        offset_curve.append(new_end)
                
    # remove tags further than radius from the offset kurve
    new_tags = []
    for tag in tags:
        if tag.dist(offset_curve) <= radius + 0.001:
            new_tags.append(tag)
    tags = new_tags

    if offset_curve.getNumVertices() <= 1:
        raise "sketch has no spans!"

    # do multiple depths
    total_to_cut = start_depth - final_depth;
    num_step_downs = int(float(total_to_cut) / math.fabs(step_down) + 0.999999)

    # tags
    if len(tags) > 0:
        # make a copy to restore to after each level
        copy_of_offset_curve = area.Curve(offset_curve)
    
    prev_depth = start_depth
    for step in range(0, num_step_downs):
        depth_of_cut = ( start_depth - final_depth ) * ( step + 1 ) / num_step_downs
        depth = start_depth - depth_of_cut
        mat_depth = prev_depth
        
        if len(tags) > 0:
            split_for_tags(offset_curve, radius, start_depth, depth, final_depth)

        # make the roll on and roll off kurves
        roll_on_curve = area.Curve()
        add_roll_on(offset_curve, roll_on_curve, direction, roll_radius, offset_extra, roll_on)
        roll_off_curve = area.Curve()
        add_roll_off(offset_curve, roll_off_curve, direction, roll_radius, offset_extra, roll_off)
        if use_CRC:
            crc_start_point = area.Point()
            add_CRC_start_line(offset_curve,roll_on_curve,roll_off_curve,radius,direction,crc_start_point,lead_in_line_len)
        
        # get the tag depth at the start
        start_z = get_tag_z_for_span(0, offset_curve, radius, start_depth, depth, final_depth)
        if start_z > mat_depth: mat_depth = start_z

        # rapid across to the start
        s = roll_on_curve.FirstVertex().p
        
        # start point 
        if use_CRC:
            rapid(crc_start_point.x,crc_start_point.y)
        else:
            rapid(s.x, s.y)
        
        # rapid down to just above the material
        rapid(z = mat_depth + rapid_safety_space)
        
        # feed down to depth
        mat_depth = depth
        if start_z > mat_depth: mat_depth = start_z
        feed(z = mat_depth)

        if use_CRC:
            start_CRC(direction == "left", radius)
            # move to the startpoint
            feed(s.x, s.y)
            
        
        # cut the roll on arc
        cut_curve(roll_on_curve)
        
        # cut the main kurve
        current_perim = 0.0
        
        for span in offset_curve.GetSpans():
            # height for tags
            current_perim += span.Length()
            ez = get_tag_z_for_span(current_perim, offset_curve, radius, start_depth, depth, final_depth)
            
            if span.v.type == 0:#line
                feed(span.v.p.x, span.v.p.y, ez)
            else:
                if span.v.type == 1:# anti-clockwise arc
                    arc_ccw(span.v.p.x, span.v.p.y, ez, i = span.v.c.x, j = span.v.c.y)
                else:
                    arc_cw(span.v.p.x, span.v.p.y, ez, i = span.v.c.x, j = span.v.c.y)
                    
    
        # cut the roll off arc
        cut_curve(roll_off_curve)

        #add CRC end_line
        if use_CRC:
            crc_end_point = area.Point()
            add_CRC_end_line(offset_curve,roll_on_curve,roll_off_curve,radius,direction,crc_end_point,lead_out_line_len)
            if direction == "on":
                rapid(z = clearance)
            else:
                feed(crc_end_point.x, crc_end_point.y)
            
              
        # restore the unsplit kurve
        if len(tags) > 0:
            offset_curve = area.Curve(copy_of_offset_curve)
        if use_CRC:
            end_CRC()            
        # rapid up to the clearance height
        rapid(z = clearance)
        


    del offset_curve
                
    if len(tags) > 0:
        del copy_of_offset_curve
Ejemplo n.º 17
0
def profile(curve, side_of_line, radius=1.0, vertfeed=0.0, horizfeed=0.0, offset_extra=0.0,
            rapid_safety_space=None, clearance=None, start_depth=None, stepdown=None,
            final_depth=None, use_CRC=False,
            roll_on=None, roll_off=None, roll_start=False, roll_end=True, roll_radius=None,
            roll_start_pt=None, roll_end_pt=None):

    output = ""
    output += "G0 Z" + str(clearance) + "\n"
    print "in profile: 151"
    offset_curve = area.Curve(curve)
    if offset_curve.getNumVertices() <= 1:
        raise Exception, "Sketch has no elements!"
    if side_of_line == "On":
        use_CRC = False

    elif (side_of_line == "Left") or (side_of_line == "Right"):
        # get tool radius plus little bit of extra offset, if needed to clean
        # up profile a little more
        offset = radius + offset_extra
        if side_of_line == 'Left':
            offset_curve.Offset(offset)

        else:
            offset_curve.Offset(-offset)

        if offset_curve is False:
            raise Exception, "couldn't offset kurve " + str(offset_curve)
    else:
        raise Exception, "Side must be 'Left','Right', or 'On'"

# =========================================================================
#     #roll_on roll_off section
#     roll_on_curve = area.Curve()
#     if offset_curve.getNumVertices() <= 1: return
#     first_span = offset_curve.GetFirstSpan()
#     if roll_on == None:
#         rollstart = first_span.p
#     elif roll_on == 'auto':
#         if roll_radius < 0.0000000001:
#             rollstart = first_span.p
#         v = first_span.GetVector(0.0)
#         if direction == 'right':
#             off_v = area.Point(v.y, -v.x)
#         else:
#             off_v = area.Point(-v.y, v.x)
#         rollstart = first_span.p + off_v * roll_radius
#     else:
#         rollstart = roll_on
#
#     rvertex = area.Vertex(first_span.p)
#
#     if first_span.p == rollstart:
#         rvertex.type = 0
#     else:
#         v = first_span.GetVector(0.0) # get start direction
#         rvertex.c, rvertex.type = area.TangentialArc(first_span.p, rollstart, -v)
#         rvertex.type = -rvertex.type # because TangentialArc was used in reverse
#     # add a start roll on point
#     roll_on_curve.append(rollstart)
#
#     # add the roll on arc
#     roll_on_curve.append(rvertex)
#     #end of roll_on roll_off section
# =========================================================================

    # do multiple depths
    layer_count = int((start_depth - final_depth) / stepdown)
    if layer_count * stepdown + 0.00001 < start_depth - final_depth:
        layer_count += 1
    # current_start_depth = start_depth
    prev_depth = start_depth
    for i in range(1, layer_count + 1):
        if i == layer_count:
            depth = final_depth
        else:
            depth = start_depth - i * stepdown
        mat_depth = prev_depth
        start_z = mat_depth
        # first move
        output += "G0 X" + str(PathUtils.fmt(offset_curve.GetFirstSpan().p.x)) +\
            " Y" + str(PathUtils.fmt(offset_curve.GetFirstSpan().p.y)) +\
            " Z" + str(PathUtils.fmt(mat_depth + rapid_safety_space)) + "\n"
        # feed down to depth
        mat_depth = depth
        if start_z > mat_depth:
            mat_depth = start_z
        # feed down in Z
        output += "G1 X" + str(PathUtils.fmt(offset_curve.GetFirstSpan().p.x)) +\
            " Y" + str(PathUtils.fmt(offset_curve.GetFirstSpan().p.y)) + " Z" + str(PathUtils.fmt(depth)) +\
            " F" + str(PathUtils.fmt(vertfeed)) + "\n"
        if use_CRC:
            if side_of_line == 'left':
                output += "G41" + "\n"
            else:
                output += "G42" + "\n"
        # cut the main kurve
        current_perim = 0.0
        lastx = offset_curve.GetFirstSpan().p.x
        lasty = offset_curve.GetFirstSpan().p.y
        for span in offset_curve.GetSpans():
            current_perim += span.Length()
            if span.v.type == 0:  # line
                # feed(span.v.p.x, span.v.p.y, ez)
                output += "G1 X" + str(PathUtils.fmt(span.v.p.x)) + " Y" + str(PathUtils.fmt(span.v.p.y)) +\
                    " Z" + str(PathUtils.fmt(depth)) + " F" + \
                    str(PathUtils.fmt(horizfeed)) + "\n"
                lastx = span.v.p.x
                lasty = span.v.p.y
            elif (span.v.type == 1) or (span.v.type == -1):
                if span.v.type == 1:  # anti-clockwise arc
                    command = 'G3'
                elif span.v.type == -1:  # clockwise arc
                    command = 'G2'
                arc_I = span.v.c.x - lastx
                arc_J = span.v.c.y - lasty
                output += command + "X" + str(PathUtils.fmt(span.v.p.x)) + " Y" + str(
                    PathUtils.fmt(span.v.p.y))  # +" Z"+ str(PathUtils.fmt(depth))
                output += " I" + str(PathUtils.fmt(arc_I)) + " J" + str(PathUtils.fmt(arc_J)) + " F" + str(
                    PathUtils.fmt(horizfeed)) + '\n'  # " K"+str(PathUtils.fmt(depth)) +"\n"
                lastx = span.v.p.x
                lasty = span.v.p.y
            else:
                raise Exception, "valid geometry identifier needed"
        if use_CRC:
            # end_CRC()
            output += "G40" + "\n"
        # rapid up to the clearance height
        output += "G0 Z" + str(PathUtils.fmt(clearance)) + "\n"

    del offset_curve

    return output
Ejemplo n.º 18
0
    def load(self, nc_filepath):
        # this converts the G1s in an NC file into arcs with G2 or G3
        pattern_main = re.compile(
            '([(!;].*|\s+|[a-zA-Z0-9_:](?:[+-])?\d*(?:\.\d*)?|\w\#\d+|\(.*?\)|\#\d+\=(?:[+-])?\d*(?:\.\d*)?)'
        )

        self.lines = []
        self.length = 0.0
        file = open(nc_filepath, 'r')
        arc = 0
        self.rapid = False
        curx = None
        cury = None
        curz = None

        while (True):
            line = file.readline().rstrip()
            if len(line) == 0: break

            move = False

            x = None
            y = None
            z = None
            i = None
            j = None

            words = pattern_main.findall(line)
            for word in words:
                word = word.upper()
                if word == 'G1' or word == 'G01':
                    self.rapid = False
                    arc = 0
                elif word == 'G2' or word == 'G02':
                    self.rapid = False
                    arc = -1
                elif word == 'G3' or word == 'G03':
                    self.rapid = False
                    arc = 1
                elif word == 'G0' or word == 'G00':
                    self.rapid = True
                    arc = 0
                elif word[0] == 'X':
                    x = eval(word[1:])
                    move = True
                elif word[0] == 'Y':
                    y = eval(word[1:])
                    move = True
                elif word[0] == 'Z':
                    z = eval(word[1:])
                    move = True
                elif word[0] == 'I':
                    i = float(eval(word[1:]))
                elif word[0] == 'J':
                    j = float(eval(word[1:]))
                elif word[0] == 'T':
                    self.current_tool = eval(word[1:])
                    if (curx != None) and (cury != None) and (curz != None):
                        self.add_line(Point(curx, cury, curz),
                                      Point(curx, cury, 30.0))
                        curz = 30.0
                elif word[0] == ';':
                    break

            if move:
                if (curx != None) and (cury != None) and (curz != None):
                    newx = curx
                    newy = cury
                    newz = curz
                    if x != None: newx = float(x)
                    if y != None: newy = float(y)
                    if z != None: newz = float(z)
                    if arc != 0:
                        area.set_units(0.05)
                        curve = area.Curve()
                        curve.append(area.Point(curx, cury))
                        # next 4 lines were for Bridgeport.
                        # this only works for LinuxCNC now
                        #if (newx > curx) != (arc > 0):
                        #    j = -j
                        #if (newy > cury) != (arc < 0):
                        #    i = -i
                        curve.append(
                            area.Vertex(arc, area.Point(newx, newy),
                                        area.Point(curx + i, cury + j)))
                        curve.UnFitArcs()
                        for span in curve.GetSpans():
                            self.add_line(Point(span.p.x, span.p.y, newz),
                                          Point(span.v.p.x, span.v.p.y, newz))
                    else:
                        self.add_line(Point(curx, cury, curz),
                                      Point(newx, newy, newz))

                if x != None: curx = float(x)
                if y != None: cury = float(y)
                if z != None: curz = float(z)

        for line in self.lines:
            self.length += line.Length()

        file.close()

        self.rewind()
Ejemplo n.º 19
0
def make_zig_curve(curve, y0, y, zig_unidirectional):
    if rightward_for_zigs:
        curve.Reverse()

    # find a high point to start looking from
    high_point = None
    for vertex in curve.getVertices():
        if high_point == None:
            high_point = vertex.p
        elif vertex.p.y > high_point.y:
            # use this as the new high point
            high_point = vertex.p
        elif math.fabs(vertex.p.y - high_point.y) < 0.002 * one_over_units:
            # equal high point
            if rightward_for_zigs:
                # use the furthest left point
                if vertex.p.x < high_point.x:
                    high_point = vertex.p
            else:
                # use the furthest right point
                if vertex.p.x > high_point.x:
                    high_point = vertex.p

    zig = area.Curve()

    high_point_found = False
    zig_started = False
    zag_found = False

    for i in range(
            0, 2
    ):  # process the curve twice because we don't know where it will start
        prev_p = None
        for vertex in curve.getVertices():
            if zag_found: break
            if prev_p != None:
                if zig_started:
                    zig.append(unrotated_vertex(vertex))
                    if math.fabs(vertex.p.y - y) < 0.002 * one_over_units:
                        zag_found = True
                        break
                elif high_point_found:
                    if math.fabs(vertex.p.y - y0) < 0.002 * one_over_units:
                        if zig_started:
                            zig.append(unrotated_vertex(vertex))
                        elif math.fabs(
                                prev_p.y - y0
                        ) < 0.002 * one_over_units and vertex.type == 0:
                            zig.append(
                                area.Vertex(0, unrotated_point(prev_p),
                                            area.Point(0, 0)))
                            zig.append(unrotated_vertex(vertex))
                            zig_started = True
                elif vertex.p.x == high_point.x and vertex.p.y == high_point.y:
                    high_point_found = True
            prev_p = vertex.p

    if zig_started:

        if zig_unidirectional == True:
            # remove the last bit of zig
            if math.fabs(zig.LastVertex().p.y - y) < 0.002 * one_over_units:
                vertices = zig.getVertices()
                while len(vertices) > 0:
                    v = vertices[len(vertices) - 1]
                    if math.fabs(v.p.y - y0) < 0.002 * one_over_units:
                        break
                    else:
                        vertices.pop()
                zig = area.Curve()
                for v in vertices:
                    zig.append(v)

        curve_list_for_zigs.append(zig)
Ejemplo n.º 20
0
def makeAreaCurve(edges, direction, startpt=None, endpt=None):
    curveobj = area.Curve()

    cleanededges = PathUtils.cleanedges(edges, 0.01)

    #sort the edges
    vlist, edgestart, common = PathSelection.Sort2Edges(
        [cleanededges[0], cleanededges[1]])

    if cleanededges[0].valueAt(cleanededges[0].FirstParameter) <> edgestart:
        firstedge = PathUtils.reverseEdge(cleanededges[0])
    else:
        firstedge = cleanededges[0]

    edgelist = []
    edgelist.append(firstedge)

    #get start and end points of each edge aligned
    for e in cleanededges[1:]:
        if DraftVecUtils.equals(common, e.valueAt(e.FirstParameter)):
            edgelist.append(e)
            common = e.valueAt(e.LastParameter)
        else:
            newedge = PathUtils.reverseEdge(e)
            common = newedge.valueAt(newedge.LastParameter)
            edgelist.append(newedge)

    curveobj.append(area.Point(edgestart.x, edgestart.y))

    #     seglist =[]
    #     if direction=='CW':
    #         edgelist.reverse()
    #         for e in edgelist:
    #             seglist.append(PathUtils.reverseEdge(e)) #swap end points on every segment
    #     else:
    #         for e in edgelist:
    #             seglist.append(e)

    for s in edgelist:
        curveobj.append(makeAreaVertex(s))

    if startpt:
        # future nearest point code yet to be worked out -fixme
        #         v1 = Vector(startpt.X,startpt.Y,startpt.Z)
        #         perppoint1 = DraftGeomUtils.findPerpendicular(v1,firstedge)
        #         perppoint1 = DraftGeomUtils.findDistance(v1,firstedge)
        #         if  perppoint1:
        #             curveobj.ChangeStart(area.Point(perppoint1[0].x,perppoint1[0].y))
        #         else:
        #             curveobj.ChangeStart(area.Point(startpt.X,startpt.Y))
        curveobj.ChangeStart(area.Point(startpt.X, startpt.Y))
    if endpt:
        # future nearest point code yet to be worked out -fixme
        #         v2 = Vector(endpt.X,endpt.Y,endpt.Z)
        #         perppoint2 = DraftGeomUtils.findPerpendicular(v2,lastedge)
        #         if perppoint2:
        #             curveobj.ChangeEnd(area.Point(perppoint2[0].x,perppoint2[0].y))
        #         else:
        #             curveobj.ChangeEnd(area.Point(endpt.X,endpt.Y))
        curveobj.ChangeEnd(area.Point(endpt.X, endpt.Y))

    if direction == 'CW':
        curveobj.Reverse()

    return curveobj