Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GRIDEDIT-1310 Added handling of multiple domains with undo #356

Merged
merged 36 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
ac5e99a
GRIDEDIT-1310 Added handling of multiple domains with undo
BillSenior Jul 24, 2024
ebe4e74
GRIDEDIT-1310 Fixed two sonarcloud warnings
BillSenior Jul 25, 2024
7177365
GRIDEDIT-1310 further changes required for multi domain undo
BillSenior Jul 29, 2024
7157d61
GRIDEDIT-1310 Passing to other computer
BillSenior Jul 29, 2024
3d6ffc1
GRIDEDIT-1310 Added first tests for multi domain undo
BillSenior Aug 1, 2024
2ce35cf
GRIDEDIT-1310 Passing to other computer, and added NoActionUndo
BillSenior Aug 5, 2024
668a72f
GRIDEDIT-1310 Added handling of multiple domains with undo
BillSenior Jul 24, 2024
a4d53a3
GRIDEDIT-1310 Fixed two sonarcloud warnings
BillSenior Jul 25, 2024
de23592
GRIDEDIT-1310 further changes required for multi domain undo
BillSenior Jul 29, 2024
41bfc8e
GRIDEDIT-1310 Passing to other computer
BillSenior Jul 29, 2024
9a4c587
GRIDEDIT-1310 Added first tests for multi domain undo
BillSenior Aug 1, 2024
4f09ab1
GRIDEDIT-1310 Passing to other computer, and added NoActionUndo
BillSenior Aug 5, 2024
7161cab
GRIDEDIT-1310 Smal tidying up
BillSenior Aug 6, 2024
08f3022
GRIDEDIT-1310 Passing to other computer
BillSenior Aug 6, 2024
80ff555
Merge branch 'feature/GRIDEDIT-1310_undo_for_multiple_domains' of htt…
BillSenior Aug 7, 2024
a8269bc
GRIDEDIT-1310 Added unit test for mesh2d_get_node_edge_data
BillSenior Aug 7, 2024
2893c51
GRIDEDIT-1310 Initialise node and edge id's with null value
BillSenior Aug 7, 2024
7646c1a
GRIDEDIT-1310 Added api unit test for connecting meshes and undoing
BillSenior Aug 7, 2024
395c3b8
GRIDEDIT-1310 extended the unit test to include extra undo and redo a…
BillSenior Aug 7, 2024
e07498b
GRIDEDIT-1310 Fixed bug in unit test when comparing CLG's. Added comp…
BillSenior Aug 7, 2024
9e581d2
GRIDEDIT-1310 Fixed a number of sonar cloud warnings
BillSenior Aug 7, 2024
26f0ece
GRIDEDIT-1310 Small tidying up of the unit test.
BillSenior Aug 7, 2024
f70e0f7
GRIDEDIT-1310 Added checks on other existing grids after manipulating…
BillSenior Aug 7, 2024
e72f17d
GRIDEDIT-1310 Fixed windows build, fixed the doxygen warnings
BillSenior Aug 7, 2024
5aa40b3
GRIDEDIT-1310 Moved undo action for mk state to separate file.
BillSenior Aug 8, 2024
72944f1
GRIDEDIT-1310 Fixed doxygen and clang formatting warnings
BillSenior Aug 8, 2024
5dbd215
GRIDEDIT-1310 Added comment
BillSenior Aug 8, 2024
c5d507c
GRIDEDIT-1310 Fixed some sonar cloud warnings
BillSenior Aug 8, 2024
fd562f1
GRIDEDIT-1310 Fixed clang-formatting warnings
BillSenior Aug 8, 2024
f6091e1
Merge branch 'master' into feature/GRIDEDIT-1310_undo_for_multiple_do…
BillSenior Aug 8, 2024
0c14b3e
GRIDEDIT-1310 Changes made after review
BillSenior Aug 21, 2024
a3da064
GRIDEDIT-1310 Minor simplification
BillSenior Aug 21, 2024
800fed0
Fix a bug in mkernel_network1d_to_mesh1d, improve Network1DComputeFix…
lucacarniato Aug 23, 2024
306135d
Remove initialization to negative values
lucacarniato Aug 26, 2024
e23f3ab
GRIDEDIT-1310 Small refactoring to work with the front end
BillSenior Aug 27, 2024
dec01bb
GRIDEDIT-1310 Removed commented out code
BillSenior Aug 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions libs/MeshKernel/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ set(
${UNDO_SRC_DIR}/DeleteNodeAction.cpp
${UNDO_SRC_DIR}/FullUnstructuredGridUndo.cpp
${UNDO_SRC_DIR}/MeshConversionAction.cpp
${UNDO_SRC_DIR}/NoActionUndo.cpp
${UNDO_SRC_DIR}/NodeTranslationAction.cpp
${UNDO_SRC_DIR}/ResetEdgeAction.cpp
${UNDO_SRC_DIR}/ResetNodeAction.cpp
Expand All @@ -84,6 +85,11 @@ set(
${UNDO_SRC_DIR}/UndoActionStack.cpp
)

set(
UTILITIES_SRC_LIST
${UTILITIES_SRC_DIR}/Utilities.cpp
)

set(
AVERAGING_STRATEGIES_SRC_LIST
${AVERAGING_STRATEGIES_SRC_DIR}/AveragingStrategyFactory.cpp
Expand Down Expand Up @@ -195,6 +201,7 @@ set(
${UNDO_INC_DIR}/DeleteNodeAction.hpp
${UNDO_INC_DIR}/FullUnstructuredGridUndo.hpp
${UNDO_INC_DIR}/MeshConversionAction.hpp
${UNDO_INC_DIR}/NoActionUndo.hpp
${UNDO_INC_DIR}/NodeTranslationAction.hpp
${UNDO_INC_DIR}/ResetEdgeAction.hpp
${UNDO_INC_DIR}/ResetNodeAction.hpp
Expand Down Expand Up @@ -265,6 +272,7 @@ set(
${UTILITIES_INC_DIR}/RTree.hpp
${UTILITIES_INC_DIR}/RTreeBase.hpp
${UTILITIES_INC_DIR}/RTreeFactory.hpp
${UTILITIES_INC_DIR}/Utilities.hpp
)

# add sources to target
Expand Down Expand Up @@ -359,6 +367,7 @@ source_group("Source Files/AveragingStrategies" FILES ${AVERAGING_STRATEGIES_SRC
source_group("Source Files/CurvilinearGrid" FILES ${CURVILINEAR_GRID_SRC_LIST})
source_group("Source Files/CurvilinearGrid/UndoActions" FILES ${CURVILINEAR_GRID_UNDO_ACTION_SRC_LIST})
source_group("Source Files/UndoActions" FILES ${UNDO_SRC_LIST})
source_group("Source Files/Utilities" FILES ${UTILITIES_SRC_LIST})

# group the headers in IDE tree
source_group("Header Files" FILES ${INC_LIST})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ namespace meshkernel
/// @param[in] projection The projection to use
CurvilinearGrid(lin_alg::Matrix<Point>&& grid, Projection projection);

/// @brief Move assignment operator for CurvilinearGrid
CurvilinearGrid& operator=(CurvilinearGrid&& copy) noexcept;

/// @brief Ccopy assignment operator for CurvilinearGrid
CurvilinearGrid& operator=(const CurvilinearGrid& copy);

/// @brief Set the grid nodes of a curvilinear grid instance
/// @details The matrix row index corresponds to the CurvilinearGrid n index, the matrix column index corresponds to the CurvilinearGrid m index
/// @param[in] gridNodes The input grid points
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ namespace meshkernel
const CurvilinearGridNodeIndices& startOffset,
const CurvilinearGridNodeIndices& endOffset);

/// @brief Return unique pointer to newly created CurvilinearGridBlockUndoAction object
///
/// The entire grid is the block
static std::unique_ptr<CurvilinearGridBlockUndoAction> Create(CurvilinearGrid& grid);

/// @brief Constructor, node values are copied from the grid for the block specified
CurvilinearGridBlockUndoAction(CurvilinearGrid& grid,
const CurvilinearGridNodeIndices& startOffset,
Expand Down
6 changes: 6 additions & 0 deletions libs/MeshKernel/include/MeshKernel/Mesh.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,12 @@ namespace meshkernel
/// @returns The resulting mesh
Mesh& operator+=(Mesh const& rhs);

/// @brief Add meshes: result is a mesh composed of the additions
/// firstMesh += secondmesh results in the second mesh being added to firstMesh
/// @param[in] rhs The mesh to add
/// @returns The undo action
std::unique_ptr<UndoAction> Join(const Mesh& rhs);

/// @brief Get the mapping/indexing from the node array mapped to valid nodes
std::vector<UInt> GetValidNodeMapping() const;

Expand Down
5 changes: 0 additions & 5 deletions libs/MeshKernel/include/MeshKernel/Operations.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -619,11 +619,6 @@ namespace meshkernel
/// @returns The computed matrix norm
[[nodiscard]] double MatrixNorm(const std::vector<double>& x, const std::vector<double>& y, const std::vector<double>& matCoefficients);

/// @brief Print the (simplified) graph in a form that can be loaded into matlab/octave.
///
/// Only nodes and node connectivity need be printed to visualise the graph.
void Print(const std::vector<Point>& nodes, const std::vector<Edge>& edges, std::ostream& out = std::cout);

/// @brief Increment a valid value by an increment
inline void IncrementValidValue(UInt& value, const UInt increment)
{
Expand Down
55 changes: 55 additions & 0 deletions libs/MeshKernel/include/MeshKernel/UndoActions/NoActionUndo.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
//---- GPL ---------------------------------------------------------------------
//
// Copyright (C) Stichting Deltares, 2011-2024.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation version 3.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
// contact: delft3d.support@deltares.nl
// Stichting Deltares
// P.O. Box 177
// 2600 MH Delft, The Netherlands
//
// All indications and logos of, and references to, "Delft3D" and "Deltares"
// are registered trademarks of Stichting Deltares, and remain the property of
// Stichting Deltares. All rights reserved.
//
//------------------------------------------------------------------------------

#pragma once

#include "MeshKernel/UndoActions/UndoAction.hpp"

namespace meshkernel
{

/// @brief A very simple undo action that makes no changes
///
/// This is required because null undo action pointers will not be added to the undo stack.
class NoActionUndo : public UndoAction
{
public:
/// @brief Allocate a NoActionUndo and return a unique_ptr to the newly created object.
static std::unique_ptr<NoActionUndo> Create();

/// @brief Default constructor
NoActionUndo() = default;

private:
/// @brief Perform the undo action, does not change anything
void DoCommit() override;

/// @brief Perform the redo action, does not change anything
void DoRestore() override;
};

} // namespace meshkernel
37 changes: 27 additions & 10 deletions libs/MeshKernel/include/MeshKernel/UndoActions/UndoActionStack.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@

#include <cstdint>
#include <list>
#include <optional>

#include "MeshKernel/Constants.hpp"
#include "MeshKernel/Definitions.hpp"
#include "MeshKernel/UndoActions/UndoAction.hpp"

Expand All @@ -49,31 +51,36 @@ namespace meshkernel
// Perhaps Short for for menu items, long form for tooltips?
// long form for any exceptions?

/// @brief Add an UndoAction.
/// @brief Add an UndoAction with an associated action-id.
///
/// All added undo-actions must be in the committed state, if not then a ConstraintError
/// will be raised.
/// No null undo-actions will be added to the stack.
/// All restored items will be removed, since after adding a new undo-action they are no
/// longer restore-able.
void Add(UndoActionPtr&& transaction);
void Add(UndoActionPtr&& transaction, const int actionId = constants::missing::intValue);

/// @brief Undo the action at the top of the committed stack
///
/// The undo-action will be moved to the restored stack in case it should be re-done.
/// \returns true if an undo-action was performed, false otherwise
bool Undo();
/// \returns a non-empty std::optional if an undo-action was performed, the value
// stored is the id used when adding the action, otherwise its empty.
std::optional<int> Undo();

// Another name
/// @brief Redo the action at the top of the restored stack.
///
/// The undo-action will be moved to the committed stack in case it needs to be undone.
/// \returns true if an redo-action was performed, false otherwise
bool Commit();
/// \returns a non-empty std::optional if an Commit-action was performed, the value
// stored is the id used when adding the action, otherwise its empty.
std::optional<int> Commit();

/// @brief Clear all undo actions.
void Clear();

/// @brief Remove all undo actions with the action-id
UInt Remove(const int actionId);

/// @brief Get the number of undo action items
///
/// The total includes both the number of committed and restored actions.
Expand All @@ -82,22 +89,32 @@ namespace meshkernel
/// @brief Get the number of undo action items
///
/// The number of committed actions.
UInt CommittedSize() const;
UInt CommittedSize(const int actionId = constants::missing::intValue) const;

/// @brief Get the number of undo action items
///
/// The number of restored actions.
UInt RestoredSize() const;
UInt RestoredSize(const int actionId = constants::missing::intValue) const;

/// \brief Compute the approximate amount of memory being used, in bytes, for all undo actions.
std::uint64_t MemorySize() const;

private:
/// @brief Undo actions relating to a specific entity, e.g. mesh
struct UndoActionForMesh
{
/// @brief Undo action.
UndoActionPtr m_undoAction;

/// @brief Identifier for entity associated with the action, most cases this will be a meshKernelId.
int m_actionId = constants::missing::intValue;
};

/// @brief Stack of committed undo actions
std::list<UndoActionPtr> m_committed;
std::list<UndoActionForMesh> m_committed;

/// @brief Stack of restored undo actions
std::list<UndoActionPtr> m_restored;
std::list<UndoActionForMesh> m_restored;
};

} // namespace meshkernel
51 changes: 51 additions & 0 deletions libs/MeshKernel/include/MeshKernel/Utilities/Utilities.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
//---- GPL ---------------------------------------------------------------------
//
// Copyright (C) Stichting Deltares, 2011-2024.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation version 3.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
// contact: delft3d.support@deltares.nl
// Stichting Deltares
// P.O. Box 177
// 2600 MH Delft, The Netherlands
//
// All indications and logos of, and references to, "Delft3D" and "Deltares"
// are registered trademarks of Stichting Deltares, and remain the property of
// Stichting Deltares. All rights reserved.
//
//------------------------------------------------------------------------------

#pragma once

#include <iostream>
#include <vector>

#include "MeshKernel/Entities.hpp"
#include "MeshKernel/Point.hpp"

namespace meshkernel
{

/// @brief Print the (simplified) graph in a form that can be loaded into matlab/octave.
///
/// Only nodes and node connectivity need be printed to visualise the graph.
void Print(const std::vector<Point>& nodes, const std::vector<Edge>& edges, std::ostream& out = std::cout);

/// @brief Print the (simplified) graph in a form that can be loaded into matlab/octave.
///
/// Only nodes and node connectivity need be printed to visualise the graph.
void Print(const std::vector<double>& xNodes,
const std::vector<double>& yNodes,
const std::vector<int>& edges, std::ostream& out = std::cout);

} // namespace meshkernel
54 changes: 54 additions & 0 deletions libs/MeshKernel/src/CurvilinearGrid/CurvilinearGrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,60 @@ CurvilinearGrid::CurvilinearGrid(lin_alg::Matrix<Point>&& grid, Projection proje
SetGridNodes(std::move(grid));
}

CurvilinearGrid& CurvilinearGrid::operator=(CurvilinearGrid&& copy) noexcept
{
if (this != &copy)
{
m_gridNodes = std::move(copy.m_gridNodes);
m_gridFacesMask = std::move(copy.m_gridFacesMask);
m_gridNodesTypes = std::move(copy.m_gridNodesTypes);
m_gridIndices = std::move(copy.m_gridIndices);
m_RTrees = std::move(copy.m_RTrees);
m_edges = std::move(copy.m_edges);

m_projection = std::exchange(copy.m_projection, Projection::cartesian);
m_nodesRTreeRequiresUpdate = std::exchange(copy.m_nodesRTreeRequiresUpdate, false);
m_edgesRTreeRequiresUpdate = std::exchange(copy.m_edgesRTreeRequiresUpdate, false);
m_facesRTreeRequiresUpdate = std::exchange(copy.m_facesRTreeRequiresUpdate, false);
m_boundingBoxCache = std::exchange(copy.m_boundingBoxCache, BoundingBox());
m_startOffset = std::exchange(copy.m_startOffset, CurvilinearGridNodeIndices(0, 0));
m_endOffset = std::exchange(copy.m_endOffset, CurvilinearGridNodeIndices(0, 0));
}

return *this;
}

CurvilinearGrid& CurvilinearGrid::operator=(const CurvilinearGrid& copy)
{
if (this != &copy)
{
m_projection = copy.m_projection;
m_gridNodes = copy.m_gridNodes;
m_gridFacesMask = copy.m_gridFacesMask;
m_gridNodesTypes = copy.m_gridNodesTypes;
m_gridIndices = copy.m_gridIndices;

m_nodesRTreeRequiresUpdate = true;
m_edgesRTreeRequiresUpdate = true;
m_facesRTreeRequiresUpdate = true;

m_RTrees.emplace(Location::Nodes, RTreeFactory::Create(m_projection));
m_RTrees.emplace(Location::Edges, RTreeFactory::Create(m_projection));
m_RTrees.emplace(Location::Faces, RTreeFactory::Create(m_projection));

m_boundingBoxCache = copy.m_boundingBoxCache;

m_edges = copy.m_edges;

m_startOffset = copy.m_startOffset;
m_endOffset = copy.m_endOffset;

SetGridNodes(m_gridNodes);
}

return *this;
}

void CurvilinearGrid::SetGridNodes(const lin_alg::Matrix<Point>& gridNodes)
{
if (gridNodes.rows() <= 1 || gridNodes.cols() <= 1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ std::unique_ptr<meshkernel::CurvilinearGridBlockUndoAction> meshkernel::Curvilin
return std::make_unique<CurvilinearGridBlockUndoAction>(grid, startOffset, endOffset);
}

std::unique_ptr<meshkernel::CurvilinearGridBlockUndoAction> meshkernel::CurvilinearGridBlockUndoAction::Create(CurvilinearGrid& grid)
{
return std::make_unique<CurvilinearGridBlockUndoAction>(grid,
CurvilinearGridNodeIndices(0, 0),
CurvilinearGridNodeIndices(grid.NumN() - 1, grid.NumM() - 1));
}

meshkernel::CurvilinearGridBlockUndoAction::CurvilinearGridBlockUndoAction(CurvilinearGrid& grid,
const CurvilinearGridNodeIndices& startOffset,
const CurvilinearGridNodeIndices& endOffset)
Expand Down
7 changes: 7 additions & 0 deletions libs/MeshKernel/src/Mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1011,6 +1011,13 @@ Mesh& Mesh::operator+=(Mesh const& rhs)
return *this;
}

std::unique_ptr<meshkernel::UndoAction> Mesh::Join(const Mesh& rhs)
{
std::unique_ptr<FullUnstructuredGridUndo> joinAction = FullUnstructuredGridUndo::Create(*this);
*this += rhs;
return joinAction;
}

meshkernel::UInt Mesh::GetNumValidNodes() const
{
return static_cast<UInt>(std::ranges::count_if(m_nodes, [](const Point& p)
Expand Down
Loading
Loading