From 8e4e8f9840b004eeb9ed18da157483ce04542b3b Mon Sep 17 00:00:00 2001 From: Michael Jackson Date: Wed, 6 Mar 2024 10:13:19 -0500 Subject: [PATCH] BUG: Fix resetting of the DataStructure::Id when importing from a file. (#879) Signed-off-by: Michael Jackson --- .../DataStructure/Geometry/IGeometry.cpp | 9 +++-- .../DataStructure/Geometry/IGridGeometry.cpp | 9 ++++- .../Geometry/INodeGeometry0D.cpp | 14 +++---- .../Geometry/INodeGeometry1D.cpp | 39 +++++-------------- .../Geometry/INodeGeometry2D.cpp | 21 +++------- .../Geometry/INodeGeometry3D.cpp | 20 +++------- .../DataStructure/Geometry/RectGridGeom.cpp | 19 +++------ .../Actions/ImportH5ObjectPathsAction.cpp | 2 +- src/simplnx/Utilities/DataObjectUtilities.hpp | 20 ++++++++++ 9 files changed, 66 insertions(+), 87 deletions(-) diff --git a/src/simplnx/DataStructure/Geometry/IGeometry.cpp b/src/simplnx/DataStructure/Geometry/IGeometry.cpp index a328a6ecd3..e32b2d1f8e 100644 --- a/src/simplnx/DataStructure/Geometry/IGeometry.cpp +++ b/src/simplnx/DataStructure/Geometry/IGeometry.cpp @@ -1,5 +1,7 @@ #include "IGeometry.hpp" +#include "simplnx/Utilities/DataObjectUtilities.hpp" + namespace nx::core { IGeometry::IGeometry(DataStructure& dataStructure, std::string name) @@ -205,12 +207,11 @@ void IGeometry::checkUpdatedIdsImpl(const std::vector> { BaseGroup::checkUpdatedIdsImpl(updatedIds); + std::vector visited(1, false); + for(const auto& updatedId : updatedIds) { - if(m_ElementSizesId == updatedId.first) - { - m_ElementSizesId = updatedId.second; - } + m_ElementSizesId = nx::core::VisitDataStructureId(m_ElementSizesId, updatedId, visited, 0); } } } // namespace nx::core diff --git a/src/simplnx/DataStructure/Geometry/IGridGeometry.cpp b/src/simplnx/DataStructure/Geometry/IGridGeometry.cpp index 92b7f2d364..bba770ffa6 100644 --- a/src/simplnx/DataStructure/Geometry/IGridGeometry.cpp +++ b/src/simplnx/DataStructure/Geometry/IGridGeometry.cpp @@ -1,5 +1,7 @@ #include "IGridGeometry.hpp" +#include "simplnx/Utilities/DataObjectUtilities.hpp" + namespace nx::core { IGridGeometry::IGridGeometry(DataStructure& dataStructure, std::string name) @@ -56,11 +58,14 @@ void IGridGeometry::checkUpdatedIdsImpl(const std::vector visited(1, false); + for(const auto& updatedId : updatedIds) { - if(m_CellDataId == updatedId.first) + m_CellDataId = nx::core::VisitDataStructureId(m_CellDataId, updatedId, visited, 0); + if(visited[0]) { - m_CellDataId = updatedId.second; + break; } } } diff --git a/src/simplnx/DataStructure/Geometry/INodeGeometry0D.cpp b/src/simplnx/DataStructure/Geometry/INodeGeometry0D.cpp index 6a32ed62e3..473cfb171e 100644 --- a/src/simplnx/DataStructure/Geometry/INodeGeometry0D.cpp +++ b/src/simplnx/DataStructure/Geometry/INodeGeometry0D.cpp @@ -1,5 +1,7 @@ #include "INodeGeometry0D.hpp" +#include "simplnx/Utilities/DataObjectUtilities.hpp" + namespace nx::core { INodeGeometry0D::INodeGeometry0D(DataStructure& dataStructure, std::string name) @@ -207,16 +209,12 @@ void INodeGeometry0D::checkUpdatedIdsImpl(const std::vector visited(2, false); + for(const auto& updatedId : updatedIds) { - if(m_VertexDataArrayId == updatedId.first) - { - m_VertexDataArrayId = updatedId.second; - } - if(m_VertexAttributeMatrixId == updatedId.first) - { - m_VertexAttributeMatrixId = updatedId.second; - } + m_VertexDataArrayId = nx::core::VisitDataStructureId(m_VertexDataArrayId, updatedId, visited, 0); + m_VertexAttributeMatrixId = nx::core::VisitDataStructureId(m_VertexAttributeMatrixId, updatedId, visited, 1); } } } // namespace nx::core diff --git a/src/simplnx/DataStructure/Geometry/INodeGeometry1D.cpp b/src/simplnx/DataStructure/Geometry/INodeGeometry1D.cpp index e5978f8a72..6709ee868d 100644 --- a/src/simplnx/DataStructure/Geometry/INodeGeometry1D.cpp +++ b/src/simplnx/DataStructure/Geometry/INodeGeometry1D.cpp @@ -1,5 +1,7 @@ #include "INodeGeometry1D.hpp" +#include "simplnx/Utilities/DataObjectUtilities.hpp" + namespace nx::core { INodeGeometry1D::INodeGeometry1D(DataStructure& dataStructure, std::string name) @@ -224,37 +226,16 @@ void INodeGeometry1D::checkUpdatedIdsImpl(const std::vector visited(7, false); + for(const auto& updatedId : updatedIds) { - if(m_EdgeAttributeMatrixId == updatedId.first) - { - m_EdgeAttributeMatrixId = updatedId.second; - } - - if(m_EdgeDataArrayId == updatedId.first) - { - m_EdgeDataArrayId = updatedId.second; - } - - if(m_CellContainingVertDataArrayId == updatedId.first) - { - m_CellContainingVertDataArrayId = updatedId.second; - } - - if(m_CellNeighborsDataArrayId == updatedId.first) - { - m_CellNeighborsDataArrayId = updatedId.second; - } - - if(m_CellCentroidsDataArrayId == updatedId.first) - { - m_CellCentroidsDataArrayId = updatedId.second; - } - - if(m_ElementSizesId == updatedId.first) - { - m_ElementSizesId = updatedId.second; - } + m_EdgeAttributeMatrixId = nx::core::VisitDataStructureId(m_EdgeAttributeMatrixId, updatedId, visited, 0); + m_EdgeDataArrayId = nx::core::VisitDataStructureId(m_EdgeDataArrayId, updatedId, visited, 1); + m_CellContainingVertDataArrayId = nx::core::VisitDataStructureId(m_CellContainingVertDataArrayId, updatedId, visited, 2); + m_CellNeighborsDataArrayId = nx::core::VisitDataStructureId(m_CellNeighborsDataArrayId, updatedId, visited, 3); + m_CellCentroidsDataArrayId = nx::core::VisitDataStructureId(m_CellCentroidsDataArrayId, updatedId, visited, 4); + m_ElementSizesId = nx::core::VisitDataStructureId(m_ElementSizesId, updatedId, visited, 5); } } } // namespace nx::core diff --git a/src/simplnx/DataStructure/Geometry/INodeGeometry2D.cpp b/src/simplnx/DataStructure/Geometry/INodeGeometry2D.cpp index 27fcf14ecd..d8224c22bc 100644 --- a/src/simplnx/DataStructure/Geometry/INodeGeometry2D.cpp +++ b/src/simplnx/DataStructure/Geometry/INodeGeometry2D.cpp @@ -1,5 +1,7 @@ #include "INodeGeometry2D.hpp" +#include "simplnx/Utilities/DataObjectUtilities.hpp" + namespace nx::core { INodeGeometry2D::INodeGeometry2D(DataStructure& dataStructure, std::string name) @@ -177,23 +179,12 @@ INodeGeometry2D::SharedEdgeList* INodeGeometry2D::createSharedEdgeList(usize num void INodeGeometry2D::checkUpdatedIdsImpl(const std::vector>& updatedIds) { INodeGeometry1D::checkUpdatedIdsImpl(updatedIds); - + std::vector visited(3, false); for(const auto& updatedId : updatedIds) { - if(m_FaceListId == updatedId.first) - { - m_FaceListId = updatedId.second; - } - - if(m_FaceAttributeMatrixId == updatedId.first) - { - m_FaceAttributeMatrixId = updatedId.second; - } - - if(m_UnsharedEdgeListId == updatedId.first) - { - m_UnsharedEdgeListId = updatedId.second; - } + m_FaceListId = nx::core::VisitDataStructureId(m_FaceListId, updatedId, visited, 0); + m_FaceAttributeMatrixId = nx::core::VisitDataStructureId(m_FaceAttributeMatrixId, updatedId, visited, 1); + m_UnsharedEdgeListId = nx::core::VisitDataStructureId(m_UnsharedEdgeListId, updatedId, visited, 2); } } } // namespace nx::core diff --git a/src/simplnx/DataStructure/Geometry/INodeGeometry3D.cpp b/src/simplnx/DataStructure/Geometry/INodeGeometry3D.cpp index 8a38b017db..4b863618ed 100644 --- a/src/simplnx/DataStructure/Geometry/INodeGeometry3D.cpp +++ b/src/simplnx/DataStructure/Geometry/INodeGeometry3D.cpp @@ -1,5 +1,7 @@ #include "INodeGeometry3D.hpp" +#include "simplnx/Utilities/DataObjectUtilities.hpp" + namespace nx::core { INodeGeometry3D::INodeGeometry3D(DataStructure& dataStructure, std::string name) @@ -187,23 +189,13 @@ INodeGeometry3D::SharedTriList* INodeGeometry3D::createSharedTriList(usize numTr void INodeGeometry3D::checkUpdatedIdsImpl(const std::vector>& updatedIds) { INodeGeometry2D::checkUpdatedIdsImpl(updatedIds); + std::vector visited(3, false); for(const auto& updatedId : updatedIds) { - if(m_PolyhedronListId == updatedId.first) - { - m_PolyhedronListId = updatedId.second; - } - - if(m_PolyhedronAttributeMatrixId == updatedId.first) - { - m_PolyhedronAttributeMatrixId = updatedId.second; - } - - if(m_UnsharedFaceListId == updatedId.first) - { - m_UnsharedFaceListId = updatedId.second; - } + m_PolyhedronListId = nx::core::VisitDataStructureId(m_PolyhedronListId, updatedId, visited, 0); + m_PolyhedronAttributeMatrixId = nx::core::VisitDataStructureId(m_PolyhedronAttributeMatrixId, updatedId, visited, 1); + m_UnsharedFaceListId = nx::core::VisitDataStructureId(m_UnsharedFaceListId, updatedId, visited, 2); } } } // namespace nx::core diff --git a/src/simplnx/DataStructure/Geometry/RectGridGeom.cpp b/src/simplnx/DataStructure/Geometry/RectGridGeom.cpp index 2dbad4a113..0927fbf724 100644 --- a/src/simplnx/DataStructure/Geometry/RectGridGeom.cpp +++ b/src/simplnx/DataStructure/Geometry/RectGridGeom.cpp @@ -2,6 +2,7 @@ #include "simplnx/DataStructure/DataStore.hpp" #include "simplnx/DataStructure/DataStructure.hpp" +#include "simplnx/Utilities/DataObjectUtilities.hpp" #include "simplnx/Utilities/GeometryHelpers.hpp" #include @@ -693,22 +694,12 @@ std::optional RectGridGeom::getIndex(float64 xCoord, float64 yCoord, floa void RectGridGeom::checkUpdatedIdsImpl(const std::vector>& updatedIds) { IGridGeometry::checkUpdatedIdsImpl(updatedIds); + std::vector visited(3, false); for(const auto& updatedId : updatedIds) { - if(m_xBoundsId == updatedId.first) - { - m_xBoundsId = updatedId.second; - } - - if(m_yBoundsId == updatedId.first) - { - m_yBoundsId = updatedId.second; - } - - if(m_zBoundsId == updatedId.first) - { - m_zBoundsId = updatedId.second; - } + m_xBoundsId = nx::core::VisitDataStructureId(m_xBoundsId, updatedId, visited, 0); + m_yBoundsId = nx::core::VisitDataStructureId(m_yBoundsId, updatedId, visited, 1); + m_zBoundsId = nx::core::VisitDataStructureId(m_zBoundsId, updatedId, visited, 2); } } diff --git a/src/simplnx/Filter/Actions/ImportH5ObjectPathsAction.cpp b/src/simplnx/Filter/Actions/ImportH5ObjectPathsAction.cpp index 6f8e3f70cf..d36e6f64af 100644 --- a/src/simplnx/Filter/Actions/ImportH5ObjectPathsAction.cpp +++ b/src/simplnx/Filter/Actions/ImportH5ObjectPathsAction.cpp @@ -81,7 +81,7 @@ Result<> ImportH5ObjectPathsAction::apply(DataStructure& dataStructure, Mode mod if(dataStructure.getDataAs(targetPath) != nullptr) { return {nonstd::make_unexpected(std::vector{ - {-6203, fmt::format("Unable to import DataObject at '{}' because an object already exists there. Consider a rename of existing object.", prefix, targetPath.toString())}})}; + {-6203, fmt::format("{}Unable to import DataObject at '{}' because an object already exists there. Consider a rename of existing object.", prefix, targetPath.toString())}})}; } if(!dataStructure.insert(importData, targetPath.getParent())) diff --git a/src/simplnx/Utilities/DataObjectUtilities.hpp b/src/simplnx/Utilities/DataObjectUtilities.hpp index c87b7fa23b..c21d3b501e 100644 --- a/src/simplnx/Utilities/DataObjectUtilities.hpp +++ b/src/simplnx/Utilities/DataObjectUtilities.hpp @@ -29,12 +29,32 @@ #include "simplnx/DataStructure/ScalarData.hpp" #include "simplnx/DataStructure/StringArray.hpp" +#include #include #include #include namespace nx::core { +/** + * @brief This method will assign a new 'id' to a value only if the boolean referenced by the visitedIndex is false. + * @param originalId The original 'id' + * @param updatedId The updated 'id' + * @param visited The vector of visited values + * @param visitedIndex The index into the visited array + * @return Either the original 'id' if this was already visited or the new 'id' if it was not visited already. + */ +inline constexpr std::optional VisitDataStructureId(std::optional& originalId, const std::pair& updatedId, + std::vector& visited, usize visitedIndex) +{ + if(originalId == updatedId.first && !visited[visitedIndex]) + { + visited[visitedIndex] = true; + return updatedId.second; + } + return originalId; +} + /** * @brief Returns a string representation of the passed in IGeometry::Type * @param dataType