Skip to content

Commit

Permalink
Improving resource ID handling for merging implicit functions
Browse files Browse the repository at this point in the history
  • Loading branch information
3dJan committed Sep 14, 2024
1 parent 09ea724 commit daf8c64
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 25 deletions.
2 changes: 1 addition & 1 deletion Source/Common/NMR_Exception.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ namespace NMR {
}
}

CNMRException::CNMRException(_In_ nfError errorcode) : std::exception()
CNMRException::CNMRException(_In_ nfError errorcode) : m_errorcode(errorcode), std::exception()
{
m_message = errorCodeToMessage(errorcode);
}
Expand Down
56 changes: 32 additions & 24 deletions Source/Model/Classes/NMR_Model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1090,30 +1090,6 @@ namespace NMR {
pNewImplicitFunction->setPackageResourceID(newPkgId);
pNewImplicitFunction->setModel(this);

for (auto & node : *pNewImplicitFunction->getNodes())
{
if (node->getNodeType() == Lib3MF::eImplicitNodeType::ConstResourceID)
{
auto const oldId = pSourceModel->findPackageResourceID(pSourceModel->currentPath(), node->getModelResourceID());
if (!oldId)
{
throw CNMRException(NMR_ERROR_RESOURCENOTFOUND);
}

auto const newIdIter = oldToNewMapping.find(oldId->getUniqueID());
if (newIdIter == oldToNewMapping.cend())
{
throw CNMRException(NMR_ERROR_RESOURCENOTFOUND, "Resource ID " + std::to_string(oldId->getUniqueID()) + " not found in mapping");
}

auto const newId = findPackageResourceID(newIdIter->second);
if (!newId)
{
throw CNMRException(NMR_ERROR_RESOURCENOTFOUND);
}
node->setModelResourceID(newId->getModelResourceID());
}
}
addResource(pNewImplicitFunction);
oldToNewMapping[pOldImplicitFunction->getPackageResourceID()->getUniqueID()] = pNewImplicitFunction->getPackageResourceID()->getUniqueID();
}
Expand All @@ -1122,6 +1098,38 @@ namespace NMR {
throw CNMRException(NMR_ERROR_NOTIMPLEMENTED);
}
}

// loop over all functions and update the references in ConstResourceID nodes
for (nIndex = 0; nIndex < nCount; nIndex++)
{
CModelImplicitFunction * pImplicitFunction = getImplicitFunction(nIndex);

for (auto & node : *pImplicitFunction->getNodes())
{
if (node->getNodeType() == Lib3MF::eImplicitNodeType::ConstResourceID)
{
auto const oldId = pSourceModel->findPackageResourceID(pSourceModel->currentPath(), node->getModelResourceID());
if (!oldId)
{
throw CNMRException(NMR_ERROR_RESOURCENOTFOUND);
}

auto const newIdIter = oldToNewMapping.find(oldId->getUniqueID());
if (newIdIter == oldToNewMapping.cend())
{
throw CNMRException(NMR_ERROR_RESOURCENOTFOUND, "Resource ID " + std::to_string(oldId->getUniqueID()) + " not found in mapping");
}

auto const newId = findPackageResourceID(newIdIter->second);
if (!newId)
{
throw CNMRException(NMR_ERROR_RESOURCENOTFOUND);
}
node->setModelResourceID(newId->getModelResourceID());
}
}
}

}

nfUint32 CModel::createHandle()
Expand Down

0 comments on commit daf8c64

Please sign in to comment.