From 29de03a0984545d29538997a46f8929fce8d5bf4 Mon Sep 17 00:00:00 2001 From: Bas Ruigrok Date: Sun, 8 Sep 2024 11:56:14 +0200 Subject: [PATCH] Move isLink and isLinkGroup from AssemblyObject to DocumentObject --- src/App/DocumentObject.h | 6 ++++ src/App/GeoFeature.cpp | 2 +- src/App/Link.cpp | 15 +++++++++ src/App/Link.h | 6 ++++ src/Mod/Assembly/App/AssemblyObject.cpp | 45 ++++--------------------- 5 files changed, 34 insertions(+), 40 deletions(-) diff --git a/src/App/DocumentObject.h b/src/App/DocumentObject.h index af4867a5bd..8c5ae02155 100644 --- a/src/App/DocumentObject.h +++ b/src/App/DocumentObject.h @@ -442,6 +442,12 @@ public: /* Return true to cause PropertyView to show linked object's property */ virtual bool canLinkProperties() const {return true;} + /* Return whether this object is a link */ + virtual bool isLink() const {return false;}; + + /* Return whether this object is a link group */ + virtual bool isLinkGroup() const {return false;}; + /* Return true to bypass duplicate label checking */ virtual bool allowDuplicateLabel() const {return false;} diff --git a/src/App/GeoFeature.cpp b/src/App/GeoFeature.cpp index 7db5db7a11..2a09632199 100644 --- a/src/App/GeoFeature.cpp +++ b/src/App/GeoFeature.cpp @@ -308,7 +308,7 @@ Base::Placement GeoFeature::getGlobalPlacement(App::DocumentObject* targetObj, if (obj == targetObj) { return plc; } - if (obj->isDerivedFrom()) { + if (obj->isLink()) { // Update doc in case its an external link. doc = obj->getLinkedObject()->getDocument(); } diff --git a/src/App/Link.cpp b/src/App/Link.cpp index 12fb793b9f..815787de66 100644 --- a/src/App/Link.cpp +++ b/src/App/Link.cpp @@ -2282,6 +2282,16 @@ bool Link::canLinkProperties() const { return true; } +bool Link::isLink() const +{ + return ElementCount.getValue() == 0; +} + +bool Link::isLinkGroup() const +{ + return ElementCount.getValue() > 0; +} + ////////////////////////////////////////////////////////////////////////////////////////// namespace App { @@ -2309,6 +2319,11 @@ bool LinkElement::canDelete() const { return !owner || !owner->getDocument()->getObjectByID(_LinkOwner.getValue()); } +bool LinkElement::isLink() const +{ + return true; +} + App::Link* LinkElement::getLinkGroup() const { std::vector inList = getInList(); diff --git a/src/App/Link.h b/src/App/Link.h index 4dcb433ee6..7cb879f75a 100644 --- a/src/App/Link.h +++ b/src/App/Link.h @@ -556,6 +556,10 @@ public: } bool canLinkProperties() const override; + + bool isLink() const override; + + bool isLinkGroup() const override; }; using LinkPython = App::FeaturePythonT; @@ -600,6 +604,8 @@ public: _handleChangedPropertyName(reader,TypeName,PropName); } + bool isLink() const override; + App::Link* getLinkGroup() const; }; diff --git a/src/Mod/Assembly/App/AssemblyObject.cpp b/src/Mod/Assembly/App/AssemblyObject.cpp index 3959be3e5c..ce1a631a7d 100644 --- a/src/Mod/Assembly/App/AssemblyObject.cpp +++ b/src/Mod/Assembly/App/AssemblyObject.cpp @@ -111,39 +111,6 @@ static void printPlacement(Base::Placement plc, const char* name) angle); }*/ -static bool isLink(App::DocumentObject* obj) -{ - if (!obj) { - return false; - } - - auto* link = dynamic_cast(obj); - if (link) { - return link->ElementCount.getValue() == 0; - } - - auto* linkEl = dynamic_cast(obj); - if (linkEl) { - return true; - } - - return false; -} - -static bool isLinkGroup(App::DocumentObject* obj) -{ - if (!obj) { - return false; - } - - auto* link = dynamic_cast(obj); - if (link) { - return link->ElementCount.getValue() > 0; - } - - return false; -} - // ================================ Assembly Object ============================ PROPERTY_SOURCE(Assembly::AssemblyObject, App::Part) @@ -1733,7 +1700,7 @@ void AssemblyObject::ensureIdentityPlacements() std::vector group = Group.getValues(); for (auto* obj : group) { // When used in assembly, link groups must have identity placements. - if (isLinkGroup(obj)) { + if (obj->isLinkGroup()) { auto* link = dynamic_cast(obj); auto* pPlc = dynamic_cast(obj->getPropertyByName("Placement")); if (!pPlc || !link) { @@ -2185,7 +2152,7 @@ App::DocumentObject* AssemblyObject::getObjFromRef(App::DocumentObject* obj, std App::Document* doc = obj->getDocument(); - std::vector names = splitSubName(sub); + std::vector names = Base::Tools::splitSubName(sub); // Lambda function to check if the typeId is a BodySubObject auto isBodySubObject = [](App::DocumentObject* obj) -> bool { @@ -2227,7 +2194,7 @@ App::DocumentObject* AssemblyObject::getObjFromRef(App::DocumentObject* obj, std return obj; } - if (obj->isDerivedFrom() || isLinkGroup(obj)) { + if (obj->isDerivedFrom() || obj->isLinkGroup()) { continue; } else if (obj->isDerivedFrom()) { @@ -2237,7 +2204,7 @@ App::DocumentObject* AssemblyObject::getObjFromRef(App::DocumentObject* obj, std // Primitive, fastener, gear, etc. return obj; } - else if (isLink(obj)) { + else if (obj->isLink()) { App::DocumentObject* linked_obj = obj->getLinkedObject(); if (linked_obj->isDerivedFrom()) { auto* retObj = handlePartDesignBody(linked_obj, it); @@ -2302,7 +2269,7 @@ App::DocumentObject* AssemblyObject::getMovingPartFromRef(App::DocumentObject* o continue; } - if (isLink(obj)) { // update the document if necessary for next object + if (obj->isLink()) { // update the document if necessary for next object doc = obj->getLinkedObject()->getDocument(); } @@ -2319,7 +2286,7 @@ App::DocumentObject* AssemblyObject::getMovingPartFromRef(App::DocumentObject* o continue; // we ignore groups. } - if (isLinkGroup(obj)) { + if (obj->isLinkGroup()) { continue; }