From 92de5cbb441ce5720e0968be18d034f8d3c72b5e Mon Sep 17 00:00:00 2001 From: wmayer Date: Sat, 13 May 2023 15:12:49 +0200 Subject: [PATCH] App: add method DocumentObject::getFirstParent() --- src/App/DocumentObject.cpp | 11 +++++++++++ src/App/DocumentObject.h | 3 +++ 2 files changed, 14 insertions(+) diff --git a/src/App/DocumentObject.cpp b/src/App/DocumentObject.cpp index 3ceb7fd4a0..396cdfb868 100644 --- a/src/App/DocumentObject.cpp +++ b/src/App/DocumentObject.cpp @@ -897,6 +897,17 @@ std::vector> DocumentObject::getPar return ret; } +App::DocumentObject* DocumentObject::getFirstParent() const +{ + for (auto obj : getInList()) { + if (obj->hasExtension(App::GroupExtension::getExtensionClassTypeId(), true)) { + return obj; + } + } + + return nullptr; +} + DocumentObject *DocumentObject::getLinkedObject( bool recursive, Base::Matrix4D *mat, bool transform, int depth) const { diff --git a/src/App/DocumentObject.h b/src/App/DocumentObject.h index a6bf95f341..6490de0605 100644 --- a/src/App/DocumentObject.h +++ b/src/App/DocumentObject.h @@ -383,6 +383,9 @@ public: ///Obtain top parents and subnames of this object using its InList std::vector > getParents(int depth=0) const; + /// Obtain the first parent group of this object + App::DocumentObject* getFirstParent() const; + /** Return the linked object with optional transformation * * @param recurse: If false, return the immediate linked object, or else