Eclipse SUMO - Simulation of Urban MObility
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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-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/****************************************************************************/
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>
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
120 template<typename T>
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*>()) {
128 }
129 for (const auto& lane : myParents.get<GNELane*>()) {
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
147 template<typename T>
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*>()) {
155 }
156 for (const auto& lane : myParents.get<GNELane*>()) {
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
175
178
181
184
185private:
186 // @brief next GNEChange (can be access by GNEChangeGroup and GNEUndoList)
188
190 GNEChange(const GNEChange&) = delete;
191
193 GNEChange& operator=(const GNEChange&) = delete;
194};
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
virtual int size() const
Return the size of the command group.
Definition GNEChange.cpp:59
bool myForward
we group antagonistic commands (create junction/delete junction) and keep them apart by this flag
Definition GNEChange.h:180
virtual void undo()=0
undo action/operation
Supermode getSupermode() const
get supermode
Definition GNEChange.cpp:66
GNEChange(const GNEChange &)=delete
Invalidated copy constructor.
GNEChange()
FOX need this.
Definition GNEChange.cpp:83
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:78
const bool mySelectedElement
flag for check if element is selected
Definition GNEChange.h:183
void addElementInParentsAndChildren(T *element)
add given element in parents and children
Definition GNEChange.h:121
~GNEChange()
Destructor.
Definition GNEChange.cpp:55
GNEChange & operator=(const GNEChange &)=delete
Invalidated assignment operator.
void removeElementFromParentsAndChildren(T *element)
remove given element from parents and children
Definition GNEChange.h:148
const Supermode mySupermode
supermode related with this change
Definition GNEChange.h:174
const GNEHierarchicalStructureParents myParents
Hierarchical container with parents.
Definition GNEChange.h:177
virtual std::string redoName() const =0
return redoName
GNEChange * next
Definition GNEChange.h:187
virtual std::string undoName() const =0
return undoName
bool canMerge() const
Return TRUE if this command can be merged with previous undo commands. This is useful to combine e....
Definition GNEChange.cpp:72
A road/street connecting two junctions (netedit-version)
Definition GNEEdge.h:53
static void insertChild(ElementType element, ChildType child)
insert child element
static void removeChild(ElementType element, ChildType child)
remove child element
Hierarchical structure used for keep parents.
const GNEHierarchicalContainerParents< ParentType > & get() const
get parents
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
Definition GNELane.h:46
A NBNetBuilder extended by visualisation and editing capabilities.
Definition GNENet.h:42