split paths on M6 and change placement to use offset

This commit is contained in:
Eric Trombly
2020-03-22 12:05:55 -05:00
parent f1ebaa4cc6
commit 7f76c5fbc3
3 changed files with 41 additions and 34 deletions

View File

@@ -25,12 +25,13 @@ import FreeCAD
import FreeCADGui
import Path
from PySide import QtCore
from copy import copy
__doc__ = """Path Custom object and FreeCAD command"""
movecommands = ['G0', 'G00', 'G1', 'G01', 'G2', 'G02', 'G3', 'G03']
# Qt translation handling
def translate(context, text, disambig=None):
return QtCore.QCoreApplication.translate(context, text, disambig)
@@ -38,11 +39,13 @@ def translate(context, text, disambig=None):
class ObjectCustom:
def __init__(self,obj):
obj.addProperty("App::PropertyStringList", "Gcode", "Path", QtCore.QT_TRANSLATE_NOOP("PathCustom", "The gcode to be inserted"))
obj.addProperty("App::PropertyLink", "ToolController", "Path", QtCore.QT_TRANSLATE_NOOP("PathCustom", "The tool controller that will be used to calculate the path"))
obj.addProperty("App::PropertyBool", "OperationPlacement", "Path", "Use operation placement")
obj.OperationPlacement = False
def __init__(self, obj):
obj.addProperty("App::PropertyStringList", "Gcode", "Path",
QtCore.QT_TRANSLATE_NOOP("PathCustom", "The gcode to be inserted"))
obj.addProperty("App::PropertyLink", "ToolController", "Path",
QtCore.QT_TRANSLATE_NOOP("PathCustom", "The tool controller that will be used to calculate the path"))
obj.addProperty("App::PropertyPlacement", "Offset", "Path",
"Placement Offset")
obj.Proxy = self
def __getstate__(self):
@@ -52,23 +55,21 @@ class ObjectCustom:
return None
def execute(self, obj):
commands = []
newPath = Path.Path
newpath = Path.Path()
if obj.Gcode:
for l in obj.Gcode:
newcommand=Path.Command(str(l))
if newcommand.Name in movecommands and obj.OperationPlacement:
newcommand = Path.Command(str(l))
if newcommand.Name in movecommands:
if 'X' in newcommand.Parameters:
newcommand.x += obj.Placement.Base.x
newcommand.x += obj.Offset.Base.x
if 'Y' in newcommand.Parameters:
newcommand.y += obj.Placement.Base.y
newcommand.y += obj.Offset.Base.y
if 'Z' in newcommand.Parameters:
newcommand.z += obj.Placement.Base.z
newcommand.z += obj.Offset.Base.z
commands.append(newcommand)
newPath.addCommands(commands)
newpath.insertCommand(newcommand)
obj.Path = newPath
obj.Path=newpath
class CommandPathCustom:
@@ -89,7 +90,7 @@ class CommandPathCustom:
FreeCAD.ActiveDocument.openTransaction("Create Custom Path")
FreeCADGui.addModule("PathScripts.PathCustom")
FreeCADGui.addModule("PathScripts.PathUtils")
FreeCADGui.doCommand('obj = FreeCAD.ActiveDocument.addObject("Path::FeaturePython","Custom")')
FreeCADGui.doCommand('obj = FreeCAD.ActiveDocument.addObject("Path::FeaturePython", "Custom")')
FreeCADGui.doCommand('PathScripts.PathCustom.ObjectCustom(obj)')
FreeCADGui.doCommand('obj.ViewObject.Proxy = 0')
FreeCADGui.doCommand('PathScripts.PathUtils.addToJob(obj)')
@@ -100,4 +101,4 @@ class CommandPathCustom:
if FreeCAD.GuiUp:
# register the FreeCAD command
FreeCADGui.addCommand('Path_Custom', CommandPathCustom())
FreeCADGui.addCommand('Path_Custom', CommandPathCustom())