From ec2328bfaa393abdaed91f5defce02102b8f7079 Mon Sep 17 00:00:00 2001 From: Markus Lampert Date: Thu, 11 Feb 2021 20:35:55 -0800 Subject: [PATCH] Ensure base geometry is valid so if it isn't one can still edit the op and fix the base geometry. --- src/Mod/Path/PathScripts/PathOp.py | 23 +++++++++++++++++++++++ src/Mod/Path/PathScripts/PathOpGui.py | 1 + 2 files changed, 24 insertions(+) diff --git a/src/Mod/Path/PathScripts/PathOp.py b/src/Mod/Path/PathScripts/PathOp.py index c0e24b03b4..f8d5b17fa4 100644 --- a/src/Mod/Path/PathScripts/PathOp.py +++ b/src/Mod/Path/PathScripts/PathOp.py @@ -300,6 +300,13 @@ class ObjectOp(object): def onChanged(self, obj, prop): '''onChanged(obj, prop) ... base implementation of the FC notification framework. Do not overwrite, overwrite opOnChanged() instead.''' + + # there's a bit of cycle going on here, if sanitizeBase causes the transaction to + # be cancelled we end right here again with the unsainitized Base - if that is the + # case, stop the cycle and return immediately + if prop == 'Base' and self.sanitizeBase(obj): + return + if 'Restore' not in obj.State and prop in ['Base', 'StartDepth', 'FinalDepth']: self.updateDepths(obj, True) @@ -463,6 +470,19 @@ class ObjectOp(object): self.opUpdateDepths(obj) + def sanitizeBase(self, obj): + '''sanitizeBase(obj) ... check if Base is valid and clear on errors.''' + if hasattr(obj, 'Base'): + try: + for (o, sublist) in obj.Base: + for sub in sublist: + e = o.Shape.getElement(sub) + except Part.OCCError as e: + PathLog.error("{} - stale base geometry detected - clearing.".format(obj.Label)) + obj.Base = [] + return True + return False + @waiting_effects def execute(self, obj): '''execute(obj) ... base implementation - do not overwrite! @@ -494,6 +514,9 @@ class ObjectOp(object): if not self._setBaseAndStock(obj): return + # make sure Base is stil valid or clear it + self.sanitizeBase(obj) + if FeatureCoolant & self.opFeatures(obj): if not hasattr(obj, 'CoolantMode'): PathLog.error(translate("Path", "No coolant property found. Please recreate operation.")) diff --git a/src/Mod/Path/PathScripts/PathOpGui.py b/src/Mod/Path/PathScripts/PathOpGui.py index d8bf2c06e3..7d62d6c01b 100644 --- a/src/Mod/Path/PathScripts/PathOpGui.py +++ b/src/Mod/Path/PathScripts/PathOpGui.py @@ -1177,6 +1177,7 @@ class TaskPanel(object): def panelSetFields(self): '''panelSetFields() ... invoked to trigger a complete transfer of the model's properties to the UI.''' PathLog.track() + self.obj.Proxy.sanitizeBase(self.obj) for page in self.featurePages: page.pageSetFields()