Commit b1ff9172 authored by sumpfralle's avatar sumpfralle

fixed some code-style issues


git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@489 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent 6984090c
......@@ -23,7 +23,8 @@ along with PyCAM. If not, see <http://www.gnu.org/licenses/>.
from pycam.Geometry import Point
from pycam.Geometry.utils import INFINITE
from pycam.PathGenerators import get_max_height_triangles, get_max_height_ode, ProgressCounter
from pycam.PathGenerators import get_max_height_triangles, get_max_height_ode, \
ProgressCounter
import pycam.Utils.log
import math
......@@ -45,7 +46,8 @@ class Dimension:
if tolerance is None:
return (value >= self.min) and (value <= self.max)
else:
return (value > self.min - tolerance) and (value < self.max + tolerance)
return (value > self.min - tolerance) \
and (value < self.max + tolerance)
def shift(self, distance):
if self.downward:
......@@ -62,7 +64,8 @@ class Dimension:
class DropCutter:
def __init__(self, cutter, model, path_processor, physics=None, safety_height=INFINITE):
def __init__(self, cutter, model, path_processor, physics=None,
safety_height=INFINITE):
self.cutter = cutter
self.model = model
self.pa = path_processor
......@@ -71,11 +74,12 @@ class DropCutter:
# remember if we already reported an invalid boundary
self._boundary_warning_already_shown = False
def GenerateToolPath(self, minx, maxx, miny, maxy, minz, maxz, d0, d1, direction, draw_callback=None):
def GenerateToolPath(self, minx, maxx, miny, maxy, minz, maxz, d0, d1,
direction, draw_callback=None):
quit_requested = False
# determine step size
num_of_x_lines = 1 + int(math.ceil(abs(maxx - minx) / d0))
num_of_y_lines = 1 + int(math.ceil(abs(maxy - miny) / d0))
num_of_y_lines = 1 + int(math.ceil(abs(maxy - miny) / d1))
x_step = abs(maxx - minx) / max(1, (num_of_x_lines - 1))
y_step = abs(maxy - miny) / max(1, (num_of_y_lines - 1))
x_steps = [(minx + i * x_step) for i in range(num_of_x_lines)]
......@@ -108,8 +112,8 @@ class DropCutter:
# for now only used for triangular collision detection
last_position = None
if draw_callback and draw_callback(text="DropCutter: processing line %d/%d" \
% (current_line, num_of_lines),
if draw_callback and draw_callback(text="DropCutter: processing " \
+ "line %d/%d" % (current_line, num_of_lines),
percent=(100.0 * current_line / num_of_lines)):
# cancel requested
quit_requested = True
......@@ -131,19 +135,17 @@ class DropCutter:
p = Point(x, y, self.safety_height)
self.pa.append(p)
if not self._boundary_warning_already_shown:
log.warn("DropCutter: exceed the height " \
+ "of the boundary box: using a safe height " \
+ "instead. This warning is reported only once.")
log.warn("DropCutter: exceed the height of the " \
+ "boundary box: using a safe height instead." \
+ " This warning is reported only once.")
self._boundary_warning_already_shown = True
self.cutter.moveto(p)
# "draw_callback" returns true, if the user requested quitting via the GUI
if draw_callback and draw_callback(tool_position=p):
finished_line = True
break
# the progress counter may return True, if cancel was requested
if progress_counter.increment():
finished_line = True
# "draw_callback" returns true, if the user requested to quit
# via the GUI.
# The progress counter may return True, if cancel was requested.
if (draw_callback and draw_callback(tool_position=p)) \
or (progress_counter.increment()):
quit_requested = True
break
self.pa.end_scanline()
......
......@@ -24,7 +24,8 @@ along with PyCAM. If not, see <http://www.gnu.org/licenses/>.
import pycam.PathProcessors.PathAccumulator
from pycam.Geometry import Point
from pycam.Geometry.utils import INFINITE
from pycam.PathGenerators import get_max_height_triangles, get_max_height_ode, get_free_paths_ode, get_free_paths_triangles, ProgressCounter
from pycam.PathGenerators import get_max_height_triangles, get_max_height_ode, \
get_free_paths_ode, get_free_paths_triangles, ProgressCounter
import pycam.Utils.log
import math
......@@ -33,8 +34,8 @@ log = pycam.Utils.log.get_logger()
class EngraveCutter:
def __init__(self, cutter, model, contour_model, path_processor, physics=None,
safety_height=INFINITE):
def __init__(self, cutter, model, contour_model, path_processor,
physics=None, safety_height=INFINITE):
self.cutter = cutter
self.model = model
self.contour_model = contour_model
......@@ -53,7 +54,8 @@ class EngraveCutter:
if num_of_layers > 1:
z_step = abs(maxz - minz) / (num_of_layers - 1)
z_steps = [(maxz - i * z_step) for i in range(num_of_layers)]
# the top layer is treated as the surface - thus it does not require engraving
# The top layer is treated as the current surface - thus it does not
# require engraving.
z_steps = z_steps[1:]
else:
z_steps = [minz]
......@@ -76,7 +78,8 @@ class EngraveCutter:
for line_group in line_groups:
for line in line_group:
self.GenerateToolPathLinePush(self.pa_push, line, z)
self.GenerateToolPathLinePush(self.pa_push, line, z,
draw_callback)
if progress_counter.increment():
# cancel requested
quit_requested = True
......@@ -104,8 +107,8 @@ class EngraveCutter:
self.pa_drop.new_direction(0)
self.pa_drop.new_scanline()
for line in line_group:
self.GenerateToolPathLineDrop(self.pa_drop, line, minz, maxz, horiz_step,
draw_callback=draw_callback)
self.GenerateToolPathLineDrop(self.pa_drop, line, minz, maxz,
horiz_step, draw_callback=draw_callback)
if progress_counter.increment():
# quit requested
quit_requested = True
......@@ -135,7 +138,7 @@ class EngraveCutter:
pa.append(p)
self.cutter.moveto(p)
if draw_callback:
draw_callback(tool_position=tool_position)
draw_callback(tool_position=p)
def GenerateToolPathLineDrop(self, pa, line, minz, maxz, horiz_step,
......@@ -178,7 +181,8 @@ class EngraveCutter:
+ "instead. This warning is reported only once.")
self._boundary_warning_already_shown = True
self.cutter.moveto(p)
# "draw_callback" returns true, if the user requested quitting via the GUI
# "draw_callback" returns true, if the user requested quitting via
# the GUI.
if draw_callback and draw_callback(tool_position=p):
break
pa.end_scanline()
......
......@@ -22,8 +22,8 @@ along with PyCAM. If not, see <http://www.gnu.org/licenses/>.
"""
from pycam.Geometry import Point
from pycam.Geometry.utils import INFINITE, epsilon
from pycam.PathGenerators import drop_cutter_test, get_free_paths_ode, get_free_paths_triangles, ProgressCounter
from pycam.PathGenerators import get_free_paths_ode, get_free_paths_triangles, \
ProgressCounter
import math
......@@ -35,7 +35,8 @@ class PushCutter:
self.pa = path_processor
self.physics = physics
def GenerateToolPath(self, minx, maxx, miny, maxy, minz, maxz, dx, dy, dz, draw_callback=None):
def GenerateToolPath(self, minx, maxx, miny, maxy, minz, maxz, dx, dy, dz,
draw_callback=None):
# calculate the number of steps
num_of_layers = 1 + int(math.ceil(abs(maxz - minz) / dz))
z_step = abs(maxz - minz) / max(1, (num_of_layers - 1))
......@@ -111,15 +112,19 @@ class PushCutter:
if dx > 0:
p1, p2 = Point(x, miny, z), Point(x, maxy, z)
if self.physics:
points = get_free_paths_ode(self.physics, p1, p2, depth=depth_x)
points = get_free_paths_ode(self.physics, p1, p2,
depth=depth_x)
else:
points = get_free_paths_triangles(self.model, self.cutter, p1, p2)
points = get_free_paths_triangles(self.model, self.cutter,
p1, p2)
else:
p1, p2 = Point(minx, y, z), Point(maxx, y, z)
if self.physics:
points = get_free_paths_ode(self.physics, p1, p2, depth=depth_y)
points = get_free_paths_ode(self.physics, p1, p2,
depth=depth_y)
else:
points = get_free_paths_triangles(self.model, self.cutter, p1, p2)
points = get_free_paths_triangles(self.model, self.cutter,
p1, p2)
if points:
for p in points:
......
......@@ -47,14 +47,14 @@ class ProgressCounter:
class Hit:
def __init__(self, cl, t, d, dir):
def __init__(self, cl, t, d, direction):
self.cl = cl
self.t = t
self.d = d
self.dir = dir
self.dir = direction
self.z = -INFINITE
def cmp(a,b):
def cmp(a, b):
return cmp(a.d, b.d)
def get_free_paths_triangles(model, cutter, p1, p2):
......@@ -68,24 +68,22 @@ def get_free_paths_triangles(model, cutter, p1, p2):
z_frac = z_dist / xyz_dist
forward = Point(x_frac, y_frac, z_frac)
backward = Point(-x_frac, -y_frac, -z_frac)
forward_small = Point(epsilon * x_frac, epsilon * y_frac, epsilon * z_frac)
backward_small = Point(-epsilon * x_frac, -epsilon * y_frac, -epsilon * z_frac)
minx = min(p1.x, p2.x)
maxx = max(p1.x, p2.x)
miny = min(p1.y, p2.y)
maxy = max(p1.y, p2.y)
minz = min(p1.z, p2.z)
maxz = max(p1.z, p2.z)
# find all hits along scan line
hits = []
triangles = model.triangles(minx - cutter.radius, miny - cutter.radius, minz,
maxx + cutter.radius, maxy + cutter.radius, INFINITE)
triangles = model.triangles(minx - cutter.radius, miny - cutter.radius,
minz, maxx + cutter.radius, maxy + cutter.radius, INFINITE)
for t in triangles:
# normals point outward... and we want to approach the model from the outside!
# Normals point outward... and we want to approach the model from the
# outside.
n = t.normal().dot(forward)
cutter.moveto(p1)
(cl, d) = cutter.intersect(backward, t)
......@@ -98,7 +96,6 @@ def get_free_paths_triangles(model, cutter, p1, p2):
# sort along the scan direction
hits.sort(Hit.cmp)
c = None
count = 0
points = []
for h in hits:
......@@ -165,8 +162,9 @@ def get_free_paths_ode(physics, p1, p2, depth=8):
group1 = get_free_paths_ode(physics, p1, p_middle, depth - 1)
group2 = get_free_paths_ode(physics, p_middle, p2, depth - 1)
if group1 and group2 and (group1[-1] == group2[0]):
# the last couple of the first group ends where the first couple of the second group starts
# we will combine them into one couple
# The last pair of the first group ends where the first pair of
# the second group starts.
# We will combine them into a single pair.
points.extend(group1[:-1])
points.extend(group2[1:])
else:
......@@ -205,7 +203,8 @@ def get_max_height_ode(physics, x, y, minz, maxz, order=None):
# there is an object between z1 and z0 - we need more=None loops
trips = trip_start
else:
# no need for further collision detection - we can go down the whole range z1..z0
# No need for further collision detection - we can go down the whole
# range z1..z0.
trips = 0
safe_z = minz
while trips > 0:
......@@ -231,7 +230,8 @@ def get_max_height_ode(physics, x, y, minz, maxz, order=None):
else:
return [Point(x, y, safe_z)]
def get_max_height_triangles(model, cutter, x, y, minz, maxz, order=None, last_pos=None):
def get_max_height_triangles(model, cutter, x, y, minz, maxz, order=None,
last_pos=None):
# TODO: "order" should be replaced with a direction vector
result = []
if last_pos is None:
......@@ -252,9 +252,10 @@ def get_max_height_triangles(model, cutter, x, y, minz, maxz, order=None, last_p
box_y_max = cutter.maxy
box_z_min = minz
box_z_max = maxz
triangles = model.triangles(box_x_min, box_y_min, box_z_min, box_x_max, box_y_max, box_z_max)
triangles = model.triangles(box_x_min, box_y_min, box_z_min, box_x_max,
box_y_max, box_z_max)
for t in triangles:
if t.normal().z < 0: continue;
if t.normal().z < 0: continue
cut = cutter.drop(t)
if cut and (cut.z > height_max or height_max is None):
height_max = cut.z
......@@ -268,10 +269,14 @@ def get_max_height_triangles(model, cutter, x, y, minz, maxz, order=None, last_p
((triangle_max and not last_pos["triangle"]) \
or (last_pos["triangle"] and not triangle_max)):
if minz <= last_pos["cut"].z <= maxz:
result.append(Point(last_pos["cut"].x, last_pos["cut"].y, cut_max.z))
result.append(Point(last_pos["cut"].x, last_pos["cut"].y,
cut_max.z))
else:
result.append(Point(cut_max.x, cut_max.y, last_pos["cut"].z))
elif (triangle_max and last_pos["triangle"] and last_pos["cut"] and cut_max) and (triangle_max != last_pos["triangle"]):
elif (triangle_max and last_pos["triangle"] and last_pos["cut"] and \
cut_max) and (triangle_max != last_pos["triangle"]):
# TODO: check if this path is ever in use (e.g. "intersect_lines" is not
# defined)
nl = range(3)
nl[0] = -getattr(last_pos["triangle"].normal(), order[0])
nl[2] = last_pos["triangle"].normal().z
......@@ -285,10 +290,11 @@ def get_max_height_triangles(model, cutter, x, y, minz, maxz, order=None, last_p
mx[0] = getattr(cut_max, order[0])
mx[2] = cut_max.z
c = range(3)
(c[0], c[2]) = intersect_lines(last[0], last[2], nl[0], nl[2], mx[0], mx[2], nm[0], nm[2])
if c[0] and last[0] < c[0] and c[0] < mx[0] and (c[2] > last[2] or c[2] > mx[2]):
(c[0], c[2]) = intersect_lines(last[0], last[2], nl[0], nl[2], mx[0],
mx[2], nm[0], nm[2])
if c[0] and last[0] < c[0] < mx[0] and (c[2] > last[2] or c[2] > mx[2]):
c[1] = getattr(last_pos["cut"], order[1])
if c[2]<minz-10 or c[2]>maxz+10:
if (c[2] < minz - 10) or (c[2] > maxz + 10):
print "^", "%sl=%s" % (order[0], last[0]), \
", %sl=%s" % ("z", last[2]), \
", n%sl=%s" % (order[0], nl[0]), \
......
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