Changes from lcorley
This commit is contained in:
@@ -162,6 +162,7 @@ class ObjectDressup:
|
||||
return None
|
||||
|
||||
def __setstate__(self, state):
|
||||
# pylint: disable=unused-argument
|
||||
return None
|
||||
|
||||
def setup(self, obj):
|
||||
@@ -247,7 +248,8 @@ class ObjectDressup:
|
||||
return FreeCAD.Vector(xnew, ynew, Vector.z)
|
||||
|
||||
def getLeadStart(self, obj, queue, action):
|
||||
"""returns Lead In G-code."""
|
||||
'''returns Lead In G-code.'''
|
||||
# Modified March 2022 by lcorley to support leadin extension
|
||||
results = []
|
||||
op = PathDressup.baseOp(obj.Base)
|
||||
tc = PathDressup.toolController(obj.Base)
|
||||
@@ -257,7 +259,7 @@ class ObjectDressup:
|
||||
arcs_identical = False
|
||||
|
||||
# Set the correct twist command
|
||||
if self.getDirectionOfPath(obj) == "left":
|
||||
if self.getDirectionOfPath(obj) == 'left':
|
||||
arcdir = "G3"
|
||||
else:
|
||||
arcdir = "G2"
|
||||
@@ -267,18 +269,18 @@ class ObjectDressup:
|
||||
p0 = queue[0].Placement.Base
|
||||
p1 = queue[1].Placement.Base
|
||||
v = self.normalize(p1.sub(p0))
|
||||
# PathLog.debug(" CURRENT_IN : P0 Z:{} p1 Z:{}".format(p0.z,p1.z))
|
||||
PathLog.debug(" CURRENT_IN Line : P0 Z:{} p1 Z:{}".format(p0.z,p1.z))
|
||||
else:
|
||||
p0 = queue[0].Placement.Base
|
||||
p1 = queue[1].Placement.Base
|
||||
v = self.normalize(p1.sub(p0))
|
||||
# PathLog.debug(" CURRENT_IN ARC : P0 X:{} Y:{} P1 X:{} Y:{} ".format(p0.x,p0.y,p1.x,p1.y))
|
||||
PathLog.debug(" CURRENT_IN ARC : P0 X:{} Y:{} P1 X:{} Y:{} ".format(p0.x,p0.y,p1.x,p1.y))
|
||||
|
||||
# Calculate offset vector (will be overwritten for arcs)
|
||||
if self.getDirectionOfPath(obj) == "right":
|
||||
off_v = FreeCAD.Vector(v.y * R, -v.x * R, 0.0)
|
||||
if self.getDirectionOfPath(obj) == 'right':
|
||||
off_v = FreeCAD.Vector(v.y*R, -v.x*R, 0.0)
|
||||
else:
|
||||
off_v = FreeCAD.Vector(-v.y * R, v.x * R, 0.0)
|
||||
off_v = FreeCAD.Vector(-v.y*R, v.x*R, 0.0)
|
||||
|
||||
# Check if we enter at line or arc command
|
||||
if queue[1].Name in movecommands and queue[1].Name not in arccommands:
|
||||
@@ -286,14 +288,14 @@ class ObjectDressup:
|
||||
vec = p1.sub(p0)
|
||||
vec_n = self.normalize(vec)
|
||||
vec_inv = self.invert(vec_n)
|
||||
vec_off = self.multiply(vec_inv, obj.ExtendLeadIn)
|
||||
# PathLog.debug("LineCMD: {}, Vxinv: {}, Vyinv: {}, Vxoff: {}, Vyoff: {}".format(queue[0].Name, vec_inv.x, vec_inv.y, vec_off.x, vec_off.y))
|
||||
vec_off = self.multiply(vec_inv, obj.ExtendLeadIn)
|
||||
PathLog.debug("LineCMD: {}, Vxinv: {}, Vyinv: {}, Vxoff: {}, Vyoff: {}".format(queue[0].Name, vec_inv.x, vec_inv.y, vec_off.x, vec_off.y))
|
||||
else:
|
||||
# We have an arc move
|
||||
# Calculate coordinates for middle of circle
|
||||
pij = copy.deepcopy(p0)
|
||||
pij.x += queue[1].Parameters["I"]
|
||||
pij.y += queue[1].Parameters["J"]
|
||||
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:
|
||||
@@ -304,9 +306,9 @@ class ObjectDressup:
|
||||
|
||||
# Rotate vector to get direction for lead in
|
||||
if arcdir == "G2":
|
||||
vec_rot = self.rotate(vec_circ, 90)
|
||||
vec_rot = self.rotate(vec_circ, 90)
|
||||
else:
|
||||
vec_rot = self.rotate(vec_circ, -90)
|
||||
vec_rot = self.rotate(vec_circ, -90)
|
||||
|
||||
# Normalize and invert vector
|
||||
vec_n = self.normalize(vec_rot)
|
||||
@@ -315,104 +317,108 @@ class ObjectDressup:
|
||||
|
||||
# Calculate offset of lead in
|
||||
if arcdir == "G3":
|
||||
off_v = FreeCAD.Vector(-v.y * R, v.x * R, 0.0)
|
||||
off_v = FreeCAD.Vector(-v.y*R, v.x*R, 0.0)
|
||||
else:
|
||||
off_v = FreeCAD.Vector(v.y * R, -v.x * R, 0.0)
|
||||
off_v = FreeCAD.Vector(v.y*R, -v.x*R, 0.0)
|
||||
|
||||
# Multiply offset by LeadIn length
|
||||
vec_off = self.multiply(vec_n, obj.ExtendLeadIn)
|
||||
#vec_off = self.multiply(vec_n, obj.ExtendLeadIn)
|
||||
|
||||
offsetvector = FreeCAD.Vector(v.x * R - vec_off.x, v.y * R - vec_off.y, 0) # IJ
|
||||
#offsetvector = FreeCAD.Vector(v.x*R-vec_off.x, v.y*R-vec_off.y, 0) # IJ
|
||||
offsetvector = FreeCAD.Vector(v.x*R, v.y*R, 0) # IJ
|
||||
|
||||
if obj.RadiusCenter == "Radius":
|
||||
if obj.RadiusCenter == 'Radius':
|
||||
leadstart = (p0.add(off_v)).sub(offsetvector) # Rmode
|
||||
if arcs_identical:
|
||||
t = p0.sub(leadstart)
|
||||
t = p0.add(t)
|
||||
leadstart = t
|
||||
offsetvector = self.multiply(offsetvector, -1)
|
||||
offsetvector = self.multiply(offsetvector, -1)
|
||||
else:
|
||||
leadstart = p0.add(off_v) # Dmode
|
||||
# At this point leadstart is the beginning of the leadin arc
|
||||
# and offsetvector points from leadstart to the center of the leadin arc
|
||||
# so the offsetvector is a radius of the leadin arc at its start
|
||||
# The extend line should be tangent to the leadin arc at this point, or perpendicular to the radius
|
||||
if arcdir == "G2":
|
||||
tangentvec = self.rotate(offsetvector, -90)
|
||||
else:
|
||||
tangentvec = self.rotate(offsetvector, 90)
|
||||
#print ("tangentvec = ", tangentvec)
|
||||
# Normalize the tangent vector
|
||||
tangentvecNorm = self.normalize(tangentvec)
|
||||
#print ("tangentvecNorm = ", tangentvecNorm)
|
||||
# Multiply tangentvecNorm by LeadIn length
|
||||
leadlinevec = self.multiply(tangentvecNorm, obj.ExtendLeadIn)
|
||||
#print ("leadlinevec = ", leadlinevec)
|
||||
# leadlinevec provides the offset from the beginning of the lead arc to the beginning of the extend line
|
||||
extendstart = leadstart.add(leadlinevec)
|
||||
#print ("extendstart = ", extendstart)
|
||||
|
||||
if action == "start":
|
||||
# extendcommand = Path.Command('G0', {"X": 0.0, "Y": 0.0, "Z": op.ClearanceHeight.Value})
|
||||
# results.append(extendcommand)
|
||||
extendcommand = Path.Command(
|
||||
"G0",
|
||||
{"X": leadstart.x, "Y": leadstart.y, "Z": op.ClearanceHeight.Value},
|
||||
)
|
||||
if action == 'start':
|
||||
if obj.ExtendLeadIn != 0:
|
||||
# Rapid move to beginning of extend line
|
||||
extendcommand = Path.Command('G0', {"X": extendstart.x, "Y": extendstart.y, "Z": op.ClearanceHeight.Value})
|
||||
else:
|
||||
# Rapid move to beginning of leadin arc
|
||||
extendcommand = Path.Command('G0', {"X": leadstart.x, "Y": leadstart.y, "Z": op.ClearanceHeight.Value})
|
||||
results.append(extendcommand)
|
||||
extendcommand = Path.Command("G0", {"Z": op.SafeHeight.Value})
|
||||
extendcommand = Path.Command('G0', {"Z": op.SafeHeight.Value})
|
||||
results.append(extendcommand)
|
||||
|
||||
if action == "layer":
|
||||
if action == 'layer':
|
||||
if not obj.KeepToolDown:
|
||||
extendcommand = Path.Command("G0", {"Z": op.SafeHeight.Value})
|
||||
extendcommand = Path.Command('G0', {"Z": op.SafeHeight.Value})
|
||||
results.append(extendcommand)
|
||||
|
||||
extendcommand = Path.Command("G0", {"X": leadstart.x, "Y": leadstart.y})
|
||||
extendcommand = Path.Command('G0', {"X": leadstart.x, "Y": leadstart.y})
|
||||
results.append(extendcommand)
|
||||
|
||||
if not obj.RapidPlunge:
|
||||
extendcommand = Path.Command(
|
||||
"G1", {"X": leadstart.x, "Y": leadstart.y, "Z": p1.z, "F": vertFeed}
|
||||
)
|
||||
extendcommand = Path.Command('G1', {"X": leadstart.x, "Y": leadstart.y, "Z": p1.z, "F": vertFeed})
|
||||
else:
|
||||
extendcommand = Path.Command(
|
||||
"G0",
|
||||
{
|
||||
"X": leadstart.x,
|
||||
"Y": leadstart.y,
|
||||
"Z": p1.z,
|
||||
},
|
||||
)
|
||||
extendcommand = Path.Command('G0', {"X": leadstart.x, "Y": leadstart.y, "Z": p1.z,})
|
||||
results.append(extendcommand)
|
||||
|
||||
if obj.UseMachineCRC:
|
||||
if self.getDirectionOfPath(obj) == "right":
|
||||
results.append(Path.Command("G42", {"D": toolnummer}))
|
||||
if self.getDirectionOfPath(obj) == 'right':
|
||||
results.append(Path.Command('G42', {'D': toolnummer}))
|
||||
else:
|
||||
results.append(Path.Command("G41", {"D": toolnummer}))
|
||||
results.append(Path.Command('G41', {'D': toolnummer}))
|
||||
|
||||
if obj.StyleOn == "Arc":
|
||||
arcmove = Path.Command(
|
||||
arcdir,
|
||||
{
|
||||
"X": p0.x + vec_off.x,
|
||||
"Y": p0.y + vec_off.y,
|
||||
"Z": p1.z,
|
||||
"I": offsetvector.x + vec_off.x,
|
||||
"J": offsetvector.y + vec_off.y,
|
||||
"K": p1.z,
|
||||
"F": horizFeed,
|
||||
},
|
||||
) # add G2/G3 move
|
||||
results.append(arcmove)
|
||||
if obj.StyleOn == 'Arc':
|
||||
if obj.ExtendLeadIn != 0:
|
||||
extendcommand = Path.Command(
|
||||
"G1", {"X": p0.x, "Y": p0.y, "F": horizFeed}
|
||||
)
|
||||
# Insert move to beginning of leadin arc
|
||||
extendcommand = Path.Command('G1', {"X": leadstart.x, "Y": leadstart.y, "F": horizFeed})
|
||||
results.append(extendcommand)
|
||||
elif obj.StyleOn == "Tangent":
|
||||
extendcommand = Path.Command("G1", {"X": p0.x, "Y": p0.y, "F": horizFeed})
|
||||
arcmove = Path.Command(arcdir, {"X": p0.x, "Y": p0.y, "I": offsetvector.x, "J": offsetvector.y, "F": horizFeed}) # add G2/G3 move
|
||||
results.append(arcmove)
|
||||
elif obj.StyleOn == 'Tangent':
|
||||
extendcommand = Path.Command('G1', {"X": p0.x, "Y": p0.y, "F": horizFeed})
|
||||
results.append(extendcommand)
|
||||
else:
|
||||
PathLog.debug(" CURRENT_IN Perp")
|
||||
|
||||
currLocation.update(results[-1].Parameters)
|
||||
currLocation["Z"] = p1.z
|
||||
currLocation['Z'] = p1.z
|
||||
|
||||
return results
|
||||
|
||||
def getLeadEnd(self, obj, queue, action):
|
||||
"""returns the Gcode of LeadOut."""
|
||||
'''returns the Gcode of LeadOut.'''
|
||||
# Modified March 2022 by lcorley to support leadout extension
|
||||
# pylint: disable=unused-argument
|
||||
results = []
|
||||
#print ("action =", action)
|
||||
#print ("queue[0] =" ,queue[0])
|
||||
#print ("queue[1] =" ,queue[1])
|
||||
#print ("queue[2] =" ,queue[2])
|
||||
horizFeed = PathDressup.toolController(obj.Base).HorizFeed.Value
|
||||
R = obj.Length.Value # Radius of roll or length
|
||||
arcs_identical = False
|
||||
|
||||
# Set the correct twist command
|
||||
if self.getDirectionOfPath(obj) == "right":
|
||||
if self.getDirectionOfPath(obj) == 'right':
|
||||
arcdir = "G2"
|
||||
else:
|
||||
arcdir = "G3"
|
||||
@@ -426,10 +432,10 @@ class ObjectDressup:
|
||||
p1 = queue[1].Placement.Base
|
||||
v = self.normalize(p1.sub(p0))
|
||||
|
||||
if self.getDirectionOfPath(obj) == "right":
|
||||
off_v = FreeCAD.Vector(v.y * R, -v.x * R, 0.0)
|
||||
if self.getDirectionOfPath(obj) == 'right':
|
||||
off_v = FreeCAD.Vector(v.y*R, -v.x*R, 0.0)
|
||||
else:
|
||||
off_v = FreeCAD.Vector(-v.y * R, v.x * R, 0.0)
|
||||
off_v = FreeCAD.Vector(-v.y*R, v.x*R, 0.0)
|
||||
|
||||
# Check if we leave at line or arc command
|
||||
if queue[1].Name in movecommands and queue[1].Name not in arccommands:
|
||||
@@ -437,82 +443,86 @@ class ObjectDressup:
|
||||
vec = p1.sub(p0)
|
||||
vec_n = self.normalize(vec)
|
||||
vec_inv = self.invert(vec_n)
|
||||
vec_off = self.multiply(vec_inv, obj.ExtendLeadOut)
|
||||
# PathLog.debug("LineCMD: {}, Vxinv: {}, Vyinv: {}, Vxoff: {}, Vyoff: {}".format(queue[0].Name, vec_inv.x, vec_inv.y, vec_off.x, vec_off.y))
|
||||
vec_off = self.multiply(vec_inv, obj.ExtendLeadOut)
|
||||
#PathLog.debug("LineCMD: {}, Vxinv: {}, Vyinv: {}, Vxoff: {}, Vyoff: {}".format(queue[0].Name, vec_inv.x, vec_inv.y, vec_off.x, vec_off.y))
|
||||
else:
|
||||
# We have an arc move
|
||||
pij = copy.deepcopy(p0)
|
||||
pij.x += queue[1].Parameters["I"]
|
||||
pij.y += queue[1].Parameters["J"]
|
||||
pij.x += queue[1].Parameters['I']
|
||||
pij.y += queue[1].Parameters['J']
|
||||
ve = pij.sub(p1)
|
||||
|
||||
if arcdir == queue[1].Name:
|
||||
arcs_identical = True
|
||||
|
||||
if arcdir == "G2":
|
||||
vec_rot = self.rotate(ve, -90)
|
||||
vec_rot = self.rotate(ve, -90)
|
||||
else:
|
||||
vec_rot = self.rotate(ve, 90)
|
||||
vec_rot = self.rotate(ve, 90)
|
||||
|
||||
vec_n = self.normalize(vec_rot)
|
||||
v = vec_n
|
||||
|
||||
if arcdir == "G3":
|
||||
off_v = FreeCAD.Vector(-v.y * R, v.x * R, 0.0)
|
||||
off_v = FreeCAD.Vector(-v.y*R, v.x*R, 0.0)
|
||||
else:
|
||||
off_v = FreeCAD.Vector(v.y * R, -v.x * R, 0.0)
|
||||
off_v = FreeCAD.Vector(v.y*R, -v.x*R, 0.0)
|
||||
|
||||
vec_inv = self.invert(vec_rot)
|
||||
|
||||
vec_off = self.multiply(vec_inv, obj.ExtendLeadOut)
|
||||
#vec_off = self.multiply(vec_inv, obj.ExtendLeadOut)
|
||||
|
||||
offsetvector = FreeCAD.Vector(v.x * R - vec_off.x, v.y * R - vec_off.y, 0.0)
|
||||
if obj.RadiusCenter == "Radius":
|
||||
#offsetvector = FreeCAD.Vector(v.x*R-vec_off.x, v.y*R-vec_off.y, 0.0)
|
||||
offsetvector = FreeCAD.Vector(v.x*R, v.y*R, 0.0)
|
||||
if obj.RadiusCenter == 'Radius':
|
||||
leadend = (p1.add(off_v)).add(offsetvector) # Rmode
|
||||
if arcs_identical:
|
||||
t = p1.sub(leadend)
|
||||
t = p1.add(t)
|
||||
leadend = t
|
||||
off_v = self.multiply(off_v, -1)
|
||||
off_v = self.multiply(off_v, -1)
|
||||
else:
|
||||
leadend = p1.add(off_v) # Dmode
|
||||
|
||||
IJ = off_v # .negative()
|
||||
# results.append(queue[1])
|
||||
if obj.StyleOff == "Arc":
|
||||
if obj.ExtendLeadOut != 0:
|
||||
extendcommand = Path.Command(
|
||||
"G1", {"X": p1.x - vec_off.x, "Y": p1.y - vec_off.y, "F": horizFeed}
|
||||
)
|
||||
results.append(extendcommand)
|
||||
arcmove = Path.Command(
|
||||
arcdir,
|
||||
{
|
||||
"X": leadend.x,
|
||||
"Y": leadend.y,
|
||||
"Z": p1.z,
|
||||
"I": IJ.x,
|
||||
"J": IJ.y,
|
||||
"K": p1.z,
|
||||
"F": horizFeed,
|
||||
},
|
||||
) # add G2/G3 move
|
||||
#print ("leadend = ", leadend)
|
||||
#print ("IJ = ", IJ)
|
||||
# At this point leadend is the location of the end of the leadout arc
|
||||
# IJ is an offset from the begining of the leadout arc to its center.
|
||||
# It is parallel to a tangent line at the end of the leadout arc
|
||||
# Create the normalized tangent vector
|
||||
tangentvecNorm = self.normalize(IJ)
|
||||
#print ("tangentvecNorm = ", tangentvecNorm)
|
||||
# Multiply tangentvecNorm by LeadOut length
|
||||
leadlinevec = self.multiply(tangentvecNorm, obj.ExtendLeadOut)
|
||||
#print ("leadlinevec = ", leadlinevec)
|
||||
# leadlinevec provides the offset from the end of the leadout arc to the end of the extend line
|
||||
extendleadoutend = leadend.add(leadlinevec)
|
||||
#print ("extendleadoutend = ", extendleadoutend)
|
||||
|
||||
#results.append(queue[1])
|
||||
if obj.StyleOff == 'Arc':
|
||||
arcmove = Path.Command(arcdir, {"X": leadend.x, "Y": leadend.y, "I": IJ.x, "J": IJ.y, "F": horizFeed}) # add G2/G3 move
|
||||
results.append(arcmove)
|
||||
elif obj.StyleOff == "Tangent":
|
||||
extendcommand = Path.Command(
|
||||
"G1", {"X": leadend.x, "Y": leadend.y, "F": horizFeed}
|
||||
)
|
||||
if obj.ExtendLeadOut != 0:
|
||||
extendcommand = Path.Command('G1', {"X": extendleadoutend.x, "Y": extendleadoutend.y, "F": horizFeed})
|
||||
results.append(extendcommand)
|
||||
elif obj.StyleOff == 'Tangent':
|
||||
extendcommand = Path.Command('G1', {"X": leadend.x, "Y": leadend.y, "F": horizFeed})
|
||||
results.append(extendcommand)
|
||||
else:
|
||||
PathLog.debug(" CURRENT_IN Perp")
|
||||
|
||||
if obj.UseMachineCRC: # crc off
|
||||
results.append(Path.Command("G40", {}))
|
||||
results.append(Path.Command('G40', {}))
|
||||
|
||||
#print ("results =",results)
|
||||
|
||||
return results
|
||||
|
||||
|
||||
def generateLeadInOutCurve(self, obj):
|
||||
global currLocation
|
||||
global currLocation # pylint: disable=global-statement
|
||||
firstmove = Path.Command("G0", {"X": 0, "Y": 0, "Z": 0})
|
||||
op = PathDressup.baseOp(obj.Base)
|
||||
currLocation.update(firstmove.Parameters)
|
||||
@@ -642,6 +652,7 @@ class ViewProviderDressup:
|
||||
return [self.obj.Base]
|
||||
|
||||
def setEdit(self, vobj, mode=0):
|
||||
# pylint: disable=unused-argument
|
||||
FreeCADGui.Control.closeDialog()
|
||||
panel = TaskDressupLeadInOut(vobj.Object, self)
|
||||
FreeCADGui.Control.showDialog(panel)
|
||||
@@ -653,6 +664,7 @@ class ViewProviderDressup:
|
||||
|
||||
def onDelete(self, arg1=None, arg2=None):
|
||||
"""this makes sure that the base operation is added back to the project and visible"""
|
||||
# pylint: disable=unused-argument
|
||||
PathLog.debug("Deleting Dressup")
|
||||
if arg1.Object and arg1.Object.Base:
|
||||
FreeCADGui.ActiveDocument.getObject(arg1.Object.Base.Name).Visibility = True
|
||||
@@ -666,6 +678,7 @@ class ViewProviderDressup:
|
||||
return None
|
||||
|
||||
def __setstate__(self, state):
|
||||
# pylint: disable=unused-argument
|
||||
return None
|
||||
|
||||
def clearTaskPanel(self):
|
||||
@@ -673,6 +686,8 @@ class ViewProviderDressup:
|
||||
|
||||
|
||||
class CommandPathDressupLeadInOut:
|
||||
# pylint: disable=no-init
|
||||
|
||||
def GetResources(self):
|
||||
return {
|
||||
"Pixmap": "Path_Dressup",
|
||||
@@ -732,7 +747,7 @@ class CommandPathDressupLeadInOut:
|
||||
FreeCADGui.doCommand(
|
||||
"Gui.ActiveDocument.getObject(base.Name).Visibility = False"
|
||||
)
|
||||
# FreeCAD.ActiveDocument.commitTransaction() # Final `commitTransaction()` called via TaskPanel.accept()
|
||||
FreeCAD.ActiveDocument.commitTransaction()
|
||||
FreeCAD.ActiveDocument.recompute()
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user