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.org/sumo
3 // Copyright (C) 2001-2020 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, FXCommand, nullptr, 0)
29 
30 // ===========================================================================
31 // member method definitions
32 // ===========================================================================
33 
34 GNEChange::GNEChange(bool forward, const bool selectedElement) :
35  myForward(forward),
36  mySelectedElement(selectedElement) {}
37 
38 
39 GNEChange::GNEChange(GNEHierarchicalElement* hierarchicalElement, bool forward, const bool selectedElement) :
40  myForward(forward),
41  mySelectedElement(selectedElement),
42  myOriginalHierarchicalContainer(hierarchicalElement->getHierarchicalContainer()) {
43  // get all hierarchical elements (Parents and children)
44  const auto hierarchicalElements = hierarchicalElement->getAllHierarchicalElements();
45  // save all hierarchical containers
46  for (const auto& element : hierarchicalElements) {
47  myHierarchicalContainers[element] = element->getHierarchicalContainer();
48  }
49 }
50 
51 
53 
54 
55 FXuint
56 GNEChange::size() const {
57  return 1;
58 }
59 
60 
61 FXString
63  return "Undo";
64 }
65 
66 
67 FXString
69  return "Redo";
70 }
71 
72 
73 void
75 
76 
77 void
79 
80 
81 void
83  // iterate over all parents and children container and restore it
84  for (const auto& container : myHierarchicalContainers) {
85  container.first->restoreHierarchicalContainer(container.second);
86  }
87 }
88 
89 /****************************************************************************/
the function-object for an editing operation (abstract base)
Definition: GNEChange.h:65
virtual FXString redoName() const
return rendoName
Definition: GNEChange.cpp:68
virtual void undo()
undo action/operation
Definition: GNEChange.cpp:74
std::map< GNEHierarchicalElement *, GNEHierarchicalContainer > myHierarchicalContainers
map with hierarchical container of all parent and children elements
Definition: GNEChange.h:224
virtual FXuint size() const
return actual size
Definition: GNEChange.cpp:56
virtual FXString undoName() const
return undoName
Definition: GNEChange.cpp:62
~GNEChange()
Destructor.
Definition: GNEChange.cpp:52
GNEChange(bool forward, const bool selectedElement)
Constructor.
Definition: GNEChange.cpp:34
virtual void redo()
redo action/operation
Definition: GNEChange.cpp:78
void restoreHierarchicalContainers()
restore container (only use in undo() function)
Definition: GNEChange.cpp:82
std::vector< GNEHierarchicalElement * > getAllHierarchicalElements() const
get all parents and children