- added options for trace segmentation that can be useful for auto-levelling (code snippet from Lei Zheng from a rejected pull request on FlatCAM https://bitbucket.org/realthunder/ )

This commit is contained in:
Marius Stanciu
2019-01-27 05:03:23 +02:00
committed by Marius S
parent c4a9c8bd77
commit 4f7b2bbb34
5 changed files with 108 additions and 3 deletions

View File

@@ -4332,6 +4332,8 @@ class CNCjob(Geometry):
spindlespeed=None, dwell=True, dwelltime=1000,
toolchangez=0.787402,
endz=2.0,
segx=None,
segy=None,
steps_per_circle=None):
# Used when parsing G-code arcs
@@ -4376,6 +4378,9 @@ class CNCjob(Geometry):
self.dwell = dwell
self.dwelltime = dwelltime
self.segx = float(segx) if segx is not None else 0.0
self.segy = float(segy) if segy is not None else 0.0
self.input_geometry_bounds = None
# Attributes to be included in serialization
@@ -5456,6 +5461,61 @@ class CNCjob(Geometry):
self.solid_geometry = cascaded_union([geo['geom'] for geo in self.gcode_parsed])
return self.solid_geometry
# code snippet added by Lei Zheng in a rejected pull request on FlatCAM https://bitbucket.org/realthunder/
def segment(self, coords):
"""
break long linear lines to make it more auto level friendly
"""
if len(coords) < 2 or self.segx <= 0 and self.segy <= 0:
return list(coords)
path = [coords[0]]
# break the line in either x or y dimension only
def linebreak_single(line, dim, dmax):
if dmax <= 0:
return None
if line[1][dim] > line[0][dim]:
sign = 1.0
d = line[1][dim] - line[0][dim]
else:
sign = -1.0
d = line[0][dim] - line[1][dim]
if d > dmax:
# make sure we don't make any new lines too short
if d > dmax * 2:
dd = dmax
else:
dd = d / 2
other = dim ^ 1
return (line[0][dim] + dd * sign, line[0][other] + \
dd * (line[1][other] - line[0][other]) / d)
return None
# recursively breaks down a given line until it is within the
# required step size
def linebreak(line):
pt_new = linebreak_single(line, 0, self.segx)
if pt_new is None:
pt_new2 = linebreak_single(line, 1, self.segy)
else:
pt_new2 = linebreak_single((line[0], pt_new), 1, self.segy)
if pt_new2 is not None:
pt_new = pt_new2[::-1]
if pt_new is None:
path.append(line[1])
else:
path.append(pt_new)
linebreak((pt_new, line[1]))
for pt in coords[1:]:
linebreak((path[-1], pt))
return path
def linear2gcode(self, linear, tolerance=0, down=True, up=True,
z_cut=None, z_move=None, zdownrate=None,
feedrate=None, feedrate_z=None, feedrate_rapid=None, cont=False):
@@ -5500,7 +5560,9 @@ class CNCjob(Geometry):
gcode = ""
path = list(target_linear.coords)
# path = list(target_linear.coords)
path = self.segment(target_linear.coords)
p = self.pp_geometry
# Move fast to 1st point