Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GNEChangeGroup.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2006-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//
19/****************************************************************************/
20
21// ===========================================================================
22// included modules
23// ===========================================================================
24
25#include "GNEChangeGroup.h"
26
27
28// ===========================================================================
29// FOX-declarations
30// ===========================================================================
31
32
33// Object implementation
34FXIMPLEMENT(GNEChangeGroup, GNEChange, nullptr, 0)
35
36// ---------------------------------------------------------------------------
37// GNEChangeGroup - methods
38// ---------------------------------------------------------------------------
39
40GNEChangeGroup::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 // get current time
48 const auto time = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
49 // extract localTime
50 const auto local_time = *localtime(&time);
51 // convert localtime to HH:MM:SS
52 myTimeStamp = toString(local_time.tm_hour) + ":" +
53 ((local_time.tm_min <= 9) ? "0" : "") + toString(local_time.tm_min) + ":" +
54 ((local_time.tm_sec <= 9) ? "0" : "") + toString(local_time.tm_sec);
55}
56
57
59 GNEChange* change = nullptr;
60 while (redoList) {
61 change = redoList;
63 delete change;
64 }
65 while (undoList) {
66 change = undoList;
68 delete change;
69 }
70 delete group;
71}
72
73
74const std::string&
78
79
80const std::string&
84
85
90
91
94 return myIcon;
95}
96
97
98std::string
100 return (TL("Undo") + std::string(" ") + myDescription);
101}
102
103
104std::string
106 return (TL("Redo") + std::string(" ") + myDescription);
107}
108
109
110bool
112 return (undoList == nullptr);
113}
114
115
116void
118 GNEChange* change = nullptr;
119 while (undoList) {
120 change = undoList;
122 change->undo();
123 change->next = redoList;
124 redoList = change;
125 }
126}
127
128
129void
131 GNEChange* change = nullptr;
132 while (redoList) {
133 change = redoList;
135 change->redo();
136 change->next = undoList;
137 undoList = change;
138 }
139}
140
141
142int
144 FXuint result = sizeof(GNEChangeGroup);
145 GNEChange* change;
146 for (change = undoList; change; change = change->next) {
147 result += change->size();
148 }
149 for (change = redoList; change; change = change->next) {
150 result += change->size();
151 }
152 return result;
153}
154
155
157 myGroupSupermode(Supermode::NETWORK),
158 myIcon(GUIIcon::UNDO),
159 undoList(nullptr),
160 redoList(nullptr),
161 group(nullptr)
162{ }
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
#define TL(string)
Definition MsgHandler.h:315
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:46
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
const std::string & getTimeStamp()
get timeStamp
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.
const GUIIcon myIcon
icon associated with this ChangeGroup
std::string redoName() const
get redo name
bool empty() const
Return TRUE if empty.
std::string myTimeStamp
timeStamp HH:MM:SS
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:56
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:225
Definition json.hpp:4471