Skip to content

Commit

Permalink
I added an engraving tool type and got attach operation to work with …
Browse files Browse the repository at this point in the history
…it. Also, I added a unidirectional option to the pocket operation, when doing zigzag mode.
  • Loading branch information
danheeks committed May 7, 2011
1 parent cf47e69 commit c3584d2
Show file tree
Hide file tree
Showing 40 changed files with 368 additions and 279 deletions.
64 changes: 41 additions & 23 deletions area_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
area_for_feed_possible = None
tool_radius_for_pocket = None

def cut_curve(curve, need_rapid, p, rapid_down_to_height, current_start_depth, final_depth):
def cut_curve(curve, need_rapid, p, rapid_safety_space, current_start_depth, final_depth):
prev_p = p
first = True

Expand All @@ -16,7 +16,7 @@ def cut_curve(curve, need_rapid, p, rapid_down_to_height, current_start_depth, f
rapid(vertex.p.x, vertex.p.y)

##rapid down
rapid(z = current_start_depth + rapid_down_to_height)
rapid(z = current_start_depth + rapid_safety_space)

#feed down
feed(z = final_depth)
Expand Down Expand Up @@ -60,6 +60,7 @@ def make_obround(p0, p1, radius):
right = area.Point(dir.y, -dir.x)
obround = area.Area()
c = area.Curve()
print "right = ", right, " radius = ", radius
vt0 = p0 + right * radius
vt1 = p1 + right * radius
vt2 = p1 - right * radius
Expand All @@ -82,7 +83,7 @@ def feed_possible(p0, p1):
return False
return True

def cut_curvelist(curve_list, rapid_down_to_height, current_start_depth, depth, clearance_height, keep_tool_down_if_poss):
def cut_curvelist(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:
Expand All @@ -97,7 +98,7 @@ def cut_curvelist(curve_list, rapid_down_to_height, current_start_depth, depth,
need_rapid = False
if need_rapid:
rapid(z = clearance_height)
p = cut_curve(curve, need_rapid, p, rapid_down_to_height, current_start_depth, depth)
p = cut_curve(curve, need_rapid, p, rapid_safety_space, current_start_depth, depth)
first = False

rapid(z = clearance_height)
Expand Down Expand Up @@ -156,7 +157,7 @@ def get_curve_list(arealist):
cos_minus_angle_for_zigs = 1.0
one_over_units = 1.0

def make_zig_curve(curve, y0, y):
def make_zig_curve(curve, y0, y, zig_unidirectional):
if rightward_for_zigs:
curve.Reverse()

Expand Down Expand Up @@ -208,11 +209,26 @@ def make_zig_curve(curve, y0, y):
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 make_zig(a, y0, y):
def make_zig(a, y0, y, zig_unidirectional):
for curve in a.getCurves():
make_zig_curve(curve, y0, y)
make_zig_curve(curve, y0, y, zig_unidirectional)

reorder_zig_list_list = []

Expand Down Expand Up @@ -270,7 +286,7 @@ def rotated_area(a):
an.append(curve_new)
return an

def zigzag(a, stepover):
def zigzag(a, stepover, zig_unidirectional):
if a.num_curves() == 0:
return

Expand Down Expand Up @@ -315,39 +331,41 @@ def zigzag(a, stepover):
a2 = area.Area()
a2.append(c)
a2.Intersect(a)
make_zig(a2, y0, y)
rightward_for_zigs = (rightward_for_zigs == False)
make_zig(a2, y0, y, zig_unidirectional)
if zig_unidirectional == False:
rightward_for_zigs = (rightward_for_zigs == False)

reorder_zigs()

def pocket(a, tool_radius, extra_offset, rapid_down_to_height, start_depth, final_depth, stepover, stepdown, clearance_height, from_center, keep_tool_down_if_poss, use_zig_zag, zig_angle):
if rapid_down_to_height > clearance_height:
rapid_down_to_height = clearance_height
def pocket(a, tool_radius, extra_offset, rapid_safety_space, start_depth, final_depth, stepover, stepdown, clearance_height, from_center, keep_tool_down_if_poss, use_zig_zag, zig_angle, zig_unidirectional = False):
global tool_radius_for_pocket
global area_for_feed_possible
tool_radius_for_pocket = tool_radius

if keep_tool_down_if_poss:
area_for_feed_possible = area.Area(a)
area_for_feed_possible.Offset(extra_offset - 0.01)

if rapid_safety_space > clearance_height:
rapid_safety_space = clearance_height

use_internal_function = False
use_internal_function = (area.holes_linked() == False) # use internal function, if area module is the Clipper library

if use_internal_function:
curve_list = a.MakePocketToolpath(tool_radius, extra_offset, stepover, from_center, use_zig_zag, zig_angle)

else:
global area_for_feed_possible
global tool_radius_for_pocket
global sin_angle_for_zigs
global cos_angle_for_zigs
global sin_minus_angle_for_zigs
global cos_minus_angle_for_zigs
tool_radius_for_pocket = tool_radius
radians_angle = zig_angle * math.pi / 180
sin_angle_for_zigs = math.sin(-radians_angle)
cos_angle_for_zigs = math.cos(-radians_angle)
sin_minus_angle_for_zigs = math.sin(radians_angle)
cos_minus_angle_for_zigs = math.cos(radians_angle)

arealist = list()

if keep_tool_down_if_poss:
area_for_feed_possible = area.Area(a)
area_for_feed_possible.Offset(extra_offset - 0.01)

a_offset = area.Area(a)
current_offset = tool_radius + extra_offset
Expand All @@ -356,7 +374,7 @@ def pocket(a, tool_radius, extra_offset, rapid_down_to_height, start_depth, fina
do_recursive = True

if use_zig_zag:
zigzag(a_offset, stepover)
zigzag(a_offset, stepover, zig_unidirectional)
curve_list = curve_list_for_zigs
else:
if do_recursive:
Expand Down Expand Up @@ -385,7 +403,7 @@ def pocket(a, tool_radius, extra_offset, rapid_down_to_height, start_depth, fina
else:
depth = start_depth - i * stepdown

cut_curvelist(curve_list, rapid_down_to_height, current_start_depth, depth, clearance_height, keep_tool_down_if_poss)
cut_curvelist(curve_list, rapid_safety_space, current_start_depth, depth, clearance_height, keep_tool_down_if_poss)
current_start_depth = depth


91 changes: 87 additions & 4 deletions bitmaps/bitmaps.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added bitmaps/engraver.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added bitmaps/pocket/zig unidirectional.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions default.tooltable
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,7 @@
<Tool title="3 mm Carbide Slot Cutter" tool_number="4" id="4">
<params diameter="3.00000000" x_offset="0.00000000" tool_length_offset="15.00000000" max_advance_per_revolution="0.12000000" automatically_generate_title="1" material="1" orientation="6" type="3" corner_radius="0.00000000" flat_radius="1.50000000" cutting_edge_angle="0.00000000" cutting_edge_height="9.00000000" front_angle="95.00000000" tool_angle="60.00000000" back_angle="25.00000000" probe_offset_x="0.00000000" probe_offset_y="0.00000000" width_over_thickness="1.80000000" feedrate="50.00000000" extrusion_material="0" layer_height="0.35000000" temperature="220.00000000" filament_diameter="3.00000000" flowrate="255.00000000" gradient="-0.10000000" pitch="1.00000000" direction="0" />
</Tool>
<Tool title="21 degreee Engraving Bit" tool_number="15" id="15">
<params diameter="3.00000000" x_offset="0.00000000" tool_length_offset="63.50000000" max_advance_per_revolution="0.12000000" automatically_generate_title="1" material="1" orientation="6" type="11" corner_radius="0.00000000" flat_radius="0.12500000" cutting_edge_angle="21.00000000" cutting_edge_height="7.48963106" front_angle="95.00000000" tool_angle="60.00000000" back_angle="25.00000000" probe_offset_x="0.00000000" probe_offset_y="0.00000000" width_over_thickness="1.80000000" feedrate="50.00000000" extrusion_material="0" layer_height="0.35000000" temperature="220.00000000" filament_diameter="3.00000000" flowrate="255.00000000" gradient="0.00000000" pitch="1.00000000" direction="0" />
</Tool>
</HeeksCAD_Document>
Binary file added icons/engraver.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions kurve_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ def add_CRC_end_line(curve,roll_on_curve,roll_off_curve,radius,direction,crc_end

# profile command,
# direction should be 'left' or 'right' or 'on'
def profile(curve, direction = "on", radius = 1.0, offset_extra = 0.0, roll_radius = 2.0, roll_on = None, roll_off = None, rapid_down_to_height = None, clearance = None, start_depth = None, step_down = None, final_depth = None, extend_at_start = 0.0, extend_at_end = 0.0):
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):
global tags

offset_curve = area.Curve(curve)
Expand Down Expand Up @@ -311,7 +311,7 @@ def profile(curve, direction = "on", radius = 1.0, offset_extra = 0.0, roll_radi
rapid(s.x, s.y)

# rapid down to just above the material
rapid(z = mat_depth + rapid_down_to_height)
rapid(z = mat_depth + rapid_safety_space)

# feed down to depth
mat_depth = depth
Expand Down
2 changes: 0 additions & 2 deletions nc/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ def __init__(self, text, fmt = Format(), modal = True):

def set(self, number):
self.str = self.text + self.fmt.string(number)
if number == 17:
print self.str

def write(self, writer):
if self.str == None: return ''
Expand Down
8 changes: 4 additions & 4 deletions nc/hxml_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ class HxmlWriter:
def __init__(self):
pass

def files_open(self, name):
def on_parse_start(self, name):
self.file_out = open(name+'.nc.xml', 'w')
self.file_out.write('<?xml version="1.0" ?>\n')
self.file_out.write('<nccode>\n')

def files_close(self):
def on_parse_end(self):
self.file_out.write('</nccode>\n')
self.file_out.close()

Expand Down Expand Up @@ -50,7 +50,7 @@ def begin_path(self, col):
def end_path(self):
self.file_out.write('\t\t</path>\n')

def add_line(self, x, y, z, a, b, c):
def add_line(self, x, y, z, a = None, b = None, c = None):
self.file_out.write('\t\t\t<line')
if (x != None) :
self.file_out.write(' x="%.6f"' % x)
Expand All @@ -63,7 +63,7 @@ def add_line(self, x, y, z, a, b, c):
if (c != None) : self.file_out.write(' c="%.6f"' % c)
self.file_out.write(' />\n')

def add_arc(self, x, y, z, i, j, k, r, d):
def add_arc(self, x, y, z, i, j, k, r = None, d = None):
self.file_out.write('\t\t\t<arc')
if (x != None) :
self.file_out.write(' x="%.6f"' % x)
Expand Down
Loading

0 comments on commit c3584d2

Please sign in to comment.