Skip to content

Commit

Permalink
Update getUnitDefs() API
Browse files Browse the repository at this point in the history
  • Loading branch information
ashwinbhat committed Oct 9, 2024
1 parent 3dd6999 commit 6251ac8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
16 changes: 13 additions & 3 deletions source/MaterialXCore/Definition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,16 +185,26 @@ StringVec TargetDef::getMatchingTargets() const

vector<UnitDefPtr> UnitTypeDef::getUnitDefs() const
{
const auto datalibrary = getDocument()->hasDataLibrary() ? getDocument()->getRegisteredDataLibrary() : getDocument();

vector<UnitDefPtr> unitDefs;
for (UnitDefPtr unitDef : datalibrary->getChildrenOfType<UnitDef>())
for (UnitDefPtr unitDef : getDocument()->getChildrenOfType<UnitDef>())
{
if (unitDef->getUnitType() == _name)
{
unitDefs.push_back(unitDef);
}
}
// Gather unitdefs from Data library
if (getDocument()->hasDataLibrary())
{
for (UnitDefPtr unitDef : getDocument()->getRegisteredDataLibrary()->getChildrenOfType<UnitDef>())
{
if (unitDef->getUnitType() == _name)
{
unitDefs.push_back(unitDef);
}
}

}
return unitDefs;
}

Expand Down
4 changes: 2 additions & 2 deletions source/MaterialXCore/Document.h
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ class MX_CORE_API Document : public GraphElement
/// Return a vector of all Member elements in the TypeDef.
vector<UnitDefPtr> getUnitDefs() const
{
return getChildrenOfType<UnitDef>();
return hasDataLibrary() ? getChildrenOfType<UnitDef>(getRegisteredDataLibrary()) : getChildrenOfType<UnitDef>();
}

/// Remove the UnitDef, if any, with the given name.
Expand Down Expand Up @@ -585,7 +585,7 @@ class MX_CORE_API Document : public GraphElement
/// Return a vector of all UnitTypeDef elements in the document.
vector<UnitTypeDefPtr> getUnitTypeDefs() const
{
return getChildrenOfType<UnitTypeDef>();
return hasDataLibrary() ? getChildrenOfType<UnitTypeDef>(getRegisteredDataLibrary()) : getChildrenOfType<UnitTypeDef>();
}

/// Remove the UnitTypeDef, if any, with the given name.
Expand Down

0 comments on commit 6251ac8

Please sign in to comment.