From e032e26dd4d742416ac4821701ec839f2b65969e Mon Sep 17 00:00:00 2001 From: Markus Lampert Date: Mon, 4 Sep 2017 19:14:26 -0700 Subject: [PATCH] Orderly deletion of a job. --- .../Path/PathScripts/PathDressupDragknife.py | 23 +++++++++--------- src/Mod/Path/PathScripts/PathJob.py | 24 +++++++++++++------ 2 files changed, 28 insertions(+), 19 deletions(-) diff --git a/src/Mod/Path/PathScripts/PathDressupDragknife.py b/src/Mod/Path/PathScripts/PathDressupDragknife.py index 6b8e456981..88ea0a35a6 100644 --- a/src/Mod/Path/PathScripts/PathDressupDragknife.py +++ b/src/Mod/Path/PathScripts/PathDressupDragknife.py @@ -429,8 +429,16 @@ class ViewProviderDressup: def attach(self, vobj): self.Object = vobj.Object - return - + if self.Object and self.Object.Base: + for i in self.Object.Base.InList: + if hasattr(i, "Group"): + group = i.Group + for g in group: + if g.Name == self.Object.Base.Name: + group.remove(g) + i.Group = group + print(i.Group) + #FreeCADGui.ActiveDocument.getObject(obj.Base.Name).Visibility = False def unsetEdit(self, vobj, mode=0): return False @@ -439,15 +447,6 @@ class ViewProviderDressup: return True def claimChildren(self): - for i in self.Object.Base.InList: - if hasattr(i, "Group"): - group = i.Group - for g in group: - if g.Name == self.Object.Base.Name: - group.remove(g) - i.Group = group - print(i.Group) - #FreeCADGui.ActiveDocument.getObject(obj.Base.Name).Visibility = False return [self.Object.Base] def __getstate__(self): @@ -458,7 +457,7 @@ class ViewProviderDressup: def onDelete(self, arg1=None, arg2=None): FreeCADGui.ActiveDocument.getObject(arg1.Object.Base.Name).Visibility = True - PathUtils.addToProject(arg1.Object.Base) + PathUtils.addToJob(arg1.Object.Base) arg1.Object.Base = None return True diff --git a/src/Mod/Path/PathScripts/PathJob.py b/src/Mod/Path/PathScripts/PathJob.py index 6acc19de2e..3e06899d37 100644 --- a/src/Mod/Path/PathScripts/PathJob.py +++ b/src/Mod/Path/PathScripts/PathJob.py @@ -124,20 +124,30 @@ class ObjectJob: '''Called by the view provider, there doesn't seem to be a callback on the obj itself.''' PathLog.track(obj.Label, arg2) doc = obj.Document - for tc in obj.ToolController: - doc.removeObject(tc.Name) - obj.ToolController = [] + # the first to tear down are the ops, they depend on other resources + PathLog.debug('taking down ops: %s' % [o.Name for o in self.allOperations()]) while obj.Operations.Group: - doc.removeObject(obj.Operations.Group[0].Name) + op = obj.Operations.Group[0] + if not op.ViewObject or not hasattr(op.ViewObject.Proxy, 'onDelete') or op.ViewObject.Proxy.onDelete(op.ViewObject, ()): + doc.removeObject(op.Name) obj.Operations.Group = [] doc.removeObject(obj.Operations.Name) obj.Operations = None - if obj.Base: - doc.removeObject(obj.Base.Name) - obj.Base = None + # stock could depend on Base if obj.Stock: + PathLog.debug('taking down stock') doc.removeObject(obj.Stock.Name) obj.Stock = None + # base doesn't depend on anything inside job + if obj.Base: + PathLog.debug('taking down base') + doc.removeObject(obj.Base.Name) + obj.Base = None + # Tool controllers don't depend on anything + PathLog.debug('taking down tool controller') + for tc in obj.ToolController: + doc.removeObject(tc.Name) + obj.ToolController = [] def fixupResourceClone(self, obj, name, icon): if not isResourceClone(obj, name, name):