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 /****************************************************************************/
15 // The representation of a single pt stop
16 /****************************************************************************/
17 
18 
19 // ===========================================================================
20 // included modules
21 // ===========================================================================
22 #include <config.h>
23 
26 #include "NBPTStop.h"
27 #include "NBEdge.h"
28 #include "NBEdgeCont.h"
29 
30 
31 // ===========================================================================
32 // method definitions
33 // ===========================================================================
34 NBPTStop::NBPTStop(std::string ptStopId, Position position, std::string edgeId, std::string origEdgeId, double length,
35  std::string name, SVCPermissions svcPermissions) :
36  myPTStopId(ptStopId),
37  myPosition(position),
38  myEdgeId(edgeId),
39  myOrigEdgeId(origEdgeId),
40  myPTStopLength(length),
41  myName(name),
42  myPermissions(svcPermissions),
43  myBidiStop(nullptr),
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, 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
188 }
189 
190 
191 void
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()) > 0) {
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  computeExtent(offset, shape.length());
214  return true;
215  }
216  }
217  return false;
218 }
219 
220 
221 void
222 NBPTStop::setMyPTStopId(std::string id) {
223  myPTStopId = id;
224 }
225 
226 void
228  myAccesses.clear();
229 }
230 
231 void
232 NBPTStop::addAccess(std::string laneID, double offset, double length) {
233  const std::string newEdgeID = SUMOXMLDefinitions::getEdgeIDFromLane(laneID);
234  // avoid duplicate access
235  for (auto it = myAccesses.begin(); it != myAccesses.end();) {
236  if (SUMOXMLDefinitions::getEdgeIDFromLane(std::get<0>(*it)) == newEdgeID) {
237  it = myAccesses.erase(it);
238  } else {
239  it++;
240  }
241  }
242  myAccesses.push_back(std::make_tuple(laneID, offset, length));
243 }
244 
245 
246 /****************************************************************************/
bool setEdgeId(std::string edgeId, NBEdgeCont &ec)
Definition: NBPTStop.cpp:167
void addAccess(std::string laneID, double offset, double length)
Definition: NBPTStop.cpp:232
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:256
void write(OutputDevice &device)
Definition: NBPTStop.cpp:93
NBEdge * getByID(const std::string &edgeID) const
Returns the edge with id if it exists.
bool myIsMultipleStopPositions
Definition: NBPTStop.h:132
void add(const Position &pos)
Adds the given position to this one.
Definition: Position.h:127
int SVCPermissions
bitset where each bit declares whether a certain SVC may use this edge/lane
The representation of a single edge during network building.
Definition: NBEdge.h:86
bool findLaneAndComputeBusStopExtent(NBEdgeCont &ec)
Definition: NBPTStop.cpp:198
T MAX2(T a, T b)
Definition: StdDefs.h:80
void clearAccess()
remove all access definitions
Definition: NBPTStop.cpp:227
const std::vector< NBEdge::Lane > & getLanes() const
Returns the lane definitions.
Definition: NBEdge.h:644
std::vector< NBPTPlatform > myPlatformCands
Definition: NBPTStop.h:131
std::string getID() const
Definition: NBPTStop.cpp:48
void setMyPTStopId(std::string id)
Definition: NBPTStop.cpp:222
void registerAdditionalEdge(std::string wayId, std::string edgeId)
Definition: NBPTStop.cpp:174
const std::string myName
Definition: NBPTStop.h:110
SVCPermissions getPermissions() const
Definition: NBPTStop.cpp:131
const std::map< std::string, std::string > & getMyAdditionalEdgeCandidates() const
Definition: NBPTStop.cpp:180
std::vector< std::tuple< std::string, double, double > > myAccesses
laneId, lanePos, accessLength
Definition: NBPTStop.h:118
NBPTStop(std::string ptStopId, Position position, std::string edgeId, std::string origEdgeId, double length, std::string name, SVCPermissions svcPermissions)
Constructor.
Definition: NBPTStop.cpp:34
std::vector< std::string > myLines
list of public transport lines (for displaying)
Definition: NBPTStop.h:121
std::string myEdgeId
Definition: NBPTStop.h:97
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:48
const std::vector< NBPTPlatform > & getPlatformCands()
Definition: NBPTStop.cpp:143
std::string getLaneID(int lane) const
get lane ID
Definition: NBEdge.cpp:3125
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:39
A list of positions.
void addLine(const std::string &line)
register line that services this stop (for displaying)
Definition: NBPTStop.cpp:84
std::string myPTStopId
Definition: NBPTStop.h:95
Storage for edges, including some functionality operating on multiple edges.
Definition: NBEdgeCont.h:61
T MIN2(T a, T b)
Definition: StdDefs.h:74
const std::string getName() const
Definition: NBPTStop.cpp:65
double getLength() const
Definition: NBPTStop.cpp:161
double myStartPos
Definition: NBPTStop.h:114
void reshiftPosition(const double offsetX, const double offsetY)
Definition: NBPTStop.cpp:122
bool getIsMultipleStopPositions() const
Definition: NBPTStop.cpp:149
static std::string escapeXML(const std::string &orig, const bool maskDoubleHyphen=false)
Replaces the standard escapes by their XML entities.
void setIsMultipleStopPositions(bool multipleStopPositions)
Definition: NBPTStop.cpp:155
double myPTStopLength
Definition: NBPTStop.h:106
void computeExtent(double center, double d)
Definition: NBPTStop.cpp:77
double length() const
Returns the length.
double myEndPos
Definition: NBPTStop.h:115
const PositionVector & getLaneShape(int i) const
Returns the shape of the nth lane.
Definition: NBEdge.cpp:871
Position myPosition
Definition: NBPTStop.h:96
std::map< std::string, std::string > myAdditionalEdgeCandidates
Definition: NBPTStop.h:98
const std::string getOrigEdgeId() const
Definition: NBPTStop.cpp:53
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:64
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
std::string myLaneId
Definition: NBPTStop.h:111
std::string myOrigEdgeId
Definition: NBPTStop.h:102
const Position & getPosition() const
Definition: NBPTStop.cpp:71
void setMyOrigEdgeId(const std::string &myOrigEdgeId)
Definition: NBPTStop.cpp:186
static std::string getEdgeIDFromLane(const std::string laneID)
return edge id when given the lane ID
const std::string getEdgeId() const
Definition: NBPTStop.cpp:59
double nearest_offset_to_point2D(const Position &p, bool perpendicular=true) const
return the nearest offest to point 2D
An access point for a train stop.
void addPlatformCand(NBPTPlatform platform)
Definition: NBPTStop.cpp:137
void setMyPTStopLength(double myPTStopLength)
Definition: NBPTStop.cpp:192
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
const SVCPermissions myPermissions
Definition: NBPTStop.h:112