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.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>
28 #include <utils/gui/div/GLHelper.h>
31 #include <utils/xml/NamespaceIDs.h>
32 
33 #include "GNEBusStop.h"
34 
35 // ===========================================================================
36 // method definitions
37 // ===========================================================================
38 
40  GNEStoppingPlace("", net, GLO_BUS_STOP, tag, GUIIconSubSys::getIcon(GUIIcon::BUSSTOP), nullptr, 0, 0, "", false, Parameterised::Map()),
41  myPersonCapacity(0),
42  myParkingLength(0),
43  myColor(RGBColor::BLACK) {
44  // reset default values
46 }
47 
48 
49 GNEBusStop::GNEBusStop(SumoXMLTag tag, const std::string& id, GNELane* lane, GNENet* net, const double startPos, const double endPos,
50  const std::string& name, const std::vector<std::string>& lines, int personCapacity, double parkingLength, const RGBColor& color,
51  bool friendlyPosition, const Parameterised::Map& parameters) :
52  GNEStoppingPlace(id, net, GLO_BUS_STOP, tag, GUIIconSubSys::getIcon(GUIIcon::BUSSTOP), lane, startPos, endPos, name, friendlyPosition, parameters),
53  myLines(lines),
54  myPersonCapacity(personCapacity),
55  myParkingLength(parkingLength),
56  myColor(color) {
57 }
58 
59 
61 
62 
63 void
65  device.openTag(getTagProperty().getTag());
66  device.writeAttr(SUMO_ATTR_ID, getID());
67  if (!myAdditionalName.empty()) {
69  }
70  device.writeAttr(SUMO_ATTR_LANE, getParentLanes().front()->getID());
73  }
76  }
77  if (myFriendlyPosition) {
78  device.writeAttr(SUMO_ATTR_FRIENDLY_POS, "true");
79  }
82  }
85  }
88  }
89  if (getAttribute(SUMO_ATTR_COLOR).size() > 0) {
91  }
92  // write all access
93  for (const auto& access : getChildAdditionals()) {
94  access->writeAdditional(device);
95  }
96  // write parameters (Always after children to avoid problems with additionals.xsd)
97  writeParams(device);
98  device.closeTag();
99 }
100 
101 
102 void
104  // Get value of option "lefthand"
105  double offsetSign = OptionsCont::getOptions().getBool("lefthand") ? -1 : 1;
106  // Update common geometry of stopping place
107  setStoppingPlaceGeometry(getParentLanes().front()->getParentEdge()->getNBEdge()->getLaneWidth(getParentLanes().front()->getIndex()) * 0.5);
108  // Obtain a copy of the shape
110  // Move shape to side
112  // Get position of the sign
113  mySignPos = tmpShape.getLineCenter();
114  // update demand element children
115  for (const auto& demandElement : getChildDemandElements()) {
116  demandElement->updateGeometry();
117  }
118 }
119 
120 
121 void
123  // check if additional has to be drawn
125  // Obtain exaggeration of the draw
126  const double busStopExaggeration = getExaggeration(s);
127  // check if draw moving geometry points
128  const bool movingGeometryPoints = drawMovingGeometryPoints(false);
129  // get width
131  // get detail level
132  const auto d = s.getDetailLevel(busStopExaggeration);
133  // draw geometry only if we'rent in drawForObjectUnderCursor mode
134  if (!s.drawForViewObjectsHandler) {
135  // declare colors
136  RGBColor baseColor, signColor;
137  // set colors
138  if (mySpecialColor) {
139  baseColor = *mySpecialColor;
140  signColor = baseColor.changedBrightness(-32);
141  } else if (drawUsingSelectColor()) {
143  signColor = baseColor.changedBrightness(-32);
144  } else if (myColor != RGBColor::INVISIBLE) {
145  baseColor = myColor;
146  signColor = s.colorSettings.busStopColorSign;
147  } else if (myTagProperty.getTag() == SUMO_TAG_TRAIN_STOP) {
148  baseColor = s.colorSettings.trainStopColor;
149  signColor = s.colorSettings.trainStopColorSign;
150  } else {
151  baseColor = s.colorSettings.busStopColor;
152  signColor = s.colorSettings.busStopColorSign;
153  }
154  // draw parent and child lines
155  drawParentChildLines(s, baseColor);
156  // Add layer matrix
158  // translate to front
160  // set base color
161  GLHelper::setColor(baseColor);
162  // Draw the area using shape, shapeRotations, shapeLengths and value of exaggeration
163  GUIGeometry::drawGeometry(d, myAdditionalGeometry, stopWidth * MIN2(1.0, busStopExaggeration));
164  // draw lines
165  drawLines(d, myLines, baseColor);
166  // draw sign
167  drawSign(d, busStopExaggeration, baseColor, signColor, (myTagProperty.getTag() == SUMO_TAG_BUS_STOP) ? "H" : "T");
168  // draw geometry points
169  if (movingGeometryPoints && (myStartPosition != INVALID_DOUBLE)) {
171  }
172  if (movingGeometryPoints && (myEndPosition != INVALID_DOUBLE)) {
174  }
175  // pop layer matrix
177  // draw lock icon
180  } else {
182  }
183  // Draw additional ID
184  drawAdditionalID(s);
185  // draw additional name
187  // draw dotted contour
189  // draw dotted contours for geometry points
192  }
193  // draw demand element children
195  // calculate contour
196  calculateStoppingPlaceContour(s, d, stopWidth, movingGeometryPoints);
197  }
198 }
199 
200 
201 std::string
203  switch (key) {
204  case SUMO_ATTR_ID:
205  return getMicrosimID();
206  case SUMO_ATTR_LANE:
207  return getParentLanes().front()->getID();
208  case SUMO_ATTR_STARTPOS:
210  return toString(myStartPosition);
211  } else {
212  return "";
213  }
214  case SUMO_ATTR_ENDPOS:
215  if (myEndPosition != INVALID_DOUBLE) {
216  return toString(myEndPosition);
217  } else {
218  return "";
219  }
220  case SUMO_ATTR_NAME:
221  return myAdditionalName;
224  case SUMO_ATTR_LINES:
225  return joinToString(myLines, " ");
227  return toString(myPersonCapacity);
229  return toString(myParkingLength);
230  case SUMO_ATTR_COLOR:
231  if (myColor == RGBColor::INVISIBLE) {
232  return "";
233  } else {
234  return toString(myColor);
235  }
236  case GNE_ATTR_SELECTED:
238  case GNE_ATTR_PARAMETERS:
239  return getParametersStr();
241  return "";
242  default:
243  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
244  }
245 }
246 
247 
248 void
249 GNEBusStop::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
250  switch (key) {
251  case SUMO_ATTR_ID:
252  case SUMO_ATTR_LANE:
253  case SUMO_ATTR_STARTPOS:
254  case SUMO_ATTR_ENDPOS:
255  case SUMO_ATTR_NAME:
257  case SUMO_ATTR_LINES:
259  case SUMO_ATTR_COLOR:
261  case GNE_ATTR_SELECTED:
262  case GNE_ATTR_PARAMETERS:
264  GNEChange_Attribute::changeAttribute(this, key, value, undoList);
265  break;
266  default:
267  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
268  }
269 }
270 
271 
272 bool
273 GNEBusStop::isValid(SumoXMLAttr key, const std::string& value) {
274  switch (key) {
275  case SUMO_ATTR_ID:
277  case SUMO_ATTR_LANE:
278  if (myNet->getAttributeCarriers()->retrieveLane(value, false) != nullptr) {
279  return true;
280  } else {
281  return false;
282  }
283  case SUMO_ATTR_STARTPOS:
284  if (value.empty()) {
285  return true;
286  } else if (canParse<double>(value)) {
287  return SUMORouteHandler::isStopPosValid(parse<double>(value), getAttributeDouble(SUMO_ATTR_ENDPOS), getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength(), POSITION_EPS, myFriendlyPosition);
288  } else {
289  return false;
290  }
291  case SUMO_ATTR_ENDPOS:
292  if (value.empty()) {
293  return true;
294  } else if (canParse<double>(value)) {
295  return SUMORouteHandler::isStopPosValid(getAttributeDouble(SUMO_ATTR_STARTPOS), parse<double>(value), getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength(), POSITION_EPS, myFriendlyPosition);
296  } else {
297  return false;
298  }
299  case SUMO_ATTR_NAME:
302  return canParse<bool>(value);
303  case SUMO_ATTR_LINES:
304  return canParse<std::vector<std::string> >(value);
306  return canParse<int>(value) && (parse<int>(value) > 0 || parse<int>(value) == -1);
308  return canParse<double>(value) && (parse<double>(value) >= 0);
309  case SUMO_ATTR_COLOR:
310  if (value.empty()) {
311  return true;
312  } else {
313  return canParse<RGBColor>(value);
314  }
315  case GNE_ATTR_SELECTED:
316  return canParse<bool>(value);
317  case GNE_ATTR_PARAMETERS:
318  return areParametersValid(value);
319  default:
320  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
321  }
322 }
323 
324 // ===========================================================================
325 // private
326 // ===========================================================================
327 
328 void
329 GNEBusStop::setAttribute(SumoXMLAttr key, const std::string& value) {
330  switch (key) {
331  case SUMO_ATTR_ID:
332  // update microsimID
333  setAdditionalID(value);
334  break;
335  case SUMO_ATTR_LANE:
337  break;
338  case SUMO_ATTR_STARTPOS:
339  if (value == "") {
341  } else {
342  myStartPosition = parse<double>(value);
343  }
344  break;
345  case SUMO_ATTR_ENDPOS:
346  if (value == "") {
348  } else {
349  myEndPosition = parse<double>(value);
350  }
351  break;
352  case SUMO_ATTR_NAME:
353  myAdditionalName = value;
354  break;
356  myFriendlyPosition = parse<bool>(value);
357  break;
358  case SUMO_ATTR_LINES:
359  myLines = GNEAttributeCarrier::parse<std::vector<std::string> >(value);
360  break;
362  myPersonCapacity = GNEAttributeCarrier::parse<int>(value);
363  break;
365  myParkingLength = GNEAttributeCarrier::parse<double>(value);
366  break;
367  case SUMO_ATTR_COLOR:
368  if (value.empty()) {
370  } else {
371  myColor = GNEAttributeCarrier::parse<RGBColor>(value);
372  }
373  break;
374  case GNE_ATTR_SELECTED:
375  if (parse<bool>(value)) {
377  } else {
379  }
380  break;
381  case GNE_ATTR_PARAMETERS:
382  setParametersStr(value);
383  break;
385  shiftLaneIndex();
386  break;
387  default:
388  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
389  }
390 }
391 
392 /****************************************************************************/
@ 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
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:654
static void popMatrix()
pop matrix
Definition: GLHelper.cpp:130
static void pushMatrix()
push matrix
Definition: GLHelper.cpp:117
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
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:273
RGBColor myColor
RGB color.
Definition: GNEBusStop.h:119
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:249
std::string getAttribute(SumoXMLAttr key) const
Definition: GNEBusStop.cpp:202
void updateGeometry()
update pre-computed geometry information
Definition: GNEBusStop.cpp:103
GNEBusStop(SumoXMLTag tag, GNENet *net)
default constructor
Definition: GNEBusStop.cpp:39
void writeAdditional(OutputDevice &device) const
write additional element into a xml file
Definition: GNEBusStop.cpp:64
double myParkingLength
custom space for vehicles that park at this stop
Definition: GNEBusStop.h:116
std::vector< std::string > myLines
The list of lines that are assigned to this stop.
Definition: GNEBusStop.h:110
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
Definition: GNEBusStop.cpp:122
~GNEBusStop()
Destructor.
Definition: GNEBusStop.cpp:60
int myPersonCapacity
maximum number of persons that can wait at this stop
Definition: GNEBusStop.h:113
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
Definition: GNEContour.cpp:307
void drawDottedContours(const GUIVisualizationSettings &s, const GUIVisualizationSettings::Detail d, const GNEAttributeCarrier *AC, const double lineWidth, const bool addOffset) const
drawing contour functions
Definition: GNEContour.cpp:265
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:122
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:2055
virtual double getAttributeDouble(SumoXMLAttr key) const
void drawSign(const GUIVisualizationSettings::Detail d, const double exaggeration, const RGBColor &baseColor, const RGBColor &signColor, const std::string &word) const
draw sign
bool myFriendlyPosition
Flag for friendly position.
void drawLines(const GUIVisualizationSettings::Detail d, const std::vector< std::string > &lines, const RGBColor &color) const
draw lines
void setStoppingPlaceGeometry(double movingToSide)
set geometry common to all stopping places
void calculateStoppingPlaceContour(const GUIVisualizationSettings &s, const GUIVisualizationSettings::Detail d, const double width, const bool movingGeometryPoints) const
check object in view
double myEndPosition
The position this stopping place is located at (-1 means empty)
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
const GNEViewNetHelper::DataViewOptions & getDataViewOptions() const
get data view options
Definition: GNEViewNet.cpp:727
void drawTranslateFrontAttributeCarrier(const GNEAttributeCarrier *AC, double typeOrLayer, const double extraOffset=0)
draw front attributeCarrier
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.
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
Definition: GUIGlObject.h:156
const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
Definition: GUIGlObject.h:143
const GUIVisualizationSettings & getVisualisationSettings() const
get visualization settings (read only)
Stores the information about how to visualize structures.
Detail getDetailLevel(const double exaggeration) const
return the detail level
GUIVisualizationColorSettings colorSettings
color settings
GUIVisualizationDottedContourSettings dottedContourSettings
dotted contour settings
GUIVisualizationStoppingPlaceSettings stoppingPlaceSettings
StoppingPlace settings.
bool drawForViewObjectsHandler
whether drawing is performed for the purpose of selecting objects in view using ViewObjectsHandler
GUIVisualizationNeteditSizeSettings neteditSizeSettings
netedit size settings
static const std::vector< SumoXMLTag > busStops
busStops namespace
Definition: NamespaceIDs.h:38
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:60
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:61
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:254
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 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