Skip to content

Commit

Permalink
More improvements for LeadInOut
Browse files Browse the repository at this point in the history
  • Loading branch information
Schildkroet committed Mar 18, 2020
1 parent c82a049 commit b9b9cd5
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions src/Mod/Path/PathScripts/PathDressupLeadInOut.py
Expand Up @@ -73,6 +73,7 @@ def __init__(self, obj):
obj.addProperty("App::PropertyDistance", "ExtendLeadIn", "Path", QtCore.QT_TRANSLATE_NOOP("App::Property", "Extends LeadIn distance"))
obj.addProperty("App::PropertyDistance", "ExtendLeadOut", "Path", QtCore.QT_TRANSLATE_NOOP("App::Property", "Extends LeadOut distance"))
obj.addProperty("App::PropertyBool", "RapidPlunge", "Path", QtCore.QT_TRANSLATE_NOOP("App::Property", "Perform plunges with G0"))
obj.addProperty("App::PropertyBool", "IncludeLayers", "Path", QtCore.QT_TRANSLATE_NOOP("App::Property", "Apply LeadInOut to layers within an operation"))

self.wire = None
self.rapids = None
Expand All @@ -96,6 +97,7 @@ def setup(self, obj):
obj.ExtendLeadIn = 0
obj.ExtendLeadOut = 0
obj.RapidPlunge = False
obj.IncludeLayers = True

def execute(self, obj):
if not obj.Base:
Expand Down Expand Up @@ -133,7 +135,6 @@ def normalize(self, Vector):
x = Vector.x
y = Vector.y
length = math.sqrt(x*x + y*y)
#print("Len: {}".format(length))
if((math.fabs(length)) > 0.0000000000001):
vx = round(x / length, 3)
vy = round(y / length, 3)
Expand Down Expand Up @@ -207,6 +208,7 @@ def getLeadStart(self, obj, queue, action):
pij.x += queue[1].Parameters['I']
pij.y += queue[1].Parameters['J']

# Check if lead in and operation go in same direction (usually for inner circles)
if arcdir == queue[1].Name:
arcs_identical = True

Expand Down Expand Up @@ -298,7 +300,7 @@ def getLeadEnd(self, obj, queue, action):
R = obj.Length.Value # Radius of roll or length
arcs_identical = False

# set the correct twist command
# Set the correct twist command
if self.getDirectionOfPath(obj) == 'right':
arcdir = "G2"
else:
Expand Down Expand Up @@ -376,7 +378,7 @@ def getLeadEnd(self, obj, queue, action):
extendcommand = Path.Command('G1', {"X": leadend.x, "Y": leadend.y, "F": horizFeed})
results.append(extendcommand)
else:
PathLog.notice(" CURRENT_IN Perp")
PathLog.debug(" CURRENT_IN Perp")

if obj.UseMachineCRC: # crc off
results.append(Path.Command('G40', {}))
Expand All @@ -392,11 +394,11 @@ def generateLeadInOutCurve(self, obj):
queue = []
action = 'start'
prevCmd = ''

layers = []

# Read in all commands
for curCommand in obj.Base.Path.Commands:
#PathLog.debug("CurCMD: {}".format(curCommand))
if curCommand.Name not in movecommands + rapidcommands:
# Don't worry about non-move commands, just add to output
newpath.append(curCommand)
Expand All @@ -410,14 +412,17 @@ def generateLeadInOutCurve(self, obj):

if curCommand.Name in movecommands:
if prevCmd.Name in rapidcommands and curCommand.Name in movecommands and len(queue) > 0:
# Layer changed: Save current layer cmds prepare next layer
# Layer changed: Save current layer cmds and prepare next layer
layers.append(queue)
queue = []
if obj.IncludeLayers and curCommand.z < currLocation['Z'] and prevCmd.Name in movecommands:
# Layer change within move cmds
#PathLog.debug("Layer change in move: {}->{}".format(currLocation['Z'], curCommand.z))
layers.append(queue)
queue = []
#print("New layer: {}".format(layers))

# Save all move commands
queue.append(curCommand)
#print("Append move: {}, P: {}".format(curCommand.Name, curCommand.Parameters))

currLocation.update(curCommand.Parameters)
prevCmd = curCommand
Expand All @@ -426,26 +431,23 @@ def generateLeadInOutCurve(self, obj):
if len(queue) > 0:
layers.append(queue)
queue = []
#print("New layer: {}".format(layers))

# Go through each layer and add leadIn/Out
idx = 0
for layer in layers:
#print("Layer {}".format(idx))
#PathLog.debug("Layer {}".format(idx))

if obj.LeadIn:
#print("Lead IN")
temp = self.getLeadStart(obj, layer, action)
newpath.extend(temp)

for cmd in layer:
#print("CurLoc: {}, NewCmd: {}".format(currLocation, cmd))
#PathLog.debug("CurLoc: {}, NewCmd: {}".format(currLocation, cmd))
#if currLocation['X'] == cmd.x and currLocation['Y'] == cmd.y and currLocation['Z'] == cmd.z and cmd.Name in ['G1', 'G01']:
#continue
newpath.append(cmd)

if obj.LeadOut:
#print("Lead OUT")
tmp = []
tmp.append(layer[-2])
tmp.append(layer[-1])
Expand Down

0 comments on commit b9b9cd5

Please sign in to comment.