From 97d25927845e70ec4b97ebdb75ad79498e8cf5ad Mon Sep 17 00:00:00 2001 From: Markus Lampert Date: Mon, 5 Jun 2017 21:40:25 -0700 Subject: [PATCH] Added export of job template - fixed output file. --- src/Mod/Path/InitGui.py | 7 +- src/Mod/Path/PathScripts/PathJob.py | 107 +++++++++++++++++++--------- 2 files changed, 79 insertions(+), 35 deletions(-) diff --git a/src/Mod/Path/InitGui.py b/src/Mod/Path/InitGui.py index 84644f5d53..9bdeb165ed 100644 --- a/src/Mod/Path/InitGui.py +++ b/src/Mod/Path/InitGui.py @@ -138,11 +138,14 @@ class PathWorkbench (Workbench): if len(FreeCADGui.Selection.getSelection()) == 1: if FreeCADGui.Selection.getSelection()[0].isDerivedFrom("Path::Feature"): self.appendContextMenu("", ["Path_Inspect"]) - if "Profile" or "Contour" in FreeCADGui.Selection.getSelection()[0].Name: + selectedName = FreeCADGui.Selection.getSelection()[0].Name + if "Job" in selectedName: + self.appendContextMenu("", ["Path_ExportTemplate"]) + if "Profile" in selectedName or "Contour" in selectedName: #self.appendContextMenu("", ["Add_Tag"]) self.appendContextMenu("", ["Set_StartPoint"]) #self.appendContextMenu("", ["Set_EndPoint"]) - if "Remote" in FreeCADGui.Selection.getSelection()[0].Name: + if "Remote" in selectedName: self.appendContextMenu("", ["Refresh_Path"]) Gui.addWorkbench(PathWorkbench()) diff --git a/src/Mod/Path/PathScripts/PathJob.py b/src/Mod/Path/PathScripts/PathJob.py index acd2f2f754..c6862478ec 100644 --- a/src/Mod/Path/PathScripts/PathJob.py +++ b/src/Mod/Path/PathScripts/PathJob.py @@ -27,6 +27,7 @@ import FreeCAD import Path import PathScripts.PathLog as PathLog import sys +import lxml.etree as xml from PySide import QtCore, QtGui from PathScripts.PathPostProcessor import PostProcessor @@ -159,38 +160,6 @@ class ViewProviderJob: vobj.setEditorMode('Transparency', mode) -class CommandJob: - - def GetResources(self): - return {'Pixmap': 'Path-Job', - 'MenuText': QtCore.QT_TRANSLATE_NOOP("Path_Job", "Job"), - 'Accel': "P, J", - 'ToolTip': QtCore.QT_TRANSLATE_NOOP("Path_Job", "Creates a Path Job object")} - - def IsActive(self): - return FreeCAD.ActiveDocument is not None - - def Activated(self): - CommandJob.Create() - FreeCAD.ActiveDocument.recompute() - - @staticmethod - def Create(): - FreeCAD.ActiveDocument.openTransaction(translate("Path_Job", "Create Job")) - FreeCADGui.addModule('PathScripts.PathUtils') - FreeCADGui.addModule('PathScripts.PathToolController') - snippet = ''' -import PathScripts.PathToolController as PathToolController -obj = FreeCAD.ActiveDocument.addObject("Path::FeatureCompoundPython", "Job") -PathScripts.PathJob.ObjectPathJob(obj) -PathToolController.CommandPathToolController.Create(obj.Name) -obj.ViewObject.Proxy.deleteOnReject = True -obj.ViewObject.startEditing() -''' - FreeCADGui.doCommand(snippet) - FreeCAD.ActiveDocument.commitTransaction() - - class TaskPanel: def __init__(self, obj, deleteOnReject): FreeCAD.ActiveDocument.openTransaction(translate("Path_Job", "Edit Job")) @@ -326,9 +295,81 @@ class TaskPanel: self.setFields() +class CommandJobCreate: + + def GetResources(self): + return {'Pixmap': 'Path-Job', + 'MenuText': QtCore.QT_TRANSLATE_NOOP("Path_Job", "Job"), + #'Accel': "P, J", + 'ToolTip': QtCore.QT_TRANSLATE_NOOP("Path_Job", "Creates a Path Job object")} + + def IsActive(self): + return FreeCAD.ActiveDocument is not None + + def Activated(self): + self.Create() + FreeCAD.ActiveDocument.recompute() + + @classmethod + def Execute(cls): + FreeCAD.ActiveDocument.openTransaction(translate("Path_Job", "Create Job")) + FreeCADGui.addModule('PathScripts.PathUtils') + FreeCADGui.addModule('PathScripts.PathToolController') + snippet = ''' +import PathScripts.PathToolController as PathToolController +obj = FreeCAD.ActiveDocument.addObject("Path::FeatureCompoundPython", "Job") +PathScripts.PathJob.ObjectPathJob(obj) +PathToolController.CommandPathToolController.Create(obj.Name) +obj.ViewObject.Proxy.deleteOnReject = True +obj.ViewObject.startEditing() +''' + FreeCADGui.doCommand(snippet) + FreeCAD.ActiveDocument.commitTransaction() + +class CommandJobExportTemplate: + + def GetResources(self): + return {'Pixmap': 'Path-Job', + 'MenuText': QtCore.QT_TRANSLATE_NOOP("Path_Job", "Export Template"), + #'Accel': "P, T", + 'ToolTip': QtCore.QT_TRANSLATE_NOOP("Path_Job", "Exports Path Job as a template to be used for other jobs")} + + def IsActive(self): + return FreeCAD.ActiveDocument is not None + + def Activated(self): + job = FreeCADGui.Selection.getSelection()[0] + self.Execute(job) + FreeCAD.ActiveDocument.recompute() + + @classmethod + def Execute(cls, job): + FreeCAD.ActiveDocument.openTransaction(translate("Path_Job", "Export Job template")) + root = xml.Element('PathJobConfiguration') + for obj in job.Group: + if hasattr(obj, 'Tool') and hasattr(obj, 'SpindleDir'): + tc = xml.SubElement(root, 'ToolController', {'Label': obj.Label}) + attrs = {} + attrs['nr'] = ("%d" % (obj.ToolNumber)) + attrs['vfeed'] = ("%s" % (obj.VertFeed)) + attrs['hfeed'] = ("%s" % (obj.HorizFeed)) + attrs['vrapid'] = ("%s" % (obj.VertRapid)) + attrs['hrapid'] = ("%s" % (obj.HorizRapid)) + attrs['speed'] = ("%f" % (obj.SpindleSpeed)) + attrs['dir'] = ("%s" % (obj.SpindleDir)) + + xml.SubElement(tc, 'Controller', attrs) + tc.append(xml.fromstring(obj.Tool.Content)) + xml.ElementTree(root).write("./%s.xml" % job.Label, pretty_print=True) + + FreeCAD.ActiveDocument.commitTransaction() + + + if FreeCAD.GuiUp: # register the FreeCAD command - FreeCADGui.addCommand('Path_Job', CommandJob()) + FreeCADGui.addCommand('Path_Job', CommandJobCreate()) + FreeCADGui.addCommand('Path_ExportTemplate', CommandJobExportTemplate()) FreeCAD.Console.PrintLog("Loading PathJob... done\n")