From e478ea7d7727d73c0735aa0c2af65d3fb34d70a5 Mon Sep 17 00:00:00 2001 From: "Zheng, Lei" Date: Sun, 17 Dec 2023 21:27:25 +0800 Subject: [PATCH] Gui: deduce object path when setting active object --- src/Gui/ActiveObjectList.cpp | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/src/Gui/ActiveObjectList.cpp b/src/Gui/ActiveObjectList.cpp index 976632da48..717a65ad2b 100644 --- a/src/Gui/ActiveObjectList.cpp +++ b/src/Gui/ActiveObjectList.cpp @@ -111,10 +111,34 @@ Gui::ActiveObjectList::ObjectInfo Gui::ActiveObjectList::getObjectInfo(App::Docu if (info.obj) break; } + if(!info.obj) { + // No selection is found, try to obtain the object hierarchy using + // DocumentObject::getParents() + unsigned long count = 0xffffffff; + for(auto &v : obj->getParents()) { + if(v.first->getDocument() != _Doc->getDocument()) + continue; - if (!info.obj && obj->getDocument()==_Doc->getDocument()) - info.obj = obj; + // We prioritize on non-linked group object having the least + // hierarchies. + unsigned long cnt = v.first->getSubObjectList(v.second.c_str()).size(); + if(v.first->getLinkedObject(false) != v.first) + cnt &= 0x8000000; + if(cnt < count) { + count = cnt; + info.obj = v.first; + info.subname = v.second; + } + } + + if(!info.obj) { + if (obj->getDocument()!=_Doc->getDocument()) + return info; + info.obj = obj; + } + } } + return info; }