Eclipse SUMO - Simulation of Urban MObility
GNEChange.h
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3// Copyright (C) 2001-2022 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 GNEAdditional;
44class GNEDataSet;
46class GNEGenericData;
47class GNEDataInterval;
48class GNEEdge;
49class GNELane;
50class GNENet;
51class GNEViewNet;
52
53// ===========================================================================
54// class definitions
55// ===========================================================================
60class GNEChange : public FXObject {
61 FXDECLARE_ABSTRACT(GNEChange)
62
63public:
65 friend class GNEChangeGroup;
66 friend class GNEUndoList;
67
73 GNEChange(Supermode supermode, bool forward, const bool selectedElement);
74
81 GNEChange(Supermode supermode, GNEHierarchicalElement* element, bool forward, const bool selectedElement);
82
84 ~GNEChange();
85
87 virtual void undo() = 0;
88
90 virtual void redo() = 0;
91
93 virtual std::string undoName() const = 0;
94
96 virtual std::string redoName() const = 0;
97
99 virtual int size() const;
100
102 Supermode getSupermode() const;
103
110 bool canMerge() const;
111
117 bool mergeWith(GNEChange* command);
118
119protected:
121 GNEChange();
122
125
127 template<typename T>
129 // add element in parents
130 for (const auto& junction : myOriginalHierarchicalContainer.getParents<std::vector<GNEJunction*> >()) {
131 junction->addChildElement(element);
132 }
133 for (const auto& edge : myOriginalHierarchicalContainer.getParents<std::vector<GNEEdge*> >()) {
134 edge->addChildElement(element);
135 }
136 for (const auto& lane : myOriginalHierarchicalContainer.getParents<std::vector<GNELane*> >()) {
137 lane->addChildElement(element);
138 }
139 for (const auto& additional : myOriginalHierarchicalContainer.getParents<std::vector<GNEAdditional*> >()) {
140 additional->addChildElement(element);
141 }
142 for (const auto& demandElement : myOriginalHierarchicalContainer.getParents<std::vector<GNEDemandElement*> >()) {
143 demandElement->addChildElement(element);
144 }
145 for (const auto& genericData : myOriginalHierarchicalContainer.getParents<std::vector<GNEGenericData*> >()) {
146 genericData->addChildElement(element);
147 }
148 // add element in children
149 for (const auto& junction : myOriginalHierarchicalContainer.getChildren<std::vector<GNEJunction*> >()) {
150 junction->addParentElement(element);
151 }
152 for (const auto& edge : myOriginalHierarchicalContainer.getChildren<std::vector<GNEEdge*> >()) {
153 edge->addParentElement(element);
154 }
155 for (const auto& lane : myOriginalHierarchicalContainer.getChildren<std::vector<GNELane*> >()) {
156 lane->addParentElement(element);
157 }
158 for (const auto& additional : myOriginalHierarchicalContainer.getChildren<std::vector<GNEAdditional*> >()) {
159 additional->addParentElement(element);
160 }
161 for (const auto& demandElement : myOriginalHierarchicalContainer.getChildren<std::vector<GNEDemandElement*> >()) {
162 demandElement->addParentElement(element);
163 }
164 for (const auto& genericData : myOriginalHierarchicalContainer.getChildren<std::vector<GNEGenericData*> >()) {
165 genericData->addParentElement(element);
166 }
167 }
168
170 template<typename T>
172 // Remove element from parents
173 for (const auto& junction : myOriginalHierarchicalContainer.getParents<std::vector<GNEJunction*> >()) {
174 junction->removeChildElement(element);
175 }
176 for (const auto& edge : myOriginalHierarchicalContainer.getParents<std::vector<GNEEdge*> >()) {
177 edge->removeChildElement(element);
178 }
179 for (const auto& lane : myOriginalHierarchicalContainer.getParents<std::vector<GNELane*> >()) {
180 lane->removeChildElement(element);
181 }
182 for (const auto& additional : myOriginalHierarchicalContainer.getParents<std::vector<GNEAdditional*> >()) {
183 additional->removeChildElement(element);
184 }
185 for (const auto& demandElement : myOriginalHierarchicalContainer.getParents<std::vector<GNEDemandElement*> >()) {
186 demandElement->removeChildElement(element);
187 }
188 for (const auto& genericData : myOriginalHierarchicalContainer.getParents<std::vector<GNEGenericData*> >()) {
189 genericData->removeChildElement(element);
190 }
191 // Remove element from children
192 for (const auto& junction : myOriginalHierarchicalContainer.getChildren<std::vector<GNEJunction*> >()) {
193 junction->removeParentElement(element);
194 }
195 for (const auto& edge : myOriginalHierarchicalContainer.getChildren<std::vector<GNEEdge*> >()) {
196 edge->removeParentElement(element);
197 }
198 for (const auto& lane : myOriginalHierarchicalContainer.getChildren<std::vector<GNELane*> >()) {
199 lane->removeParentElement(element);
200 }
201 for (const auto& additional : myOriginalHierarchicalContainer.getChildren<std::vector<GNEAdditional*> >()) {
202 additional->removeParentElement(element);
203 }
204 for (const auto& demandElement : myOriginalHierarchicalContainer.getChildren<std::vector<GNEDemandElement*> >()) {
205 demandElement->removeParentElement(element);
206 }
207 for (const auto& genericData : myOriginalHierarchicalContainer.getChildren<std::vector<GNEGenericData*> >()) {
208 genericData->removeParentElement(element);
209 }
210 }
211
214
217
220
223
225 std::map<GNEHierarchicalElement*, GNEHierarchicalContainer> myHierarchicalContainers;
226
227private:
228 // @brief next GNEChange (can be access by GNEChangeGroup and GNEUndoList)
230
232 GNEChange(const GNEChange&) = delete;
233
235 GNEChange& operator=(const GNEChange&) = delete;
236};
Supermode
@brie enum for supermodes
An Element which don't belong to GNENet but has influence in the simulation.
Definition: GNEAdditional.h:48
the function-object for an editing operation (abstract base)
Definition: GNEChange.h:60
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:225
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:216
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:219
void addElementInParentsAndChildren(T *element)
add given element into parents and children (only use in redo() function)
Definition: GNEChange.h:128
~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:171
const Supermode mySupermode
supermode related with this change
Definition: GNEChange.h:213
virtual std::string redoName() const =0
return rendoName
GNEChange * next
Definition: GNEChange.h:229
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:222
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.
An Element which don't belong to GNENet but has influence in the simulation.
A road/street connecting two junctions (netedit-version)
Definition: GNEEdge.h:53
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
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