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:
MONOTONE=2
def __init__(self, policy=MONOTONE):
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):
if (self.current_dir==0):
......@@ -302,10 +307,11 @@ class PolygonExtractor:
self.prev_line = self.curr_line
def merge_path_lists(self):
self.merge_path_list = []
pass
dx = 1
dy = 1
if self.hor_path_list:
self.merge_path_list = self.hor_path_list
else:
self.merge_path_list = self.ver_path_list
return
# find matching path to merge with */
for s0 in self.hor_path_list:
......
......@@ -239,6 +239,8 @@ class SimpleGui(Frame):
self.option = ZigZagCutter()
elif self.PathProcessorName.get() == "PolygonCutter":
self.option = PolygonCutter()
elif self.PathProcessorName.get() == "ContourCutter":
self.option = ContourCutter()
else:
self.option = None
self.pathgenerator = PushCutter(self.cutter, self.model, self.option);
......
......@@ -56,7 +56,7 @@ class DropCutter:
(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):
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
else:
pa.append(Point(X,Y,Z))
......@@ -111,7 +111,7 @@ class DropCutter:
(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):
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
else:
pa.append(Point(X,Y,Z))
......
......@@ -19,21 +19,48 @@ class PushCutter:
self.pa = pathextractor
def GenerateToolPath(self, minx, maxx, miny, maxy, minz, maxz, dx, dy, dz):
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)
if dx != 0:
self.pa.dx = dx
else:
self.pa.dx = dy
if dy != 0:
self.pa.dy = dy
else:
self.pa.dy = dx
z = maxz
c = self.cutter
model = self.model
paths = []
while z >= minz:
if dy > 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
y = miny
while x<=maxx and y<=maxy:
......@@ -116,10 +143,3 @@ class PushCutter:
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:
def finish(self):
self.pe.finish()
paths = []
if self.pe.hor_path_list:
for path in self.pe.hor_path_list:
points = path.points
for i in range(0, (len(points)+1)/2):
......@@ -37,5 +38,17 @@ class PolygonCutter:
p.append(points[-i-1])
p.append(points[i])
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
list = ["PathAccumulator", "SimpleCutter", "ZigZagCutter", "PolygonCutter"]
list = ["PathAccumulator", "SimpleCutter", "ZigZagCutter", "PolygonCutter", "ContourCutter"]
__all__ = list
......@@ -6,3 +6,5 @@ from PathAccumulator import PathAccumulator
from SimpleCutter import SimpleCutter
from ZigZagCutter import ZigZagCutter
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