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