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-2024 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(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 myPTStopId(ptStopId),
36 myPosition(position),
37 myEdgeId(edgeId),
38 myOrigEdgeId(origEdgeId),
39 myPTStopLength(length),
40 myName(name),
41 myParkingLength(parkingLength),
42 myColor(color),
43 myPermissions(svcPermissions),
44 myStartPos(0),
45 myEndPos(0),
46 myBidiStop(std::weak_ptr<NBPTStop>()),
47 myIsLoose(origEdgeId == ""),
48 myIsPlatform(false),
49 myIsMultipleStopPositions(false),
50 myAreaID(-1),
51 myGivenStartPos(givenStartPos) {
52}
53
54
55std::string
57 return myPTStopId;
58}
59
60
61const std::string
63 return myOrigEdgeId;
64}
65
66
67const std::string&
69 return myEdgeId;
70}
71
72
73const std::string
75 return myName;
76}
77
78
79const Position&
81 return myPosition;
82}
83
84
85void
87 myPosition.mul(1, -1);
88}
89
90
91void
92NBPTStop::addLine(const std::string& line) {
93 const std::string l = StringUtils::escapeXML(line);
94 if (std::find(myLines.begin(), myLines.end(), l) == myLines.end()) {
95 myLines.push_back(l);
96 }
97}
98
99
100void
104 if (!myName.empty()) {
106 }
110 device.writeAttr(SUMO_ATTR_FRIENDLY_POS, "true");
111 if (myLines.size() > 0) {
113 }
114 if (myParkingLength > 0) {
116 }
117 if (myColor.isValid()) {
119 }
120 if (!myAccesses.empty()) {
121 std::sort(myAccesses.begin(), myAccesses.end());
122 for (auto tuple : myAccesses) {
123 device.openTag(SUMO_TAG_ACCESS);
124 device.writeAttr(SUMO_ATTR_LANE, std::get<0>(tuple));
125 device.writeAttr(SUMO_ATTR_POSITION, std::get<1>(tuple));
126 device.writeAttr(SUMO_ATTR_LENGTH, std::get<2>(tuple));
127 device.writeAttr(SUMO_ATTR_FRIENDLY_POS, true);
128 device.closeTag();
129 }
130 }
131 writeParams(device);
132 device.closeTag();
133}
134
135
136void
137NBPTStop::reshiftPosition(const double offsetX, const double offsetY) {
138 myPosition.add(offsetX, offsetY, 0);
139 for (NBPTPlatform& platformCand : myPlatformCands) {
140 platformCand.reshiftPosition(offsetX, offsetY);
141 }
142}
143
144
147 return myPermissions;
148}
149
150
151void
153 myPlatformCands.push_back(platform);
154}
155
156
157const std::vector<NBPTPlatform>&
161
162
163bool
167
168
169void
170NBPTStop::setIsMultipleStopPositions(bool multipleStopPositions, long long int areaID) {
171 myIsMultipleStopPositions = multipleStopPositions;
172 myAreaID = areaID;
173}
174
175
176double
178 return myPTStopLength;
179}
180
181
182bool
183NBPTStop::setEdgeId(std::string edgeId, const NBEdgeCont& ec) {
184 myEdgeId = edgeId;
186}
187
188
189void
190NBPTStop::registerAdditionalEdge(std::string wayId, std::string edgeId) {
191 myAdditionalEdgeCandidates[wayId] = edgeId;
192}
193
194
195bool
200
201
202bool
204 if (edge != nullptr) {
205 myEdgeId = edge->getID();
206 int laneNr = -1;
207 for (const auto& it : edge->getLanes()) {
208 if ((it.permissions & getPermissions()) == getPermissions()) {
209 ++laneNr;
210 break;
211 }
212 laneNr++;
213 }
214 if (laneNr != -1) {
215 myLaneId = edge->getLaneID(laneNr);
216 const PositionVector& shape = edge->getLaneShape(laneNr);
217 double offset = shape.nearest_offset_to_point2D(getPosition(), false);
218 const double edgeLength = edge->getFinalLength();
219 offset *= edgeLength / shape.length2D();
220 if (myGivenStartPos >= 0) {
223 } else {
224 myStartPos = MAX2(0.0, offset - myPTStopLength / 2.);
225 myEndPos = MIN2(myStartPos + myPTStopLength, edgeLength);
226 double missing = myPTStopLength - (myEndPos - myStartPos);
227 if (missing > 0) {
228 myStartPos = MAX2(0.0, myStartPos - missing);
229 }
230 }
231 return true;
232 }
233 }
234 return myEdgeId == ""; // loose stop. Try later when processing lines
235}
236
237
238void
240 myAccesses.clear();
241}
242
243
244void
245NBPTStop::addAccess(std::string laneID, double offset, double length) {
246 const std::string newEdgeID = SUMOXMLDefinitions::getEdgeIDFromLane(laneID);
247 // avoid duplicate access
248 for (auto it = myAccesses.begin(); it != myAccesses.end();) {
249 if (SUMOXMLDefinitions::getEdgeIDFromLane(std::get<0>(*it)) == newEdgeID) {
250 it = myAccesses.erase(it);
251 } else {
252 it++;
253 }
254 }
255 myAccesses.push_back(std::make_tuple(laneID, offset, length));
256}
257
258
259bool
260NBPTStop::replaceEdge(const std::string& edgeID, const EdgeVector& replacement) {
261 if (myEdgeId == edgeID) {
262 // find best edge among replacement edges
263 double bestDist = std::numeric_limits<double>::max();
264 NBEdge* bestEdge = nullptr;
265 for (NBEdge* cand : replacement) {
266 if (myPermissions == 0 || (cand->getPermissions() & myPermissions) != 0) {
267 const double dist = cand->getGeometry().distance2D(myPosition) + MAX2(0., myPTStopLength - cand->getLoadedLength());
268 if (dist < bestDist) {
269 bestDist = dist;
270 bestEdge = cand;
271 }
272 }
273 }
274 if (bestEdge != nullptr) {
275 if ((bestEdge->getPermissions() & SVC_PEDESTRIAN) != 0) {
276 // no need for access
277 clearAccess();
278 }
279 return findLaneAndComputeBusStopExtent(bestEdge);
280 }
281 return false;
282 }
283 return true;
284}
285
286
287/****************************************************************************/
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
@ SUMO_TAG_ACCESS
An access point for a train stop.
@ SUMO_TAG_BUS_STOP
A bus 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:76
T MAX2(T a, T b)
Definition StdDefs.h:82
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:4378
const PositionVector & getGeometry() const
Returns the geometry of the edge.
Definition NBEdge.h:783
const std::vector< NBEdge::Lane > & getLanes() const
Returns the lane definitions.
Definition NBEdge.h:730
const std::string & getID() const
Definition NBEdge.h:1528
std::string getLaneID(int lane) const
get lane ID
Definition NBEdge.cpp:4016
const PositionVector & getLaneShape(int i) const
Returns the shape of the nth lane.
Definition NBEdge.cpp:986
double getFinalLength() const
get length that will be assigned to the lanes in the final network
Definition NBEdge.cpp:4714
The representation of a single pt stop.
Definition NBPTStop.h:45
bool myIsMultipleStopPositions
Definition NBPTStop.h:190
NBPTStop(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
std::map< std::string, std::string > myAdditionalEdgeCandidates
Definition NBPTStop.h:163
double myStartPos
Definition NBPTStop.h:172
void registerAdditionalEdge(std::string wayId, std::string edgeId)
Definition NBPTStop.cpp:190
const SVCPermissions myPermissions
Definition NBPTStop.h:170
double myPTStopLength
Definition NBPTStop.h:165
bool findLaneAndComputeBusStopExtent(const NBEdgeCont &ec)
Definition NBPTStop.cpp:196
void addPlatformCand(NBPTPlatform platform)
Definition NBPTStop.cpp:152
void clearAccess()
remove all access definitions
Definition NBPTStop.cpp:239
std::string myLaneId
Definition NBPTStop.h:169
std::string myPTStopId
Definition NBPTStop.h:160
double myGivenStartPos
Definition NBPTStop.h:192
std::vector< NBPTPlatform > myPlatformCands
Definition NBPTStop.h:189
std::vector< std::string > myLines
list of public transport lines (for displaying)
Definition NBPTStop.h:179
bool setEdgeId(std::string edgeId, const NBEdgeCont &ec)
Definition NBPTStop.cpp:183
std::string getID() const
Definition NBPTStop.cpp:56
void mirrorX()
mirror coordinates along the x-axis
Definition NBPTStop.cpp:86
bool getIsMultipleStopPositions() const
Definition NBPTStop.cpp:164
void addAccess(std::string laneID, double offset, double length)
Definition NBPTStop.cpp:245
void write(OutputDevice &device)
Definition NBPTStop.cpp:101
const std::vector< NBPTPlatform > & getPlatformCands()
Definition NBPTStop.cpp:158
const std::string myName
Definition NBPTStop.h:166
std::vector< std::tuple< std::string, double, double > > myAccesses
laneId, lanePos, accessLength
Definition NBPTStop.h:176
Position myPosition
Definition NBPTStop.h:161
void addLine(const std::string &line)
register line that services this stop (for displaying)
Definition NBPTStop.cpp:92
double getLength() const
Definition NBPTStop.cpp:177
void reshiftPosition(const double offsetX, const double offsetY)
Definition NBPTStop.cpp:137
double myEndPos
Definition NBPTStop.h:173
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:260
void setIsMultipleStopPositions(bool multipleStopPositions, long long int areaID)
Definition NBPTStop.cpp:170
SVCPermissions getPermissions() const
Definition NBPTStop.cpp:146
const std::string & getEdgeId() const
Definition NBPTStop.cpp:68
const double myParkingLength
Definition NBPTStop.h:167
const Position & getPosition() const
Definition NBPTStop.cpp:80
const RGBColor myColor
Definition NBPTStop.h:168
std::string myOrigEdgeId
Definition NBPTStop.h:164
long long int myAreaID
Definition NBPTStop.h:191
const std::string getOrigEdgeId() const
Definition NBPTStop.cpp:62
const std::string getName() const
Definition NBPTStop.cpp:74
std::string myEdgeId
Definition NBPTStop.h:162
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:132
void mul(double val)
Multiplies position with the given value.
Definition Position.h:105
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