Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netedit/elements/additional/GNEBusStop.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 GNEBusStop.cpp
15
/// @author Pablo Alvarez Lopez
16
/// @date Nov 2015
17
///
18
// A lane area vehicles can halt at (GNE version)
19
/****************************************************************************/
20
21
#include <netedit/GNENet.h>
22
#include <netedit/GNETagProperties.h>
23
#include <netedit/changes/GNEChange_Attribute.h>
24
#include <utils/options/OptionsCont.h>
25
#include <utils/gui/div/GLHelper.h>
26
27
#include "GNEBusStop.h"
28
29
// ===========================================================================
30
// method definitions
31
// ===========================================================================
32
33
GNEBusStop*
34
GNEBusStop::buildBusStop(GNENet* net) {
35
return new GNEBusStop(SUMO_TAG_BUS_STOP, net);
36
}
37
38
39
GNEBusStop*
40
GNEBusStop::buildTrainStop(GNENet* net) {
41
return new GNEBusStop(SUMO_TAG_TRAIN_STOP, net);
42
}
43
44
45
GNEBusStop*
46
GNEBusStop::buildBusStop(const std::string& id, GNENet* net, const std::string& filename, GNELane* lane,
47
const double startPos, const double endPos, const std::string& name, const std::vector<std::string>& lines,
48
const int personCapacity, const double parkingLength, const RGBColor& color, const bool friendlyPosition,
49
const double angle, const Parameterised::Map& parameters) {
50
return new GNEBusStop(SUMO_TAG_BUS_STOP, id, net, filename, lane, startPos, endPos, name, lines,
51
personCapacity, parkingLength, color, friendlyPosition, angle, parameters);
52
}
53
54
55
GNEBusStop*
56
GNEBusStop::buildTrainStop(const std::string& id, GNENet* net, const std::string& filename, GNELane* lane,
57
const double startPos, const double endPos, const std::string& name, const std::vector<std::string>& lines,
58
const int personCapacity, const double parkingLength, const RGBColor& color, const bool friendlyPosition,
59
const double angle, const Parameterised::Map& parameters) {
60
return new GNEBusStop(SUMO_TAG_TRAIN_STOP, id, net, filename, lane, startPos, endPos, name, lines,
61
personCapacity, parkingLength, color, friendlyPosition, angle, parameters);
62
}
63
64
65
GNEBusStop::~GNEBusStop() {}
66
67
68
void
69
GNEBusStop::writeAdditional(OutputDevice& device) const {
70
device.openTag(getTagProperty()->getTag());
71
// write common attributes
72
writeStoppingPlaceAttributes(device);
73
// write specific attributes
74
if (getAttribute(SUMO_ATTR_LINES) != myTagProperty->getDefaultStringValue(SUMO_ATTR_LINES)) {
75
device.writeAttr(SUMO_ATTR_LINES, toString(myLines));
76
}
77
if (myPersonCapacity != myTagProperty->getDefaultIntValue(SUMO_ATTR_PERSON_CAPACITY)) {
78
device.writeAttr(SUMO_ATTR_PERSON_CAPACITY, myPersonCapacity);
79
}
80
if (myParkingLength != myTagProperty->getDefaultDoubleValue(SUMO_ATTR_PARKING_LENGTH)) {
81
device.writeAttr(SUMO_ATTR_PARKING_LENGTH, myParkingLength);
82
}
83
// write all access
84
for (const auto& access : getChildAdditionals()) {
85
access->writeAdditional(device);
86
}
87
// write parameters (Always after children to avoid problems with additionals.xsd)
88
writeParams(device);
89
device.closeTag();
90
}
91
92
93
void
94
GNEBusStop::updateGeometry() {
95
// Get value of option "lefthand"
96
double offsetSign = OptionsCont::getOptions().getBool("lefthand") ? -1 : 1;
97
// Update common geometry of stopping place
98
setStoppingPlaceGeometry(getParentLanes().front()->getParentEdge()->getNBEdge()->getLaneWidth(getParentLanes().front()->getIndex()) * 0.5);
99
// Obtain a copy of the shape
100
PositionVector tmpShape = myAdditionalGeometry.getShape();
101
// Move shape to side
102
tmpShape.move2side(myNet->getViewNet()->getVisualisationSettings().stoppingPlaceSettings.stoppingPlaceSignOffset * offsetSign);
103
// Get position of the sign
104
mySymbolPosition = tmpShape.getLineCenter();
105
// update demand element children
106
for (const auto& demandElement : getChildDemandElements()) {
107
demandElement->updateGeometry();
108
}
109
}
110
111
112
void
113
GNEBusStop::drawGL(const GUIVisualizationSettings& s) const {
114
// check if additional has to be drawn
115
if (myNet->getViewNet()->getDataViewOptions().showAdditionals()) {
116
// Obtain exaggeration of the draw
117
const double busStopExaggeration = getExaggeration(s);
118
// check if draw moving geometry points
119
const bool movingGeometryPoints = drawMovingGeometryPoints(false);
120
// get width
121
const double stopWidth = (myTagProperty->getTag() == SUMO_TAG_BUS_STOP) ? s.stoppingPlaceSettings.busStopWidth : s.stoppingPlaceSettings.trainStopWidth;
122
// get detail level
123
const auto d = s.getDetailLevel(busStopExaggeration);
124
// draw geometry only if we'rent in drawForObjectUnderCursor mode
125
if (s.checkDrawAdditional(d, isAttributeCarrierSelected())) {
126
// declare colors
127
RGBColor baseColor, signColor;
128
// set colors
129
if (mySpecialColor) {
130
baseColor = *mySpecialColor;
131
signColor = baseColor.changedBrightness(-32);
132
} else if (drawUsingSelectColor()) {
133
baseColor = s.colorSettings.selectedAdditionalColor;
134
signColor = baseColor.changedBrightness(-32);
135
} else if (myColor != RGBColor::INVISIBLE) {
136
baseColor = myColor;
137
signColor = s.colorSettings.busStopColorSign;
138
} else if (myTagProperty->getTag() == SUMO_TAG_TRAIN_STOP) {
139
baseColor = s.colorSettings.trainStopColor;
140
signColor = s.colorSettings.trainStopColorSign;
141
} else {
142
baseColor = s.colorSettings.busStopColor;
143
signColor = s.colorSettings.busStopColorSign;
144
}
145
// draw parent and child lines
146
drawParentChildLines(s, baseColor);
147
// Add layer matrix
148
GLHelper::pushMatrix();
149
// translate to front
150
drawInLayer(GLO_BUS_STOP);
151
// set base color
152
GLHelper::setColor(baseColor);
153
// Draw the area using shape, shapeRotations, shapeLengths and value of exaggeration
154
GUIGeometry::drawGeometry(d, myAdditionalGeometry, stopWidth * MIN2(1.0, busStopExaggeration));
155
// draw lines
156
drawLines(d, myLines, baseColor);
157
// draw sign
158
drawSign(s, d, busStopExaggeration, baseColor, signColor, (myTagProperty->getTag() == SUMO_TAG_BUS_STOP) ? "H" : "T");
159
// draw geometry points
160
if (movingGeometryPoints && (myStartPosition != INVALID_DOUBLE)) {
161
drawLeftGeometryPoint(s, d, myAdditionalGeometry.getShape().front(), myAdditionalGeometry.getShapeRotations().front(), baseColor);
162
}
163
if (movingGeometryPoints && (myEndPosition != INVALID_DOUBLE)) {
164
drawRightGeometryPoint(s, d, myAdditionalGeometry.getShape().back(), myAdditionalGeometry.getShapeRotations().back(), baseColor);
165
}
166
// pop layer matrix
167
GLHelper::popMatrix();
168
// draw lock icon
169
if (myTagProperty->getTag() == SUMO_TAG_BUS_STOP) {
170
GNEViewNetHelper::LockIcon::drawLockIcon(d, this, getType(), myAdditionalGeometry.getShape().getCentroid(), busStopExaggeration, 0.5);
171
} else {
172
GNEViewNetHelper::LockIcon::drawLockIcon(d, this, getType(), myAdditionalGeometry.getShape().getCentroid(), busStopExaggeration, 0.25);
173
}
174
// Draw additional ID
175
drawAdditionalID(s);
176
// draw additional name
177
drawAdditionalName(s);
178
// draw dotted contours
179
if (movingGeometryPoints) {
180
myAdditionalContour.drawDottedContourGeometryPoints(s, d, this, myAdditionalGeometry.getShape(), s.neteditSizeSettings.additionalGeometryPointRadius,
181
1, s.dottedContourSettings.segmentWidthSmall);
182
} else {
183
myAdditionalContour.drawDottedContours(s, d, this, s.dottedContourSettings.segmentWidth, true);
184
mySymbolContour.drawDottedContours(s, d, this, s.dottedContourSettings.segmentWidthSmall, true);
185
}
186
}
187
// draw demand element children
188
drawDemandElementChildren(s);
189
// calculate contours
190
calculateStoppingPlaceContour(s, d, stopWidth, busStopExaggeration, movingGeometryPoints);
191
}
192
}
193
194
195
std::string
196
GNEBusStop::getAttribute(SumoXMLAttr key) const {
197
switch (key) {
198
case SUMO_ATTR_LINES:
199
return joinToString(myLines, " ");
200
case SUMO_ATTR_PERSON_CAPACITY:
201
return toString(myPersonCapacity);
202
case SUMO_ATTR_PARKING_LENGTH:
203
return toString(myParkingLength);
204
default:
205
return getStoppingPlaceAttribute(this, key);
206
}
207
}
208
209
210
double
211
GNEBusStop::getAttributeDouble(SumoXMLAttr key) const {
212
return getStoppingPlaceAttributeDouble(key);
213
}
214
215
216
void
217
GNEBusStop::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
218
switch (key) {
219
case SUMO_ATTR_LINES:
220
case SUMO_ATTR_PERSON_CAPACITY:
221
case SUMO_ATTR_PARKING_LENGTH:
222
GNEChange_Attribute::changeAttribute(this, key, value, undoList);
223
break;
224
default:
225
setStoppingPlaceAttribute(key, value, undoList);
226
break;
227
}
228
}
229
230
231
bool
232
GNEBusStop::isValid(SumoXMLAttr key, const std::string& value) {
233
switch (key) {
234
case SUMO_ATTR_LINES:
235
return true;
236
case SUMO_ATTR_PERSON_CAPACITY:
237
return canParse<int>(value) && (parse<int>(value) > 0 || parse<int>(value) == -1);
238
case SUMO_ATTR_PARKING_LENGTH:
239
return canParse<double>(value) && (parse<double>(value) >= 0);
240
default:
241
return isStoppingPlaceValid(key, value);
242
}
243
}
244
245
// ===========================================================================
246
// private
247
// ===========================================================================
248
249
void
250
GNEBusStop::setAttribute(SumoXMLAttr key, const std::string& value) {
251
switch (key) {
252
case SUMO_ATTR_LINES:
253
myLines = GNEAttributeCarrier::parse<std::vector<std::string> >(value);
254
break;
255
case SUMO_ATTR_PERSON_CAPACITY:
256
myPersonCapacity = GNEAttributeCarrier::parse<int>(value);
257
break;
258
case SUMO_ATTR_PARKING_LENGTH:
259
myParkingLength = GNEAttributeCarrier::parse<double>(value);
260
break;
261
default:
262
setStoppingPlaceAttribute(this, key, value);
263
break;
264
}
265
}
266
267
268
GNEBusStop::GNEBusStop(SumoXMLTag tag, GNENet* net) :
269
GNEStoppingPlace(net, tag) {
270
}
271
272
273
GNEBusStop::GNEBusStop(SumoXMLTag tag, const std::string& id, GNENet* net, const std::string& filename,
274
GNELane* lane, const double startPos, const double endPos, const std::string& name,
275
const std::vector<std::string>& lines, const int personCapacity, const double parkingLength,
276
const RGBColor& color, const bool friendlyPosition, const double angle,
277
const Parameterised::Map& parameters) :
278
GNEStoppingPlace(id, net, filename, tag, lane, startPos, endPos, name, friendlyPosition, color, angle, parameters),
279
myLines(lines),
280
myPersonCapacity(personCapacity),
281
myParkingLength(parkingLength) {
282
}
283
284
/****************************************************************************/
285
286