From 694fb31df18ae0107fefb90144ced4ec6436db7d Mon Sep 17 00:00:00 2001 From: sliptonic Date: Wed, 23 Aug 2017 16:00:32 -0500 Subject: [PATCH] Path: Command to duplicate an operation. Creates a copy of the currently selected operation in the same job --- src/Mod/Path/Gui/Resources/Path.qrc | 1 + .../Path/Gui/Resources/icons/Path-OpCopy.svg | 704 ++++++++++++++++++ src/Mod/Path/InitGui.py | 11 +- src/Mod/Path/PathCommands.py | 54 +- 4 files changed, 755 insertions(+), 15 deletions(-) create mode 100644 src/Mod/Path/Gui/Resources/icons/Path-OpCopy.svg diff --git a/src/Mod/Path/Gui/Resources/Path.qrc b/src/Mod/Path/Gui/Resources/Path.qrc index d620a393d1..a80ce319fe 100644 --- a/src/Mod/Path/Gui/Resources/Path.qrc +++ b/src/Mod/Path/Gui/Resources/Path.qrc @@ -29,6 +29,7 @@ icons/Path-Machine.svg icons/Path-OperationA.svg icons/Path-OperationB.svg + icons/Path-OpCopy.svg icons/Path-Plane.svg icons/Path-Pocket.svg icons/Path-Post.svg diff --git a/src/Mod/Path/Gui/Resources/icons/Path-OpCopy.svg b/src/Mod/Path/Gui/Resources/icons/Path-OpCopy.svg new file mode 100644 index 0000000000..0079645ea4 --- /dev/null +++ b/src/Mod/Path/Gui/Resources/icons/Path-OpCopy.svg @@ -0,0 +1,704 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + Path-FaceProfile + 2016-01-19 + http://www.freecadweb.org/wiki/index.php?title=Artwork + + + FreeCAD + + + FreeCAD/src/Mod/Path/Gui/Resources/icons/Path- + + + FreeCAD LGPL2+ + + + https://www.gnu.org/copyleft/lesser.html + + + [agryson] Alexander Gryson + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Mod/Path/InitGui.py b/src/Mod/Path/InitGui.py index 0f7529287a..1ece0b794f 100644 --- a/src/Mod/Path/InitGui.py +++ b/src/Mod/Path/InitGui.py @@ -37,6 +37,7 @@ class PathWorkbench (Workbench): # load the builtin modules import Path + import PathScripts import PathGui from PySide import QtGui FreeCADGui.addLanguagePath(":/translations") @@ -86,7 +87,7 @@ class PathWorkbench (Workbench): threedopcmdlist = ["Path_Surfacing"] modcmdlist = ["Path_Copy", "Path_CompoundExtended", "Path_Array", "Path_SimpleCopy" ] dressupcmdlist = ["PathDressup_Dogbone", "PathDressup_DragKnife", "PathDressup_Tag", "PathDressup_RampEntry"] - extracmdlist = ["Path_SelectLoop", "Path_Shape", "Path_Area", "Path_Area_Workplane", "Path_Stock"] + extracmdlist = ["Path_SelectLoop", "Path_Shape", "Path_Area", "Path_Area_Workplane", "Path_Stock", "Path_CloneOperation"] #modcmdmore = ["Path_Hop",] #remotecmdlist = ["Path_Remote"] @@ -136,10 +137,12 @@ class PathWorkbench (Workbench): Msg("Path workbench deactivated\n") def ContextMenu(self, recipient): + import PathScripts if len(FreeCADGui.Selection.getSelection()) == 1: - if FreeCADGui.Selection.getSelection()[0].isDerivedFrom("Path::Feature"): + obj = FreeCADGui.Selection.getSelection()[0] + if obj.isDerivedFrom("Path::Feature"): self.appendContextMenu("", ["Path_Inspect"]) - selectedName = FreeCADGui.Selection.getSelection()[0].Name + selectedName = obj.Name if "Job" in selectedName: self.appendContextMenu("", ["Path_ExportTemplate"]) if "Profile" in selectedName or "Contour" in selectedName or "Dressup" in selectedName: @@ -149,6 +152,8 @@ class PathWorkbench (Workbench): self.appendContextMenu("", [cmd]) if "Remote" in selectedName: self.appendContextMenu("", ["Refresh_Path"]) + if isinstance (obj.Proxy, PathScripts.PathOp.ObjectOp): + self.appendContextMenu("", ["Path_CloneOperation"]) Gui.addWorkbench(PathWorkbench()) diff --git a/src/Mod/Path/PathCommands.py b/src/Mod/Path/PathCommands.py index e44b816905..68cab460c5 100644 --- a/src/Mod/Path/PathCommands.py +++ b/src/Mod/Path/PathCommands.py @@ -23,13 +23,17 @@ # *************************************************************************** import FreeCAD +import PathScripts from PathScripts.PathUtils import loopdetect +from PathScripts.PathUtils import addToJob +from PathScripts.PathUtils import findParentJob + if FreeCAD.GuiUp: import FreeCADGui from PySide import QtCore from DraftTools import translate else: - def translate(ctxt,txt): + def translate(ctxt, txt): return txt __title__="FreeCAD Path Commands" @@ -38,11 +42,11 @@ __url__ = "http://www.freecadweb.org" class _CommandSelectLoop: - "the Arch RemoveShape command definition" + "the Path command to complete loop selection definition" def GetResources(self): - return {'Pixmap' : 'Path-SelectLoop', - 'MenuText': QtCore.QT_TRANSLATE_NOOP("Path_SelectLoop","Finish Selecting Loop"), - 'ToolTip': QtCore.QT_TRANSLATE_NOOP("Path_SelectLoop","Complete loop selection from two edges"), + return {'Pixmap': 'Path-SelectLoop', + 'MenuText': QtCore.QT_TRANSLATE_NOOP("Path_SelectLoop", "Finish Selecting Loop"), + 'ToolTip': QtCore.QT_TRANSLATE_NOOP("Path_SelectLoop", "Complete loop selection from two edges"), 'CmdType': "ForEdit"} def IsActive(self): @@ -60,8 +64,6 @@ class _CommandSelectLoop: except: return False - - def Activated(self): sel = FreeCADGui.Selection.getSelectionEx()[0] obj = sel.Object @@ -77,9 +79,37 @@ class _CommandSelectLoop: FreeCADGui.Selection.addSelection(obj, "Edge"+str(elist.index(e)+1)) if FreeCAD.GuiUp: - FreeCADGui.addCommand('Path_SelectLoop',_CommandSelectLoop()) + FreeCADGui.addCommand('Path_SelectLoop', _CommandSelectLoop()) -def findShape(shape,subname=None,subtype=None): + +class _CloneOperation: + "the Path Clone Operation command definition" + def GetResources(self): + return {'Pixmap': 'Path-OpCopy', + 'MenuText': QtCore.QT_TRANSLATE_NOOP("Path_CloneOperation", "Duplicate the operation in the job"), + 'ToolTip': QtCore.QT_TRANSLATE_NOOP("Path_CloneOperation", "Create a copy of the operation in the same job"), + '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 + jobname = findParentJob(obj).Name + addToJob(FreeCAD.ActiveDocument.copyObject(obj, False), jobname) + + +if FreeCAD.GuiUp: + FreeCADGui.addCommand('Path_CloneOperation', _CloneOperation()) + + +def findShape(shape, subname=None, subtype=None): '''To find a higher oder shape containing the subshape with subname. E.g. to find the wire containing 'Edge1' in shape, findShape(shape,'Edge1','Wires') @@ -88,7 +118,7 @@ def findShape(shape,subname=None,subtype=None): return shape ret = shape.getElement(subname) if not subtype or not ret or ret.isNull(): - return ret; + return ret if subname.startswith('Face'): tp = 'Faces' elif subname.startswith('Edge'): @@ -97,8 +127,8 @@ def findShape(shape,subname=None,subtype=None): tp = 'Vertex' else: return ret - for obj in getattr(shape,subtype): - for sobj in getattr(obj,tp): + for obj in getattr(shape, subtype): + for sobj in getattr(obj, tp): if sobj.isEqual(ret): return obj return ret