From c02ccca6404a2ec4d65757c9b4fd82fb5d5117a0 Mon Sep 17 00:00:00 2001 From: sliptonic Date: Thu, 24 Mar 2022 09:46:15 -0500 Subject: [PATCH 1/4] Changes from lcorley --- .../Path/PathScripts/PathDressupLeadInOut.py | 229 ++++++++++-------- 1 file changed, 122 insertions(+), 107 deletions(-) diff --git a/src/Mod/Path/PathScripts/PathDressupLeadInOut.py b/src/Mod/Path/PathScripts/PathDressupLeadInOut.py index 4b460da593..13bd8fe3b2 100644 --- a/src/Mod/Path/PathScripts/PathDressupLeadInOut.py +++ b/src/Mod/Path/PathScripts/PathDressupLeadInOut.py @@ -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() From 1f453b23397bf37d6d37ec2859c9e1df8f6ea99a Mon Sep 17 00:00:00 2001 From: sliptonic Date: Thu, 24 Mar 2022 09:46:40 -0500 Subject: [PATCH 2/4] Black reformat --- .../Path/PathScripts/PathDressupLeadInOut.py | 209 +++++++++++------- 1 file changed, 127 insertions(+), 82 deletions(-) diff --git a/src/Mod/Path/PathScripts/PathDressupLeadInOut.py b/src/Mod/Path/PathScripts/PathDressupLeadInOut.py index 13bd8fe3b2..3c0671b65f 100644 --- a/src/Mod/Path/PathScripts/PathDressupLeadInOut.py +++ b/src/Mod/Path/PathScripts/PathDressupLeadInOut.py @@ -248,7 +248,7 @@ 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) @@ -259,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" @@ -269,18 +269,22 @@ class ObjectDressup: p0 = queue[0].Placement.Base p1 = queue[1].Placement.Base v = self.normalize(p1.sub(p0)) - PathLog.debug(" CURRENT_IN Line : 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: @@ -288,14 +292,18 @@ 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: @@ -306,9 +314,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) @@ -317,23 +325,23 @@ 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, v.y*R, 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 @@ -344,81 +352,111 @@ class ObjectDressup: tangentvec = self.rotate(offsetvector, -90) else: tangentvec = self.rotate(offsetvector, 90) - #print ("tangentvec = ", tangentvec) + # print ("tangentvec = ", tangentvec) # Normalize the tangent vector tangentvecNorm = self.normalize(tangentvec) - #print ("tangentvecNorm = ", tangentvecNorm) + # print ("tangentvecNorm = ", tangentvecNorm) # Multiply tangentvecNorm by LeadIn length - leadlinevec = self.multiply(tangentvecNorm, obj.ExtendLeadIn) - #print ("leadlinevec = ", leadlinevec) + 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) + # print ("extendstart = ", extendstart) - if action == 'start': + 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}) + 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}) + 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': + if obj.StyleOn == "Arc": if obj.ExtendLeadIn != 0: # Insert move to beginning of leadin arc - extendcommand = Path.Command('G1', {"X": leadstart.x, "Y": leadstart.y, "F": horizFeed}) + extendcommand = Path.Command( + "G1", {"X": leadstart.x, "Y": leadstart.y, "F": horizFeed} + ) results.append(extendcommand) - arcmove = Path.Command(arcdir, {"X": p0.x, "Y": p0.y, "I": offsetvector.x, "J": offsetvector.y, "F": horizFeed}) # add G2/G3 move + 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}) + 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 + # pylint: disable=unused-argument results = [] - #print ("action =", action) - #print ("queue[0] =" ,queue[0]) - #print ("queue[1] =" ,queue[1]) - #print ("queue[2] =" ,queue[2]) + # 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" @@ -432,10 +470,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: @@ -443,84 +481,91 @@ 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) - offsetvector = FreeCAD.Vector(v.x*R, v.y*R, 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() - #print ("leadend = ", leadend) - #print ("IJ = ", IJ) + # 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) + # print ("tangentvecNorm = ", tangentvecNorm) # Multiply tangentvecNorm by LeadOut length - leadlinevec = self.multiply(tangentvecNorm, obj.ExtendLeadOut) - #print ("leadlinevec = ", leadlinevec) + 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) + # 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(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) if obj.ExtendLeadOut != 0: - extendcommand = Path.Command('G1', {"X": extendleadoutend.x, "Y": extendleadoutend.y, "F": horizFeed}) + 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}) + 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', {})) - - #print ("results =",results) + results.append(Path.Command("G40", {})) + + # print ("results =",results) return results - def generateLeadInOutCurve(self, obj): global currLocation # pylint: disable=global-statement firstmove = Path.Command("G0", {"X": 0, "Y": 0, "Z": 0}) From 8fd52094f5ee9719be4ee7c2bc38387c2cea730b Mon Sep 17 00:00:00 2001 From: sliptonic Date: Thu, 24 Mar 2022 10:07:59 -0500 Subject: [PATCH 3/4] remove pylint, commented code, and uncomment PathLogs --- .../Path/PathScripts/PathDressupLeadInOut.py | 51 +++---------------- 1 file changed, 8 insertions(+), 43 deletions(-) diff --git a/src/Mod/Path/PathScripts/PathDressupLeadInOut.py b/src/Mod/Path/PathScripts/PathDressupLeadInOut.py index 3c0671b65f..0fecc17184 100644 --- a/src/Mod/Path/PathScripts/PathDressupLeadInOut.py +++ b/src/Mod/Path/PathScripts/PathDressupLeadInOut.py @@ -162,7 +162,6 @@ class ObjectDressup: return None def __setstate__(self, state): - # pylint: disable=unused-argument return None def setup(self, obj): @@ -329,10 +328,6 @@ class ObjectDressup: else: 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) - - # 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": @@ -352,16 +347,12 @@ class ObjectDressup: 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": if obj.ExtendLeadIn != 0: @@ -444,13 +435,7 @@ class ObjectDressup: def getLeadEnd(self, obj, queue, action): """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 @@ -482,7 +467,7 @@ class ObjectDressup: 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)) + 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) @@ -508,9 +493,6 @@ class ObjectDressup: vec_inv = self.invert(vec_rot) - # 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) offsetvector = FreeCAD.Vector(v.x * R, v.y * R, 0.0) if obj.RadiusCenter == "Radius": leadend = (p1.add(off_v)).add(offsetvector) # Rmode @@ -522,23 +504,15 @@ class ObjectDressup: else: leadend = p1.add(off_v) # Dmode - IJ = off_v # .negative() - # print ("leadend = ", leadend) - # print ("IJ = ", IJ) + IJ = off_v # 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. + # IJ is an offset from the beginning 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, @@ -562,12 +536,10 @@ class ObjectDressup: if obj.UseMachineCRC: # crc off results.append(Path.Command("G40", {})) - # print ("results =",results) - return results def generateLeadInOutCurve(self, obj): - global currLocation # pylint: disable=global-statement + global currLocation firstmove = Path.Command("G0", {"X": 0, "Y": 0, "Z": 0}) op = PathDressup.baseOp(obj.Base) currLocation.update(firstmove.Parameters) @@ -579,7 +551,7 @@ class ObjectDressup: # Read in all commands for curCommand in obj.Base.Path.Commands: - # PathLog.debug("CurCMD: {}".format(curCommand)) + 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) @@ -606,7 +578,7 @@ class ObjectDressup: and prevCmd.Name in movecommands ): # Layer change within move cmds - # PathLog.debug("Layer change in move: {}->{}".format(currLocation['Z'], curCommand.z)) + PathLog.debug("Layer change in move: {}->{}".format(currLocation['Z'], curCommand.z)) layers.append(queue) queue = [] @@ -623,16 +595,14 @@ class ObjectDressup: # Go through each layer and add leadIn/Out idx = 0 for layer in layers: - # PathLog.debug("Layer {}".format(idx)) + PathLog.debug("Layer {}".format(idx)) if obj.LeadIn: temp = self.getLeadStart(obj, layer, action) newpath.extend(temp) for cmd in layer: - # 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 + PathLog.debug("CurLoc: {}, NewCmd: {}".format(currLocation, cmd)) newpath.append(cmd) if obj.LeadOut: @@ -693,11 +663,9 @@ class ViewProviderDressup: group.remove(g) i.Group = group print(i.Group) - # FreeCADGui.ActiveDocument.getObject(obj.Base.Name).Visibility = False 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) @@ -709,7 +677,6 @@ 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 @@ -723,7 +690,6 @@ class ViewProviderDressup: return None def __setstate__(self, state): - # pylint: disable=unused-argument return None def clearTaskPanel(self): @@ -731,7 +697,6 @@ class ViewProviderDressup: class CommandPathDressupLeadInOut: - # pylint: disable=no-init def GetResources(self): return { From 1e9094272c1dfc0e20687253f0fb95f7982a583c Mon Sep 17 00:00:00 2001 From: sliptonic Date: Mon, 28 Mar 2022 16:30:41 -0500 Subject: [PATCH 4/4] [Path] Fix initial descent at start --- .../Path/PathScripts/PathDressupLeadInOut.py | 54 +++++++++++++------ 1 file changed, 37 insertions(+), 17 deletions(-) diff --git a/src/Mod/Path/PathScripts/PathDressupLeadInOut.py b/src/Mod/Path/PathScripts/PathDressupLeadInOut.py index 0fecc17184..e1076adc22 100644 --- a/src/Mod/Path/PathScripts/PathDressupLeadInOut.py +++ b/src/Mod/Path/PathScripts/PathDressupLeadInOut.py @@ -41,7 +41,7 @@ from PathPythonGui.simple_edit_panel import SimpleEditPanel translate = FreeCAD.Qt.translate -if False: +if True: PathLog.setLevel(PathLog.Level.DEBUG, PathLog.thisModule()) PathLog.trackModule(PathLog.thisModule()) else: @@ -354,6 +354,16 @@ class ObjectDressup: # leadlinevec provides the offset from the beginning of the lead arc to the beginning of the extend line extendstart = leadstart.add(leadlinevec) + # commandname = "G0" if obj.RapidPlunge else "G1" + # extendcommand = Path.Command( + # commandname, + # { + # "X": leadstart.x, + # "Y": leadstart.y, + # "Z": p1.z, + # }, + # ) + # results.append(extendcommand) if action == "start": if obj.ExtendLeadIn != 0: # Rapid move to beginning of extend line @@ -369,7 +379,7 @@ class ObjectDressup: # Rapid move to beginning of leadin arc extendcommand = Path.Command( "G0", - {"X": leadstart.x, "Y": leadstart.y, "Z": op.ClearanceHeight.Value}, + {"X": extendstart.x, "Y": extendstart.y, "Z": op.ClearanceHeight.Value}, ) results.append(extendcommand) extendcommand = Path.Command("G0", {"Z": op.SafeHeight.Value}) @@ -380,23 +390,33 @@ class ObjectDressup: 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": extendstart.x, "Y": extendstart.y}) results.append(extendcommand) - if not obj.RapidPlunge: - 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, - }, - ) + commandname = "G0" if obj.RapidPlunge else "G1" + extendcommand = Path.Command( + commandname, + { + # "X": leadstart.x, + # "Y": leadstart.y, + "Z": p1.z, + }, + ) results.append(extendcommand) + # if not obj.RapidPlunge: + # 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, + # }, + # ) + # results.append(extendcommand) if obj.UseMachineCRC: if self.getDirectionOfPath(obj) == "right": @@ -602,7 +622,7 @@ class ObjectDressup: newpath.extend(temp) for cmd in layer: - PathLog.debug("CurLoc: {}, NewCmd: {}".format(currLocation, cmd)) + PathLog.debug("CurLoc: {}, NewCmd: {}!!".format(currLocation, cmd)) newpath.append(cmd) if obj.LeadOut: