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-2020 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 
36 GNEBusStop::GNEBusStop(const std::string& id, GNELane* lane, GNENet* net, const double startPos, const double endPos, const int parametersSet,
37  const std::string& name, const std::vector<std::string>& lines, int personCapacity, double parkingLength, bool friendlyPosition, bool blockMovement) :
38  GNEStoppingPlace(id, net, GLO_BUS_STOP, SUMO_TAG_BUS_STOP, lane, startPos, endPos, parametersSet, name, friendlyPosition, blockMovement),
39  myLines(lines),
40  myPersonCapacity(personCapacity),
41  myParkingLength(parkingLength) {
42  // update centering boundary without updating grid
44 }
45 
46 
48 
49 
50 void
52  // Get value of option "lefthand"
53  double offsetSign = OptionsCont::getOptions().getBool("lefthand") ? -1 : 1;
54 
55  // Update common geometry of stopping place
56  setStoppingPlaceGeometry(getParentLanes().front()->getParentEdge()->getNBEdge()->getLaneWidth(getParentLanes().front()->getIndex()) * 0.5);
57 
58  // Obtain a copy of the shape
60 
61  // Move shape to side
63 
64  // Get position of the sign
65  mySignPos = tmpShape.getLineCenter();
66 
67  // update child demand elements geometry
68  for (const auto& demandElement : getChildDemandElements()) {
69  // special case for person trips
70  if (demandElement->getTagProperty().isPersonTrip()) {
71  // update previous and next person plan
72  GNEDemandElement* previousDemandElement = demandElement->getParentDemandElements().front()->getPreviousChildDemandElement(demandElement);
73  if (previousDemandElement) {
74  previousDemandElement->updatePartialGeometry(getParentLanes().front());
75  }
76  GNEDemandElement* nextDemandElement = demandElement->getParentDemandElements().front()->getNextChildDemandElement(demandElement);
77  if (nextDemandElement) {
78  nextDemandElement->updatePartialGeometry(getParentLanes().front());
79  }
80  }
81  demandElement->updatePartialGeometry(getParentLanes().front());
82  }
83 }
84 
85 
86 void
88  // Obtain exaggeration of the draw
89  const double busStopExaggeration = s.addSize.getExaggeration(s, this);
90  // first check if additional has to be drawn
91  if (s.drawAdditionals(busStopExaggeration) && myNet->getViewNet()->getDataViewOptions().showAdditionals()) {
92  // declare colors
93  RGBColor baseColor, signColor;
94  // set colors
95  if (mySpecialColor) {
96  baseColor = *mySpecialColor;
97  signColor = baseColor.changedBrightness(-32);
98  } else if (drawUsingSelectColor()) {
100  signColor = baseColor.changedBrightness(-32);
101  } else {
102  baseColor = s.stoppingPlaceSettings.busStopColor;
104  }
105  // Start drawing adding an gl identificator
106  glPushName(getGlID());
107  // Add a draw matrix
108  glPushMatrix();
109  // translate to front
111  // set base color
112  GLHelper::setColor(baseColor);
113  // Draw the area using shape, shapeRotations, shapeLengths and value of exaggeration
115  // draw detail
116  if (s.drawDetail(s.detailSettings.stoppingPlaceDetails, busStopExaggeration)) {
117  // draw lines
118  drawLines(s, myLines, baseColor);
119  // draw sign
120  drawSign(s, busStopExaggeration, baseColor, signColor, "H");
121  // draw lock icon
122  GNEViewNetHelper::LockIcon::drawLockIcon(this, myAdditionalGeometry, busStopExaggeration, 0, 0, true);
123  }
124  // pop draw matrix
125  glPopMatrix();
126  // Pop name
127  glPopName();
128  // draw connection betwen access
129  drawConnectionAccess(s, baseColor);
130  // Draw additional ID
131  drawAdditionalID(s);
132  // draw additional name
134  // check if dotted contours has to be drawn
137  }
138  if (s.drawDottedContour() || myNet->getViewNet()->getFrontAttributeCarrier() == this) {
140  }
141  // draw child demand elements
142  for (const auto& demandElement : getChildDemandElements()) {
143  if (!demandElement->getTagProperty().isPlacedInRTree()) {
144  demandElement->drawGL(s);
145  }
146  }
147  }
148 }
149 
150 
151 std::string
153  switch (key) {
154  case SUMO_ATTR_ID:
155  return getID();
156  case SUMO_ATTR_LANE:
157  return getParentLanes().front()->getID();
158  case SUMO_ATTR_STARTPOS:
160  return toString(myStartPosition);
161  } else {
162  return "";
163  }
164  case SUMO_ATTR_ENDPOS:
166  return toString(myEndPosition);
167  } else {
168  return "";
169  }
170  case SUMO_ATTR_NAME:
171  return myAdditionalName;
174  case SUMO_ATTR_LINES:
175  return joinToString(myLines, " ");
177  return toString(myPersonCapacity);
179  return toString(myParkingLength);
181  return toString(myBlockMovement);
182  case GNE_ATTR_SELECTED:
184  case GNE_ATTR_PARAMETERS:
185  return getParametersStr();
186  default:
187  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
188  }
189 }
190 
191 
192 void
193 GNEBusStop::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
194  if (value == getAttribute(key)) {
195  return; //avoid needless changes, later logic relies on the fact that attributes have changed
196  }
197  switch (key) {
198  case SUMO_ATTR_ID:
199  case SUMO_ATTR_LANE:
200  case SUMO_ATTR_STARTPOS:
201  case SUMO_ATTR_ENDPOS:
202  case SUMO_ATTR_NAME:
204  case SUMO_ATTR_LINES:
208  case GNE_ATTR_SELECTED:
209  case GNE_ATTR_PARAMETERS:
210  undoList->p_add(new GNEChange_Attribute(this, key, value));
211  break;
212  default:
213  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
214  }
215 }
216 
217 
218 bool
219 GNEBusStop::isValid(SumoXMLAttr key, const std::string& value) {
220  switch (key) {
221  case SUMO_ATTR_ID:
222  return isValidAdditionalID(value);
223  case SUMO_ATTR_LANE:
224  if (myNet->retrieveLane(value, false) != nullptr) {
225  return true;
226  } else {
227  return false;
228  }
229  case SUMO_ATTR_STARTPOS:
230  if (value.empty()) {
231  return true;
232  } else if (canParse<double>(value)) {
233  return SUMORouteHandler::isStopPosValid(parse<double>(value), myEndPosition, getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength(), POSITION_EPS, myFriendlyPosition);
234  } else {
235  return false;
236  }
237  case SUMO_ATTR_ENDPOS:
238  if (value.empty()) {
239  return true;
240  } else if (canParse<double>(value)) {
241  return SUMORouteHandler::isStopPosValid(myStartPosition, parse<double>(value), getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength(), POSITION_EPS, myFriendlyPosition);
242  } else {
243  return false;
244  }
245  case SUMO_ATTR_NAME:
248  return canParse<bool>(value);
249  case SUMO_ATTR_LINES:
250  return canParse<std::vector<std::string> >(value);
252  return canParse<int>(value) && (parse<int>(value) > 0 || parse<int>(value) == -1);
254  return canParse<double>(value) && (parse<double>(value) >= 0);
256  return canParse<bool>(value);
257  case GNE_ATTR_SELECTED:
258  return canParse<bool>(value);
259  case GNE_ATTR_PARAMETERS:
260  return Parameterised::areParametersValid(value);
261  default:
262  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
263  }
264 }
265 
266 // ===========================================================================
267 // private
268 // ===========================================================================
269 
270 void
271 GNEBusStop::setAttribute(SumoXMLAttr key, const std::string& value) {
272  switch (key) {
273  case SUMO_ATTR_ID:
274  myNet->getAttributeCarriers()->updateID(this, value);
275  // Change IDs of all access children
276  for (const auto& access : getChildAdditionals()) {
277  access->setMicrosimID(getID());
278  }
279  break;
280  case SUMO_ATTR_LANE:
282  break;
283  case SUMO_ATTR_STARTPOS:
284  if (!value.empty()) {
285  myStartPosition = parse<double>(value);
287  } else {
289  }
290  break;
291  case SUMO_ATTR_ENDPOS:
292  if (!value.empty()) {
293  myEndPosition = parse<double>(value);
295  } else {
297  }
298  break;
299  case SUMO_ATTR_NAME:
300  myAdditionalName = value;
301  break;
303  myFriendlyPosition = parse<bool>(value);
304  break;
305  case SUMO_ATTR_LINES:
306  myLines = GNEAttributeCarrier::parse<std::vector<std::string> >(value);
307  break;
309  myPersonCapacity = GNEAttributeCarrier::parse<int>(value);
310  break;
312  myParkingLength = GNEAttributeCarrier::parse<double>(value);
313  break;
315  myBlockMovement = parse<bool>(value);
316  break;
317  case GNE_ATTR_SELECTED:
318  if (parse<bool>(value)) {
320  } else {
322  }
323  break;
324  case GNE_ATTR_PARAMETERS:
325  setParametersStr(value);
326  break;
327  default:
328  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
329  }
330 }
331 
332 
333 void
336  // Add a draw matrix for details
337  glPushMatrix();
338  // move to GLO_BUS_STOP
339  glTranslated(0, 0, GLO_BUS_STOP);
340  // set color
341  GLHelper::setColor(color);
342  // draw lines between BusStops and Access
343  for (const auto& access : getChildAdditionals()) {
344  // get busStop center
345  const Position busStopCenter = myAdditionalGeometry.getShape().getLineCenter();
346  // get access center
347  const Position accessCenter = access->getAdditionalGeometry().getShape().front();
348  GLHelper::drawBoxLine(accessCenter,
349  RAD2DEG(busStopCenter.angleTo2D(accessCenter)) - 90,
350  busStopCenter.distanceTo2D(accessCenter), .05);
351  }
352  // pop draw matrix
353  glPopMatrix();
354  }
355 }
356 
357 /****************************************************************************/
const int STOPPINGPLACE_STARTPOS_SET
const int STOPPINGPLACE_ENDPOS_SET
@ GLO_BUS_STOP
a busStop
#define RAD2DEG(x)
Definition: GeomHelper.h:36
@ SUMO_TAG_BUS_STOP
A bus stop.
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ SUMO_ATTR_STARTPOS
@ SUMO_ATTR_LINES
@ SUMO_ATTR_LANE
@ SUMO_ATTR_PARKING_LENGTH
@ GNE_ATTR_BLOCK_MOVEMENT
block movement of a graphic element
@ 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_ID
@ SUMO_ATTR_PERSON_CAPACITY
std::string joinToString(const std::vector< T > &v, const T_BETWEEN &between, std::streamsize accuracy=gPrecision)
Definition: ToString.h:250
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:44
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:446
static void drawBoxLine(const Position &beg, double rot, double visLength, double width, double offset=0)
Draws a thick line.
Definition: GLHelper.cpp:135
const std::string & getID() const
get ID
GNEGeometry::Geometry 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
bool myBlockMovement
boolean to check if additional element is blocked (i.e. cannot be moved with mouse)
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
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
void unselectAttributeCarrier(const bool changeFlag=true)
unselect attribute carrier using GUIGlobalSelection
bool drawUsingSelectColor() const
check if attribute carrier must be drawn using selecting color.
GNENet * myNet
pointer to net
void selectAttributeCarrier(const bool changeFlag=true)
select attribute carrier using GUIGlobalSelection
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
Definition: GNEBusStop.cpp:219
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:193
std::string getAttribute(SumoXMLAttr key) const
Definition: GNEBusStop.cpp:152
void updateGeometry()
update pre-computed geometry information
Definition: GNEBusStop.cpp:51
double myParkingLength
custom space for vehicles that park at this stop
Definition: GNEBusStop.h:99
void drawConnectionAccess(const GUIVisualizationSettings &s, const RGBColor &color) const
draw connections between busStops and access
Definition: GNEBusStop.cpp:334
std::vector< std::string > myLines
The list of lines that are assigned to this stop.
Definition: GNEBusStop.h:93
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
Definition: GNEBusStop.cpp:87
~GNEBusStop()
Destructor.
Definition: GNEBusStop.cpp:47
GNEBusStop(const std::string &id, GNELane *lane, GNENet *net, const double startPos, const double endPos, const int parametersSet, const std::string &name, const std::vector< std::string > &lines, int personCapacity, double parkingLength, bool friendlyPosition, bool blockMovement)
Constructor.
Definition: GNEBusStop.cpp:36
int myPersonCapacity
maximum number of persons that can wait at this stop
Definition: GNEBusStop.h:96
An Element which don't belongs to GNENet but has influency in the simulation.
void updatePartialGeometry(const GNELane *lane)
partial update pre-computed geometry information
const PositionVector & getShape() const
The shape of the additional element.
const std::vector< GNEDemandElement * > & getChildDemandElements() const
return child demand elements
const std::vector< GNEDemandElement * > & getParentDemandElements() const
get parent 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:45
void updateID(GNEAttributeCarrier *AC, const std::string newID)
update ID
A NBNetBuilder extended by visualisation and editing capabilities.
Definition: GNENet.h:40
GNELane * retrieveLane(const std::string &id, bool failHard=true, bool checkVolatileChange=false)
get lane by id
Definition: GNENet.cpp:1337
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
retrieve all attribute carriers of Net
Definition: GNENet.cpp:130
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:2245
void updateCenteringBoundary(const bool updateGrid)
update centering boundary (implies change in RTREE)
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 (optional, if empty takes the lane length)
void drawSign(const GUIVisualizationSettings &s, const double exaggeration, const RGBColor &baseColor, const RGBColor &signColor, const std::string &word) const
draw sign
int myParametersSet
Variable used for set/unset start/endPositions.
Position mySignPos
The position of the sign.
double myStartPosition
The relative start position this stopping place is located at (optional, if empty takes 0)
void p_add(GNEChange_Attribute *cmd)
special method, avoid empty changes, always execute
const GNEViewNetHelper::DataViewOptions & getDataViewOptions() const
get data view options
Definition: GNEViewNet.cpp:491
const GNEAttributeCarrier * getFrontAttributeCarrier() const
get front attributeCarrier
bool isAttributeCarrierInspected(const GNEAttributeCarrier *AC) const
check if attribute carrier is being inspected
void drawTranslateFrontAttributeCarrier(const GNEAttributeCarrier *AC, GUIGlObjectType objectType, const double extraOffset=0)
draw front attributeCarrier
GUIGlID getGlID() const
Returns the numerical id of the object.
GUIVisualizationSettings & getVisualisationSettings() const
get visualization settings
Stores the information about how to visualize structures.
bool drawForRectangleSelection
whether drawing is performed for the purpose of selecting objects using a rectangle
GUIVisualizationDetailSettings detailSettings
detail settings
GUIVisualizationSizeSettings addSize
bool drawForPositionSelection
whether drawing is performed for the purpose of selecting objects with a single click
bool drawDottedContour() const
check if dotted contour can be drawn
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 bool areParametersValid(const std::string &value, bool report=false, ParameterisedAttrType attrType=ParameterisedAttrType::STRING, 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"
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 point in 2D or 3D with translation and scaling methods.
Definition: Position.h:36
double distanceTo2D(const Position &p2) const
returns the euclidean distance in the x-y-plane
Definition: Position.h:241
double angleTo2D(const Position &other) const
returns the angle in the plane of the vector pointing from here to the other position
Definition: Position.h:251
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
RGBColor changedBrightness(int change, int toChange=3) const
Returns a new color with altered brightness.
Definition: RGBColor.cpp:145
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 void drawDottedContourShape(const DottedContourType type, const GUIVisualizationSettings &s, const PositionVector &shape, const double width, const double exaggeration)
draw dotted contour for the given shape (used by additionals)
static void drawGeometry(const GNEViewNet *viewNet, const Geometry &geometry, const double width)
draw geometry
bool showAdditionals() const
check if additionals has to be drawn
static void drawLockIcon(const GNEAttributeCarrier *AC, const GNEGeometry::Geometry &geometry, const double exaggeration, const double offsetx, const double offsety, const bool overlane, const double size=0.5)
draw lock icon
RGBColor selectedAdditionalColor
additional selection color (busStops, Detectors...)
static const double stoppingPlaceDetails
details for stopping places
double getExaggeration(const GUIVisualizationSettings &s, const GUIGlObject *o, double factor=20) const
return the drawing size including exaggeration and constantSize values
static const double stoppingPlaceSignOffset
busStop offset
static const double busStopWidth
busStop width
static const RGBColor busStopColorSign
color for busStops signs
static const RGBColor busStopColor
color for busStops