Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netedit/elements/additional/GNERerouterInterval.cpp
193813 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2001-2026 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 GNERerouterInterval.cpp
15
/// @author Pablo Alvarez Lopez
16
/// @date Jan 2017
17
///
18
//
19
/****************************************************************************/
20
21
#include <netedit/GNENet.h>
22
#include <netedit/changes/GNEChange_Attribute.h>
23
24
#include "GNERerouterInterval.h"
25
26
// ===========================================================================
27
// member method definitions
28
// ===========================================================================
29
30
GNERerouterInterval::GNERerouterInterval(GNENet* net) :
31
GNEAdditional(net, SUMO_TAG_INTERVAL),
32
GNEAdditionalListed(this) {
33
}
34
35
36
GNERerouterInterval::GNERerouterInterval(GNEAdditional* rerouterParent, const SUMOTime begin, const SUMOTime end) :
37
GNEAdditional(rerouterParent, SUMO_TAG_INTERVAL, ""),
38
GNEAdditionalListed(this),
39
myBegin(begin),
40
myEnd(end) {
41
// set parents
42
setParent<GNEAdditional*>(rerouterParent);
43
// update boundary of rerouter parent
44
rerouterParent->updateCenteringBoundary(true);
45
}
46
47
48
GNERerouterInterval::~GNERerouterInterval() {}
49
50
51
GNEMoveElement*
52
GNERerouterInterval::getMoveElement() const {
53
return nullptr;
54
}
55
56
57
Parameterised*
58
GNERerouterInterval::getParameters() {
59
return nullptr;
60
}
61
62
63
const Parameterised*
64
GNERerouterInterval::getParameters() const {
65
return nullptr;
66
}
67
68
69
void
70
GNERerouterInterval::writeAdditional(OutputDevice& device) const {
71
// avoid write empty intervals
72
if (getChildAdditionals().size() > 0) {
73
device.openTag(SUMO_TAG_INTERVAL);
74
// write common additional attributes
75
writeAdditionalAttributes(device);
76
// write specific attributes
77
device.writeAttr(SUMO_ATTR_BEGIN, getAttribute(SUMO_ATTR_BEGIN));
78
device.writeAttr(SUMO_ATTR_END, getAttribute(SUMO_ATTR_END));
79
// write all rerouter interval
80
for (const auto& rerouterElement : getChildAdditionals()) {
81
rerouterElement->writeAdditional(device);
82
}
83
device.closeTag();
84
}
85
}
86
87
88
bool
89
GNERerouterInterval::isAdditionalValid() const {
90
return true;
91
}
92
93
94
std::string
95
GNERerouterInterval::getAdditionalProblem() const {
96
return "";
97
}
98
99
100
void
101
GNERerouterInterval::fixAdditionalProblem() {
102
// nothing to fix
103
}
104
105
106
bool
107
GNERerouterInterval::checkDrawMoveContour() const {
108
return false;
109
}
110
111
112
void
113
GNERerouterInterval::updateGeometry() {
114
updateGeometryListedAdditional();
115
}
116
117
118
Position
119
GNERerouterInterval::getPositionInView() const {
120
return getListedPositionInView();
121
}
122
123
124
void
125
GNERerouterInterval::updateCenteringBoundary(const bool /*updateGrid*/) {
126
// nothing to do
127
}
128
129
130
void
131
GNERerouterInterval::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
132
// geometry of this element cannot be splitted
133
}
134
135
136
std::string
137
GNERerouterInterval::getParentName() const {
138
return getParentAdditionals().at(0)->getID();
139
}
140
141
142
void
143
GNERerouterInterval::drawGL(const GUIVisualizationSettings& s) const {
144
// draw rerouter interval as listed attribute
145
drawListedAdditional(s, RGBColor::RED, RGBColor::YELLOW, GUITexture::REROUTER_INTERVAL,
146
getAttribute(SUMO_ATTR_BEGIN) + " -> " + getAttribute(SUMO_ATTR_END));
147
const auto& inspectedElements = myNet->getViewNet()->getInspectedElements();
148
// iterate over additionals and check if drawn
149
for (const auto& rerouterElement : getChildAdditionals()) {
150
// if rerouter or their child is selected, then draw
151
if (isAttributeCarrierSelected() || inspectedElements.isACInspected(this) ||
152
rerouterElement->isAttributeCarrierSelected() || inspectedElements.isACInspected(rerouterElement) ||
153
rerouterElement->isMarkedForDrawingFront()) {
154
rerouterElement->drawGL(s);
155
}
156
}
157
}
158
159
160
std::string
161
GNERerouterInterval::getAttribute(SumoXMLAttr key) const {
162
switch (key) {
163
case SUMO_ATTR_ID:
164
return getParentAdditionals().front()->getID();
165
case SUMO_ATTR_BEGIN:
166
return time2string(myBegin);
167
case SUMO_ATTR_END:
168
return time2string(myEnd);
169
case GNE_ATTR_PARENT:
170
return getParentAdditionals().at(0)->getID();
171
default:
172
return getCommonAttribute(key);
173
}
174
}
175
176
177
double
178
GNERerouterInterval::getAttributeDouble(SumoXMLAttr key) const {
179
switch (key) {
180
case SUMO_ATTR_BEGIN:
181
return STEPS2TIME(myBegin);
182
case SUMO_ATTR_END:
183
return STEPS2TIME(myEnd);
184
default:
185
return getCommonAttributeDouble(key);
186
}
187
}
188
189
190
Position
191
GNERerouterInterval::getAttributePosition(SumoXMLAttr key) const {
192
return getCommonAttributePosition(key);
193
}
194
195
196
PositionVector
197
GNERerouterInterval::getAttributePositionVector(SumoXMLAttr key) const {
198
return getCommonAttributePositionVector(key);
199
}
200
201
202
void
203
GNERerouterInterval::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
204
if (value == getAttribute(key)) {
205
return; //avoid needless changes, later logic relies on the fact that attributes have changed
206
}
207
switch (key) {
208
case SUMO_ATTR_BEGIN:
209
case SUMO_ATTR_END:
210
GNEChange_Attribute::changeAttribute(this, key, value, undoList);
211
break;
212
default:
213
setCommonAttribute(key, value, undoList);
214
break;
215
}
216
}
217
218
219
bool
220
GNERerouterInterval::isValid(SumoXMLAttr key, const std::string& value) {
221
switch (key) {
222
case SUMO_ATTR_BEGIN:
223
if (canParse<SUMOTime>(value)) {
224
const auto begin = parse<SUMOTime>(value);
225
if (begin < 0) {
226
return false;
227
} else {
228
return (begin <= myEnd);
229
}
230
} else {
231
return false;
232
}
233
case SUMO_ATTR_END:
234
if (canParse<SUMOTime>(value)) {
235
const auto end = parse<SUMOTime>(value);
236
if (end < 0) {
237
return false;
238
} else {
239
return (myBegin <= end);
240
}
241
} else {
242
return false;
243
}
244
default:
245
return isCommonAttributeValid(key, value);
246
}
247
}
248
249
250
std::string
251
GNERerouterInterval::getPopUpID() const {
252
return getTagStr();
253
}
254
255
256
std::string
257
GNERerouterInterval::getHierarchyName() const {
258
return getTagStr() + ": " + getAttribute(SUMO_ATTR_BEGIN) + " -> " + getAttribute(SUMO_ATTR_END);
259
}
260
261
// ===========================================================================
262
// private
263
// ===========================================================================
264
265
void
266
GNERerouterInterval::setAttribute(SumoXMLAttr key, const std::string& value) {
267
switch (key) {
268
case SUMO_ATTR_BEGIN:
269
myBegin = parse<SUMOTime>(value);
270
break;
271
case SUMO_ATTR_END:
272
myEnd = parse<SUMOTime>(value);
273
break;
274
default:
275
setCommonAttribute(key, value);
276
break;
277
}
278
}
279
280
/****************************************************************************/
281
282