From d5edb6ed2a81948e898d1954c302ea5e1ec77411 Mon Sep 17 00:00:00 2001 From: sliptonic Date: Mon, 15 Oct 2018 18:13:56 -0500 Subject: [PATCH] Path: Make a command and icon to toggle op active status --- src/Mod/Path/InitGui.py | 8 ++++---- src/Mod/Path/PathCommands.py | 29 +++++++++++++++++++++++++++-- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/src/Mod/Path/InitGui.py b/src/Mod/Path/InitGui.py index 9551c10938..27458ac767 100644 --- a/src/Mod/Path/InitGui.py +++ b/src/Mod/Path/InitGui.py @@ -76,7 +76,7 @@ class PathWorkbench (Workbench): # build commands list projcmdlist = ["Path_Job", "Path_Post"] - toolcmdlist = ["Path_Inspect", "Path_Simulator", "Path_ToolLibraryEdit", "Path_SelectLoop"] + toolcmdlist = ["Path_Inspect", "Path_Simulator", "Path_ToolLibraryEdit", "Path_SelectLoop", "Path_OpActiveToggle"] prepcmdlist = ["Path_Fixture", "Path_Comment", "Path_Stop", "Path_Custom"] twodopcmdlist = ["Path_Contour", "Path_Profile_Faces", "Path_Profile_Edges", "Path_Pocket_Shape", "Path_Drilling", "Path_MillFace", "Path_Helix", "Path_Adaptive" ] threedopcmdlist = ["Path_Pocket_3D"] @@ -151,7 +151,7 @@ class PathWorkbench (Workbench): if "Job" in selectedName: self.appendContextMenu("", ["Path_ExportTemplate"]) if isinstance (obj.Proxy, PathScripts.PathOp.ObjectOp): - self.appendContextMenu("", ["Path_OperationCopy"]) + self.appendContextMenu("", ["Path_OperationCopy", "Path_OpActiveToggle"]) if obj.isDerivedFrom("Path::Feature"): if "Profile" in selectedName or "Contour" in selectedName or "Dressup" in selectedName: self.appendContextMenu("", "Separator") @@ -164,6 +164,6 @@ Gui.addWorkbench(PathWorkbench()) FreeCAD.addImportType( "GCode (*.nc *.gc *.ncc *.ngc *.cnc *.tap *.gcode)", "PathGui") -FreeCAD.addExportType( - "GCode (*.nc *.gc *.ncc *.ngc *.cnc *.tap *.gcode)", "PathGui") +# FreeCAD.addExportType( +# "GCode (*.nc *.gc *.ncc *.ngc *.cnc *.tap *.gcode)", "PathGui") diff --git a/src/Mod/Path/PathCommands.py b/src/Mod/Path/PathCommands.py index c4c5c1a0c0..63aae97ba9 100644 --- a/src/Mod/Path/PathCommands.py +++ b/src/Mod/Path/PathCommands.py @@ -78,9 +78,9 @@ class _CommandSelectLoop: PathLog.error(exc) traceback.print_exc(exc) return False - + def Activated(self): - from PathScripts.PathUtils import loopdetect + #from PathScripts.PathUtils import loopdetect from PathScripts.PathUtils import horizontalEdgeLoop from PathScripts.PathUtils import horizontalFaceLoop sel = FreeCADGui.Selection.getSelectionEx()[0] @@ -120,6 +120,31 @@ class _CommandSelectLoop: if FreeCAD.GuiUp: FreeCADGui.addCommand('Path_SelectLoop', _CommandSelectLoop()) +class _ToggleOperation: + "command definition to toggle Operation Active state" + def GetResources(self): + return {'Pixmap': 'Path-OpActive', + 'MenuText': QtCore.QT_TRANSLATE_NOOP("Path_OpActiveToggle", "Toggle the Active State of the Operation"), + 'Accel': "P, X", + 'ToolTip': QtCore.QT_TRANSLATE_NOOP("Path_OpActiveToggle", "Toggle the Active State of the Operation"), + 'CmdType': "ForEdit"} + + def IsActive(self): + if bool(FreeCADGui.Selection.getSelection()) is False: + return False + try: + obj = FreeCADGui.Selection.getSelectionEx()[0].Object + return isinstance(obj.Proxy, PathScripts.PathOp.ObjectOp) + except: + return False + + def Activated(self): + obj = FreeCADGui.Selection.getSelectionEx()[0].Object + obj.Active = not(obj.Active) + FreeCAD.ActiveDocument.recompute() + +if FreeCAD.GuiUp: + FreeCADGui.addCommand('Path_OpActiveToggle', _ToggleOperation()) class _CopyOperation: "the Path Copy Operation command definition"