Loading [MathJax]/extensions/tex2jax.js
MeshKernel
All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages Concepts
CurvilinearFrozenLinesAddUndoAction.hpp
1//---- GPL ---------------------------------------------------------------------
2//
3// Copyright (C) Stichting Deltares, 2011-2024.
4//
5// This program is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation version 3.
8//
9// This program is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with this program. If not, see <http://www.gnu.org/licenses/>.
16//
17// contact: delft3d.support@deltares.nl
18// Stichting Deltares
19// P.O. Box 177
20// 2600 MH Delft, The Netherlands
21//
22// All indications and logos of, and references to, "Delft3D" and "Deltares"
23// are registered trademarks of Stichting Deltares, and remain the property of
24// Stichting Deltares. All rights reserved.
25//
26//------------------------------------------------------------------------------
27
28#pragma once
29
30#include <memory>
31
32#include "MeshKernel/UndoActions/UndoAction.hpp"
33#include "MeshKernelApi/State.hpp"
34
35namespace meshkernelapi
36{
37
39 class CurvilinearFrozenLinesAddUndoAction : public meshkernel::UndoAction
40 {
41 public:
46 int frozenLineId,
47 const std::pair<meshkernel::Point, meshkernel::Point>& frozenLinePoints) : m_mkStateReference(mkState),
48 m_frozenLinesCounter(frozenLineId),
49 m_frozenLinePoints(frozenLinePoints)
50 {
51 }
52
53 private:
55 void DoCommit() override
56 {
57 if (m_mkStateReference.m_frozenLines.contains(m_frozenLinesCounter))
58 {
59 throw meshkernel::MeshKernelError("Frozen line counter in meshkernel state should not exist when committing an addition of a frozen line");
60 }
61 m_mkStateReference.m_frozenLines[m_frozenLinesCounter] = m_frozenLinePoints;
62 }
63
65 void DoRestore() override
66 {
67 if (!m_mkStateReference.m_frozenLines.contains(m_frozenLinesCounter))
68 {
69 throw meshkernel::MeshKernelError("Frozen line counter in meshkernel state should not exist when restoring an addition of a frozen line");
70 }
71
72 m_mkStateReference.m_frozenLines.erase(m_frozenLinesCounter);
73 }
74
76 MeshKernelState& m_mkStateReference;
77
79 int m_frozenLinesCounter;
80
82 std::pair<meshkernel::Point, meshkernel::Point> m_frozenLinePoints;
83 };
84
85} // namespace meshkernelapi
A class for throwing general MeshKernel exceptions.
Definition Exceptions.hpp:142
Undo action for adding frozen lines.
Definition CurvilinearFrozenLinesAddUndoAction.hpp:40
CurvilinearFrozenLinesAddUndoAction(MeshKernelState &mkState, int frozenLineId, const std::pair< meshkernel::Point, meshkernel::Point > &frozenLinePoints)
Constructor.
Definition CurvilinearFrozenLinesAddUndoAction.hpp:45
Contains all structs and functions exposed at the API level.
Definition BoundingBox.hpp:33
The class holding the state of the C API library.
Definition State.hpp:56
std::unordered_map< meshkernel::UInt, std::pair< meshkernel::Point, meshkernel::Point > > m_frozenLines
Map for string the frozen lines.
Definition State.hpp:83