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 /****************************************************************************/
21 #include <netedit/GNENet.h>
22 #include <netedit/GNEUndoList.h>
23 #include <netedit/GNEViewNet.h>
27 #include <utils/gui/div/GLHelper.h>
29 
30 #include "GNEBusStop.h"
31 
32 // ===========================================================================
33 // method definitions
34 // ===========================================================================
35 
37  GNEStoppingPlace("", net, GLO_BUS_STOP, tag, nullptr, 0, 0, "", false, std::map<std::string, std::string>()),
38  myPersonCapacity(0),
39  myParkingLength(0),
40  myColor(RGBColor::BLACK) {
41  // reset default values
43 }
44 
45 
46 GNEBusStop::GNEBusStop(SumoXMLTag tag, const std::string& id, GNELane* lane, GNENet* net, const double startPos, const double endPos,
47  const std::string& name, const std::vector<std::string>& lines, int personCapacity, double parkingLength, const RGBColor& color,
48  bool friendlyPosition, const std::map<std::string, std::string>& parameters) :
49  GNEStoppingPlace(id, net, GLO_BUS_STOP, tag, lane, startPos, endPos, name, friendlyPosition, parameters),
50  myLines(lines),
51  myPersonCapacity(personCapacity),
52  myParkingLength(parkingLength),
53  myColor(color) {
54  // update centering boundary without updating grid
56 }
57 
58 
60 
61 
62 void
64  device.openTag(getTagProperty().getTag());
65  device.writeAttr(SUMO_ATTR_ID, getID());
66  if (!myAdditionalName.empty()) {
68  }
69  device.writeAttr(SUMO_ATTR_LANE, getParentLanes().front()->getID());
72  }
75  }
76  if (myFriendlyPosition) {
77  device.writeAttr(SUMO_ATTR_FRIENDLY_POS, "true");
78  }
81  }
84  }
87  }
88  if (getAttribute(SUMO_ATTR_COLOR).size() > 0) {
90  }
91  // write all access
92  for (const auto& access : getChildAdditionals()) {
93  access->writeAdditional(device);
94  }
95  // write parameters (Always after children to avoid problems with additionals.xsd)
96  writeParams(device);
97  device.closeTag();
98 }
99 
100 
101 void
103  // Get value of option "lefthand"
104  double offsetSign = OptionsCont::getOptions().getBool("lefthand") ? -1 : 1;
105  // Update common geometry of stopping place
106  setStoppingPlaceGeometry(getParentLanes().front()->getParentEdge()->getNBEdge()->getLaneWidth(getParentLanes().front()->getIndex()) * 0.5);
107  // Obtain a copy of the shape
109  // Move shape to side
111  // Get position of the sign
112  mySignPos = tmpShape.getLineCenter();
113  // update demand element children
114  for (const auto& demandElement : getChildDemandElements()) {
115  demandElement->updateGeometry();
116  }
117 }
118 
119 
120 void
122  // Obtain exaggeration of the draw
123  const double busStopExaggeration = getExaggeration(s);
124  // first check if additional has to be drawn
126  // check exaggeration
127  if (s.drawAdditionals(busStopExaggeration)) {
128  // get width
130  // declare colors
131  RGBColor baseColor, signColor;
132  // set colors
133  if (mySpecialColor) {
134  baseColor = *mySpecialColor;
135  signColor = baseColor.changedBrightness(-32);
136  } else if (drawUsingSelectColor()) {
138  signColor = baseColor.changedBrightness(-32);
139  } else if (myColor.isValid()) {
140  baseColor = myColor;
141  signColor = s.colorSettings.busStopColorSign;
142  } else if (myTagProperty.getTag() == SUMO_TAG_TRAIN_STOP) {
143  baseColor = s.colorSettings.trainStopColor;
144  signColor = s.colorSettings.trainStopColorSign;
145  } else {
146  baseColor = s.colorSettings.busStopColor;
147  signColor = s.colorSettings.busStopColorSign;
148  }
149  // draw parent and child lines
150  drawParentChildLines(s, baseColor);
151  // Start drawing adding an gl identificator
153  // Add layer matrix
155  // translate to front
157  // set base color
158  GLHelper::setColor(baseColor);
159  // Draw the area using shape, shapeRotations, shapeLengths and value of exaggeration
160  GUIGeometry::drawGeometry(s, myNet->getViewNet()->getPositionInformation(), myAdditionalGeometry, stopWidth * MIN2(1.0, busStopExaggeration));
161  // draw detail
162  if (s.drawDetail(s.detailSettings.stoppingPlaceDetails, busStopExaggeration)) {
163  // draw lines
164  drawLines(s, myLines, baseColor);
165  // draw sign
166  drawSign(s, busStopExaggeration, baseColor, signColor, (myTagProperty.getTag() == SUMO_TAG_BUS_STOP) ? "H" : "T");
167  }
168  // draw geometry points
171  }
172  if (myEndPosition != INVALID_DOUBLE) {
174  }
175  // pop layer matrix
177  // Pop name
179  // draw lock icon
181  // check if dotted contours has to be drawn
184  busStopExaggeration, true, true);
185  }
186  if (myNet->getViewNet()->getFrontAttributeCarrier() == this) {
188  busStopExaggeration, true, true);
189  }
190  // draw child demand elements
191  for (const auto& demandElement : getChildDemandElements()) {
192  if (!demandElement->getTagProperty().isPlacedInRTree()) {
193  demandElement->drawGL(s);
194  }
195  }
196  }
197  // Draw additional ID
198  drawAdditionalID(s);
199  // draw additional name
201  }
202 }
203 
204 
205 std::string
207  switch (key) {
208  case SUMO_ATTR_ID:
209  return getID();
210  case SUMO_ATTR_LANE:
211  return getParentLanes().front()->getID();
212  case SUMO_ATTR_STARTPOS:
214  return toString(myStartPosition);
215  } else {
216  return "";
217  }
218  case SUMO_ATTR_ENDPOS:
219  if (myEndPosition != INVALID_DOUBLE) {
220  return toString(myEndPosition);
221  } else {
222  return "";
223  }
224  case SUMO_ATTR_NAME:
225  return myAdditionalName;
228  case SUMO_ATTR_LINES:
229  return joinToString(myLines, " ");
231  return toString(myPersonCapacity);
233  return toString(myParkingLength);
234  case SUMO_ATTR_COLOR:
235  if (!myColor.isValid()) {
236  return "";
237  } else {
238  return toString(myColor);
239  }
240  case GNE_ATTR_SELECTED:
242  case GNE_ATTR_PARAMETERS:
243  return getParametersStr();
245  return "";
246  default:
247  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
248  }
249 }
250 
251 
252 void
253 GNEBusStop::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
254  switch (key) {
255  case SUMO_ATTR_ID:
256  case SUMO_ATTR_LANE:
257  case SUMO_ATTR_STARTPOS:
258  case SUMO_ATTR_ENDPOS:
259  case SUMO_ATTR_NAME:
261  case SUMO_ATTR_LINES:
263  case SUMO_ATTR_COLOR:
265  case GNE_ATTR_SELECTED:
266  case GNE_ATTR_PARAMETERS:
268  undoList->changeAttribute(new GNEChange_Attribute(this, key, value));
269  break;
270  default:
271  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
272  }
273 }
274 
275 
276 bool
277 GNEBusStop::isValid(SumoXMLAttr key, const std::string& value) {
278  switch (key) {
279  case SUMO_ATTR_ID:
280  return isValidAdditionalID(value);
281  case SUMO_ATTR_LANE:
282  if (myNet->getAttributeCarriers()->retrieveLane(value, false) != nullptr) {
283  return true;
284  } else {
285  return false;
286  }
287  case SUMO_ATTR_STARTPOS:
288  if (value.empty()) {
289  return true;
290  } else if (canParse<double>(value)) {
291  return SUMORouteHandler::isStopPosValid(parse<double>(value), getAttributeDouble(SUMO_ATTR_ENDPOS), getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength(), POSITION_EPS, myFriendlyPosition);
292  } else {
293  return false;
294  }
295  case SUMO_ATTR_ENDPOS:
296  if (value.empty()) {
297  return true;
298  } else if (canParse<double>(value)) {
299  return SUMORouteHandler::isStopPosValid(getAttributeDouble(SUMO_ATTR_STARTPOS), parse<double>(value), getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength(), POSITION_EPS, myFriendlyPosition);
300  } else {
301  return false;
302  }
303  case SUMO_ATTR_NAME:
306  return canParse<bool>(value);
307  case SUMO_ATTR_LINES:
308  return canParse<std::vector<std::string> >(value);
310  return canParse<int>(value) && (parse<int>(value) > 0 || parse<int>(value) == -1);
312  return canParse<double>(value) && (parse<double>(value) >= 0);
313  case SUMO_ATTR_COLOR:
314  if (value.empty()) {
315  return true;
316  } else {
317  return canParse<RGBColor>(value);
318  }
319  case GNE_ATTR_SELECTED:
320  return canParse<bool>(value);
321  case GNE_ATTR_PARAMETERS:
322  return Parameterised::areParametersValid(value);
323  default:
324  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
325  }
326 }
327 
328 // ===========================================================================
329 // private
330 // ===========================================================================
331 
332 void
333 GNEBusStop::setAttribute(SumoXMLAttr key, const std::string& value) {
334  switch (key) {
335  case SUMO_ATTR_ID:
336  // update microsimID
337  setMicrosimID(value);
338  // change IDs of all access children
339  for (const auto& access : getChildAdditionals()) {
340  access->setMicrosimID(getID());
341  }
342  // enable save demand elements if there are stops
343  for (const auto& stop : getChildDemandElements()) {
344  if (stop->getTagProperty().isStop() || stop->getTagProperty().isStopPerson()) {
346  }
347  }
348  break;
349  case SUMO_ATTR_LANE:
351  break;
352  case SUMO_ATTR_STARTPOS:
353  if (value == "") {
355  } else {
356  myStartPosition = parse<double>(value);
357  }
358  break;
359  case SUMO_ATTR_ENDPOS:
360  if (value == "") {
362  } else {
363  myEndPosition = parse<double>(value);
364  }
365  break;
366  case SUMO_ATTR_NAME:
367  myAdditionalName = value;
368  break;
370  myFriendlyPosition = parse<bool>(value);
371  break;
372  case SUMO_ATTR_LINES:
373  myLines = GNEAttributeCarrier::parse<std::vector<std::string> >(value);
374  break;
376  myPersonCapacity = GNEAttributeCarrier::parse<int>(value);
377  break;
379  myParkingLength = GNEAttributeCarrier::parse<double>(value);
380  break;
381  case SUMO_ATTR_COLOR:
382  if (value.empty()) {
383  myColor.setValid(false);
384  } else {
385  myColor = GNEAttributeCarrier::parse<RGBColor>(value);
386  }
387  break;
388  case GNE_ATTR_SELECTED:
389  if (parse<bool>(value)) {
391  } else {
393  }
394  break;
395  case GNE_ATTR_PARAMETERS:
396  setParametersStr(value);
397  break;
399  shiftLaneIndex();
400  break;
401  default:
402  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
403  }
404 }
405 
406 /****************************************************************************/
@ GLO_BUS_STOP
a busStop
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:63
T MIN2(T a, T b)
Definition: StdDefs.h:74
std::string joinToString(const std::vector< T > &v, const T_BETWEEN &between, std::streamsize accuracy=gPrecision)
Definition: ToString.h:269
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:507
static void pushName(unsigned int name)
push Name
Definition: GLHelper.cpp:132
static void popMatrix()
pop matrix
Definition: GLHelper.cpp:123
static void popName()
pop Name
Definition: GLHelper.cpp:141
static void pushMatrix()
push matrix
Definition: GLHelper.cpp:114
static void drawRightGeometryPoint(const GNEViewNet *viewNet, const Position &pos, const double rot, const RGBColor &baseColor)
draw right geometry point
const std::string & getID() const
get ID
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 asociated 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...
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
static void drawLeftGeometryPoint(const GNEViewNet *viewNet, const Position &pos, const double rot, const RGBColor &baseColor)
draw left geometry point
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 conrrespond attribute are valids
Definition: GNEBusStop.cpp:277
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:253
std::string getAttribute(SumoXMLAttr key) const
Definition: GNEBusStop.cpp:206
void updateGeometry()
update pre-computed geometry information
Definition: GNEBusStop.cpp:102
GNEBusStop(SumoXMLTag tag, GNENet *net)
default constructor
Definition: GNEBusStop.cpp:36
void writeAdditional(OutputDevice &device) const
writte additional element into a xml file
Definition: GNEBusStop.cpp:63
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:121
~GNEBusStop()
Destructor.
Definition: GNEBusStop.cpp:59
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:125
void requireSaveDemandElements(bool value)
inform that demand elements has to be saved
Definition: GNENet.cpp:2058
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:1964
void updateCenteringBoundary(const bool updateGrid)
update centering boundary (implies change in RTREE)
virtual double getAttributeDouble(SumoXMLAttr key) const
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:537
const GNEAttributeCarrier * getFrontAttributeCarrier() const
get front attributeCarrier
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 DottedContourType type, const GUIVisualizationSettings &s, const PositionVector &shape, const double width, const double exaggeration, const bool drawFirstExtrem, const bool drawLastExtrem, const double lineWidth=-1)
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.
virtual void setMicrosimID(const std::string &newID)
Changes the microsimID of the object.
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
GUIGlID getGlID() const
Returns the numerical id of the object.
GUIVisualizationSettings & getVisualisationSettings() const
get visualization settings
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:58
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:248
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
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|....
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)
void setValid(const bool value)
set valid
Definition: RGBColor.cpp:114
bool isValid() const
check if RGBColor is valid
Definition: RGBColor.cpp:120
RGBColor changedBrightness(int change, int toChange=3) const
Returns a new color with altered brightness.
Definition: RGBColor.cpp:197
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