Eclipse SUMO - Simulation of Urban MObility
GNEChangeGroup.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2006-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 //
19 /****************************************************************************/
20 
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 
25 #include "GNEChangeGroup.h"
26 
27 
28 // ===========================================================================
29 // FOX-declarations
30 // ===========================================================================
31 
32 
33 // Object implementation
34 FXIMPLEMENT(GNEChangeGroup, GNEChange, nullptr, 0)
35 
36 // ---------------------------------------------------------------------------
37 // GNEChangeGroup - methods
38 // ---------------------------------------------------------------------------
39 
40 GNEChangeGroup::GNEChangeGroup(Supermode groupSupermode, GUIIcon icon, const std::string& description) :
41  myDescription(description),
42  myGroupSupermode(groupSupermode),
43  myIcon(icon),
44  undoList(nullptr),
45  redoList(nullptr),
46  group(nullptr) {
47 }
48 
49 
51  GNEChange* change = nullptr;
52  while (redoList) {
53  change = redoList;
55  delete change;
56  }
57  while (undoList) {
58  change = undoList;
60  delete change;
61  }
62  delete group;
63 }
64 
65 
66 const std::string&
68  return myDescription;
69 }
70 
71 
74  return myGroupSupermode;
75 }
76 
77 
78 GUIIcon
80  return myIcon;
81 }
82 
83 
84 std::string
86  return ("Undo " + myDescription);
87 }
88 
89 
90 std::string
92  return ("Redo " + myDescription);
93 }
94 
95 
96 bool
98  return (undoList == nullptr);
99 }
100 
101 
102 void
104  GNEChange* change = nullptr;
105  while (undoList) {
106  change = undoList;
108  change->undo();
109  change->next = redoList;
110  redoList = change;
111  }
112 }
113 
114 
115 void
117  GNEChange* change = nullptr;
118  while (redoList) {
119  change = redoList;
121  change->redo();
122  change->next = undoList;
123  undoList = change;
124  }
125 }
126 
127 
128 int
130  FXuint result = sizeof(GNEChangeGroup);
131  GNEChange* change;
132  for (change = undoList; change; change = change->next) {
133  result += change->size();
134  }
135  for (change = redoList; change; change = change->next) {
136  result += change->size();
137  }
138  return result;
139 }
140 
141 
143  myGroupSupermode(Supermode::NETWORK),
144  undoList(nullptr),
145  redoList(nullptr),
146  group(nullptr)
147 { }
Supermode
@brie enum for supermodes
@ NETWORK
Network mode (Edges, junctions, etc..)
GUIIcon
An enumeration of icons used by the gui applications.
Definition: GUIIcons.h:33
GNEChange * undoList
undo list command (can be access by GNEUndoList)
const std::string myDescription
description of command
const Supermode myGroupSupermode
supermode associated with this ChangeGroup
GUIIcon getGroupIcon() const
get icon associated with this ChangeGroup
std::string undoName() const
get undo Name
GNEChange * redoList
redo list command (can be access by GNEUndoList)
GNEChangeGroup * group
group (can be access by GNEUndoList)
int size() const
Return the size of the command group.
std::string redoName() const
get redo name
bool empty() const
Return TRUE if empty.
GUIIcon myIcon
icon associated with this ChangeGroup
const std::string & getDescription()
get description
Supermode getGroupSupermode() const
get supermode associated with this ChangeGroup
void redo()
Redo whole command group.
void undo()
Undo whole command group.
GNEChangeGroup()
FOX need this.
~GNEChangeGroup()
Delete undo command and sub-commands.
the function-object for an editing operation (abstract base)
Definition: GNEChange.h:64
virtual void redo()=0
redo action/operation
virtual int size() const
Return the size of the command group.
Definition: GNEChange.cpp:61
virtual void undo()=0
undo action/operation
GNEChange * next
Definition: GNEChange.h:257