Eclipse SUMO - Simulation of Urban MObility
GNEBusStop.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3// Copyright (C) 2001-2022 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>
31
32#include "GNEBusStop.h"
33
34// ===========================================================================
35// method definitions
36// ===========================================================================
37
39 GNEStoppingPlace("", net, GLO_BUS_STOP, tag, GUIIconSubSys::getIcon(GUIIcon::BUSSTOP), nullptr, 0, 0, "", false, Parameterised::Map()),
40 myPersonCapacity(0),
41 myParkingLength(0),
42 myColor(RGBColor::BLACK) {
43 // reset default values
45}
46
47
48GNEBusStop::GNEBusStop(SumoXMLTag tag, const std::string& id, GNELane* lane, GNENet* net, const double startPos, const double endPos,
49 const std::string& name, const std::vector<std::string>& lines, int personCapacity, double parkingLength, const RGBColor& color,
50 bool friendlyPosition, const Parameterised::Map& parameters) :
51 GNEStoppingPlace(id, net, GLO_BUS_STOP, tag, GUIIconSubSys::getIcon(GUIIcon::BUSSTOP), lane, startPos, endPos, name, friendlyPosition, parameters),
52 myLines(lines),
53 myPersonCapacity(personCapacity),
54 myParkingLength(parkingLength),
55 myColor(color) {
56 // update centering boundary without updating grid
58}
59
60
62
63
64void
66 device.openTag(getTagProperty().getTag());
67 device.writeAttr(SUMO_ATTR_ID, getID());
68 if (!myAdditionalName.empty()) {
70 }
71 device.writeAttr(SUMO_ATTR_LANE, getParentLanes().front()->getID());
74 }
77 }
79 device.writeAttr(SUMO_ATTR_FRIENDLY_POS, "true");
80 }
83 }
86 }
89 }
90 if (getAttribute(SUMO_ATTR_COLOR).size() > 0) {
92 }
93 // write all access
94 for (const auto& access : getChildAdditionals()) {
95 access->writeAdditional(device);
96 }
97 // write parameters (Always after children to avoid problems with additionals.xsd)
98 writeParams(device);
99 device.closeTag();
100}
101
102
103void
105 // Get value of option "lefthand"
106 double offsetSign = OptionsCont::getOptions().getBool("lefthand") ? -1 : 1;
107 // Update common geometry of stopping place
108 setStoppingPlaceGeometry(getParentLanes().front()->getParentEdge()->getNBEdge()->getLaneWidth(getParentLanes().front()->getIndex()) * 0.5);
109 // Obtain a copy of the shape
111 // Move shape to side
113 // Get position of the sign
114 mySignPos = tmpShape.getLineCenter();
115 // update demand element children
116 for (const auto& demandElement : getChildDemandElements()) {
117 demandElement->updateGeometry();
118 }
119}
120
121
122void
124 // Obtain exaggeration of the draw
125 const double busStopExaggeration = getExaggeration(s);
126 // first check if additional has to be drawn
128 // check exaggeration
129 if (s.drawAdditionals(busStopExaggeration)) {
130 // get width
132 // declare colors
133 RGBColor baseColor, signColor;
134 // set colors
135 if (mySpecialColor) {
136 baseColor = *mySpecialColor;
137 signColor = baseColor.changedBrightness(-32);
138 } else if (drawUsingSelectColor()) {
140 signColor = baseColor.changedBrightness(-32);
141 } else if (myColor != RGBColor::INVISIBLE) {
142 baseColor = myColor;
143 signColor = s.colorSettings.busStopColorSign;
144 } else if (myTagProperty.getTag() == SUMO_TAG_TRAIN_STOP) {
145 baseColor = s.colorSettings.trainStopColor;
146 signColor = s.colorSettings.trainStopColorSign;
147 } else {
148 baseColor = s.colorSettings.busStopColor;
149 signColor = s.colorSettings.busStopColorSign;
150 }
151 // draw parent and child lines
152 drawParentChildLines(s, baseColor);
153 // Start drawing adding an gl identificator
155 // Add layer matrix
157 // translate to front
159 // set base color
160 GLHelper::setColor(baseColor);
161 // Draw the area using shape, shapeRotations, shapeLengths and value of exaggeration
162 GUIGeometry::drawGeometry(s, myNet->getViewNet()->getPositionInformation(), myAdditionalGeometry, stopWidth * MIN2(1.0, busStopExaggeration));
163 // draw detail
164 if (s.drawDetail(s.detailSettings.stoppingPlaceDetails, busStopExaggeration)) {
165 // draw lines
166 drawLines(s, myLines, baseColor);
167 // draw sign
168 drawSign(s, busStopExaggeration, baseColor, signColor, (myTagProperty.getTag() == SUMO_TAG_BUS_STOP) ? "H" : "T");
169 }
170 // draw geometry points
173 }
176 }
177 // pop layer matrix
179 // Pop name
181 // draw lock icon
183 // check if mouse is over element
184 mouseWithinGeometry(myAdditionalGeometry.getShape(), stopWidth * MIN2(1.0, busStopExaggeration));
186 // inspect contour
189 busStopExaggeration, true, true);
190 }
191 // front attribute contour
192 if (myNet->getViewNet()->getFrontAttributeCarrier() == this) {
194 busStopExaggeration, true, true);
195 }
196 // delete contour
197 if (myNet->getViewNet()->drawDeleteContour(this, this)) {
199 busStopExaggeration, true, true);
200 }
201 // delete contour
202 if (myNet->getViewNet()->drawSelectContour(this, this)) {
204 busStopExaggeration, true, true);
205 }
206 // draw child demand elements
207 for (const auto& demandElement : getChildDemandElements()) {
208 if (!demandElement->getTagProperty().isPlacedInRTree() &&
209 (!demandElement->getTagProperty().isPersonPlan() || demandElement->getTagProperty().isStopPerson())) {
210 demandElement->drawGL(s);
211 }
212 }
213 }
214 // Draw additional ID
216 // draw additional name
218 }
219}
220
221
222std::string
224 switch (key) {
225 case SUMO_ATTR_ID:
226 return getMicrosimID();
227 case SUMO_ATTR_LANE:
228 return getParentLanes().front()->getID();
232 } else {
233 return "";
234 }
235 case SUMO_ATTR_ENDPOS:
237 return toString(myEndPosition);
238 } else {
239 return "";
240 }
241 case SUMO_ATTR_NAME:
242 return myAdditionalName;
245 case SUMO_ATTR_LINES:
246 return joinToString(myLines, " ");
251 case SUMO_ATTR_COLOR:
253 return "";
254 } else {
255 return toString(myColor);
256 }
260 return getParametersStr();
262 return "";
263 default:
264 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
265 }
266}
267
268
269void
270GNEBusStop::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
271 switch (key) {
272 case SUMO_ATTR_ID:
273 case SUMO_ATTR_LANE:
275 case SUMO_ATTR_ENDPOS:
276 case SUMO_ATTR_NAME:
278 case SUMO_ATTR_LINES:
280 case SUMO_ATTR_COLOR:
285 undoList->changeAttribute(new GNEChange_Attribute(this, key, value));
286 break;
287 default:
288 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
289 }
290}
291
292
293bool
294GNEBusStop::isValid(SumoXMLAttr key, const std::string& value) {
295 switch (key) {
296 case SUMO_ATTR_ID:
297 return isValidAdditionalID(value);
298 case SUMO_ATTR_LANE:
299 if (myNet->getAttributeCarriers()->retrieveLane(value, false) != nullptr) {
300 return true;
301 } else {
302 return false;
303 }
305 if (value.empty()) {
306 return true;
307 } else if (canParse<double>(value)) {
308 return SUMORouteHandler::isStopPosValid(parse<double>(value), getAttributeDouble(SUMO_ATTR_ENDPOS), getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength(), POSITION_EPS, myFriendlyPosition);
309 } else {
310 return false;
311 }
312 case SUMO_ATTR_ENDPOS:
313 if (value.empty()) {
314 return true;
315 } else if (canParse<double>(value)) {
316 return SUMORouteHandler::isStopPosValid(getAttributeDouble(SUMO_ATTR_STARTPOS), parse<double>(value), getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength(), POSITION_EPS, myFriendlyPosition);
317 } else {
318 return false;
319 }
320 case SUMO_ATTR_NAME:
323 return canParse<bool>(value);
324 case SUMO_ATTR_LINES:
325 return canParse<std::vector<std::string> >(value);
327 return canParse<int>(value) && (parse<int>(value) > 0 || parse<int>(value) == -1);
329 return canParse<double>(value) && (parse<double>(value) >= 0);
330 case SUMO_ATTR_COLOR:
331 if (value.empty()) {
332 return true;
333 } else {
334 return canParse<RGBColor>(value);
335 }
337 return canParse<bool>(value);
339 return areParametersValid(value);
340 default:
341 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
342 }
343}
344
345// ===========================================================================
346// private
347// ===========================================================================
348
349void
350GNEBusStop::setAttribute(SumoXMLAttr key, const std::string& value) {
351 switch (key) {
352 case SUMO_ATTR_ID:
353 // update microsimID
354 setMicrosimID(value);
355 // change IDs of all access children
356 for (const auto& access : getChildAdditionals()) {
357 access->setMicrosimID(getID());
358 }
359 // enable save demand elements if there are stops
360 for (const auto& stop : getChildDemandElements()) {
361 if (stop->getTagProperty().isStop() || stop->getTagProperty().isStopPerson()) {
363 }
364 }
365 break;
366 case SUMO_ATTR_LANE:
368 break;
370 if (value == "") {
372 } else {
373 myStartPosition = parse<double>(value);
374 }
375 break;
376 case SUMO_ATTR_ENDPOS:
377 if (value == "") {
379 } else {
380 myEndPosition = parse<double>(value);
381 }
382 break;
383 case SUMO_ATTR_NAME:
384 myAdditionalName = value;
385 break;
387 myFriendlyPosition = parse<bool>(value);
388 break;
389 case SUMO_ATTR_LINES:
390 myLines = GNEAttributeCarrier::parse<std::vector<std::string> >(value);
391 break;
393 myPersonCapacity = GNEAttributeCarrier::parse<int>(value);
394 break;
396 myParkingLength = GNEAttributeCarrier::parse<double>(value);
397 break;
398 case SUMO_ATTR_COLOR:
399 if (value.empty()) {
401 } else {
402 myColor = GNEAttributeCarrier::parse<RGBColor>(value);
403 }
404 break;
406 if (parse<bool>(value)) {
408 } else {
410 }
411 break;
413 setParametersStr(value);
414 break;
417 break;
418 default:
419 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
420 }
421}
422
423/****************************************************************************/
@ GLO_BUS_STOP
a busStop
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_SELECTED
element is selected
@ 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
Definition: StdDefs.h:60
T MIN2(T a, T b)
Definition: StdDefs.h:71
std::string joinToString(const std::vector< T > &v, const T_BETWEEN &between, std::streamsize accuracy=gPrecision)
Definition: ToString.h:282
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:583
static void pushName(unsigned int name)
push Name
Definition: GLHelper.cpp:139
static void popMatrix()
pop matrix
Definition: GLHelper.cpp:130
static void popName()
pop Name
Definition: GLHelper.cpp:148
static void pushMatrix()
push matrix
Definition: GLHelper.cpp:117
static void drawRightGeometryPoint(const GNEViewNet *viewNet, const Position &pos, const double rot, const RGBColor &baseColor, const bool ignoreShift=false)
draw right geometry point
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
const RGBColor * mySpecialColor
pointer to special color (used for drawing Additional with a certain color, mainly used for selection...
static void drawLeftGeometryPoint(const GNEViewNet *viewNet, const Position &pos, const double rot, const RGBColor &baseColor, const bool ignoreShift=false)
draw left geometry point
bool isValidAdditionalID(const std::string &newID) const
check if a new additional ID is valid
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
friend class GNEChange_Attribute
declare friend class
const std::string & getTagStr() const
get tag assigned to this object in string format
const GNETagProperties & getTagProperty() const
get tagProperty associated with this Attribute Carrier
void unselectAttributeCarrier(const bool changeFlag=true)
unselect attribute carrier using GUIGlobalSelection
bool drawUsingSelectColor() const
check if attribute carrier must be drawn using selecting color.
void resetDefaultValues()
reset attribute carrier to their default values
GNENet * myNet
pointer to net
void selectAttributeCarrier(const bool changeFlag=true)
select attribute carrier using GUIGlobalSelection
const GNETagProperties & myTagProperty
reference to tagProperty associated with this attribute carrier
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their correspondent attribute are valids
Definition: GNEBusStop.cpp:294
RGBColor myColor
RGB color.
Definition: GNEBusStop.h:116
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform additional changes
Definition: GNEBusStop.cpp:270
std::string getAttribute(SumoXMLAttr key) const
Definition: GNEBusStop.cpp:223
void updateGeometry()
update pre-computed geometry information
Definition: GNEBusStop.cpp:104
GNEBusStop(SumoXMLTag tag, GNENet *net)
default constructor
Definition: GNEBusStop.cpp:38
void writeAdditional(OutputDevice &device) const
write additional element into a xml file
Definition: GNEBusStop.cpp:65
double myParkingLength
custom space for vehicles that park at this stop
Definition: GNEBusStop.h:113
std::vector< std::string > myLines
The list of lines that are assigned to this stop.
Definition: GNEBusStop.h:107
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
Definition: GNEBusStop.cpp:123
~GNEBusStop()
Destructor.
Definition: GNEBusStop.cpp:61
int myPersonCapacity
maximum number of persons that can wait at this stop
Definition: GNEBusStop.h:110
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:132
void requireSaveDemandElements(bool value)
inform that demand elements has to be saved
Definition: GNENet.cpp:2083
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:1987
void updateCenteringBoundary(const bool updateGrid)
update centering boundary (implies change in RTREE)
virtual double getAttributeDouble(SumoXMLAttr key) const
static const double myCircleWidth
circle width resolution for all stopping places
bool myFriendlyPosition
Flag for friendly position.
void drawLines(const GUIVisualizationSettings &s, const std::vector< std::string > &lines, const RGBColor &color) const
draw lines
void setStoppingPlaceGeometry(double movingToSide)
set geometry common to all stopping places
double myEndPosition
The position this stopping place is located at (-1 means empty)
void drawSign(const GUIVisualizationSettings &s, const double exaggeration, const RGBColor &baseColor, const RGBColor &signColor, const std::string &word) const
draw sign
Position mySignPos
The position of the sign.
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
void changeAttribute(GNEChange_Attribute *change)
special method for change attributes, avoid empty changes, always execute
const GNEViewNetHelper::DataViewOptions & getDataViewOptions() const
get data view options
Definition: GNEViewNet.cpp:656
const GNEAttributeCarrier * getFrontAttributeCarrier() const
get front attributeCarrier
bool drawSelectContour(const GUIGlObject *GLObject, const GNEAttributeCarrier *AC) const
check if draw select contour
bool drawDeleteContour(const GUIGlObject *GLObject, const GNEAttributeCarrier *AC) const
check if draw delete contour
void drawTranslateFrontAttributeCarrier(const GNEAttributeCarrier *AC, double typeOrLayer, const double extraOffset=0)
draw front attributeCarrier
bool isAttributeCarrierInspected(const GNEAttributeCarrier *AC) const
check if attribute carrier is being inspected
static void drawDottedContourShape(const GUIVisualizationSettings &s, const DottedContourType type, const PositionVector &shape, const double width, const double exaggeration, const bool drawFirstExtrem, const bool drawLastExtrem)
draw dotted contour for the given shape (used by additionals)
const std::vector< double > & getShapeRotations() const
The rotations of the single shape parts.
static void drawGeometry(const GUIVisualizationSettings &s, const Position &mousePos, 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.
Definition: GUIGlObject.h:141
virtual void setMicrosimID(const std::string &newID)
Changes the microsimID of the object.
void mouseWithinGeometry(const Position center, const double radius) const
check if mouse is within elements geometry (for circles)
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
Definition: GUIGlObject.h:154
GUIGlID getGlID() const
Returns the numerical id of the object.
Definition: GUIGlObject.h:102
const GUIVisualizationSettings & getVisualisationSettings() const
get visualization settings (read only)
virtual Position getPositionInformation() const
Returns the cursor's x/y position within the network.
Stores the information about how to visualize structures.
GUIVisualizationDetailSettings detailSettings
detail settings
bool drawAdditionals(const double exaggeration) const
check if additionals must be drawn
GUIVisualizationColorSettings colorSettings
color settings
GUIVisualizationStoppingPlaceSettings stoppingPlaceSettings
StoppingPlace settings.
bool drawDetail(const double detail, const double exaggeration) const
check if details can be drawn for the given GUIVisualizationDetailSettings and current scale and exxa...
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.
Definition: OptionsCont.cpp:59
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:61
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:251
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.
Definition: Parameterised.h:41
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
Definition: Parameterised.h:45
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 ammount
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 GNEAttributeCarrier *AC, GUIGlObjectType type, const Position viewPosition, 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 stoppingPlaceDetails
details for stopping places
static const double stoppingPlaceSignOffset
busStop offset
static const double busStopWidth
busStop width
static const double trainStopWidth
trainStop width