Commit 4b8afbdc authored by lode_leroy's avatar lode_leroy

add ContourCutter

git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@21 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent 09281b60
...@@ -11,6 +11,11 @@ class PolygonExtractor: ...@@ -11,6 +11,11 @@ class PolygonExtractor:
MONOTONE=2 MONOTONE=2
def __init__(self, policy=MONOTONE): def __init__(self, policy=MONOTONE):
self.policy = policy self.policy = policy
self.hor_path_list = None
self.ver_path_list = None
self.merge_path_list = None
self.dx = 1
self.dy = 1
def append(self, p): def append(self, p):
if (self.current_dir==0): if (self.current_dir==0):
...@@ -302,10 +307,11 @@ class PolygonExtractor: ...@@ -302,10 +307,11 @@ class PolygonExtractor:
self.prev_line = self.curr_line self.prev_line = self.curr_line
def merge_path_lists(self): def merge_path_lists(self):
self.merge_path_list = [] if self.hor_path_list:
pass self.merge_path_list = self.hor_path_list
dx = 1 else:
dy = 1 self.merge_path_list = self.ver_path_list
return
# find matching path to merge with */ # find matching path to merge with */
for s0 in self.hor_path_list: for s0 in self.hor_path_list:
......
...@@ -239,6 +239,8 @@ class SimpleGui(Frame): ...@@ -239,6 +239,8 @@ class SimpleGui(Frame):
self.option = ZigZagCutter() self.option = ZigZagCutter()
elif self.PathProcessorName.get() == "PolygonCutter": elif self.PathProcessorName.get() == "PolygonCutter":
self.option = PolygonCutter() self.option = PolygonCutter()
elif self.PathProcessorName.get() == "ContourCutter":
self.option = ContourCutter()
else: else:
self.option = None self.option = None
self.pathgenerator = PushCutter(self.cutter, self.model, self.option); self.pathgenerator = PushCutter(self.cutter, self.model, self.option);
......
...@@ -56,7 +56,7 @@ class DropCutter: ...@@ -56,7 +56,7 @@ class DropCutter:
(X,Z) = intersect_lines(xl, zl, nxl, nzl, xm, zm, nxm, nzm) (X,Z) = intersect_lines(xl, zl, nxl, nzl, xm, zm, nxm, nzm)
if X and xl < X and X < xm and (Z > zl or Z > zm): if X and xl < X and X < xm and (Z > zl or Z > zm):
Y = cl_last.y Y = cl_last.y
if Z<z0 or Z>z1: if Z<z0-10 or Z>z1+10:
print "^", "xl=",xl,", zl=",zl,"nxl=",nxl,", nzl=",nzl,", X=", X, ", Z=",Z,", xm=",xm,",zm=",zm, ", nxm=",nxm,",nzm=",nzm print "^", "xl=",xl,", zl=",zl,"nxl=",nxl,", nzl=",nzl,", X=", X, ", Z=",Z,", xm=",xm,",zm=",zm, ", nxm=",nxm,",nzm=",nzm
else: else:
pa.append(Point(X,Y,Z)) pa.append(Point(X,Y,Z))
...@@ -111,7 +111,7 @@ class DropCutter: ...@@ -111,7 +111,7 @@ class DropCutter:
(Y,Z) = intersect_lines(yl, zl, nyl, nzl, ym, zm, nym, nzm) (Y,Z) = intersect_lines(yl, zl, nyl, nzl, ym, zm, nym, nzm)
if Y and yl < Y and Y < ym and (Z > zl or Z > zm): if Y and yl < Y and Y < ym and (Z > zl or Z > zm):
X = cl_last.x X = cl_last.x
if Z<z0 or Z>z1: if Z<z0-10 or Z>z1+10:
print "^", "yl=",yl,", zl=",zl,"nyl=",nyl,", nzl=",nzl,", Y=", Y, ", Z=",Z,", ym=",ym,",zm=",zm, ", nym=",nym,",nzm=",nzm print "^", "yl=",yl,", zl=",zl,"nyl=",nyl,", nzl=",nzl,", Y=", Y, ", Z=",Z,", ym=",ym,",zm=",zm, ", nym=",nym,",nzm=",nzm
else: else:
pa.append(Point(X,Y,Z)) pa.append(Point(X,Y,Z))
......
...@@ -19,21 +19,48 @@ class PushCutter: ...@@ -19,21 +19,48 @@ class PushCutter:
self.pa = pathextractor self.pa = pathextractor
def GenerateToolPath(self, minx, maxx, miny, maxy, minz, maxz, dx, dy, dz): def GenerateToolPath(self, minx, maxx, miny, maxy, minz, maxz, dx, dy, dz):
if dx==0: if dx != 0:
forward = Point(1,0,0) self.pa.dx = dx
backward = Point(-1,0,0) else:
elif dy == 0: self.pa.dx = dy
forward = Point(0,1,0)
backward = Point(0,-1,0) if dy != 0:
self.pa.dy = dy
else:
self.pa.dy = dx
z = maxz z = maxz
c = self.cutter
model = self.model
paths = [] paths = []
while z >= minz: while z >= minz:
if dy > 0:
self.pa.new_direction(0) self.pa.new_direction(0)
self.GenerateToolPathSlice(minx, maxx, miny, maxy, z, 0, dy)
self.pa.end_direction()
if dx > 0:
self.pa.new_direction(1)
self.GenerateToolPathSlice(minx, maxx, miny, maxy, z, dx, 0)
self.pa.end_direction()
self.pa.finish()
if self.pa.paths:
paths += self.pa.paths
z -= dz
return paths
def GenerateToolPathSlice(self, minx, maxx, miny, maxy, z, dx, dy):
c = self.cutter
model = self.model
if dx==0:
forward = Point(1,0,0)
backward = Point(-1,0,0)
elif dy == 0:
forward = Point(0,1,0)
backward = Point(0,-1,0)
x = minx x = minx
y = miny y = miny
while x<=maxx and y<=maxy: while x<=maxx and y<=maxy:
...@@ -116,10 +143,3 @@ class PushCutter: ...@@ -116,10 +143,3 @@ class PushCutter:
self.pa.end_scanline() self.pa.end_scanline()
self.pa.end_direction()
self.pa.finish()
paths += self.pa.paths
z -= dz
return paths
from pycam.Geometry import *
from pycam.Geometry.PolygonExtractor import *
class ContourCutter:
def __init__(self):
self.paths = []
self.curr_path = None
self.scanline = None
self.pe = PolygonExtractor(PolygonExtractor.CONTOUR)
self.points = []
def append(self, p):
self.points.append(p)
def new_direction(self, dir):
self.pe.new_direction(dir)
def end_direction(self):
self.pe.end_direction()
def new_scanline(self):
self.pe.new_scanline()
self.points = []
def end_scanline(self):
for i in range(1, len(self.points)-1):
self.pe.append(self.points[i])
self.pe.end_scanline()
def finish(self):
self.pe.finish()
if True:
if self.pe.hor_path_list:
self.paths = self.pe.hor_path_list
else:
self.paths = self.pe.ver_path_list
for p in self.paths:
p.append(p.points[0])
else:
if self.pe.merge_path_list:
self.paths = self.pe.merge_path_list
...@@ -26,6 +26,7 @@ class PolygonCutter: ...@@ -26,6 +26,7 @@ class PolygonCutter:
def finish(self): def finish(self):
self.pe.finish() self.pe.finish()
paths = [] paths = []
if self.pe.hor_path_list:
for path in self.pe.hor_path_list: for path in self.pe.hor_path_list:
points = path.points points = path.points
for i in range(0, (len(points)+1)/2): for i in range(0, (len(points)+1)/2):
...@@ -37,5 +38,17 @@ class PolygonCutter: ...@@ -37,5 +38,17 @@ class PolygonCutter:
p.append(points[-i-1]) p.append(points[-i-1])
p.append(points[i]) p.append(points[i])
paths.append(p) paths.append(p)
if self.pe.ver_path_list:
for path in self.pe.ver_path_list:
points = path.points
for i in range(0, (len(points)+1)/2):
p = Path()
if i % 2 == 0:
p.append(points[i])
p.append(points[-i-1])
else:
p.append(points[-i-1])
p.append(points[i])
paths.append(p)
self.paths = paths self.paths = paths
list = ["PathAccumulator", "SimpleCutter", "ZigZagCutter", "PolygonCutter"] list = ["PathAccumulator", "SimpleCutter", "ZigZagCutter", "PolygonCutter", "ContourCutter"]
__all__ = list __all__ = list
...@@ -6,3 +6,5 @@ from PathAccumulator import PathAccumulator ...@@ -6,3 +6,5 @@ from PathAccumulator import PathAccumulator
from SimpleCutter import SimpleCutter from SimpleCutter import SimpleCutter
from ZigZagCutter import ZigZagCutter from ZigZagCutter import ZigZagCutter
from PolygonCutter import PolygonCutter from PolygonCutter import PolygonCutter
from ContourCutter import ContourCutter
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment