From 1672d8edecdb575fc364c8c27824bbc47399a8c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=B6m=C3=B6t=C3=B6r=20Guly=C3=A1s?= Date: Sun, 25 Sep 2016 14:35:28 +0200 Subject: [PATCH] adds always-on ramping into area cut --- area_funcs.py | 99 +++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 84 insertions(+), 15 deletions(-) diff --git a/area_funcs.py b/area_funcs.py index a4d0cd11..3206b179 100644 --- a/area_funcs.py +++ b/area_funcs.py @@ -7,29 +7,98 @@ area_for_feed_possible = None tool_radius_for_pocket = None -def cut_curve(curve, need_rapid, p, rapid_safety_space, current_start_depth, final_depth): - prev_p = p - first = True - - for vertex in curve.getVertices(): - if need_rapid and first: - # rapid across +def rapid_to_start(need_rapid, vertex, rapid_safety_space, current_start_depth): + # rapid to start XY, then down + if need_rapid: rapid(vertex.p.x, vertex.p.y) - ##rapid down rapid(z = current_start_depth + rapid_safety_space) - #feed down - feed(z = final_depth) - first = False - else: + + +def ramp_in(curve, need_rapid, p, rapid_safety_space, current_start_depth, final_depth): + prev_p = p + # lets see if we can make it cut on a ramp + # add enough vertices for a ramp of 45 degrees, so length of: + rampStartDepth = current_start_depth + rapid_safety_space; + rampEndDepth = final_depth + rampDepth = rampEndDepth - rampStartDepth + rampLength = math.fabs(rampDepth) + + origVertices = curve.getVertices() + origSpans = curve.GetSpans() + revVertices = list(reversed(origVertices)) + if len(origSpans) > 1: + reverseRampVertices = [revVertices[0]] + # the spans tell us about the lengths + countedLength = 0.0 + countedVertices = 1 + while countedLength < rampLength: + for (span, vertex) in zip(reversed(origSpans), revVertices[1:]): + vlen = span.Length() + countedLength = countedLength + vlen + countedVertices = countedVertices+1 + if vlen > 0.0: + reverseRampVertices.append(vertex) + if countedLength > rampLength: + break + + rampVertices = list(reversed(reverseRampVertices)) + rampCurve = area.Curve() + for vertex in rampVertices: + rampCurve.append(vertex) + + rampSpans = rampCurve.GetSpans() + + # compute z offsets + + if countedLength == 0.0: + raise NameError('bugger, zero length of ramp should be %f, but %d spans and %d original spans and %d vertices, %d rampVertices' % (rampLength, len(rampSpans), len(origSpans), len(origVertices), len(reverseRampVertices))) + + zProgress = [0.0] + zFactor = 1.0/countedLength + lastZProgress = 0.0 + for (span, vertex) in zip(rampSpans, rampVertices[1:]): + vlen = span.Length() + zp = lastZProgress+vlen*zFactor + lastZProgress = zp + zProgress.append(zp) + + + + rapid_to_start(need_rapid, rampVertices[0], rapid_safety_space, current_start_depth) + + # do the ramp + for (vertex, zProgress) in zip(rampVertices, zProgress): + z = rampStartDepth + zProgress*rampDepth if vertex.type == 1: - arc_ccw(vertex.p.x, vertex.p.y, i = vertex.c.x, j = vertex.c.y) + arc_ccw(vertex.p.x, vertex.p.y, z, i = vertex.c.x, j = vertex.c.y) elif vertex.type == -1: - arc_cw(vertex.p.x, vertex.p.y, i = vertex.c.x, j = vertex.c.y) + arc_cw(vertex.p.x, vertex.p.y, z, i = vertex.c.x, j = vertex.c.y) else: - feed(vertex.p.x, vertex.p.y) + feed(vertex.p.x, vertex.p.y, z) + prev_p = vertex.p + else: + rapid_to_start(need_rapid, origVertices[0], rapid_safety_space, current_start_depth) + feed(z = final_depth) + prev_p = origVertices[0].p + return prev_p + +def cut_curve(curve, need_rapid, p, rapid_safety_space, current_start_depth, final_depth): + prev_p = p + first = True + + prev_p = ramp_in(curve, need_rapid, p, rapid_safety_space, current_start_depth, final_depth) + + for vertex in curve.getVertices(): + if vertex.type == 1: + arc_ccw(vertex.p.x, vertex.p.y, i = vertex.c.x, j = vertex.c.y) + elif vertex.type == -1: + arc_cw(vertex.p.x, vertex.p.y, i = vertex.c.x, j = vertex.c.y) + else: + feed(vertex.p.x, vertex.p.y) prev_p = vertex.p return prev_p + def area_distance(a, old_area): best_dist = None