diff --git a/Source/Model/Classes/NMR_ModelMetaDataGroup.cpp b/Source/Model/Classes/NMR_ModelMetaDataGroup.cpp index 08e1f841b..e3265d347 100644 --- a/Source/Model/Classes/NMR_ModelMetaDataGroup.cpp +++ b/Source/Model/Classes/NMR_ModelMetaDataGroup.cpp @@ -113,7 +113,11 @@ namespace NMR { std::string sName; std::string sValue; PModelMetaData metaData = pSourceMetaDataGroup->getMetaData(nIndex); - addMetaData(metaData->getNameSpace(), metaData->getName(), metaData->getValue(), metaData->getType(), metaData->getPreserve()); + + // only add metadata, if the key does not exist yet + if (!hasMetaData(metaData->getKey())) { + addMetaData(metaData->getNameSpace(), metaData->getName(), metaData->getValue(), metaData->getType(), metaData->getPreserve()); + } } } } diff --git a/Tests/CPP_Bindings/Source/Volumetric.cpp b/Tests/CPP_Bindings/Source/Volumetric.cpp index 9518750ab..e60448c47 100644 --- a/Tests/CPP_Bindings/Source/Volumetric.cpp +++ b/Tests/CPP_Bindings/Source/Volumetric.cpp @@ -1258,7 +1258,7 @@ namespace Lib3MF auto const reader = sourceModel->QueryReader("3mf"); reader->ReadFromFile(InFolder + "SphereInACage.3mf"); - auto sourcetModelFunctionCount = sourceModel->GetFunctions()->Count(); + auto sourceModelFunctionCount = sourceModel->GetFunctions()->Count(); auto const targetModel = wrapper->CreateModel(); @@ -1268,7 +1268,31 @@ namespace Lib3MF targetModel->MergeFromModel(sourceModel.get()); auto targetFunctionsIter = targetModel->GetFunctions(); - EXPECT_EQ(targetFunctionsIter->Count(), sourcetModelFunctionCount + 1); + EXPECT_EQ(targetFunctionsIter->Count(), sourceModelFunctionCount + 1); + } + + TEST_F(Volumetric, + Volumetric_Merge_FunctionsFromLoadedModelIntoLoadedTargetModel_FunctionCountIncreases) + { + // load the source model + auto const sourceModel = wrapper->CreateModel(); + auto reader = sourceModel->QueryReader("3mf"); + reader->SetStrictModeActive(true); + reader->ReadFromFile(InFolder + "SphereInACage.3mf"); + + auto sourceModelFunctionCount = sourceModel->GetFunctions()->Count(); + + auto const targetModel = wrapper->CreateModel(); + auto targetReader = targetModel->QueryReader("3mf"); + targetReader->SetStrictModeActive(true); + + targetReader->ReadFromFile(InFolder + "template.3mf"); + auto previousTargetFunctionCount = targetModel->GetFunctions()->Count(); + + EXPECT_NO_THROW(targetModel->MergeFromModel(sourceModel.get())); + + auto targetFunctionsIter = targetModel->GetFunctions(); + EXPECT_EQ(targetFunctionsIter->Count(), sourceModelFunctionCount + previousTargetFunctionCount); } } // namespace Lib3MF diff --git a/Tests/TestFiles/Volumetric/template.3mf b/Tests/TestFiles/Volumetric/template.3mf new file mode 100644 index 000000000..4cd785eba Binary files /dev/null and b/Tests/TestFiles/Volumetric/template.3mf differ