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-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
17 // The representation of a single pt stop
18 /****************************************************************************/
19 
20 
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #ifdef _MSC_VER
25 #include <windows_config.h>
26 #else
27 #include <config.h>
28 #endif
29 
32 #include "NBPTStop.h"
33 #include "NBEdge.h"
34 #include "NBEdgeCont.h"
35 
36 
37 // ===========================================================================
38 // method definitions
39 // ===========================================================================
40 NBPTStop::NBPTStop(std::string ptStopId, Position position, std::string edgeId, std::string origEdgeId, double length,
41  std::string name, SVCPermissions svcPermissions)
42  :
43  myPTStopId(ptStopId),
44  myPosition(position),
45  myEdgeId(edgeId),
46  myOrigEdgeId(origEdgeId),
47  myPTStopLength(length),
48  myName(name),
49  myPermissions(svcPermissions),
50  myIsMultipleStopPositions(false) {
51 }
52 
53 std::string
54 NBPTStop::getID() const {
55  return myPTStopId;
56 }
57 
58 const std::string
60  return myOrigEdgeId;
61 }
62 
63 const std::string
65  return myEdgeId;
66 }
67 
68 const std::string
70  return myName;
71 }
73  return myPosition;
74 }
75 
76 void NBPTStop::computExtent(double center, double edgeLength) {
77  myStartPos = MAX2(0.0, center - myPTStopLength / 2.);
78  myEndPos = MIN2(center + myPTStopLength / 2., edgeLength);
79 }
80 
82  device.openTag(SUMO_TAG_BUS_STOP);
84  if (!myName.empty()) {
86  }
90  device.writeAttr(SUMO_ATTR_FRIENDLY_POS, "true");
91  if (!myAccesses.empty()) {
92 
93  for (auto tuple : myAccesses) {
94  device.openTag(SUMO_TAG_ACCESS);
95  device.writeAttr(SUMO_ATTR_LANE, std::get<0>(tuple));
96  device.writeAttr(SUMO_ATTR_POSITION, std::get<1>(tuple));
97  device.writeAttr(SUMO_ATTR_FRIENDLY_POS, true);
98  device.closeTag();
99  }
100  }
101  device.closeTag();
102 
103 }
104 void NBPTStop::reshiftPostion(const double offsetX, const double offsetY) {
105  myPosition.add(offsetX, offsetY, 0);
106  for (auto& myPlatformCand : myPlatformCands) {
107  Position* pos = (&myPlatformCand)->getMyPos();
108  pos->add(offsetX, offsetY, 0);
109  }
110 
111 
112 }
114  return myPermissions;
115 }
117  myPlatformCands.push_back(platform);
118 }
119 std::vector<NBPTPlatform>& NBPTStop::getPlatformCands() {
120  return myPlatformCands;
121 }
124 }
125 
126 void NBPTStop::setIsMultipleStopPositions(bool multipleStopPositions) {
127  myIsMultipleStopPositions = multipleStopPositions;
128 }
130  return myPTStopLength;
131 }
132 
133 bool
134 NBPTStop::setEdgeId(std::string edgeId, NBEdgeCont& ec) {
135  myEdgeId = edgeId;
137 }
138 
139 void NBPTStop::registerAdditionalEdge(std::string wayId, std::string edgeId) {
140  myAdditionalEdgeCandidates[wayId] = edgeId;
141 }
142 const std::map<std::string, std::string>& NBPTStop::getMyAdditionalEdgeCandidates() const {
144 }
145 void NBPTStop::setMyOrigEdgeId(const std::string& myOrigEdgeId) {
147 }
148 
151 }
152 
153 
154 bool
156  NBEdge* edge = ec.getByID(myEdgeId);
157  if (edge != nullptr) {
158  int laneNr = -1;
159  for (const auto& it : edge->getLanes()) {
160  if ((it.permissions & getPermissions()) > 0) {
161  ++laneNr;
162  break;
163  }
164  laneNr++;
165  }
166  if (laneNr != -1) {
167  myLaneId = edge->getLaneID(laneNr);
168  const PositionVector& shape = edge->getLaneShape(laneNr);
169  double offset = shape.nearest_offset_to_point2D(getPosition(), true);
170  computExtent(offset, shape.length());
171  return true;
172  }
173  }
174  return false;
175 }
176 void NBPTStop::setMyPTStopId(std::string id) {
177  myPTStopId = id;
178 }
179 void NBPTStop::addAccess(std::string laneID, double offset) {
180  myAccesses.push_back(std::make_tuple(laneID, offset));
181 }
182 
183 
bool setEdgeId(std::string edgeId, NBEdgeCont &ec)
Definition: NBPTStop.cpp:134
const std::string getName()
Definition: NBPTStop.cpp:69
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:260
void write(OutputDevice &device)
Definition: NBPTStop.cpp:81
NBEdge * getByID(const std::string &edgeID) const
Returns the edge with id if it exists.
Definition: NBEdgeCont.cpp:850
bool myIsMultipleStopPositions
Definition: NBPTStop.h:115
std::vector< std::tuple< std::string, double > > myAccesses
Definition: NBPTStop.h:106
void add(const Position &pos)
Adds the given position to this one.
Definition: Position.h:132
const std::string getEdgeId()
Definition: NBPTStop.cpp:64
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:70
T MAX2(T a, T b)
Definition: StdDefs.h:73
const std::vector< NBEdge::Lane > & getLanes() const
Returns the lane definitions.
Definition: NBEdge.h:569
std::vector< NBPTPlatform > myPlatformCands
Definition: NBPTStop.h:114
std::string getID() const
Definition: NBPTStop.cpp:54
void setMyPTStopId(std::string id)
Definition: NBPTStop.cpp:176
void registerAdditionalEdge(std::string wayId, std::string edgeId)
Definition: NBPTStop.cpp:139
const std::string myName
Definition: NBPTStop.h:99
const std::map< std::string, std::string > & getMyAdditionalEdgeCandidates() const
Definition: NBPTStop.cpp:142
NBPTStop(std::string ptStopId, Position position, std::string edgeId, std::string origEdgeId, double length, std::string name, SVCPermissions svcPermissions)
Constructor.
Definition: NBPTStop.cpp:40
SVCPermissions getPermissions()
Definition: NBPTStop.cpp:113
std::string myEdgeId
Definition: NBPTStop.h:86
void addAccess(std::string laneID, double offset)
Definition: NBPTStop.cpp:179
std::string getLaneID(int lane) const
get Lane ID (Secure)
Definition: NBEdge.cpp:2783
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:45
A list of positions.
void computExtent(double center, double d)
Definition: NBPTStop.cpp:76
std::string myPTStopId
Definition: NBPTStop.h:84
Storage for edges, including some functionality operating on multiple edges.
Definition: NBEdgeCont.h:66
T MIN2(T a, T b)
Definition: StdDefs.h:67
double myStartPos
Definition: NBPTStop.h:103
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:126
double myPTStopLength
Definition: NBPTStop.h:95
void reshiftPostion(const double offsetX, const double offsetY)
Definition: NBPTStop.cpp:104
bool getIsMultipleStopPositions()
Definition: NBPTStop.cpp:122
bool findLaneAndComputeBusStopExtend(NBEdgeCont &ec)
Definition: NBPTStop.cpp:155
double length() const
Returns the length.
double myEndPos
Definition: NBPTStop.h:104
const PositionVector & getLaneShape(int i) const
Returns the shape of the nth lane.
Definition: NBEdge.cpp:778
Position myPosition
Definition: NBPTStop.h:85
std::vector< NBPTPlatform > & getPlatformCands()
Definition: NBPTStop.cpp:119
std::map< std::string, std::string > myAdditionalEdgeCandidates
Definition: NBPTStop.h:87
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:70
const Position & getPosition()
Definition: NBPTStop.cpp:72
bool closeTag()
Closes the most recently opened tag.
std::string myLaneId
Definition: NBPTStop.h:100
std::string myOrigEdgeId
Definition: NBPTStop.h:91
void setMyOrigEdgeId(const std::string &myOrigEdgeId)
Definition: NBPTStop.cpp:145
double getLength()
Definition: NBPTStop.cpp:129
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:116
void setMyPTStopLength(double myPTStopLength)
Definition: NBPTStop.cpp:149
const std::string getOrigEdgeId()
Definition: NBPTStop.cpp:59
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
const SVCPermissions myPermissions
Definition: NBPTStop.h:101