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