Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GNEBusStop.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2001-2024 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/****************************************************************************/
18// A lane area vehicles can halt at (GNE version)
19/****************************************************************************/
20#include <config.h>
21
23#include <netedit/GNENet.h>
24#include <netedit/GNEUndoList.h>
25#include <netedit/GNEViewNet.h>
32
33#include "GNEBusStop.h"
34
35// ===========================================================================
36// method definitions
37// ===========================================================================
38
43
44
49
50
52GNEBusStop::buildBusStop(const std::string& id, GNELane* lane, GNENet* net,
53 const double startPos, const double endPos, const std::string& name, const std::vector<std::string>& lines,
54 int personCapacity, double parkingLength, const RGBColor& color, bool friendlyPosition,
55 const Parameterised::Map& parameters) {
56 return new GNEBusStop(SUMO_TAG_BUS_STOP, GLO_BUS_STOP, GUIIcon::BUSSTOP, id, lane, net, startPos, endPos, name, lines,
57 personCapacity, parkingLength, color, friendlyPosition, parameters);
58}
59
60
62GNEBusStop::buildTrainStop(const std::string& id, GNELane* lane, GNENet* net,
63 const double startPos, const double endPos, const std::string& name, const std::vector<std::string>& lines,
64 int personCapacity, double parkingLength, const RGBColor& color, bool friendlyPosition,
65 const Parameterised::Map& parameters) {
66 return new GNEBusStop(SUMO_TAG_TRAIN_STOP, GLO_TRAIN_STOP, GUIIcon::TRAINSTOP, id, lane, net, startPos, endPos, name, lines,
67 personCapacity, parkingLength, color, friendlyPosition, parameters);
68}
69
70
72
73
74void
76 device.openTag(getTagProperty().getTag());
77 device.writeAttr(SUMO_ATTR_ID, getID());
78 if (!myAdditionalName.empty()) {
80 }
81 device.writeAttr(SUMO_ATTR_LANE, getParentLanes().front()->getID());
84 }
87 }
89 device.writeAttr(SUMO_ATTR_FRIENDLY_POS, "true");
90 }
93 }
96 }
99 }
100 if (getAttribute(SUMO_ATTR_COLOR).size() > 0) {
102 }
103 // write all access
104 for (const auto& access : getChildAdditionals()) {
105 access->writeAdditional(device);
106 }
107 // write parameters (Always after children to avoid problems with additionals.xsd)
108 writeParams(device);
109 device.closeTag();
110}
111
112
113void
115 // Get value of option "lefthand"
116 double offsetSign = OptionsCont::getOptions().getBool("lefthand") ? -1 : 1;
117 // Update common geometry of stopping place
118 setStoppingPlaceGeometry(getParentLanes().front()->getParentEdge()->getNBEdge()->getLaneWidth(getParentLanes().front()->getIndex()) * 0.5);
119 // Obtain a copy of the shape
121 // Move shape to side
123 // Get position of the sign
124 mySymbolPosition = tmpShape.getLineCenter();
125 // update demand element children
126 for (const auto& demandElement : getChildDemandElements()) {
127 demandElement->updateGeometry();
128 }
129}
130
131
132void
134 // check if additional has to be drawn
136 // Obtain exaggeration of the draw
137 const double busStopExaggeration = getExaggeration(s);
138 // check if draw moving geometry points
139 const bool movingGeometryPoints = drawMovingGeometryPoints(false);
140 // get width
142 // get detail level
143 const auto d = s.getDetailLevel(busStopExaggeration);
144 // draw geometry only if we'rent in drawForObjectUnderCursor mode
146 // declare colors
147 RGBColor baseColor, signColor;
148 // set colors
149 if (mySpecialColor) {
150 baseColor = *mySpecialColor;
151 signColor = baseColor.changedBrightness(-32);
152 } else if (drawUsingSelectColor()) {
154 signColor = baseColor.changedBrightness(-32);
155 } else if (myColor != RGBColor::INVISIBLE) {
156 baseColor = myColor;
157 signColor = s.colorSettings.busStopColorSign;
158 } else if (myTagProperty.getTag() == SUMO_TAG_TRAIN_STOP) {
159 baseColor = s.colorSettings.trainStopColor;
160 signColor = s.colorSettings.trainStopColorSign;
161 } else {
162 baseColor = s.colorSettings.busStopColor;
163 signColor = s.colorSettings.busStopColorSign;
164 }
165 // draw parent and child lines
166 drawParentChildLines(s, baseColor);
167 // Add layer matrix
169 // translate to front
171 // set base color
172 GLHelper::setColor(baseColor);
173 // Draw the area using shape, shapeRotations, shapeLengths and value of exaggeration
174 GUIGeometry::drawGeometry(d, myAdditionalGeometry, stopWidth * MIN2(1.0, busStopExaggeration));
175 // draw lines
176 drawLines(d, myLines, baseColor);
177 // draw sign
178 drawSign(s, d, busStopExaggeration, baseColor, signColor, (myTagProperty.getTag() == SUMO_TAG_BUS_STOP) ? "H" : "T");
179 // draw geometry points
180 if (movingGeometryPoints && (myStartPosition != INVALID_DOUBLE)) {
182 }
183 if (movingGeometryPoints && (myEndPosition != INVALID_DOUBLE)) {
185 }
186 // pop layer matrix
188 // draw lock icon
191 } else {
193 }
194 // Draw additional ID
196 // draw additional name
198 // draw dotted contours
199 if (movingGeometryPoints) {
202 } else {
205 }
206 }
207 // draw demand element children
209 // calculate contours
210 calculateStoppingPlaceContour(s, d, stopWidth, busStopExaggeration, movingGeometryPoints);
211 }
212}
213
214
215std::string
217 switch (key) {
218 case SUMO_ATTR_ID:
219 return getMicrosimID();
220 case SUMO_ATTR_LANE:
221 return getParentLanes().front()->getID();
225 } else {
226 return "";
227 }
228 case SUMO_ATTR_ENDPOS:
230 return toString(myEndPosition);
231 } else {
232 return "";
233 }
234 case SUMO_ATTR_NAME:
235 return myAdditionalName;
238 case SUMO_ATTR_LINES:
239 return joinToString(myLines, " ");
244 case SUMO_ATTR_COLOR:
246 return "";
247 } else {
248 return toString(myColor);
249 }
251 return getParametersStr();
253 return "";
254 default:
255 return getCommonAttribute(key);
256 }
257}
258
259
260void
261GNEBusStop::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
262 switch (key) {
263 case SUMO_ATTR_ID:
264 case SUMO_ATTR_LANE:
266 case SUMO_ATTR_ENDPOS:
267 case SUMO_ATTR_NAME:
269 case SUMO_ATTR_LINES:
271 case SUMO_ATTR_COLOR:
275 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
276 break;
277 default:
278 setCommonAttribute(key, value, undoList);
279 break;
280 }
281}
282
283
284bool
285GNEBusStop::isValid(SumoXMLAttr key, const std::string& value) {
286 switch (key) {
287 case SUMO_ATTR_ID:
289 case SUMO_ATTR_LANE:
290 if (myNet->getAttributeCarriers()->retrieveLane(value, false) != nullptr) {
291 return true;
292 } else {
293 return false;
294 }
296 if (value.empty()) {
297 return true;
298 } else if (canParse<double>(value)) {
299 return SUMORouteHandler::isStopPosValid(parse<double>(value), getAttributeDouble(SUMO_ATTR_ENDPOS), getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength(), POSITION_EPS, myFriendlyPosition);
300 } else {
301 return false;
302 }
303 case SUMO_ATTR_ENDPOS:
304 if (value.empty()) {
305 return true;
306 } else if (canParse<double>(value)) {
307 return SUMORouteHandler::isStopPosValid(getAttributeDouble(SUMO_ATTR_STARTPOS), parse<double>(value), getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength(), POSITION_EPS, myFriendlyPosition);
308 } else {
309 return false;
310 }
311 case SUMO_ATTR_NAME:
314 return canParse<bool>(value);
315 case SUMO_ATTR_LINES:
316 return canParse<std::vector<std::string> >(value);
318 return canParse<int>(value) && (parse<int>(value) > 0 || parse<int>(value) == -1);
320 return canParse<double>(value) && (parse<double>(value) >= 0);
321 case SUMO_ATTR_COLOR:
322 if (value.empty()) {
323 return true;
324 } else {
325 return canParse<RGBColor>(value);
326 }
327
329 return areParametersValid(value);
330 default:
331 return isCommonValid(key, value);
332 }
333}
334
335// ===========================================================================
336// private
337// ===========================================================================
338
339void
340GNEBusStop::setAttribute(SumoXMLAttr key, const std::string& value) {
341 switch (key) {
342 case SUMO_ATTR_ID:
343 // update microsimID
344 setAdditionalID(value);
345 break;
346 case SUMO_ATTR_LANE:
348 break;
350 if (value == "") {
352 } else {
353 myStartPosition = parse<double>(value);
354 }
355 break;
356 case SUMO_ATTR_ENDPOS:
357 if (value == "") {
359 } else {
360 myEndPosition = parse<double>(value);
361 }
362 break;
363 case SUMO_ATTR_NAME:
364 myAdditionalName = value;
365 break;
367 myFriendlyPosition = parse<bool>(value);
368 break;
369 case SUMO_ATTR_LINES:
370 myLines = GNEAttributeCarrier::parse<std::vector<std::string> >(value);
371 break;
373 myPersonCapacity = GNEAttributeCarrier::parse<int>(value);
374 break;
376 myParkingLength = GNEAttributeCarrier::parse<double>(value);
377 break;
378 case SUMO_ATTR_COLOR:
379 if (value.empty()) {
381 } else {
382 myColor = GNEAttributeCarrier::parse<RGBColor>(value);
383 }
384 break;
386 setParametersStr(value);
387 break;
390 break;
391 default:
392 setCommonAttribute(key, value);
393 break;
394 }
395}
396
397
399 GNEStoppingPlace("", net, type, tag, GUIIconSubSys::getIcon(icon), nullptr, 0, 0, "", false, Parameterised::Map()),
400 myPersonCapacity(0),
401 myParkingLength(0),
402 myColor(RGBColor::BLACK) {
403 // reset default values
405}
406
407
408GNEBusStop::GNEBusStop(SumoXMLTag tag, GUIGlObjectType type, GUIIcon icon, const std::string& id, GNELane* lane, GNENet* net,
409 const double startPos, const double endPos, const std::string& name, const std::vector<std::string>& lines,
410 int personCapacity, double parkingLength, const RGBColor& color, bool friendlyPosition, const Parameterised::Map& parameters) :
411 GNEStoppingPlace(id, net, type, tag, GUIIconSubSys::getIcon(icon), lane, startPos, endPos, name, friendlyPosition, parameters),
412 myLines(lines),
413 myPersonCapacity(personCapacity),
414 myParkingLength(parkingLength),
415 myColor(color) {
416}
417
418/****************************************************************************/
GUIGlObjectType
@ GLO_BUS_STOP
a busStop
@ GLO_TRAIN_STOP
a trainStop
GUIIcon
An enumeration of icons used by the gui applications.
Definition GUIIcons.h:33
SumoXMLTag
Numbers representing SUMO-XML - element names.
@ SUMO_TAG_BUS_STOP
A bus stop.
@ SUMO_TAG_TRAIN_STOP
A train stop (alias for bus stop)
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ SUMO_ATTR_STARTPOS
@ SUMO_ATTR_LINES
@ SUMO_ATTR_LANE
@ SUMO_ATTR_PARKING_LENGTH
@ SUMO_ATTR_ENDPOS
@ GNE_ATTR_PARAMETERS
parameters "key1=value1|key2=value2|...|keyN=valueN"
@ SUMO_ATTR_NAME
@ SUMO_ATTR_FRIENDLY_POS
@ SUMO_ATTR_COLOR
A color information.
@ SUMO_ATTR_ID
@ SUMO_ATTR_PERSON_CAPACITY
@ GNE_ATTR_SHIFTLANEINDEX
shift lane index (only used by elements over lanes)
const double INVALID_DOUBLE
invalid double
Definition StdDefs.h:64
T MIN2(T a, T b)
Definition StdDefs.h:76
std::string joinToString(const std::vector< T > &v, const T_BETWEEN &between, std::streamsize accuracy=gPrecision)
Definition ToString.h:283
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:46
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition GLHelper.cpp:649
static void popMatrix()
pop matrix
Definition GLHelper.cpp:131
static void pushMatrix()
push matrix
Definition GLHelper.cpp:118
bool isValidAdditionalID(const std::string &value) const
check if a new additional ID is valid
void drawRightGeometryPoint(const GUIVisualizationSettings &s, const GUIVisualizationSettings::Detail d, const Position &pos, const double rot, const RGBColor &baseColor, const bool ignoreShift=false) const
draw right geometry point
void setAdditionalID(const std::string &newID)
set additional ID
GNEContour myAdditionalContour
variable used for draw additional contours
GUIGeometry myAdditionalGeometry
geometry to be precomputed in updateGeometry(...)
void drawAdditionalID(const GUIVisualizationSettings &s) const
draw additional ID
void replaceAdditionalParentLanes(const std::string &value)
replace additional parent lanes
void shiftLaneIndex()
shift lane index
double getExaggeration(const GUIVisualizationSettings &s) const
return exaggeration associated with this GLObject
std::string myAdditionalName
name of additional
void drawAdditionalName(const GUIVisualizationSettings &s) const
draw additional name
void drawDemandElementChildren(const GUIVisualizationSettings &s) const
draw demand element children
const RGBColor * mySpecialColor
pointer to special color (used for drawing Additional with a certain color, mainly used for selection...
bool drawMovingGeometryPoints(const bool ignoreShift) const
check if draw additional extrem geometry points
void drawLeftGeometryPoint(const GUIVisualizationSettings &s, const GUIVisualizationSettings::Detail d, const Position &pos, const double rot, const RGBColor &baseColor, const bool ignoreShift=false) const
draw left geometry point
void drawParentChildLines(const GUIVisualizationSettings &s, const RGBColor &color, const bool onlySymbols=false) const
draw parent and child lines
const std::string getID() const
get ID (all Attribute Carriers have one)
bool isAttributeCarrierSelected() const
check if attribute carrier is selected
void setCommonAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
const GNETagProperties & getTagProperty() const
get tagProperty associated with this Attribute Carrier
bool drawUsingSelectColor() const
check if attribute carrier must be drawn using selecting color.
bool isCommonValid(SumoXMLAttr key, const std::string &value)
void drawInLayer(const double typeOrLayer, const double extraOffset=0) const
draw element in the given layer, or in front if corresponding flag is enabled
void resetDefaultValues()
reset attribute carrier to their default values
GNENet * myNet
pointer to net
std::string getCommonAttribute(SumoXMLAttr key) const
const GNETagProperties & myTagProperty
reference to tagProperty associated with this attribute carrier
A lane area vehicles can halt at (netedit-version)
Definition GNEBusStop.h:33
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their correspondent attribute are valids
RGBColor myColor
RGB color.
Definition GNEBusStop.h:141
GNEBusStop(SumoXMLTag tag, GUIGlObjectType type, GUIIcon icon, GNENet *net)
default constructor
static GNEBusStop * buildTrainStop(GNENet *net)
default constructor
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform additional changes
std::string getAttribute(SumoXMLAttr key) const
void updateGeometry()
update pre-computed geometry information
void writeAdditional(OutputDevice &device) const
write additional element into a xml file
double myParkingLength
custom space for vehicles that park at this stop
Definition GNEBusStop.h:138
std::vector< std::string > myLines
The list of lines that are assigned to this stop.
Definition GNEBusStop.h:132
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
~GNEBusStop()
Destructor.
static GNEBusStop * buildBusStop(GNENet *net)
default constructor
int myPersonCapacity
maximum number of persons that can wait at this stop
Definition GNEBusStop.h:135
static void changeAttribute(GNEAttributeCarrier *AC, SumoXMLAttr key, const std::string &value, GNEUndoList *undoList, const bool force=false)
change attribute
void drawDottedContourGeometryPoints(const GUIVisualizationSettings &s, const GUIVisualizationSettings::Detail d, const GNEAttributeCarrier *AC, const PositionVector &shape, const double radius, const double scale, const double lineWidth) const
draw dotted contour for geometry points
bool drawDottedContours(const GUIVisualizationSettings &s, const GUIVisualizationSettings::Detail d, const GNEAttributeCarrier *AC, const double lineWidth, const bool addOffset) const
draw dotted contours (basics, select, delete, inspect...)
const std::vector< GNEDemandElement * > & getChildDemandElements() const
return child demand elements
const std::vector< GNELane * > & getParentLanes() const
get parent lanes
const std::vector< GNEAdditional * > & getChildAdditionals() const
return child additionals
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
Definition GNELane.h:46
GNELane * retrieveLane(const std::string &id, bool hardFail=true, bool checkVolatileChange=false) const
get lane by id
A NBNetBuilder extended by visualisation and editing capabilities.
Definition GNENet.h:42
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
get all attribute carriers used in this net
Definition GNENet.cpp:127
GNEViewNet * getViewNet() const
get view net
Definition GNENet.cpp:2163
virtual double getAttributeDouble(SumoXMLAttr key) const
void drawSign(const GUIVisualizationSettings &s, const GUIVisualizationSettings::Detail d, const double exaggeration, const RGBColor &baseColor, const RGBColor &signColor, const std::string &word) const
draw sign
void calculateStoppingPlaceContour(const GUIVisualizationSettings &s, const GUIVisualizationSettings::Detail d, const double width, const double exaggeration, const bool movingGeometryPoints) const
check object in view
bool myFriendlyPosition
Flag for friendly position.
void drawLines(const GUIVisualizationSettings::Detail d, const std::vector< std::string > &lines, const RGBColor &color) const
draw lines
Position mySymbolPosition
The position of the sign.
void setStoppingPlaceGeometry(double movingToSide)
set geometry common to all stopping places
double myEndPosition
The position this stopping place is located at (-1 means empty)
GNEContour mySymbolContour
circle contour
double myStartPosition
The relative start position this stopping place is located at (-1 means empty)
SumoXMLTag getTag() const
get Tag vinculated with this attribute Property
const std::string & getDefaultValue(SumoXMLAttr attr) const
return the default value of the attribute of an element
const GNEViewNetHelper::DataViewOptions & getDataViewOptions() const
get data view options
const std::vector< double > & getShapeRotations() const
The rotations of the single shape parts.
static void drawGeometry(const GUIVisualizationSettings::Detail d, const GUIGeometry &geometry, const double width, double offset=0)
draw geometry
const PositionVector & getShape() const
The shape of the additional element.
const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
const GUIVisualizationSettings & getVisualisationSettings() const
get visualization settings (read only)
Stores the information about how to visualize structures.
bool checkDrawAdditional(Detail d, const bool selected) const
check if draw additionals
Detail getDetailLevel(const double exaggeration) const
return the detail level
GUIVisualizationColorSettings colorSettings
color settings
GUIVisualizationDottedContourSettings dottedContourSettings
dotted contour settings
GUIVisualizationStoppingPlaceSettings stoppingPlaceSettings
StoppingPlace settings.
GUIVisualizationNeteditSizeSettings neteditSizeSettings
netedit size settings
static const std::vector< SumoXMLTag > busStops
busStops namespace
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
static OptionsCont & getOptions()
Retrieves the options.
Static storage of an output device and its base (abstract) implementation.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
An upper class for objects with additional parameters.
static bool areParametersValid(const std::string &value, bool report=false, const std::string kvsep="=", const std::string sep="|")
check if given string can be parsed to a parameters map "key1=value1|key2=value2|....
std::map< std::string, std::string > Map
parameters map
void setParametersStr(const std::string &paramsString, const std::string kvsep="=", const std::string sep="|")
set the inner key/value map in string format "key1=value1|key2=value2|...|keyN=valueN"
void writeParams(OutputDevice &device) const
write Params in the given outputdevice
std::string getParametersStr(const std::string kvsep="=", const std::string sep="|") const
Returns the inner key/value map in string format "key1=value1|key2=value2|...|keyN=valueN".
A list of positions.
void move2side(double amount, double maxExtension=100)
move position vector to side using certain amount
Position getLineCenter() const
get line center
Position getCentroid() const
Returns the centroid (closes the polygon if unclosed)
static const RGBColor INVISIBLE
Definition RGBColor.h:195
RGBColor changedBrightness(int change, int toChange=3) const
Returns a new color with altered brightness.
Definition RGBColor.cpp:200
static bool isStopPosValid(const double startPos, const double endPos, const double laneLength, const double minLength, const bool friendlyPos)
check if start and end position of a stop is valid
static bool isValidAttribute(const std::string &value)
whether the given string is a valid attribute for a certain key (for example, a name)
static std::string escapeXML(const std::string &orig, const bool maskDoubleHyphen=false)
Replaces the standard escapes by their XML entities.
bool showAdditionals() const
check if additionals has to be drawn
static void drawLockIcon(const GUIVisualizationSettings::Detail d, const GNEAttributeCarrier *AC, GUIGlObjectType type, const Position position, const double exaggeration, const double size=0.5, const double offsetx=0, const double offsety=0)
draw lock icon
RGBColor trainStopColorSign
color for trainStops signs
RGBColor busStopColorSign
color for busStops signs
RGBColor selectedAdditionalColor
additional selection color (busStops, Detectors...)
RGBColor busStopColor
color for busStops
RGBColor trainStopColor
color for trainStops
static const double segmentWidthSmall
width of small dotted contour segments
static const double segmentWidth
width of dotted contour segments
static const double additionalGeometryPointRadius
moving additional geometry point radius
static const double stoppingPlaceSignOffset
busStop offset
static const double busStopWidth
busStop width
static const double trainStopWidth
trainStop width