Skip to content

Commit

Permalink
Custom shaped tabs implemented!!! :-)
Browse files Browse the repository at this point in the history
  • Loading branch information
Harvie committed Jul 4, 2018
1 parent 59bcfa2 commit f8c0223
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 33 deletions.
85 changes: 55 additions & 30 deletions CNC.py
Original file line number Diff line number Diff line change
Expand Up @@ -3434,44 +3434,69 @@ def cut(self, items, depth=None, stepz=None, surface=None, feed=None, feedz=None
# @param dx width of tabs
# @param dy depth of tabs
# @param z height of tabs
# @param isl create tabs from islands?
#----------------------------------------------------------------------
def createTabs(self, items, ntabs, dtabs, dx, dy, z):
def createTabs(self, items, ntabs, dtabs, dx, dy, z, isl=False):
msg = None
undoinfo = []
if ntabs==0 and dtabs==0: return
if ntabs==0 and dtabs==0 and not isl: return

#Get list of islands and remove them from items
islands = []
for bid in items:
if self.blocks[bid].operationTest('island'):
islands.append(bid)
items.remove(bid)
if isl and not items: msg = "You must select toolpaths along with islands!"

for bid in items:
block = self.blocks[bid]
if block.name() in ("Header", "Footer"): continue
for path in self.toPath(bid):
length = path.length()
d = max(length / float(ntabs), dtabs)
# running length
s = d/2. # start from half distance to add first tab
for segment in path:
l = segment.length()
# if we haven't reach d
if s+l < d:
s += l
continue
n = 0
while True:
n += 1
remain = n*d - s
if remain > l:
s = d-(remain-l)
break
if segment.type == Segment.LINE:
P = segment.A + (remain/l)*segment.AB
else:
if segment.type == Segment.CW:
phi = segment.startPhi - remain / segment.radius


if isl:
#Add island tabs
if not islands: msg = "You must select islands along with toolpaths!"

for island in islands:
tab = Tab()
tab.path = self.toPath(island)[0]
undoinfo.append(self.addTabUndo(bid,0,tab))
else:
#Add regular tabs
for path in self.toPath(bid):
length = path.length()
d = max(length / float(ntabs), dtabs)
# running length
s = d/2. # start from half distance to add first tab
for segment in path:
l = segment.length()
# if we haven't reach d
if s+l < d:
s += l
continue
n = 0
while True:
n += 1
remain = n*d - s
if remain > l:
s = d-(remain-l)
break
if segment.type == Segment.LINE:
P = segment.A + (remain/l)*segment.AB
else:
phi = segment.startPhi + remain / segment.radius
P = Vector(segment.C[0] + segment.radius*math.cos(phi),
segment.C[1] + segment.radius*math.sin(phi))
tab = Tab(P[0],P[1],dx,dy,z)
undoinfo.append(self.addTabUndo(bid,0,tab))
if segment.type == Segment.CW:
phi = segment.startPhi - remain / segment.radius
else:
phi = segment.startPhi + remain / segment.radius
P = Vector(segment.C[0] + segment.radius*math.cos(phi),
segment.C[1] + segment.radius*math.sin(phi))
tab = Tab(P[0],P[1],dx,dy,z)
undoinfo.append(self.addTabUndo(bid,0,tab))
self.addUndo(undoinfo)

return msg

#----------------------------------------------------------------------
# Reverse direction of cut
#----------------------------------------------------------------------
Expand Down
5 changes: 4 additions & 1 deletion ToolsPage.py
Original file line number Diff line number Diff line change
Expand Up @@ -786,6 +786,7 @@ def __init__(self, master):
DataBase.__init__(self, master, "Tabs")
self.variables = [
("name", "db" , "", _("Name")),
("islands", "bool", False, _("Create tabs from selected islands?")),
("ntabs", "int", 5, _("Number of tabs")),
("dtabs", "mm", 0.0, _("Min. Distance of tabs")),
("dx", "mm", 5.0, "Dx"),
Expand Down Expand Up @@ -813,7 +814,9 @@ def execute(self,app):
tkMessageBox.showerror(_("Tabs error"),
_("You cannot have both the number of tabs or distance equal to zero"))

app.executeOnSelection("TABS", True, ntabs, dtabs, dx, dy, z)
islands = self["islands"]

app.executeOnSelection("TABS", True, ntabs, dtabs, dx, dy, z, islands)
app.setStatus(_("Create tabs on blocks"))

#==============================================================================
Expand Down
6 changes: 4 additions & 2 deletions bCNC.py
Original file line number Diff line number Diff line change
Expand Up @@ -1598,7 +1598,9 @@ def execute(self, line):
except: dy = tabs.fromMm("dy")
try: z = float(line[5])
except: z = tabs.fromMm("z")
self.executeOnSelection("TABS", True, ntabs, dtabs, dx, dy, z)
try: islands = bool(line[6])
except: islands = False
self.executeOnSelection("TABS", True, ntabs, dtabs, dx, dy, z, islands)

# TERM*INAL: switch to terminal tab
elif rexx.abbrev("TERMINAL",cmd,4):
Expand Down Expand Up @@ -1713,7 +1715,7 @@ def executeOnSelection(self, cmd, blocksonly, *args):
elif cmd == "ROTATE":
self.gcode.rotateLines(items, *args)
elif cmd == "TABS":
self.gcode.createTabs(items, *args)
sel = self.gcode.createTabs(items, *args)

# Fill listbox and update selection
self.editor.fill()
Expand Down

0 comments on commit f8c0223

Please sign in to comment.