[PATH] make -custom- op compliant. Improve gcode_pre importer

This commit is contained in:
sliptonic
2020-06-04 15:26:55 -05:00
parent 11a2b948ea
commit df2884f810
11 changed files with 332 additions and 116 deletions

View File

@@ -22,84 +22,58 @@
# ***************************************************************************
import FreeCAD
import FreeCADGui
import Path
import PathScripts.PathOp as PathOp
import PathScripts.PathLog as PathLog
from PySide import QtCore
from copy import copy
__title__ = "Path Custom Operation"
__author__ = "sliptonic (Brad Collette)"
__url__ = "http://www.freecadweb.org"
__doc__ = "Path Custom object and FreeCAD command"
__doc__ = """Path Custom object and FreeCAD command"""
if False:
PathLog.setLevel(PathLog.Level.DEBUG, PathLog.thisModule())
PathLog.trackModule(PathLog.thisModule())
else:
PathLog.setLevel(PathLog.Level.INFO, PathLog.thisModule())
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)
class ObjectCustom:
def __init__(self, obj):
class ObjectCustom(PathOp.ObjectOp):
def opFeatures(self, obj):
return PathOp.FeatureTool | PathOp.FeatureCoolant
def initOperation(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):
return None
def __setstate__(self, state):
return None
def execute(self, obj):
newpath = Path.Path()
def opExecute(self, obj):
self.commandlist.append(Path.Command("(Begin Custom)"))
if obj.Gcode:
for l in obj.Gcode:
newcommand = Path.Command(str(l))
if newcommand.Name in movecommands:
if 'X' in newcommand.Parameters:
newcommand.x += obj.Offset.Base.x
if 'Y' in newcommand.Parameters:
newcommand.y += obj.Offset.Base.y
if 'Z' in newcommand.Parameters:
newcommand.z += obj.Offset.Base.z
self.commandlist.append(newcommand)
newpath.insertCommand(newcommand)
obj.Path=newpath
self.commandlist.append(Path.Command("(End Custom)"))
class CommandPathCustom:
def GetResources(self):
return {'Pixmap': 'Path-Custom',
'MenuText': QtCore.QT_TRANSLATE_NOOP("Path_Custom", "Custom"),
'ToolTip': QtCore.QT_TRANSLATE_NOOP("Path_Custom", "Creates a path object based on custom G-code")}
def IsActive(self):
if FreeCAD.ActiveDocument is not None:
for o in FreeCAD.ActiveDocument.Objects:
if o.Name[:3] == "Job":
return True
return False
def Activated(self):
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('PathScripts.PathCustom.ObjectCustom(obj)')
FreeCADGui.doCommand('obj.ViewObject.Proxy = 0')
FreeCADGui.doCommand('PathScripts.PathUtils.addToJob(obj)')
FreeCADGui.doCommand('obj.ToolController = PathScripts.PathUtils.findToolController(obj)')
FreeCAD.ActiveDocument.commitTransaction()
FreeCAD.ActiveDocument.recompute()
def SetupProperties():
setup = []
return setup
if FreeCAD.GuiUp:
# register the FreeCAD command
FreeCADGui.addCommand('Path_Custom', CommandPathCustom())
def Create(name, obj=None):
'''Create(name) ... Creates and returns a Custom operation.'''
if obj is None:
obj = FreeCAD.ActiveDocument.addObject("Path::FeaturePython", name)
proxy = ObjectCustom(obj, name)
return obj