From daf8c64d3451c3100367ced116849eaf75f2c096 Mon Sep 17 00:00:00 2001 From: Jan Orend <56254096+3dJan@users.noreply.github.com> Date: Sat, 14 Sep 2024 10:38:56 +0200 Subject: [PATCH] Improving resource ID handling for merging implicit functions --- Source/Common/NMR_Exception.cpp | 2 +- Source/Model/Classes/NMR_Model.cpp | 56 +++++++++++++++++------------- 2 files changed, 33 insertions(+), 25 deletions(-) diff --git a/Source/Common/NMR_Exception.cpp b/Source/Common/NMR_Exception.cpp index b95eb66ac..ecd27d85f 100644 --- a/Source/Common/NMR_Exception.cpp +++ b/Source/Common/NMR_Exception.cpp @@ -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); } diff --git a/Source/Model/Classes/NMR_Model.cpp b/Source/Model/Classes/NMR_Model.cpp index eee4631ec..b4817fd63 100644 --- a/Source/Model/Classes/NMR_Model.cpp +++ b/Source/Model/Classes/NMR_Model.cpp @@ -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(); } @@ -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()