Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
NBPTStop.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-2026 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// The representation of a single pt stop
19/****************************************************************************/
20#include <config.h>
21
24#include "NBEdge.h"
25#include "NBEdgeCont.h"
26#include "NBPTPlatform.h"
27#include "NBPTStop.h"
28
29
30// ===========================================================================
31// method definitions
32// ===========================================================================
33NBPTStop::NBPTStop(SumoXMLTag tag, std::string ptStopId, Position position, std::string edgeId, std::string origEdgeId, double length,
34 std::string name, SVCPermissions svcPermissions, double parkingLength, const RGBColor color, double givenStartPos) :
35 myTag(tag),
36 myPTStopId(ptStopId),
37 myPosition(position),
38 myEdgeId(edgeId),
39 myOrigEdgeId(origEdgeId),
40 myPTStopLength(length),
41 myName(name),
42 myParkingLength(parkingLength),
43 myColor(color),
44 myPermissions(svcPermissions),
45 myStartPos(0),
46 myEndPos(0),
47 myBidiStop(std::weak_ptr<NBPTStop>()),
48 myIsLoose(origEdgeId == ""),
49 myIsPlatform(false),
50 myIsMultipleStopPositions(false),
51 myAreaID(-1),
52 myGivenStartPos(givenStartPos) {
53}
54
55
56std::string
58 return myPTStopId;
59}
60
61
62const std::string
64 return myOrigEdgeId;
65}
66
67
68const std::string&
70 return myEdgeId;
71}
72
73
74const std::string
76 return myName;
77}
78
79
80const Position&
82 return myPosition;
83}
84
85
86void
88 myPosition.mul(1, -1);
89}
90
91
92void
93NBPTStop::addLine(const std::string& line) {
94 const std::string l = StringUtils::escapeXML(line);
95 if (std::find(myLines.begin(), myLines.end(), l) == myLines.end()) {
96 myLines.push_back(l);
97 }
98}
99
100
101void
103 device.openTag(myTag);
105 if (!myName.empty()) {
107 }
111 device.writeAttr(SUMO_ATTR_FRIENDLY_POS, "true");
112 if (myLines.size() > 0) {
114 }
115 if (myParkingLength > 0) {
117 }
118 if (myColor.isValid()) {
120 }
121 if (!myAccesses.empty()) {
122 std::sort(myAccesses.begin(), myAccesses.end());
123 for (auto tuple : myAccesses) {
124 device.openTag(SUMO_TAG_ACCESS);
125 device.writeAttr(SUMO_ATTR_LANE, std::get<0>(tuple));
126 device.writeAttr(SUMO_ATTR_POSITION, std::get<1>(tuple));
127 device.writeAttr(SUMO_ATTR_LENGTH, std::get<2>(tuple));
128 device.writeAttr(SUMO_ATTR_FRIENDLY_POS, true);
129 device.closeTag();
130 }
131 }
132 writeParams(device);
133 device.closeTag();
134}
135
136
137void
138NBPTStop::reshiftPosition(const double offsetX, const double offsetY) {
139 myPosition.add(offsetX, offsetY, 0);
140 for (NBPTPlatform& platformCand : myPlatformCands) {
141 platformCand.reshiftPosition(offsetX, offsetY);
142 }
143}
144
145
148 return myPermissions;
149}
150
151
152void
154 myPlatformCands.push_back(platform);
155}
156
157
158const std::vector<NBPTPlatform>&
162
163
164bool
168
169
170void
171NBPTStop::setIsMultipleStopPositions(bool multipleStopPositions, long long int areaID) {
172 myIsMultipleStopPositions = multipleStopPositions;
173 myAreaID = areaID;
174}
175
176
177double
179 return myPTStopLength;
180}
181
182
183bool
184NBPTStop::setEdgeId(std::string edgeId, const NBEdgeCont& ec) {
185 myEdgeId = edgeId;
187}
188
189
190void
191NBPTStop::registerAdditionalEdge(std::string wayId, std::string edgeId) {
192 myAdditionalEdgeCandidates[wayId] = edgeId;
193}
194
195
196bool
201
202
203bool
205 if (edge != nullptr) {
206 myEdgeId = edge->getID();
207 int laneNr = -1;
208 for (const auto& it : edge->getLanes()) {
209 if ((it.permissions & getPermissions()) == getPermissions()) {
210 ++laneNr;
211 break;
212 }
213 laneNr++;
214 }
215 if (laneNr != -1) {
216 myLaneId = edge->getLaneID(laneNr);
217 const PositionVector& shape = edge->getLaneShape(laneNr);
218 double offset = shape.nearest_offset_to_point2D(getPosition(), false);
219 const double edgeLength = edge->getFinalLength();
220 offset *= edgeLength / shape.length2D();
221 if (wasLoaded()) {
224 } else {
225 myStartPos = MAX2(0.0, offset - myPTStopLength / 2.);
226 myEndPos = MIN2(myStartPos + myPTStopLength, edgeLength);
227 double missing = myPTStopLength - (myEndPos - myStartPos);
228 if (missing > 0) {
229 myStartPos = MAX2(0.0, myStartPos - missing);
230 }
231 }
232 return true;
233 }
234 }
235 return myEdgeId == ""; // loose stop. Try later when processing lines
236}
237
238
239void
241 myAccesses.clear();
242}
243
244
245void
246NBPTStop::addAccess(std::string laneID, double offset, double length) {
247 const std::string newEdgeID = SUMOXMLDefinitions::getEdgeIDFromLane(laneID);
248 // avoid duplicate access
249 for (auto it = myAccesses.begin(); it != myAccesses.end();) {
250 if (SUMOXMLDefinitions::getEdgeIDFromLane(std::get<0>(*it)) == newEdgeID) {
251 it = myAccesses.erase(it);
252 } else {
253 it++;
254 }
255 }
256 myAccesses.push_back(std::make_tuple(laneID, offset, length));
257}
258
259
260bool
261NBPTStop::replaceEdge(const std::string& edgeID, const EdgeVector& replacement) {
262 if (myEdgeId == edgeID) {
263 // find best edge among replacement edges
264 double bestDist = std::numeric_limits<double>::max();
265 NBEdge* bestEdge = nullptr;
266 for (NBEdge* cand : replacement) {
267 if (myPermissions == 0 || (cand->getPermissions() & myPermissions) != 0) {
268 const double dist = cand->getGeometry().distance2D(myPosition) + MAX2(0., myPTStopLength - cand->getLoadedLength());
269 if (dist < bestDist) {
270 bestDist = dist;
271 bestEdge = cand;
272 }
273 }
274 }
275 if (bestEdge != nullptr) {
276 if ((bestEdge->getPermissions() & SVC_PEDESTRIAN) != 0) {
277 // no need for access
278 clearAccess();
279 }
280 return findLaneAndComputeBusStopExtent(bestEdge);
281 }
282 return false;
283 }
284 return true;
285}
286
287
288/****************************************************************************/
std::vector< NBEdge * > EdgeVector
container for (sorted) edges
Definition NBCont.h:42
long long int SVCPermissions
bitset where each bit declares whether a certain SVC may use this edge/lane
@ SVC_PEDESTRIAN
pedestrian
SumoXMLTag
Numbers representing SUMO-XML - element names.
@ SUMO_TAG_ACCESS
An access point for a train stop.
@ SUMO_ATTR_STARTPOS
@ SUMO_ATTR_LINES
@ SUMO_ATTR_LANE
@ SUMO_ATTR_PARKING_LENGTH
@ SUMO_ATTR_ENDPOS
@ SUMO_ATTR_NAME
@ SUMO_ATTR_FRIENDLY_POS
@ SUMO_ATTR_LENGTH
@ SUMO_ATTR_COLOR
A color information.
@ SUMO_ATTR_ID
@ SUMO_ATTR_POSITION
T MIN2(T a, T b)
Definition StdDefs.h:80
T MAX2(T a, T b)
Definition StdDefs.h:86
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:46
Storage for edges, including some functionality operating on multiple edges.
Definition NBEdgeCont.h:59
NBEdge * getByID(const std::string &edgeID) const
Returns the edge with id if it exists.
The representation of a single edge during network building.
Definition NBEdge.h:92
SVCPermissions getPermissions(int lane=-1) const
get the union of allowed classes over all lanes or for a specific lane
Definition NBEdge.cpp:4540
const PositionVector & getGeometry() const
Returns the geometry of the edge.
Definition NBEdge.h:789
const std::vector< NBEdge::Lane > & getLanes() const
Returns the lane definitions.
Definition NBEdge.h:736
const std::string & getID() const
Definition NBEdge.h:1551
std::string getLaneID(int lane) const
get lane ID
Definition NBEdge.cpp:4178
const PositionVector & getLaneShape(int i) const
Returns the shape of the nth lane.
Definition NBEdge.cpp:1009
double getFinalLength() const
get length that will be assigned to the lanes in the final network
Definition NBEdge.cpp:4884
The representation of a single pt stop.
Definition NBPTStop.h:45
bool myIsMultipleStopPositions
Definition NBPTStop.h:203
std::map< std::string, std::string > myAdditionalEdgeCandidates
Definition NBPTStop.h:176
double myStartPos
Definition NBPTStop.h:185
void registerAdditionalEdge(std::string wayId, std::string edgeId)
Definition NBPTStop.cpp:191
const SVCPermissions myPermissions
Definition NBPTStop.h:183
double myPTStopLength
Definition NBPTStop.h:178
bool findLaneAndComputeBusStopExtent(const NBEdgeCont &ec)
Definition NBPTStop.cpp:197
void addPlatformCand(NBPTPlatform platform)
Definition NBPTStop.cpp:153
void clearAccess()
remove all access definitions
Definition NBPTStop.cpp:240
std::string myLaneId
Definition NBPTStop.h:182
SumoXMLTag myTag
Definition NBPTStop.h:172
std::string myPTStopId
Definition NBPTStop.h:173
double myGivenStartPos
Definition NBPTStop.h:205
std::vector< NBPTPlatform > myPlatformCands
Definition NBPTStop.h:202
std::vector< std::string > myLines
list of public transport lines (for displaying)
Definition NBPTStop.h:192
bool setEdgeId(std::string edgeId, const NBEdgeCont &ec)
Definition NBPTStop.cpp:184
bool wasLoaded() const
Definition NBPTStop.h:112
std::string getID() const
Definition NBPTStop.cpp:57
void mirrorX()
mirror coordinates along the x-axis
Definition NBPTStop.cpp:87
bool getIsMultipleStopPositions() const
Definition NBPTStop.cpp:165
NBPTStop(SumoXMLTag tag, std::string ptStopId, Position position, std::string edgeId, std::string origEdgeId, double length, std::string name, SVCPermissions svcPermissions, double parkingLength=0, const RGBColor color=RGBColor(false), double givenStartPos=-1)
Constructor.
Definition NBPTStop.cpp:33
void addAccess(std::string laneID, double offset, double length)
Definition NBPTStop.cpp:246
void write(OutputDevice &device)
Definition NBPTStop.cpp:102
const std::vector< NBPTPlatform > & getPlatformCands()
Definition NBPTStop.cpp:159
const std::string myName
Definition NBPTStop.h:179
std::vector< std::tuple< std::string, double, double > > myAccesses
laneId, lanePos, accessLength
Definition NBPTStop.h:189
Position myPosition
Definition NBPTStop.h:174
void addLine(const std::string &line)
register line that services this stop (for displaying)
Definition NBPTStop.cpp:93
double getLength() const
Definition NBPTStop.cpp:178
void reshiftPosition(const double offsetX, const double offsetY)
Definition NBPTStop.cpp:138
double myEndPos
Definition NBPTStop.h:186
bool replaceEdge(const std::string &edgeID, const std::vector< NBEdge * > &replacement)
replace the stop edge with the closest edge on the given edge list in all stops
Definition NBPTStop.cpp:261
void setIsMultipleStopPositions(bool multipleStopPositions, long long int areaID)
Definition NBPTStop.cpp:171
SVCPermissions getPermissions() const
Definition NBPTStop.cpp:147
const std::string & getEdgeId() const
Definition NBPTStop.cpp:69
const double myParkingLength
Definition NBPTStop.h:180
const Position & getPosition() const
Definition NBPTStop.cpp:81
const RGBColor myColor
Definition NBPTStop.h:181
std::string myOrigEdgeId
Definition NBPTStop.h:177
long long int myAreaID
Definition NBPTStop.h:204
const std::string getOrigEdgeId() const
Definition NBPTStop.cpp:63
const std::string getName() const
Definition NBPTStop.cpp:75
std::string myEdgeId
Definition NBPTStop.h:175
Static storage of an output device and its base (abstract) implementation.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
void writeParams(OutputDevice &device) const
write Params in the given outputdevice
A point in 2D or 3D with translation and scaling methods.
Definition Position.h:37
void add(const Position &pos)
Adds the given position to this one.
Definition Position.h:129
void mul(double val)
Multiplies position with the given value.
Definition Position.h:102
A list of positions.
double length2D() const
Returns the length.
double distance2D(const Position &p, bool perpendicular=false) const
closest 2D-distance to point p (or -1 if perpendicular is true and the point is beyond this vector)
double nearest_offset_to_point2D(const Position &p, bool perpendicular=true) const
return the nearest offest to point 2D
bool isValid() const
check if RGBColor is valid
Definition RGBColor.cpp:120
static std::string getEdgeIDFromLane(const std::string laneID)
return edge id when given the lane ID
static std::string escapeXML(const std::string &orig, const bool maskDoubleHyphen=false)
Replaces the standard escapes by their XML entities.
Definition json.hpp:4471