From 5d950cc1044134cfbc265ce6825479be46388016 Mon Sep 17 00:00:00 2001 From: Ashwin Bhat Date: Tue, 15 Oct 2024 10:28:26 -0700 Subject: [PATCH] Remove overrides from mx::Document Remove getChildOfType and getChildrenOfType from Document and introduce datalibrary handling in Element. --- source/MaterialXCore/Document.h | 27 --------------------------- source/MaterialXCore/Element.cpp | 16 +++++++++++++++- 2 files changed, 15 insertions(+), 28 deletions(-) diff --git a/source/MaterialXCore/Document.h b/source/MaterialXCore/Document.h index e5e16fcfc0..ab01bbbc11 100644 --- a/source/MaterialXCore/Document.h +++ b/source/MaterialXCore/Document.h @@ -121,33 +121,6 @@ class MX_CORE_API Document : public GraphElement /// nodes, and include both Input and Output elements. vector getMatchingPorts(const string& nodeName) const; - /// Return the child element, if any, with the given document and data library - template shared_ptr getChildOfType(const string& name) const - { - ElementPtr child = hasDataLibrary() ? getDataLibrary()->getChild(name) : nullptr; - if (!child) - { - child = getChild(name); - } - return child ? child->asA() : shared_ptr(); - } - - /// Return a vector of all child elements within the document and data library - template vector> getChildrenOfType(const string& category = EMPTY_STRING) const - { - vector> children = hasDataLibrary() ? getDataLibrary()->getChildrenOfType(category) : vector>(); - for (ElementPtr child : _childOrder) - { - shared_ptr instance = child->asA(); - if (!instance) - continue; - if (!category.empty() && child->getCategory() != category) - continue; - children.push_back(instance); - } - return children; - } - /// @} /// @name GeomInfo Elements /// @{ diff --git a/source/MaterialXCore/Element.cpp b/source/MaterialXCore/Element.cpp index 1a48142962..f8d5117de7 100644 --- a/source/MaterialXCore/Element.cpp +++ b/source/MaterialXCore/Element.cpp @@ -286,13 +286,27 @@ ElementPtr Element::changeChildCategory(ElementPtr child, const string& category template shared_ptr Element::getChildOfType(const string& name) const { - ElementPtr child = getChild(name); + ElementPtr child = nullptr; + if (isA() && asA()->hasDataLibrary()) + { + child = asA()->getDataLibrary()->getChild(name); + } + + if (!child) + { + child = getChild(name); + } return child ? child->asA() : shared_ptr(); } template vector> Element::getChildrenOfType(const string& category) const { vector> children; + if (isA() && asA()->hasDataLibrary()) + { + children = asA()->getDataLibrary()->getChildrenOfType(category); + } + for (ElementPtr child : _childOrder) { shared_ptr instance = child->asA();