Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GUIBusStop.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/****************************************************************************/
21// A lane area vehicles can halt at (gui-version)
22/****************************************************************************/
23#include <config.h>
24
25#include <string>
29#include <utils/geom/Boundary.h>
32#include <microsim/MSNet.h>
33#include <microsim/MSLane.h>
34#include <microsim/MSEdge.h>
37#include "GUINet.h"
38#include "GUIEdge.h"
41#include <gui/GUIGlobals.h>
48#include <guisim/GUIBusStop.h>
51
52
53
54// ===========================================================================
55// method definitions
56// ===========================================================================
57GUIBusStop::GUIBusStop(const std::string& id, SumoXMLTag element, const std::vector<std::string>& lines, MSLane& lane,
58 double frompos, double topos, const std::string name, int personCapacity,
59 double parkingLength, const RGBColor& color) :
60 MSStoppingPlace(id, element, lines, lane, frompos, topos, name, personCapacity, parkingLength, color),
62 // see MSVehicleControl defContainerType
63 myWidth = MAX2(1.0, ceil((double)personCapacity / getTransportablesAbreast()) * myTransportableDepth);
65 if (lane.getShape(true).size() > 0) {
67 }
68}
69
70
72
73
74void
76 std::vector<double>& fgShapeRotations, std::vector<double>& fgShapeLengths,
77 Position& fgSignPos, double& fgSignRot,
78 bool secondaryShape) {
79 const double offsetSign = MSGlobals::gLefthand ? -1 : 1;
80 const double lgf = myLane.getLengthGeometryFactor(secondaryShape);
81 fgShape = myLane.getShape(secondaryShape);
82 fgShape = fgShape.getSubpart(lgf * myBegPos, lgf * myEndPos);
83 fgShape.move2side(((myLane.getWidth() + myWidth) * 0.5 - 0.2) * offsetSign);
84 fgShapeRotations.reserve(fgShape.size() - 1);
85 fgShapeLengths.reserve(fgShape.size() - 1);
86 int e = (int) fgShape.size() - 1;
87 for (int i = 0; i < e; ++i) {
88 const Position& f = fgShape[i];
89 const Position& s = fgShape[i + 1];
90 fgShapeLengths.push_back(f.distanceTo(s));
91 fgShapeRotations.push_back((double) atan2((s.x() - f.x()), (f.y() - s.y())) * (double) 180.0 / (double) M_PI);
92 }
93 PositionVector tmp = fgShape;
94 tmp.move2side(myWidth / 2 * offsetSign);
95 fgSignPos = tmp.getLineCenter();
96 fgSignRot = 0;
97 if (tmp.length() != 0) {
98 fgSignRot = fgShape.rotationDegreeAtOffset(double((fgShape.length() / 2.)));
99 const double rotSign = MSGlobals::gLefthand ? -1 : 1;
100 fgSignRot -= 90 * rotSign;
101 }
102}
103
104
105bool
106GUIBusStop::addAccess(MSLane* const lane, const double startPos, const double endPos, double length, const MSStoppingPlace::AccessExit exit) {
107 const bool added = MSStoppingPlace::addAccess(lane, startPos, endPos, length, exit);
108 if (added) {
109 myAccessCoords.push_back(lane->geometryPositionAtOffset((startPos + endPos) / 2.));
110 }
111 return added;
112}
113
114
117 GUISUMOAbstractView& parent) {
118 GUIGLObjectPopupMenu* ret = new GUIGLObjectPopupMenu(app, parent, *this);
119 buildPopupHeader(ret, app);
124 buildPositionCopyEntry(ret, app);
125 return ret;
126}
127
128
133 new GUIParameterTableWindow(app, *this);
134 // add items
135 ret->mkItem(TL("name"), false, getMyName());
136 ret->mkItem(TL("begin position [m]"), false, myBegPos);
137 ret->mkItem(TL("end position [m]"), false, myEndPos);
138 ret->mkItem(TL("lines"), false, joinToString(myLines, " "));
139 ret->mkItem(TL("parking length [m]"), false, (myEndPos - myBegPos) / myParkingFactor);
140 const std::string transportable = (myElement == SUMO_TAG_CONTAINER_STOP ? "container" : "person");
141 ret->mkItem((transportable + " capacity [#]").c_str(), false, myTransportableCapacity);
142 ret->mkItem((transportable + " number [#]").c_str(), true, new FunctionBinding<GUIBusStop, int>(this, &MSStoppingPlace::getTransportableNumber));
143 ret->mkItem(TL("stopped vehicles [#]"), true, new FunctionBinding<GUIBusStop, int>(this, &MSStoppingPlace::getStoppedVehicleNumber));
144 ret->mkItem(TL("last free pos [m]"), true, new FunctionBinding<GUIBusStop, double>(this, &GUIBusStop::getCroppedLastFreePos));
145 // rides-being-waited-on statistic
146 std::map<std::string, int> stats;
147 for (const MSTransportable* t : getTransportables()) {
148 MSStageDriving* s = dynamic_cast<MSStageDriving*>(t->getCurrentStage());
149 if (s != nullptr) {
150 if (s->getIntendedVehicleID() != "") {
151 stats[s->getIntendedVehicleID()] += 1;
152 } else {
153 stats[joinToString(s->getLines(), " ")] += 1;
154 }
155 }
156 }
157 if (stats.size() > 0) {
158 ret->mkItem(TL("waiting for:"), false, "[#]");
159 for (auto item : stats) {
160 ret->mkItem(item.first.c_str(), false, toString(item.second));
161 }
162 }
163
164 // close building
165 ret->closeBuilding();
166 return ret;
167}
168
169
170void
172 // get colors
173 RGBColor color, colorSign;
177 } else if (myElement == SUMO_TAG_TRAIN_STOP) {
179 colorSign = s.colorSettings.trainStopColorSign;
180 } else {
181 color = s.colorSettings.busStopColor;
182 colorSign = s.colorSettings.busStopColorSign;
183 }
184 // set color
185 if (getColor() != RGBColor::INVISIBLE) {
186 color = getColor();
187 }
190 // draw the area
191 glTranslated(0, 0, getType());
192 GLHelper::setColor(color);
193 const double exaggeration = getExaggeration(s);
194 // only shrink the box but never enlarge it (only enlarge the sign)
195 const bool s2 = s.secondaryShape;
196 if (s2) {
198 } else {
200 }
201 const double signRot = s2 ? myFGSignRot2 : myFGSignRot;
202 const Position& signPos = s2 ? myFGSignPos2 : myFGSignPos;
203 // draw details unless zoomed out to far
204 if (s.drawDetail(10, exaggeration)) {
206 // draw the lines
207 const double rotSign = MSGlobals::gLefthand ? 1 : -1;
208 const double lineAngle = s.getTextAngle(signRot);
209 // Iterate over every line
210 RGBColor lineColor = color.changedBrightness(-51);
211 const double textOffset = s.flippedTextAngle(rotSign * signRot) ? -1 : 1;
212 const double textOffset2 = s.flippedTextAngle(rotSign * signRot) ? -1 : 0.3;
213 for (int i = 0; i < (int)myLines.size(); ++i) {
214 // push a new matrix for every line
216 // traslate and rotate
217 glTranslated(signPos.x(), signPos.y(), 0);
218 glRotated(-lineAngle, 0, 0, 1);
219 // draw line
220 GLHelper::drawText(myLines[i].c_str(), Position(1.2, i * textOffset + textOffset2), .1, 1.f, lineColor, 0, FONS_ALIGN_LEFT);
221 // pop matrix for every line
223 }
224 GLHelper::setColor(color);
225 const Position accessOrigin = getCenterPos();
226 for (std::vector<Position>::const_iterator i = myAccessCoords.begin(); i != myAccessCoords.end(); ++i) {
227 GLHelper::drawBoxLine(*i, RAD2DEG(accessOrigin.angleTo2D(*i)) - 90, accessOrigin.distanceTo2D(*i), .05);
228 }
229 // draw the sign
230 glTranslated(signPos.x(), signPos.y(), 0);
231 int noPoints = 9;
232 if (s.scale * exaggeration > 25) {
233 noPoints = MIN2((int)(9.0 + (s.scale * exaggeration) / 10.0), 36);
234 }
235 glScaled(exaggeration, exaggeration, 1);
236 GLHelper::drawFilledCircle((double) 1.1, noPoints);
237 glTranslated(0, 0, .1);
238 GLHelper::setColor(colorSign);
239 GLHelper::drawFilledCircle((double) 0.9, noPoints);
241 GLHelper::drawText("C", Position(), .1, 1.6, color, signRot);
242 } else if (myElement == SUMO_TAG_TRAIN_STOP) {
243 GLHelper::drawText("T", Position(), .1, 1.6, color, signRot);
244 } else {
245 GLHelper::drawText("H", Position(), .1, 1.6, color, signRot);
246 }
248 }
249 if (s.addFullName.show(this) && getMyName() != "") {
251 }
254 drawName(signPos, s.scale, s.addName, s.angle);
255}
256
257
258double
262
263
267 Boundary b = shape.getBoxBoundary();
268 b.grow(myWidth);
269 for (const Position& p : myAccessCoords) {
270 b.add(p);
271 }
272 return b;
273}
274
275const std::string
277 return myName;
278}
279
280double
282 return MAX2(0., getLastFreePos());
283}
284
285/****************************************************************************/
@ GLO_BUS_STOP
a busStop
@ GLO_MAX
empty max
GUIIcon
An enumeration of icons used by the gui applications.
Definition GUIIcons.h:33
#define RAD2DEG(x)
Definition GeomHelper.h:36
#define TL(string)
Definition MsgHandler.h:315
SumoXMLTag
Numbers representing SUMO-XML - element names.
@ SUMO_TAG_CONTAINER_STOP
A container stop.
@ SUMO_TAG_TRAIN_STOP
A train stop (alias for bus stop)
T MIN2(T a, T b)
Definition StdDefs.h:76
T MAX2(T a, T b)
Definition StdDefs.h:82
std::string joinToString(const std::vector< T > &v, const T_BETWEEN &between, std::streamsize accuracy=gPrecision)
Definition ToString.h:283
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:46
A class that stores a 2D geometrical boundary.
Definition Boundary.h:39
void add(double x, double y, double z=0)
Makes the boundary include the given coordinate.
Definition Boundary.cpp:78
Boundary & grow(double by)
extends the boundary by the given amount
Definition Boundary.cpp:343
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition GLHelper.cpp:649
static void pushName(unsigned int name)
push Name
Definition GLHelper.cpp:140
static void drawFilledCircle(const double widradiusth, const int steps=8)
Draws a filled circle around (0,0)
Definition GLHelper.cpp:564
static void popMatrix()
pop matrix
Definition GLHelper.cpp:131
static void drawBoxLines(const PositionVector &geom, const std::vector< double > &rots, const std::vector< double > &lengths, double width, int cornerDetail=0, double offset=0)
Draws thick lines.
Definition GLHelper.cpp:348
static void drawBoxLine(const Position &beg, double rot, double visLength, double width, double offset=0)
Draws a thick line.
Definition GLHelper.cpp:296
static void popName()
pop Name
Definition GLHelper.cpp:149
static void pushMatrix()
push matrix
Definition GLHelper.cpp:118
static void drawText(const std::string &text, const Position &pos, const double layer, const double size, const RGBColor &col=RGBColor::BLACK, const double angle=0, const int align=0, double width=-1)
Definition GLHelper.cpp:751
static void drawTextSettings(const GUIVisualizationTextSettings &settings, const std::string &text, const Position &pos, const double scale, const double angle=0, const double layer=2048, const int align=0)
Definition GLHelper.cpp:782
Position myFGSignPos
The position of the sign.
Definition GUIBusStop.h:158
std::vector< double > myFGShapeRotations2
Definition GUIBusStop.h:147
double myFGSignRot
The rotation of the sign.
Definition GUIBusStop.h:162
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
double myFGSignRot2
Definition GUIBusStop.h:163
void initShape(PositionVector &fgShape, std::vector< double > &fgShapeRotations, std::vector< double > &fgShapeLengths, Position &fgSignPos, double &fgSignRot, bool secondaryShape=false)
init constants for faster rendering
GUIGLObjectPopupMenu * getPopUpMenu(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own popup-menu.
bool addAccess(MSLane *const lane, const double startPos, const double endPos, double length, const MSStoppingPlace::AccessExit exit)
adds an access point to this stop
~GUIBusStop()
Destructor.
std::vector< double > myFGShapeLengths
The lengths of the shape parts.
Definition GUIBusStop.h:150
PositionVector myFGShape
The shape.
Definition GUIBusStop.h:154
std::vector< double > myFGShapeLengths2
Definition GUIBusStop.h:151
GUIParameterTableWindow * getParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own parameter window.
double myWidth
The visual width of the stoppling place.
Definition GUIBusStop.h:166
std::vector< double > myFGShapeRotations
The rotations of the shape parts.
Definition GUIBusStop.h:146
const std::string getOptionalName() const
Returns the street name.
double getCroppedLastFreePos() const
Formats the last free pos value.
PositionVector myAccessCoords
The coordinates of access points.
Definition GUIBusStop.h:169
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
double getExaggeration(const GUIVisualizationSettings &s) const
return exaggeration associated with this GLObject
GUIBusStop(const std::string &id, SumoXMLTag element, const std::vector< std::string > &lines, MSLane &lane, double frompos, double topos, const std::string name, int personCapacity, double parkingLength, const RGBColor &color)
Constructor.
Position myFGSignPos2
Definition GUIBusStop.h:159
PositionVector myFGShape2
Definition GUIBusStop.h:155
The popup menu of a globject.
void buildShowParamsPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to open the parameter window.
void buildCenterPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to center to the object.
void buildNameCopyPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds entries which allow to copy the name / typed name into the clipboard.
void buildPopupHeader(GUIGLObjectPopupMenu *ret, GUIMainWindow &app, bool addSeparator=true)
Builds the header.
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
void buildSelectionPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to (de)select the object.
void buildPositionCopyEntry(GUIGLObjectPopupMenu *ret, const GUIMainWindow &app) const
Builds an entry which allows to copy the cursor position if geo projection is used,...
GUIGlID getGlID() const
Returns the numerical id of the object.
void drawName(const Position &pos, const double scale, const GUIVisualizationTextSettings &settings, const double angle=0, bool forceShow=false) const
draw name of item
static bool gSecondaryShape
whether secondary shapes are currently being drawn
Definition GUIGlobals.h:49
A window containing a gl-object's parameter.
void mkItem(const char *name, bool dynamic, ValueSource< T > *src)
Adds a row which obtains its value from a ValueSource.
void closeBuilding(const Parameterised *p=0)
Closes the building of the table.
Stores the information about how to visualize structures.
GUIVisualizationTextSettings addName
GUIVisualizationSizeSettings addSize
bool flippedTextAngle(double objectAngle) const
return wether the text was flipped for reading at the given angle
GUIVisualizationTextSettings addFullName
GUIVisualizationColorSettings colorSettings
color settings
double scale
information about a lane's width (temporary, used for a single view)
bool secondaryShape
whether secondary lane shape shall be drawn
bool drawDetail(const double detail, const double exaggeration) const
check if details can be drawn for the given GUIVisualizationDetailSettings and current scale and exxa...
double getTextAngle(double objectAngle) const
return an angle that is suitable for reading text aligned with the given angle (degrees)
double angle
The current view rotation angle.
static bool gLefthand
Whether lefthand-drive is being simulated.
Definition MSGlobals.h:174
Representation of a lane in the micro simulation.
Definition MSLane.h:84
virtual double getLengthGeometryFactor(bool) const
Definition MSLane.h:290
virtual const PositionVector & getShape(bool) const
Definition MSLane.h:294
double getWidth() const
Returns the lane's width.
Definition MSLane.h:635
const Position geometryPositionAtOffset(double offset, double lateralOffset=0) const
Definition MSLane.h:560
std::string getIntendedVehicleID() const
const std::set< std::string > & getLines() const
A lane area vehicles can halt at.
int getStoppedVehicleNumber() const
Returns the number of stopped vehicles waiting on this stop.
const SumoXMLTag myElement
the type of stopping place
const double myBegPos
The begin position this bus stop is located at.
const MSLane & myLane
The lane this bus stop is located at.
int getTransportablesAbreast() const
std::vector< const MSTransportable * > getTransportables() const
Returns the transportables waiting on this stop.
int getTransportableNumber() const
Returns the number of transportables waiting on this stop.
const double myParkingFactor
the scaled space capacity for parking vehicles
Position getCenterPos() const
the position in the middle of the stop shape
const std::string myName
The name of the stopping place.
const double myEndPos
The end position this bus stop is located at.
std::vector< std::string > myLines
The list of lines that are assigned to this stop.
const RGBColor & getColor() const
const int myTransportableCapacity
The number of transportables that can wait here.
const std::string & getMyName() const
virtual bool addAccess(MSLane *const lane, const double startPos, const double endPos, double length, const MSStoppingPlace::AccessExit exit)
adds an access point to this stop
double getLastFreePos() const
const double myTransportableDepth
row depth of waiting transportables
A point in 2D or 3D with translation and scaling methods.
Definition Position.h:37
double distanceTo2D(const Position &p2) const
returns the euclidean distance in the x-y-plane
Definition Position.h:276
double distanceTo(const Position &p2) const
returns the euclidean distance in 3 dimensions
Definition Position.h:266
double x() const
Returns the x-position.
Definition Position.h:55
double angleTo2D(const Position &other) const
returns the angle in the plane of the vector pointing from here to the other position (in radians bet...
Definition Position.h:286
double y() const
Returns the y-position.
Definition Position.h:60
A list of positions.
double length() const
Returns the length.
double rotationDegreeAtOffset(double pos) const
Returns the rotation at the given length.
void move2side(double amount, double maxExtension=100)
move position vector to side using certain amount
Boundary getBoxBoundary() const
Returns a boundary enclosing this list of lines.
Position getLineCenter() const
get line center
PositionVector getSubpart(double beginOffset, double endOffset) const
get subpart of a position vector
static const RGBColor INVISIBLE
Definition RGBColor.h:195
RGBColor changedBrightness(int change, int toChange=3) const
Returns a new color with altered brightness.
Definition RGBColor.cpp:200
@ FONS_ALIGN_LEFT
Definition fontstash.h:42
#define M_PI
Definition odrSpiral.cpp:45
RGBColor trainStopColorSign
color for trainStops signs
RGBColor containerStopColor
color for containerStops
RGBColor busStopColorSign
color for busStops signs
RGBColor containerStopColorSign
color for containerStop signs
RGBColor busStopColor
color for busStops
RGBColor trainStopColor
color for trainStops
double getExaggeration(const GUIVisualizationSettings &s, const GUIGlObject *o, double factor=20) const
return the drawing size including exaggeration and constantSize values
bool show(const GUIGlObject *o) const
whether to show the text