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-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 // The representation of a single pt stop
19 /****************************************************************************/
20 #include <config.h>
21 
24 #include "NBPTStop.h"
25 #include "NBEdge.h"
26 #include "NBEdgeCont.h"
27 
28 
29 // ===========================================================================
30 // method definitions
31 // ===========================================================================
32 NBPTStop::NBPTStop(std::string ptStopId, Position position, std::string edgeId, std::string origEdgeId, double length,
33  std::string name, SVCPermissions svcPermissions, double parkingLength) :
34  myPTStopId(ptStopId),
35  myPosition(position),
36  myEdgeId(edgeId),
37  myOrigEdgeId(origEdgeId),
38  myPTStopLength(length),
39  myName(name),
40  myParkingLength(parkingLength),
41  myPermissions(svcPermissions),
42  myStartPos(0),
43  myEndPos(0),
44  myBidiStop(nullptr),
45  myIsLoose(origEdgeId == ""),
46  myIsMultipleStopPositions(false) {
47 }
48 
49 std::string
50 NBPTStop::getID() const {
51  return myPTStopId;
52 }
53 
54 const std::string
56  return myOrigEdgeId;
57 }
58 
59 
60 const std::string
62  return myEdgeId;
63 }
64 
65 
66 const std::string
68  return myName;
69 }
70 
71 
72 const Position&
74  return myPosition;
75 }
76 
77 void
79  myPosition.mul(1, -1);
80 }
81 
82 void
83 NBPTStop::computeExtent(double center, double edgeLength) {
84  myStartPos = MAX2(0.0, center - myPTStopLength / 2.);
85  myEndPos = MIN2(center + myPTStopLength / 2., edgeLength);
86 }
87 
88 
89 void
90 NBPTStop::addLine(const std::string& line) {
91  const std::string l = StringUtils::escapeXML(line);
92  if (std::find(myLines.begin(), myLines.end(), l) == myLines.end()) {
93  myLines.push_back(l);
94  }
95 }
96 
97 
98 void
100  device.openTag(SUMO_TAG_BUS_STOP);
102  if (!myName.empty()) {
104  }
108  device.writeAttr(SUMO_ATTR_FRIENDLY_POS, "true");
109  if (myLines.size() > 0) {
111  }
112  if (myParkingLength > 0) {
114  }
115  if (!myAccesses.empty()) {
116  std::sort(myAccesses.begin(), myAccesses.end());
117  for (auto tuple : myAccesses) {
118  device.openTag(SUMO_TAG_ACCESS);
119  device.writeAttr(SUMO_ATTR_LANE, std::get<0>(tuple));
120  device.writeAttr(SUMO_ATTR_POSITION, std::get<1>(tuple));
121  device.writeAttr(SUMO_ATTR_LENGTH, std::get<2>(tuple));
122  device.writeAttr(SUMO_ATTR_FRIENDLY_POS, true);
123  device.closeTag();
124  }
125  }
126  device.closeTag();
127 }
128 
129 
130 void
131 NBPTStop::reshiftPosition(const double offsetX, const double offsetY) {
132  myPosition.add(offsetX, offsetY, 0);
133  for (NBPTPlatform& platformCand : myPlatformCands) {
134  platformCand.reshiftPosition(offsetX, offsetY);
135  }
136 }
137 
138 
141  return myPermissions;
142 }
143 
144 
145 void
147  myPlatformCands.push_back(platform);
148 }
149 
150 
151 const std::vector<NBPTPlatform>&
153  return myPlatformCands;
154 }
155 
156 
157 bool
160 }
161 
162 
163 void
164 NBPTStop::setIsMultipleStopPositions(bool multipleStopPositions) {
165  myIsMultipleStopPositions = multipleStopPositions;
166 }
167 
168 
169 double
171  return myPTStopLength;
172 }
173 
174 
175 bool
176 NBPTStop::setEdgeId(std::string edgeId, const NBEdgeCont& ec) {
177  myEdgeId = edgeId;
179 }
180 
181 
182 void
183 NBPTStop::registerAdditionalEdge(std::string wayId, std::string edgeId) {
184  myAdditionalEdgeCandidates[wayId] = edgeId;
185 }
186 
187 
188 const std::map<std::string, std::string>&
191 }
192 
193 
194 void
195 NBPTStop::setMyOrigEdgeId(const std::string& myOrigEdgeId) {
197 }
198 
199 
200 void
201 NBPTStop::setMyPTStopLength(double myPTStopLength) {
203 }
204 
205 bool
207  NBEdge* edge = ec.getByID(myEdgeId);
208  return findLaneAndComputeBusStopExtent(edge);
209 }
210 
211 bool
213  if (edge != nullptr) {
214  myEdgeId = edge->getID();
215  int laneNr = -1;
216  for (const auto& it : edge->getLanes()) {
217  if ((it.permissions & getPermissions()) == getPermissions()) {
218  ++laneNr;
219  break;
220  }
221  laneNr++;
222  }
223  if (laneNr != -1) {
224  myLaneId = edge->getLaneID(laneNr);
225  const PositionVector& shape = edge->getLaneShape(laneNr);
226  double offset = shape.nearest_offset_to_point2D(getPosition(), false);
227  offset = offset * edge->getLoadedLength() / edge->getLength();
228  computeExtent(offset, edge->getLoadedLength());
229  return true;
230  }
231  }
232  return myEdgeId == ""; // loose stop. Try later when processing lines
233 }
234 
235 
236 void
237 NBPTStop::setMyPTStopId(std::string id) {
238  myPTStopId = id;
239 }
240 
241 void
243  myAccesses.clear();
244 }
245 
246 void
247 NBPTStop::addAccess(std::string laneID, double offset, double length) {
248  const std::string newEdgeID = SUMOXMLDefinitions::getEdgeIDFromLane(laneID);
249  // avoid duplicate access
250  for (auto it = myAccesses.begin(); it != myAccesses.end();) {
251  if (SUMOXMLDefinitions::getEdgeIDFromLane(std::get<0>(*it)) == newEdgeID) {
252  it = myAccesses.erase(it);
253  } else {
254  it++;
255  }
256  }
257  myAccesses.push_back(std::make_tuple(laneID, offset, length));
258 }
259 
260 
261 /****************************************************************************/
int SVCPermissions
bitset where each bit declares whether a certain SVC may use this edge/lane
@ 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_ID
@ SUMO_ATTR_POSITION
T MIN2(T a, T b)
Definition: StdDefs.h:73
T MAX2(T a, T b)
Definition: StdDefs.h:79
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:44
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:91
double getLength() const
Returns the computed length of the edge.
Definition: NBEdge.h:563
double getLoadedLength() const
Returns the length was set explicitly or the computed length if it wasn't set.
Definition: NBEdge.h:572
const std::string & getID() const
Definition: NBEdge.h:1423
const std::vector< NBEdge::Lane > & getLanes() const
Returns the lane definitions.
Definition: NBEdge.h:677
std::string getLaneID(int lane) const
get lane ID
Definition: NBEdge.cpp:3345
const PositionVector & getLaneShape(int i) const
Returns the shape of the nth lane.
Definition: NBEdge.cpp:901
bool myIsMultipleStopPositions
Definition: NBPTStop.h:148
std::map< std::string, std::string > myAdditionalEdgeCandidates
Definition: NBPTStop.h:111
double myStartPos
Definition: NBPTStop.h:128
void registerAdditionalEdge(std::string wayId, std::string edgeId)
Definition: NBPTStop.cpp:183
const SVCPermissions myPermissions
Definition: NBPTStop.h:126
double myPTStopLength
Definition: NBPTStop.h:119
bool findLaneAndComputeBusStopExtent(const NBEdgeCont &ec)
Definition: NBPTStop.cpp:206
void addPlatformCand(NBPTPlatform platform)
Definition: NBPTStop.cpp:146
void clearAccess()
remove all access definitions
Definition: NBPTStop.cpp:242
std::string myLaneId
Definition: NBPTStop.h:125
std::string myPTStopId
Definition: NBPTStop.h:108
std::vector< NBPTPlatform > myPlatformCands
Definition: NBPTStop.h:147
std::vector< std::string > myLines
list of public transport lines (for displaying)
Definition: NBPTStop.h:135
bool setEdgeId(std::string edgeId, const NBEdgeCont &ec)
Definition: NBPTStop.cpp:176
const std::string getEdgeId() const
Definition: NBPTStop.cpp:61
void computeExtent(double center, double d)
Definition: NBPTStop.cpp:83
std::string getID() const
Definition: NBPTStop.cpp:50
NBPTStop(std::string ptStopId, Position position, std::string edgeId, std::string origEdgeId, double length, std::string name, SVCPermissions svcPermissions, double parkingLength=0)
Constructor.
Definition: NBPTStop.cpp:32
void mirrorX()
mirror coordinates along the x-axis
Definition: NBPTStop.cpp:78
bool getIsMultipleStopPositions() const
Definition: NBPTStop.cpp:158
void addAccess(std::string laneID, double offset, double length)
Definition: NBPTStop.cpp:247
void write(OutputDevice &device)
Definition: NBPTStop.cpp:99
const std::vector< NBPTPlatform > & getPlatformCands()
Definition: NBPTStop.cpp:152
const std::string myName
Definition: NBPTStop.h:123
std::vector< std::tuple< std::string, double, double > > myAccesses
laneId, lanePos, accessLength
Definition: NBPTStop.h:132
void setMyOrigEdgeId(const std::string &myOrigEdgeId)
Definition: NBPTStop.cpp:195
Position myPosition
Definition: NBPTStop.h:109
void addLine(const std::string &line)
register line that services this stop (for displaying)
Definition: NBPTStop.cpp:90
double getLength() const
Definition: NBPTStop.cpp:170
void reshiftPosition(const double offsetX, const double offsetY)
Definition: NBPTStop.cpp:131
double myEndPos
Definition: NBPTStop.h:129
void setMyPTStopLength(double myPTStopLength)
Definition: NBPTStop.cpp:201
SVCPermissions getPermissions() const
Definition: NBPTStop.cpp:140
const std::map< std::string, std::string > & getMyAdditionalEdgeCandidates() const
Definition: NBPTStop.cpp:189
void setIsMultipleStopPositions(bool multipleStopPositions)
Definition: NBPTStop.cpp:164
const double myParkingLength
Definition: NBPTStop.h:124
void setMyPTStopId(std::string id)
Definition: NBPTStop.cpp:237
const Position & getPosition() const
Definition: NBPTStop.cpp:73
std::string myOrigEdgeId
Definition: NBPTStop.h:115
const std::string getOrigEdgeId() const
Definition: NBPTStop.cpp:55
const std::string getName() const
Definition: NBPTStop.cpp:67
std::string myEdgeId
Definition: NBPTStop.h:110
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:60
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:239
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:36
void add(const Position &pos)
Adds the given position to this one.
Definition: Position.h:124
void mul(double val)
Multiplies both positions with the given value.
Definition: Position.h:104
A list of positions.
double nearest_offset_to_point2D(const Position &p, bool perpendicular=true) const
return the nearest offest to point 2D
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.