Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netedit/changes/GNEChangeGroup.cpp
169678 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2006-2025 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
/****************************************************************************/
14
/// @file GNEChangeGroup.cpp
15
/// @author Pablo Alvarez Lopez
16
/// @date Sep 2021
17
///
18
//
19
/****************************************************************************/
20
21
#include "GNEChangeGroup.h"
22
23
// ===========================================================================
24
// FOX-declarations
25
// ===========================================================================
26
27
// Object implementation
28
FXIMPLEMENT(GNEChangeGroup, GNEChange, nullptr, 0)
29
30
// ---------------------------------------------------------------------------
31
// GNEChangeGroup - methods
32
// ---------------------------------------------------------------------------
33
34
GNEChangeGroup::GNEChangeGroup(Supermode groupSupermode, GUIIcon icon, const std::string& description) :
35
myDescription(description),
36
myGroupSupermode(groupSupermode),
37
myIcon(icon),
38
undoList(nullptr),
39
redoList(nullptr),
40
group(nullptr) {
41
// get current time
42
const auto time = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
43
// extract localTime
44
const auto local_time = *localtime(&time);
45
// convert localtime to HH:MM:SS
46
myTimeStamp = toString(local_time.tm_hour) + ":" +
47
((local_time.tm_min <= 9) ? "0" : "") + toString(local_time.tm_min) + ":" +
48
((local_time.tm_sec <= 9) ? "0" : "") + toString(local_time.tm_sec);
49
}
50
51
52
GNEChangeGroup::~GNEChangeGroup() {
53
GNEChange* change = nullptr;
54
while (redoList) {
55
change = redoList;
56
redoList = redoList->next;
57
delete change;
58
}
59
while (undoList) {
60
change = undoList;
61
undoList = undoList->next;
62
delete change;
63
}
64
delete group;
65
}
66
67
68
const std::string&
69
GNEChangeGroup::getDescription() {
70
return myDescription;
71
}
72
73
74
const std::string&
75
GNEChangeGroup::getTimeStamp() {
76
return myTimeStamp;
77
}
78
79
80
Supermode
81
GNEChangeGroup::getGroupSupermode() const {
82
return myGroupSupermode;
83
}
84
85
86
GUIIcon
87
GNEChangeGroup::getGroupIcon() const {
88
return myIcon;
89
}
90
91
92
std::string
93
GNEChangeGroup::undoName() const {
94
return (TL("Undo") + std::string(" ") + myDescription);
95
}
96
97
98
std::string
99
GNEChangeGroup::redoName() const {
100
return (TL("Redo") + std::string(" ") + myDescription);
101
}
102
103
104
bool
105
GNEChangeGroup::empty() const {
106
return (undoList == nullptr);
107
}
108
109
110
void
111
GNEChangeGroup::undo() {
112
GNEChange* change = nullptr;
113
while (undoList) {
114
change = undoList;
115
undoList = undoList->next;
116
change->undo();
117
change->next = redoList;
118
redoList = change;
119
}
120
}
121
122
123
void
124
GNEChangeGroup::redo() {
125
GNEChange* change = nullptr;
126
while (redoList) {
127
change = redoList;
128
redoList = redoList->next;
129
change->redo();
130
change->next = undoList;
131
undoList = change;
132
}
133
}
134
135
136
int
137
GNEChangeGroup::size() const {
138
FXuint result = sizeof(GNEChangeGroup);
139
GNEChange* change;
140
for (change = undoList; change; change = change->next) {
141
result += change->size();
142
}
143
for (change = redoList; change; change = change->next) {
144
result += change->size();
145
}
146
return result;
147
}
148
149
150
GNEChangeGroup::GNEChangeGroup() :
151
myGroupSupermode(Supermode::NETWORK),
152
myIcon(GUIIcon::UNDO),
153
undoList(nullptr),
154
redoList(nullptr),
155
group(nullptr)
156
{ }
157
158