def GetHelixRampCircleCentreGivenAngle(p, h_angle, circle_radius): if helix_diameter_factor < 0.1: raise Exception('Invalid helix_diameter_factor: ' + str(helix_diameter_factor) + ', must be at least 0.1') if helix_diameter_factor > 1.0: raise Exception('Invalid helix_diameter_factor: ' + str(helix_diameter_factor) + ', must be no more than 1.0') centre = p + area.Point( math.cos(math.radians(helix_diameter_factor)), math.sin(math.radians(helix_diameter_factor))) * circle_radius circle = make_circle(centre, circle_radius + tool_radius_for_pocket) a = area.Area(area_for_feed_possible) circle.Subtract(a) if circle.num_curves() > 0: return None return centre
def cut_curvelist1(curve_list, rapid_safety_space, current_start_depth, depth, clearance_height, keep_tool_down_if_poss): p = area.Point(0, 0) first = True for curve in curve_list: need_rapid = True if first == False: s = curve.FirstVertex().p if keep_tool_down_if_poss == True: # see if we can feed across if feed_possible(p, s): need_rapid = False elif s.x == p.x and s.y == p.y: need_rapid = False if need_rapid: rapid(z = clearance_height) p = cut_curve(curve, need_rapid, p, rapid_safety_space, current_start_depth, depth) first = False rapid(z = clearance_height)
def Parse(self, name): self.file_in = open(name, 'r') self.path_col = None self.f = None self.arc = 0 self.q = None self.r = None self.drilling = None self.drilling_uses_clearance = False self.drilling_clearance_height = None while (self.readline()): self.a = None self.b = None self.c = None self.h = None self.i = None self.j = None self.k = None self.p = None self.s = None self.x = None self.y = None self.z = None self.t = None self.m6 = False self.writer.begin_ncblock() self.move = False self.height_offset = False self.drill = False self.drill_off = False self.no_move = False words = self.pattern_main.findall(self.line) for word in words: self.col = None self.cdata = False self.ParseWord(word) self.writer.add_text(word, self.col, self.cdata) if self.t != None: if (self.m6 == True) or (self.need_m6_for_t_change == False): self.writer.tool_change( self.t ) if self.height_offset and (self.z != None): self.drilling_clearance_height = self.z if self.drill: self.drilling = True if self.drill_off: self.drilling = False if self.drilling: rapid_z = self.r if self.drilling_uses_clearance and (self.drilling_clearance_height != None): rapid_z = self.drilling_clearance_height if self.z != None: self.drillz = self.z self.writer.rapid(self.x, self.y, rapid_z) self.writer.feed(self.x, self.y, self.drillz) self.writer.feed(self.x, self.y, rapid_z) else: if (self.move and not self.no_move): if (self.arc==0): if self.path_col == "feed": self.writer.feed(self.x, self.y, self.z) else: self.writer.rapid(self.x, self.y, self.z, self.a, self.b, self.c) else: i = self.i j = self.j k = self.k if self.arc_centre_absolute == True: pass else: if (self.arc_centre_positive == True) and (self.oldx != None) and (self.oldy != None): x = self.oldx if self.x != None: x = self.x if (self.x > self.oldx) != (self.arc > 0): j = -j y = self.oldy if self.y != None: y = self.y if (self.y > self.oldy) != (self.arc < 0): i = -i #fix centre point r = math.sqrt(i*i + j*j) p0 = area.Point(self.oldx, self.oldy) p1 = area.Point(x, y) v = p1 - p0 l = v.length() h = l/2 d = math.sqrt(r*r - h*h) n = area.Point(-v.y, v.x) n.normalize() if self.arc == -1: d = -d c = p0 + (v * 0.5) + (n * d) i = c.x j = c.y else: i = i + self.oldx j = j + self.oldy if self.arc == -1: self.writer.arc_cw(self.x, self.y, self.z, i, j, k) else: self.writer.arc_ccw(self.x, self.y, self.z, i, j, k) if self.x != None: self.oldx = self.x if self.y != None: self.oldy = self.y if self.z != None: self.oldz = self.z self.writer.end_ncblock()
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
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
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 extend_at_end = 0 lead_in_line_len = 0
def _buildPathLibarea(self, obj, edgelist): import PathScripts.PathKurveUtils as PathKurveUtils import math import area output = "" if obj.Comment != "": output += '(' + str(obj.Comment) + ')\n' if obj.StartPoint and obj.UseStartPoint: startpoint = obj.StartPoint else: startpoint = None if obj.EndPoint and obj.UseEndPoint: endpoint = obj.EndPoint else: endpoint = None PathKurveUtils.output('mem') PathKurveUtils.feedrate_hv(self.horizFeed, self.vertFeed) output = "" output += "G0 Z" + str( obj.ClearanceHeight.Value) + "F " + PathUtils.fmt( self.vertRapid) + "\n" curve = PathKurveUtils.makeAreaCurve(edgelist, obj.Direction, startpoint, endpoint) roll_radius = 2.0 extend_at_start = 0.0 extend_at_end = 0.0 lead_in_line_len = 0.0 lead_out_line_len = 0.0 if obj.UseComp is False: side = 'On' else: if obj.Direction == 'CW': side = 'Left' else: side = 'Right' PathKurveUtils.clear_tags() for i in range(len(obj.locs)): tag = obj.locs[i] h = obj.heights[i] l = obj.lengths[i] a = math.radians(obj.angles[i]) PathKurveUtils.add_tag(area.Point(tag.x, tag.y), l, a, h) depthparams = depth_params(obj.ClearanceHeight.Value, obj.SafeHeight.Value, obj.StartDepth.Value, obj.StepDown, 0.0, obj.FinalDepth.Value, None) PathKurveUtils.profile2(curve, side, self.radius, self.vertFeed, self.horizFeed, self.vertRapid, self.horizRapid, obj.OffsetExtra.Value, roll_radius, None, None, depthparams, extend_at_start, extend_at_end, lead_in_line_len, lead_out_line_len) output += PathKurveUtils.retrieve_gcode() return output
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)))
def unrotated_point(p): return area.Point( p.x * cos_minus_angle_for_zigs - p.y * sin_minus_angle_for_zigs, p.x * sin_minus_angle_for_zigs + p.y * cos_minus_angle_for_zigs)
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)
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()
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
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()
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
def _buildPathLibarea(self, obj, edgelist, isHole): import PathScripts.PathKurveUtils as PathKurveUtils import math import area output = "" if obj.Comment != "": output += '(' + str(obj.Comment) + ')\n' if obj.StartPoint and obj.UseStartPoint: startpoint = obj.StartPoint else: startpoint = None if obj.EndPoint and obj.UseEndPoint: endpoint = obj.EndPoint else: endpoint = None PathKurveUtils.output('mem') PathKurveUtils.feedrate_hv(self.horizFeed, self.vertFeed) # Reverse the direction for holes if isHole: direction = "CW" if obj.Direction == "CCW" else "CCW" else: direction = obj.Direction output = "" output += "G0 Z" + str( obj.ClearanceHeight.Value) + "F " + PathUtils.fmt( self.vertRapid) + "\n" curve = PathKurveUtils.makeAreaCurve(edgelist, direction, startpoint, endpoint) '''The following line uses a profile function written for use with FreeCAD. It's clean but incomplete. It doesn't handle print "x = " + str(point.x) print "y - " + str(point.y) holding tags start location CRC or probably other features in heekscnc''' # output += PathKurveUtils.profile(curve, side, radius, vf, hf, offset_extra, rapid_safety_space, clearance, start_depth, step_down, final_depth, use_CRC) '''The following calls the original procedure from h toolLoad = obj.activeTCeekscnc profile function. This, in turn, calls many other procedures to modify the profile. This procedure is hacked together from heekscnc and has not been thoroughly reviewed or understood for FreeCAD. It can probably be thoroughly optimized and improved but it'll take a smarter mind than mine to do it. -sliptonic Feb16''' roll_radius = 2.0 extend_at_start = 0.0 extend_at_end = 0.0 lead_in_line_len = 0.0 lead_out_line_len = 0.0 ''' Right here, I need to know the Holding Tags group from the tree that refers to this profile operation and build up the tags for PathKurve Utils. I need to access the location vector, length, angle in radians and height. ''' PathKurveUtils.clear_tags() for i in range(len(obj.locs)): tag = obj.locs[i] h = obj.heights[i] l = obj.lengths[i] a = math.radians(obj.angles[i]) PathKurveUtils.add_tag(area.Point(tag.x, tag.y), l, a, h) depthparams = depth_params(obj.ClearanceHeight.Value, obj.SafeHeight.Value, obj.StartDepth.Value, obj.StepDown, 0.0, obj.FinalDepth.Value, None) PathKurveUtils.profile2(curve, obj.Side, self.radius, self.vertFeed, self.horizFeed, self.vertRapid, self.horizRapid, obj.OffsetExtra.Value, roll_radius, None, None, depthparams, extend_at_start, extend_at_end, lead_in_line_len, lead_out_line_len) output += PathKurveUtils.retrieve_gcode() return output
def unrotated_vertex(v): if v.type: return area.Vertex(v.type, unrotated_point(v.p), unrotated_point(v.c)) return area.Vertex(v.type, unrotated_point(v.p), area.Point(0, 0))
import area p = area.Point(0, 0) m = area.Matrix([1, 0, 0, 12, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]) p.Transform(m) print(p.x, p.y)
from nc import * import centroid1 output(strippedpath[:-striptmp]+ 'tmp/test.tap') program_begin(123, 'Test program') absolute() metric() comment('') workplane(1) curve = area.Curve() #closed path curve.append(area.Point( 16.2551994324, 9.0)) curve.append(area.Vertex(1 , area.Point( 16.2552, 17.7616031082), area.Point(16.2552, 13.3808))) curve.append(area.Point( -24.0, 17.7616004944)) curve.append(area.Vertex(1 , area.Point( -24.0, 8.99999689178), area.Point(-24.0, 13.3808))) curve.append(area.Point(-24.0,17.7616031082))curve.append(area.Point(16.2551994324,9.0)) curve.Reverse() tool_diameter = float(6.35) tool_side ='left' flush_nc() clearance = float(50.0) rapid_safety_space = float(5.0) roll_on = 'auto' roll_off = 'auto' roll_radius = 2.0 lead_in_line_len= 2.0 lead_out_line_len= 2.0