Eclipse SUMO - Simulation of Urban MObility
NBPTStop.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-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
14 // The representation of a single pt stop
15 /****************************************************************************/
16 
17 
18 // ===========================================================================
19 // included modules
20 // ===========================================================================
21 #include <config.h>
22 
25 #include "NBPTStop.h"
26 #include "NBEdge.h"
27 #include "NBEdgeCont.h"
28 
29 
30 // ===========================================================================
31 // method definitions
32 // ===========================================================================
33 NBPTStop::NBPTStop(std::string ptStopId, Position position, std::string edgeId, std::string origEdgeId, double length,
34  std::string name, SVCPermissions svcPermissions) :
35  myPTStopId(ptStopId),
36  myPosition(position),
37  myEdgeId(edgeId),
38  myOrigEdgeId(origEdgeId),
39  myPTStopLength(length),
40  myName(name),
41  myPermissions(svcPermissions),
42  myBidiStop(nullptr),
43  myIsLoose(origEdgeId == ""),
44  myIsMultipleStopPositions(false) {
45 }
46 
47 std::string
48 NBPTStop::getID() const {
49  return myPTStopId;
50 }
51 
52 const std::string
54  return myOrigEdgeId;
55 }
56 
57 
58 const std::string
60  return myEdgeId;
61 }
62 
63 
64 const std::string
66  return myName;
67 }
68 
69 
70 const Position&
72  return myPosition;
73 }
74 
75 
76 void
77 NBPTStop::computeExtent(double center, double edgeLength) {
78  myStartPos = MAX2(0.0, center - myPTStopLength / 2.);
79  myEndPos = MIN2(center + myPTStopLength / 2., edgeLength);
80 }
81 
82 
83 void
84 NBPTStop::addLine(const std::string& line) {
85  const std::string l = StringUtils::escapeXML(line);
86  if (std::find(myLines.begin(), myLines.end(), l) == myLines.end()) {
87  myLines.push_back(l);
88  }
89 }
90 
91 
92 void
94  device.openTag(SUMO_TAG_BUS_STOP);
96  if (!myName.empty()) {
98  }
102  device.writeAttr(SUMO_ATTR_FRIENDLY_POS, "true");
103  if (myLines.size() > 0) {
105  }
106  if (!myAccesses.empty()) {
107  std::sort(myAccesses.begin(), myAccesses.end());
108  for (auto tuple : myAccesses) {
109  device.openTag(SUMO_TAG_ACCESS);
110  device.writeAttr(SUMO_ATTR_LANE, std::get<0>(tuple));
111  device.writeAttr(SUMO_ATTR_POSITION, std::get<1>(tuple));
112  device.writeAttr(SUMO_ATTR_LENGTH, std::get<2>(tuple));
113  device.writeAttr(SUMO_ATTR_FRIENDLY_POS, true);
114  device.closeTag();
115  }
116  }
117  device.closeTag();
118 }
119 
120 
121 void
122 NBPTStop::reshiftPosition(const double offsetX, const double offsetY) {
123  myPosition.add(offsetX, offsetY, 0);
124  for (NBPTPlatform& platformCand : myPlatformCands) {
125  platformCand.reshiftPosition(offsetX, offsetY);
126  }
127 }
128 
129 
132  return myPermissions;
133 }
134 
135 
136 void
138  myPlatformCands.push_back(platform);
139 }
140 
141 
142 const std::vector<NBPTPlatform>&
144  return myPlatformCands;
145 }
146 
147 
148 bool
151 }
152 
153 
154 void
155 NBPTStop::setIsMultipleStopPositions(bool multipleStopPositions) {
156  myIsMultipleStopPositions = multipleStopPositions;
157 }
158 
159 
160 double
162  return myPTStopLength;
163 }
164 
165 
166 bool
167 NBPTStop::setEdgeId(std::string edgeId, const NBEdgeCont& ec) {
168  myEdgeId = edgeId;
170 }
171 
172 
173 void
174 NBPTStop::registerAdditionalEdge(std::string wayId, std::string edgeId) {
175  myAdditionalEdgeCandidates[wayId] = edgeId;
176 }
177 
178 
179 const std::map<std::string, std::string>&
182 }
183 
184 
185 void
186 NBPTStop::setMyOrigEdgeId(const std::string& myOrigEdgeId) {
188 }
189 
190 
191 void
192 NBPTStop::setMyPTStopLength(double myPTStopLength) {
194 }
195 
196 
197 bool
199  NBEdge* edge = ec.getByID(myEdgeId);
200  if (edge != nullptr) {
201  int laneNr = -1;
202  for (const auto& it : edge->getLanes()) {
203  if ((it.permissions & getPermissions()) == getPermissions()) {
204  ++laneNr;
205  break;
206  }
207  laneNr++;
208  }
209  if (laneNr != -1) {
210  myLaneId = edge->getLaneID(laneNr);
211  const PositionVector& shape = edge->getLaneShape(laneNr);
212  double offset = shape.nearest_offset_to_point2D(getPosition(), false);
213  offset = offset * edge->getLoadedLength() / edge->getLength();
214  computeExtent(offset, edge->getLoadedLength());
215  return true;
216  }
217  }
218  return myEdgeId == ""; // loose stop. Try later when processing lines
219 }
220 
221 
222 void
223 NBPTStop::setMyPTStopId(std::string id) {
224  myPTStopId = id;
225 }
226 
227 void
229  myAccesses.clear();
230 }
231 
232 void
233 NBPTStop::addAccess(std::string laneID, double offset, double length) {
234  const std::string newEdgeID = SUMOXMLDefinitions::getEdgeIDFromLane(laneID);
235  // avoid duplicate access
236  for (auto it = myAccesses.begin(); it != myAccesses.end();) {
237  if (SUMOXMLDefinitions::getEdgeIDFromLane(std::get<0>(*it)) == newEdgeID) {
238  it = myAccesses.erase(it);
239  } else {
240  it++;
241  }
242  }
243  myAccesses.push_back(std::make_tuple(laneID, offset, length));
244 }
245 
246 
247 /****************************************************************************/
NBPTStop::myLines
std::vector< std::string > myLines
list of public transport lines (for displaying)
Definition: NBPTStop.h:124
NBPTStop::setIsMultipleStopPositions
void setIsMultipleStopPositions(bool multipleStopPositions)
Definition: NBPTStop.cpp:155
MIN2
T MIN2(T a, T b)
Definition: StdDefs.h:73
NBPTStop::computeExtent
void computeExtent(double center, double d)
Definition: NBPTStop.cpp:77
NBEdgeCont
Storage for edges, including some functionality operating on multiple edges.
Definition: NBEdgeCont.h:60
SUMO_ATTR_LENGTH
@ SUMO_ATTR_LENGTH
Definition: SUMOXMLDefinitions.h:393
NBPTStop::myLaneId
std::string myLaneId
Definition: NBPTStop.h:114
OutputDevice
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:63
NBPTStop::getPermissions
SVCPermissions getPermissions() const
Definition: NBPTStop.cpp:131
NBPTStop::getLength
double getLength() const
Definition: NBPTStop.cpp:161
NBPTStop::getMyAdditionalEdgeCandidates
const std::map< std::string, std::string > & getMyAdditionalEdgeCandidates() const
Definition: NBPTStop.cpp:180
NBPTStop::myStartPos
double myStartPos
Definition: NBPTStop.h:117
NBPTStop::setMyPTStopLength
void setMyPTStopLength(double myPTStopLength)
Definition: NBPTStop.cpp:192
NBPTStop::write
void write(OutputDevice &device)
Definition: NBPTStop.cpp:93
SUMO_ATTR_LINES
@ SUMO_ATTR_LINES
Definition: SUMOXMLDefinitions.h:776
NBEdgeCont.h
NBPTStop::myAdditionalEdgeCandidates
std::map< std::string, std::string > myAdditionalEdgeCandidates
Definition: NBPTStop.h:101
NBPTStop::myEdgeId
std::string myEdgeId
Definition: NBPTStop.h:100
NBPTStop::getID
std::string getID() const
Definition: NBPTStop.cpp:48
NBPTStop::getPlatformCands
const std::vector< NBPTPlatform > & getPlatformCands()
Definition: NBPTStop.cpp:143
NBEdgeCont::getByID
NBEdge * getByID(const std::string &edgeID) const
Returns the edge with id if it exists.
Definition: NBEdgeCont.cpp:1045
NBPTStop::getOrigEdgeId
const std::string getOrigEdgeId() const
Definition: NBPTStop.cpp:53
SUMO_ATTR_ID
@ SUMO_ATTR_ID
Definition: SUMOXMLDefinitions.h:378
SUMO_ATTR_LANE
@ SUMO_ATTR_LANE
Definition: SUMOXMLDefinitions.h:637
NBPTStop::clearAccess
void clearAccess()
remove all access definitions
Definition: NBPTStop.cpp:228
SUMO_ATTR_ENDPOS
@ SUMO_ATTR_ENDPOS
Definition: SUMOXMLDefinitions.h:798
PositionVector
A list of positions.
Definition: PositionVector.h:45
NBPTStop::addLine
void addLine(const std::string &line)
register line that services this stop (for displaying)
Definition: NBPTStop.cpp:84
NBPTStop::getEdgeId
const std::string getEdgeId() const
Definition: NBPTStop.cpp:59
NBEdge
The representation of a single edge during network building.
Definition: NBEdge.h:91
OutputDevice::closeTag
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
Definition: OutputDevice.cpp:253
MAX2
T MAX2(T a, T b)
Definition: StdDefs.h:79
NBPTStop::reshiftPosition
void reshiftPosition(const double offsetX, const double offsetY)
Definition: NBPTStop.cpp:122
PositionVector::nearest_offset_to_point2D
double nearest_offset_to_point2D(const Position &p, bool perpendicular=true) const
return the nearest offest to point 2D
Definition: PositionVector.cpp:817
OutputDevice::writeAttr
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:255
SUMO_ATTR_STARTPOS
@ SUMO_ATTR_STARTPOS
Definition: SUMOXMLDefinitions.h:797
SVCPermissions
int SVCPermissions
bitset where each bit declares whether a certain SVC may use this edge/lane
Definition: SUMOVehicleClass.h:218
NBPTStop::getIsMultipleStopPositions
bool getIsMultipleStopPositions() const
Definition: NBPTStop.cpp:149
NBPTStop::myPTStopLength
double myPTStopLength
Definition: NBPTStop.h:109
NBEdge::getLaneID
std::string getLaneID(int lane) const
get lane ID
Definition: NBEdge.cpp:3093
NBPTStop::setMyOrigEdgeId
void setMyOrigEdgeId(const std::string &myOrigEdgeId)
Definition: NBPTStop.cpp:186
StringUtils::escapeXML
static std::string escapeXML(const std::string &orig, const bool maskDoubleHyphen=false)
Replaces the standard escapes by their XML entities.
Definition: StringUtils.cpp:190
NBPTStop::myEndPos
double myEndPos
Definition: NBPTStop.h:118
OutputDevice.h
NBPTStop::setMyPTStopId
void setMyPTStopId(std::string id)
Definition: NBPTStop.cpp:223
Position
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:38
NBPTStop::addAccess
void addAccess(std::string laneID, double offset, double length)
Definition: NBPTStop.cpp:233
SUMO_ATTR_FRIENDLY_POS
@ SUMO_ATTR_FRIENDLY_POS
Definition: SUMOXMLDefinitions.h:765
NBPTPlatform
Definition: NBPTPlatform.h:22
SUMO_ATTR_POSITION
@ SUMO_ATTR_POSITION
Definition: SUMOXMLDefinitions.h:660
NBEdge::getLanes
const std::vector< NBEdge::Lane > & getLanes() const
Returns the lane definitions.
Definition: NBEdge.h:656
NBPTStop::myIsMultipleStopPositions
bool myIsMultipleStopPositions
Definition: NBPTStop.h:137
NBEdge::getLoadedLength
double getLoadedLength() const
Returns the length was set explicitly or the computed length if it wasn't set.
Definition: NBEdge.h:554
NBEdge::getLength
double getLength() const
Returns the computed length of the edge.
Definition: NBEdge.h:545
NBEdge::getLaneShape
const PositionVector & getLaneShape(int i) const
Returns the shape of the nth lane.
Definition: NBEdge.cpp:879
OutputDevice::openTag
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
Definition: OutputDevice.cpp:239
toString
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:47
StringUtils.h
SUMO_TAG_BUS_STOP
@ SUMO_TAG_BUS_STOP
A bus stop.
Definition: SUMOXMLDefinitions.h:97
NBPTStop::getPosition
const Position & getPosition() const
Definition: NBPTStop.cpp:71
NBPTStop::registerAdditionalEdge
void registerAdditionalEdge(std::string wayId, std::string edgeId)
Definition: NBPTStop.cpp:174
NBPTStop::myOrigEdgeId
std::string myOrigEdgeId
Definition: NBPTStop.h:105
NBPTStop::myPlatformCands
std::vector< NBPTPlatform > myPlatformCands
Definition: NBPTStop.h:136
NBPTStop::myName
const std::string myName
Definition: NBPTStop.h:113
NBPTStop::getName
const std::string getName() const
Definition: NBPTStop.cpp:65
NBPTStop::myPosition
Position myPosition
Definition: NBPTStop.h:99
SUMOXMLDefinitions::getEdgeIDFromLane
static std::string getEdgeIDFromLane(const std::string laneID)
return edge id when given the lane ID
Definition: SUMOXMLDefinitions.cpp:961
NBPTStop::findLaneAndComputeBusStopExtent
bool findLaneAndComputeBusStopExtent(const NBEdgeCont &ec)
Definition: NBPTStop.cpp:198
NBPTStop.h
config.h
Position::add
void add(const Position &pos)
Adds the given position to this one.
Definition: Position.h:126
NBPTStop::NBPTStop
NBPTStop(std::string ptStopId, Position position, std::string edgeId, std::string origEdgeId, double length, std::string name, SVCPermissions svcPermissions)
Constructor.
Definition: NBPTStop.cpp:33
SUMO_ATTR_NAME
@ SUMO_ATTR_NAME
Definition: SUMOXMLDefinitions.h:380
SUMO_TAG_ACCESS
@ SUMO_TAG_ACCESS
An access point for a train stop.
Definition: SUMOXMLDefinitions.h:103
NBPTStop::setEdgeId
bool setEdgeId(std::string edgeId, const NBEdgeCont &ec)
Definition: NBPTStop.cpp:167
NBPTStop::myPTStopId
std::string myPTStopId
Definition: NBPTStop.h:98
NBPTStop::myPermissions
const SVCPermissions myPermissions
Definition: NBPTStop.h:115
NBPTStop::addPlatformCand
void addPlatformCand(NBPTPlatform platform)
Definition: NBPTStop.cpp:137
NBEdge.h
NBPTStop::myAccesses
std::vector< std::tuple< std::string, double, double > > myAccesses
laneId, lanePos, accessLength
Definition: NBPTStop.h:121