From 39a73f4e7f6eff764544c5d7fb98ae70925cd98d Mon Sep 17 00:00:00 2001 From: Markus Lampert Date: Thu, 30 Aug 2018 22:40:16 -0700 Subject: [PATCH] Preserve selection over moves and rotations --- src/Mod/Path/PathScripts/PathJobGui.py | 51 ++++++++++++++++++-------- 1 file changed, 35 insertions(+), 16 deletions(-) diff --git a/src/Mod/Path/PathScripts/PathJobGui.py b/src/Mod/Path/PathScripts/PathJobGui.py index 3d258222ad..5feee1c51b 100644 --- a/src/Mod/Path/PathScripts/PathJobGui.py +++ b/src/Mod/Path/PathScripts/PathJobGui.py @@ -43,6 +43,7 @@ import sys import traceback from PySide import QtCore, QtGui +from contextlib import contextmanager from pivy import coin # Qt tanslation handling @@ -63,6 +64,17 @@ def _OpenCloseResourceEditor(obj, vobj, edit): else: job.ViewObject.Proxy.uneditObject(obj) +@contextmanager +def selectionEx(): + sel = FreeCADGui.Selection.getSelectionEx() + try: + yield sel + finally: + FreeCADGui.Selection.clearSelection() + for s in sel: + FreeCADGui.Selection.addSelection(s.Object, s.SubElementNames) + + class ViewProvider: def __init__(self, vobj): @@ -823,28 +835,36 @@ class TaskPanel: FreeCADGui.Selection.clearSelection() FreeCADGui.Selection.addSelection(selObject, selFeature) + def restoreSelection(self, selection): + FreeCADGui.Selection.clearSelection() + for sel in selection: + FreeCADGui.Selection.addSelection(sel.Object, sel.SubElementNames) + def modelSet0(self, axis): - for sel in FreeCADGui.Selection.getSelectionEx(): - model = sel.Object - for name in sel.SubElementNames: - feature = model.Shape.getElement(name) - bb = feature.BoundBox - offset = FreeCAD.Vector(axis.x * bb.XMax, axis.y * bb.YMax, axis.z * bb.ZMax) - PathLog.track(feature.BoundBox.ZMax, offset) - p = model.Placement - p.move(offset) - model.Placement = p + with selectionEx() as selection: + for sel in selection: + model = sel.Object + for name in sel.SubElementNames: + feature = model.Shape.getElement(name) + bb = feature.BoundBox + offset = FreeCAD.Vector(axis.x * bb.XMax, axis.y * bb.YMax, axis.z * bb.ZMax) + PathLog.track(feature.BoundBox.ZMax, offset) + p = model.Placement + p.move(offset) + model.Placement = p def modelMove(self, axis): scale = self.form.modelMoveValue.value() - for sel in FreeCADGui.Selection.getSelectionEx(): - offset = axis * scale - Draft.move(sel.Object, offset) + with selectionEx() as selection: + for sel in selection: + offset = axis * scale + Draft.move(sel.Object, offset) def modelRotate(self, axis): angle = self.form.modelRotateValue.value() - for sel in FreeCADGui.Selection.getSelectionEx(): - Draft.rotate(sel.Object, angle, sel.Object.Shape.BoundBox.Center, axis) + with selectionEx() as selection: + for sel in selection: + Draft.rotate(sel.Object, angle, sel.Object.Shape.BoundBox.Center, axis) def alignSetOrigin(self): (obj, by) = self.alignMoveToOrigin() @@ -948,7 +968,6 @@ class TaskPanel: def updateSelection(self): sel = FreeCADGui.Selection.getSelectionEx() - PathLog.track(len(sel)) if len(sel) == 1 and len(sel[0].SubObjects) == 1: if 'Vertex' == sel[0].SubObjects[0].ShapeType: self.form.modelSetXAxis.setEnabled(False)