Eclipse SUMO - Simulation of Urban MObility
GNEChange.cpp
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 
22 #include "GNEChange.h"
23 
24 // ===========================================================================
25 // FOX-declarations
26 // ===========================================================================
27 
28 FXIMPLEMENT_ABSTRACT(GNEChange, FXObject, nullptr, 0)
29 
30 // ===========================================================================
31 // member method definitions
32 // ===========================================================================
33 
34 GNEChange::GNEChange(Supermode supermode, bool forward, const bool selectedElement) :
35  mySupermode(supermode),
36  myForward(forward),
37  mySelectedElement(selectedElement),
38  next(nullptr) {
39 }
40 
41 
42 GNEChange::GNEChange(Supermode supermode, GNEHierarchicalElement* hierarchicalElement, bool forward, const bool selectedElement) :
43  mySupermode(supermode),
44  myForward(forward),
45  mySelectedElement(selectedElement),
46  myOriginalHierarchicalContainer(hierarchicalElement->getHierarchicalContainer()),
47  next(nullptr) {
48  // get all hierarchical elements (Parents and children)
49  const auto hierarchicalElements = hierarchicalElement->getAllHierarchicalElements();
50  // save all hierarchical containers
51  for (const auto& element : hierarchicalElements) {
52  myHierarchicalContainers[element] = element->getHierarchicalContainer();
53  }
54 }
55 
56 
58 
59 
60 int
61 GNEChange::size() const {
62  // by default, 1
63  return 1;
64 }
65 
66 
69  return mySupermode;
70 }
71 
72 
73 bool
75  return false;
76 }
77 
78 
79 bool
81  return false;
82 }
83 
84 
86  mySupermode(Supermode::NETWORK),
87  myForward(false),
88  mySelectedElement(false),
89  next(nullptr) {
90 }
91 
92 
93 void
95  // iterate over all parents and children container and restore it
96  for (const auto& container : myHierarchicalContainers) {
97  container.first->restoreHierarchicalContainer(container.second);
98  }
99 }
100 
101 /****************************************************************************/
Supermode
@brie enum for supermodes
@ NETWORK
Network mode (Edges, junctions, etc..)
the function-object for an editing operation (abstract base)
Definition: GNEChange.h:56
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
Supermode getSupermode() const
get supermode
Definition: GNEChange.cpp:68
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
~GNEChange()
Destructor.
Definition: GNEChange.cpp:57
const Supermode mySupermode
supermode related with this change
Definition: GNEChange.h:209
void restoreHierarchicalContainers()
restore container (only use in undo() function)
Definition: GNEChange.cpp:94
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
std::vector< GNEHierarchicalElement * > getAllHierarchicalElements() const
get all parents and children