From 45aa103dd4f38d6559d89076447ed5a919f4a88f Mon Sep 17 00:00:00 2001 From: carlopav Date: Sun, 6 Jun 2021 11:21:09 +0200 Subject: [PATCH] Draft: Autogroup, insert guard to prevent cyclic references ref. Forum discussion: Draft_OrthoArray: Crash when using active Std_Part. https://forum.freecadweb.org/viewtopic.php?f=23&t=59155&p=508132#p508132 Autogroup try to add new created Draft Objects into the active Part, but if the Part is used as a Base for the new object this could create a cyclic reference. This behaviour is prevented by adding a check for " obj in active_part.InListRecursive" --- src/Mod/Draft/draftguitools/gui_edit_sketcher_objects.py | 1 + src/Mod/Draft/draftutils/gui_utils.py | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/src/Mod/Draft/draftguitools/gui_edit_sketcher_objects.py b/src/Mod/Draft/draftguitools/gui_edit_sketcher_objects.py index e62b8d7792..20b94192f7 100644 --- a/src/Mod/Draft/draftguitools/gui_edit_sketcher_objects.py +++ b/src/Mod/Draft/draftguitools/gui_edit_sketcher_objects.py @@ -69,6 +69,7 @@ class SketcherSketchObjectGuiTools(GuiTools): 0 : startpoint 1 : endpoint """ + import Sketcher if node_idx == 0: obj.movePoint(0, 1, v) elif node_idx == 1: diff --git a/src/Mod/Draft/draftutils/gui_utils.py b/src/Mod/Draft/draftutils/gui_utils.py index afc2a0eff3..2e731fa7d6 100644 --- a/src/Mod/Draft/draftutils/gui_utils.py +++ b/src/Mod/Draft/draftutils/gui_utils.py @@ -129,6 +129,9 @@ def autogroup(obj): if Gui.ActiveDocument.ActiveView.getActiveObject("Arch"): # add object to active Arch Container active_arch_obj = Gui.ActiveDocument.ActiveView.getActiveObject("Arch") + if obj in active_arch_obj.InListRecursive: + # do not autogroup if obj points to active_arch_obj to prevent cyclic references + return active_arch_obj.addObject(obj) elif Gui.ActiveDocument.ActiveView.getActiveObject("part", False) is not None: @@ -136,6 +139,9 @@ def autogroup(obj): # so object does not jump to different position, works with App::Link # if not scaled. Modified accordingly to realthunder suggestions active_part, parent, sub = Gui.ActiveDocument.ActiveView.getActiveObject("part", False) + if obj in active_part.InListRecursive: + # do not autogroup if obj points to active_part to prevent cyclic references + return matrix = parent.getSubObject(sub, retType=4) if matrix.hasScale() == 1: err = translate("Draft",