Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netedit/changes/GNEChange.h
169678 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2001-2025 German Aerospace Center (DLR) and others.
4
// This program and the accompanying materials are made available under the
5
// terms of the Eclipse Public License 2.0 which is available at
6
// https://www.eclipse.org/legal/epl-2.0/
7
// This Source Code may also be made available under the following Secondary
8
// Licenses when the conditions for such availability set forth in the Eclipse
9
// Public License 2.0 are satisfied: GNU General Public License, version 2
10
// or later which is available at
11
// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13
/****************************************************************************/
14
/// @file GNEChange.h
15
/// @author Jakob Erdmann
16
/// @date Mar 2011
17
///
18
// The reification of a netedit editing operation (see command pattern)
19
// inherits from FXCommand and is used to for undo/redo
20
/****************************************************************************/
21
#pragma once
22
#include <config.h>
23
24
#include <netbuild/NBEdge.h>
25
#include <netbuild/NBNode.h>
26
#include <netedit/GNEViewNet.h>
27
#include <netedit/elements/GNEHierarchicalStructureParents.h>
28
#include <netedit/elements/additional/GNETAZSourceSink.h>
29
#include <netedit/elements/data/GNEGenericData.h>
30
#include <netedit/elements/demand/GNEDemandElement.h>
31
#include <netedit/elements/network/GNEEdge.h>
32
#include <netedit/elements/network/GNEJunction.h>
33
#include <netedit/elements/network/GNELane.h>
34
#include <utils/foxtools/fxheader.h>
35
#include <utils/geom/PositionVector.h>
36
#include <utils/xml/SUMOXMLDefinitions.h>
37
38
// ===========================================================================
39
// class declarations
40
// ===========================================================================
41
class GNEHierarchicalElement;
42
class GNEAttributeCarrier;
43
class GNEDataSet;
44
class GNEDataInterval;
45
class GNEMeanData;
46
class GNENet;
47
class GNEViewNet;
48
49
// ===========================================================================
50
// class definitions
51
// ===========================================================================
52
/**
53
* @class GNEChange
54
* @brief the function-object for an editing operation (abstract base)
55
*/
56
class GNEChange : public FXObject {
57
FXDECLARE_ABSTRACT(GNEChange)
58
59
public:
60
/// @name friend class
61
friend class GNEChangeGroup;
62
friend class GNEUndoList;
63
64
/**@brief Constructor
65
* @param[in] supermode related with this change
66
* @param[in] forward The direction of this change
67
* @param[in] selectedElement flag to mark if element is selected
68
*/
69
GNEChange(Supermode supermode, bool forward, const bool selectedElement);
70
71
/**@brief Constructor
72
* @param[in] supermode related with this change
73
* @param[in] element hierarchical element
74
* @param[in] forward The direction of this change
75
* @param[in] selectedElement flag to mark if element is selected
76
*/
77
GNEChange(Supermode supermode, GNEHierarchicalElement* element, bool forward, const bool selectedElement);
78
79
/// @brief Destructor
80
~GNEChange();
81
82
/// @brief undo action/operation
83
virtual void undo() = 0;
84
85
/// @brief redo action/operation
86
virtual void redo() = 0;
87
88
/// @brief return undoName
89
virtual std::string undoName() const = 0;
90
91
/// @brief return redoName
92
virtual std::string redoName() const = 0;
93
94
/// @brief Return the size of the command group
95
virtual int size() const;
96
97
/// @brief get supermode
98
Supermode getSupermode() const;
99
100
/**
101
* @brief Return TRUE if this command can be merged with previous undo
102
* commands. This is useful to combine e.g. multiple consecutive
103
* single-character text changes into a single block change.
104
* The default implementation returns FALSE.
105
*/
106
bool canMerge() const;
107
108
/**
109
* @brief Called by the undo system to try and merge the new incoming command
110
* with this command; should return TRUE if merging was possible.
111
* The default implementation returns FALSE.
112
*/
113
bool mergeWith(GNEChange* command);
114
115
protected:
116
/// @brief FOX need this
117
GNEChange();
118
119
/// @brief add given element in parents and children
120
template<typename T>
121
void addElementInParentsAndChildren(T* element) {
122
// add element in children
123
for (const auto& junction : myParents.get<GNEJunction*>()) {
124
GNEHierarchicalElement::insertChild(junction, element);
125
}
126
for (const auto& edge : myParents.get<GNEEdge*>()) {
127
GNEHierarchicalElement::insertChild(edge, element);
128
}
129
for (const auto& lane : myParents.get<GNELane*>()) {
130
GNEHierarchicalElement::insertChild(lane, element);
131
}
132
for (const auto& additional : myParents.get<GNEAdditional*>()) {
133
GNEHierarchicalElement::insertChild(additional, element);
134
}
135
for (const auto& sourceSink : myParents.get<GNETAZSourceSink*>()) {
136
GNEHierarchicalElement::insertChild(sourceSink, element);
137
}
138
for (const auto& demandElement : myParents.get<GNEDemandElement*>()) {
139
GNEHierarchicalElement::insertChild(demandElement, element);
140
}
141
for (const auto& genericData : myParents.get<GNEGenericData*>()) {
142
GNEHierarchicalElement::insertChild(genericData, element);
143
}
144
}
145
146
/// @brief remove given element from parents and children
147
template<typename T>
148
void removeElementFromParentsAndChildren(T* element) {
149
// Remove element from parents
150
for (const auto& junction : myParents.get<GNEJunction*>()) {
151
GNEHierarchicalElement::removeChild(junction, element);
152
}
153
for (const auto& edge : myParents.get<GNEEdge*>()) {
154
GNEHierarchicalElement::removeChild(edge, element);
155
}
156
for (const auto& lane : myParents.get<GNELane*>()) {
157
GNEHierarchicalElement::removeChild(lane, element);
158
}
159
for (const auto& additional : myParents.get<GNEAdditional*>()) {
160
GNEHierarchicalElement::removeChild(additional, element);
161
}
162
for (const auto& sourceSink : myParents.get<GNETAZSourceSink*>()) {
163
GNEHierarchicalElement::removeChild(sourceSink, element);
164
}
165
for (const auto& demandElement : myParents.get<GNEDemandElement*>()) {
166
GNEHierarchicalElement::removeChild(demandElement, element);
167
}
168
for (const auto& genericData : myParents.get<GNEGenericData*>()) {
169
GNEHierarchicalElement::removeChild(genericData, element);
170
}
171
}
172
173
/// @brief supermode related with this change
174
const Supermode mySupermode;
175
176
/// @brief Hierarchical container with parents
177
const GNEHierarchicalStructureParents myParents;
178
179
/// @brief we group antagonistic commands (create junction/delete junction) and keep them apart by this flag
180
bool myForward;
181
182
/// @brief flag for check if element is selected
183
const bool mySelectedElement;
184
185
private:
186
// @brief next GNEChange (can be access by GNEChangeGroup and GNEUndoList)
187
GNEChange* next;
188
189
/// @brief Invalidated copy constructor.
190
GNEChange(const GNEChange&) = delete;
191
192
/// @brief Invalidated assignment operator.
193
GNEChange& operator=(const GNEChange&) = delete;
194
};
195
196