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