Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GNEChange.h
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2001-2024 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/****************************************************************************/
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>
36
37
38// ===========================================================================
39// class declarations
40// ===========================================================================
43class GNEDataSet;
44class GNEDataInterval;
45class GNEMeanData;
46class GNENet;
47class GNEViewNet;
48
49// ===========================================================================
50// class definitions
51// ===========================================================================
56class GNEChange : public FXObject {
57 FXDECLARE_ABSTRACT(GNEChange)
58
59public:
61 friend class GNEChangeGroup;
62 friend class GNEUndoList;
63
69 GNEChange(Supermode supermode, bool forward, const bool selectedElement);
70
77 GNEChange(Supermode supermode, GNEHierarchicalElement* element, bool forward, const bool selectedElement);
78
80 ~GNEChange();
81
83 virtual void undo() = 0;
84
86 virtual void redo() = 0;
87
89 virtual std::string undoName() const = 0;
90
92 virtual std::string redoName() const = 0;
93
95 virtual int size() const;
96
98 Supermode getSupermode() const;
99
106 bool canMerge() const;
107
113 bool mergeWith(GNEChange* command);
114
115protected:
117 GNEChange();
118
121
123 template<typename T>
125 // add element in parents
126 for (const auto& junction : myOriginalHierarchicalContainer.getParents<std::vector<GNEJunction*> >()) {
127 junction->addChildElement(element);
128 }
129 for (const auto& edge : myOriginalHierarchicalContainer.getParents<std::vector<GNEEdge*> >()) {
130 edge->addChildElement(element);
131 }
132 for (const auto& lane : myOriginalHierarchicalContainer.getParents<std::vector<GNELane*> >()) {
133 lane->addChildElement(element);
134 }
135 for (const auto& additional : myOriginalHierarchicalContainer.getParents<std::vector<GNEAdditional*> >()) {
136 additional->addChildElement(element);
137 }
138 for (const auto& demandElement : myOriginalHierarchicalContainer.getParents<std::vector<GNEDemandElement*> >()) {
139 demandElement->addChildElement(element);
140 }
141 for (const auto& genericData : myOriginalHierarchicalContainer.getParents<std::vector<GNEGenericData*> >()) {
142 genericData->addChildElement(element);
143 }
144 // add element in children
145 for (const auto& junction : myOriginalHierarchicalContainer.getChildren<std::vector<GNEJunction*> >()) {
146 junction->addParentElement(element);
147 }
148 for (const auto& edge : myOriginalHierarchicalContainer.getChildren<std::vector<GNEEdge*> >()) {
149 edge->addParentElement(element);
150 }
151 for (const auto& lane : myOriginalHierarchicalContainer.getChildren<std::vector<GNELane*> >()) {
152 lane->addParentElement(element);
153 }
154 for (const auto& additional : myOriginalHierarchicalContainer.getChildren<std::vector<GNEAdditional*> >()) {
155 additional->addParentElement(element);
156 }
157 for (const auto& demandElement : myOriginalHierarchicalContainer.getChildren<std::vector<GNEDemandElement*> >()) {
158 demandElement->addParentElement(element);
159 }
160 for (const auto& genericData : myOriginalHierarchicalContainer.getChildren<std::vector<GNEGenericData*> >()) {
161 genericData->addParentElement(element);
162 }
163 }
164
166 template<typename T>
168 // Remove element from parents
169 for (const auto& junction : myOriginalHierarchicalContainer.getParents<std::vector<GNEJunction*> >()) {
170 junction->removeChildElement(element);
171 }
172 for (const auto& edge : myOriginalHierarchicalContainer.getParents<std::vector<GNEEdge*> >()) {
173 edge->removeChildElement(element);
174 }
175 for (const auto& lane : myOriginalHierarchicalContainer.getParents<std::vector<GNELane*> >()) {
176 lane->removeChildElement(element);
177 }
178 for (const auto& additional : myOriginalHierarchicalContainer.getParents<std::vector<GNEAdditional*> >()) {
179 additional->removeChildElement(element);
180 }
181 for (const auto& demandElement : myOriginalHierarchicalContainer.getParents<std::vector<GNEDemandElement*> >()) {
182 demandElement->removeChildElement(element);
183 }
184 for (const auto& genericData : myOriginalHierarchicalContainer.getParents<std::vector<GNEGenericData*> >()) {
185 genericData->removeChildElement(element);
186 }
187 // Remove element from children
188 for (const auto& junction : myOriginalHierarchicalContainer.getChildren<std::vector<GNEJunction*> >()) {
189 junction->removeParentElement(element);
190 }
191 for (const auto& edge : myOriginalHierarchicalContainer.getChildren<std::vector<GNEEdge*> >()) {
192 edge->removeParentElement(element);
193 }
194 for (const auto& lane : myOriginalHierarchicalContainer.getChildren<std::vector<GNELane*> >()) {
195 lane->removeParentElement(element);
196 }
197 for (const auto& additional : myOriginalHierarchicalContainer.getChildren<std::vector<GNEAdditional*> >()) {
198 additional->removeParentElement(element);
199 }
200 for (const auto& demandElement : myOriginalHierarchicalContainer.getChildren<std::vector<GNEDemandElement*> >()) {
201 demandElement->removeParentElement(element);
202 }
203 for (const auto& genericData : myOriginalHierarchicalContainer.getChildren<std::vector<GNEGenericData*> >()) {
204 genericData->removeParentElement(element);
205 }
206 }
207
210
213
216
219
221 std::map<GNEHierarchicalElement*, GNEHierarchicalContainer> myHierarchicalContainers;
222
223private:
224 // @brief next GNEChange (can be access by GNEChangeGroup and GNEUndoList)
226
228 GNEChange(const GNEChange&) = delete;
229
231 GNEChange& operator=(const GNEChange&) = delete;
232};
Supermode
@brie enum for supermodes
the function-object for an editing operation (abstract base)
Definition GNEChange.h:56
virtual void redo()=0
redo action/operation
std::map< GNEHierarchicalElement *, GNEHierarchicalContainer > myHierarchicalContainers
map with hierarchical container of all parent and children elements
Definition GNEChange.h:221
virtual int size() const
Return the size of the command group.
Definition GNEChange.cpp:61
bool myForward
we group antagonistic commands (create junction/delete junction) and keep them apart by this flag
Definition GNEChange.h:212
virtual void undo()=0
undo action/operation
Supermode getSupermode() const
get supermode
Definition GNEChange.cpp:68
GNEChange(const GNEChange &)=delete
Invalidated copy constructor.
GNEChange()
FOX need this.
Definition GNEChange.cpp:85
bool mergeWith(GNEChange *command)
Called by the undo system to try and merge the new incoming command with this command; should return ...
Definition GNEChange.cpp:80
const bool mySelectedElement
flag for check if element is selected
Definition GNEChange.h:215
void addElementInParentsAndChildren(T *element)
add given element into parents and children (only use in redo() function)
Definition GNEChange.h:124
~GNEChange()
Destructor.
Definition GNEChange.cpp:57
GNEChange & operator=(const GNEChange &)=delete
Invalidated assignment operator.
void removeElementFromParentsAndChildren(T *element)
remove given element from parents and children (only use in redo() function)
Definition GNEChange.h:167
const Supermode mySupermode
supermode related with this change
Definition GNEChange.h:209
virtual std::string redoName() const =0
return redoName
GNEChange * next
Definition GNEChange.h:225
virtual std::string undoName() const =0
return undoName
void restoreHierarchicalContainers()
restore container (only use in undo() function)
Definition GNEChange.cpp:94
const GNEHierarchicalContainer myOriginalHierarchicalContainer
Hierarchical container with parent and children.
Definition GNEChange.h:218
bool canMerge() const
Return TRUE if this command can be merged with previous undo commands. This is useful to combine e....
Definition GNEChange.cpp:74
An Element which don't belong to GNENet but has influence in the simulation.
Hierarchical container (used for keep myParent and myChildren.
const T & getChildren() const
get children
const T & getParents() const
get parents
An Element which don't belong to GNENet but has influence in the simulation.
Definition GNEMeanData.h:33
A NBNetBuilder extended by visualisation and editing capabilities.
Definition GNENet.h:42