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-2023 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>
50
51
52
53// ===========================================================================
54// method definitions
55// ===========================================================================
56GUIBusStop::GUIBusStop(const std::string& id, SumoXMLTag element, const std::vector<std::string>& lines, MSLane& lane,
57 double frompos, double topos, const std::string name, int personCapacity,
58 double parkingLength, const RGBColor& color) :
59 MSStoppingPlace(id, element, lines, lane, frompos, topos, name, personCapacity, parkingLength, color),
61 // see MSVehicleControl defContainerType
62 myWidth = MAX2(1.0, ceil((double)personCapacity / getTransportablesAbreast()) * myTransportableDepth);
64 if (lane.getShape(true).size() > 0) {
66 }
67}
68
69
71
72
73void
75 std::vector<double>& fgShapeRotations, std::vector<double>& fgShapeLengths,
76 Position& fgSignPos, double& fgSignRot,
77 bool secondaryShape) {
78 const double offsetSign = MSGlobals::gLefthand ? -1 : 1;
79 const double lgf = myLane.getLengthGeometryFactor(secondaryShape);
80 fgShape = myLane.getShape(secondaryShape);
81 fgShape = fgShape.getSubpart(lgf * myBegPos, lgf * myEndPos);
82 fgShape.move2side((myLane.getWidth() + myWidth) * 0.45 * offsetSign);
83 fgShapeRotations.reserve(fgShape.size() - 1);
84 fgShapeLengths.reserve(fgShape.size() - 1);
85 int e = (int) fgShape.size() - 1;
86 for (int i = 0; i < e; ++i) {
87 const Position& f = fgShape[i];
88 const Position& s = fgShape[i + 1];
89 fgShapeLengths.push_back(f.distanceTo(s));
90 fgShapeRotations.push_back((double) atan2((s.x() - f.x()), (f.y() - s.y())) * (double) 180.0 / (double) M_PI);
91 }
92 PositionVector tmp = fgShape;
93 tmp.move2side(myWidth / 2 * offsetSign);
94 fgSignPos = tmp.getLineCenter();
95 fgSignRot = 0;
96 if (tmp.length() != 0) {
97 fgSignRot = fgShape.rotationDegreeAtOffset(double((fgShape.length() / 2.)));
98 fgSignRot -= 90;
99 }
100}
101
102
103bool
104GUIBusStop::addAccess(MSLane* lane, const double pos, double length) {
105 const bool added = MSStoppingPlace::addAccess(lane, pos, length);
106 if (added) {
107 myAccessCoords.push_back(lane->geometryPositionAtOffset(pos));
108 }
109 return added;
110}
111
112
115 GUISUMOAbstractView& parent) {
116 GUIGLObjectPopupMenu* ret = new GUIGLObjectPopupMenu(app, parent, *this);
117 buildPopupHeader(ret, app);
122 buildPositionCopyEntry(ret, app);
123 return ret;
124}
125
126
131 new GUIParameterTableWindow(app, *this);
132 // add items
133 ret->mkItem("name", false, getMyName());
134 ret->mkItem("begin position [m]", false, myBegPos);
135 ret->mkItem("end position [m]", false, myEndPos);
136 ret->mkItem("lines", false, joinToString(myLines, " "));
137 ret->mkItem("parking length [m]", false, (myEndPos - myBegPos) / myParkingFactor);
138 const std::string transportable = (myElement == SUMO_TAG_CONTAINER_STOP ? "container" : "person");
139 ret->mkItem((transportable + " capacity [#]").c_str(), false, myTransportableCapacity);
140 ret->mkItem((transportable + " number [#]").c_str(), true, new FunctionBinding<GUIBusStop, int>(this, &MSStoppingPlace::getTransportableNumber));
141 ret->mkItem("stopped vehicles[#]", true, new FunctionBinding<GUIBusStop, int>(this, &MSStoppingPlace::getStoppedVehicleNumber));
142 ret->mkItem("last free pos[m]", true, new FunctionBinding<GUIBusStop, double>(this, &MSStoppingPlace::getLastFreePos));
143 // rides-being-waited-on statistic
144 std::map<std::string, int> stats;
145 for (const MSTransportable* t : getTransportables()) {
146 MSStageDriving* s = dynamic_cast<MSStageDriving*>(t->getCurrentStage());
147 if (s != nullptr) {
148 if (s->getIntendedVehicleID() != "") {
149 stats[s->getIntendedVehicleID()] += 1;
150 } else {
151 stats[joinToString(s->getLines(), " ")] += 1;
152 }
153 }
154 }
155 if (stats.size() > 0) {
156 ret->mkItem("waiting for:", false, "[#]");
157 for (auto item : stats) {
158 ret->mkItem(item.first.c_str(), false, toString(item.second));
159 }
160 }
161
162 // close building
163 ret->closeBuilding();
164 return ret;
165}
166
167
168void
170 // get colors
171 RGBColor color, colorSign;
175 } else if (myElement == SUMO_TAG_TRAIN_STOP) {
177 colorSign = s.colorSettings.trainStopColorSign;
178 } else {
179 color = s.colorSettings.busStopColor;
180 colorSign = s.colorSettings.busStopColorSign;
181 }
182 // set color
183 if (getColor() != RGBColor::INVISIBLE) {
184 color = getColor();
185 }
188 // draw the area
189 glTranslated(0, 0, getType());
190 GLHelper::setColor(color);
191 const double exaggeration = getExaggeration(s);
192 // only shrink the box but never enlarge it (only enlarge the sign)
193 const bool s2 = s.secondaryShape;
194 if (s2) {
196 } else {
198 }
199 const double signRot = s2 ? myFGSignRot2 : myFGSignRot;
200 const Position& signPos = s2 ? myFGSignPos2 : myFGSignPos;
201 // draw details unless zoomed out to far
202 if (s.drawDetail(s.detailSettings.stoppingPlaceDetails, exaggeration)) {
204 // draw the lines
205 const double rotSign = MSGlobals::gLefthand ? 1 : -1;
206 // Iterate over every line
207 const double lineAngle = s.getTextAngle(rotSign * signRot);
208 RGBColor lineColor = color.changedBrightness(-51);
209 const double textOffset = s.flippedTextAngle(rotSign * signRot) ? -1 : 1;
210 const double textOffset2 = s.flippedTextAngle(rotSign * signRot) ? -1 : 0.3;
211 for (int i = 0; i < (int)myLines.size(); ++i) {
212 // push a new matrix for every line
214 // traslate and rotate
215 glTranslated(signPos.x(), signPos.y(), 0);
216 glRotated(lineAngle, 0, 0, 1);
217 // draw line
218 GLHelper::drawText(myLines[i].c_str(), Position(1.2, i * textOffset + textOffset2), .1, 1.f, lineColor, 0, FONS_ALIGN_LEFT);
219 // pop matrix for every line
221 }
222 GLHelper::setColor(color);
223 const Position accessOrigin = getCenterPos();
224 for (std::vector<Position>::const_iterator i = myAccessCoords.begin(); i != myAccessCoords.end(); ++i) {
225 GLHelper::drawBoxLine(*i, RAD2DEG(accessOrigin.angleTo2D(*i)) - 90, accessOrigin.distanceTo2D(*i), .05);
226 }
227 // draw the sign
228 glTranslated(signPos.x(), signPos.y(), 0);
229 int noPoints = 9;
230 if (s.scale * exaggeration > 25) {
231 noPoints = MIN2((int)(9.0 + (s.scale * exaggeration) / 10.0), 36);
232 }
233 glScaled(exaggeration, exaggeration, 1);
234 GLHelper::drawFilledCircle((double) 1.1, noPoints);
235 glTranslated(0, 0, .1);
236 GLHelper::setColor(colorSign);
237 GLHelper::drawFilledCircle((double) 0.9, noPoints);
238 if (s.drawDetail(s.detailSettings.stoppingPlaceText, exaggeration)) {
240 GLHelper::drawText("C", Position(), .1, 1.6, color, signRot);
241 } else if (myElement == SUMO_TAG_TRAIN_STOP) {
242 GLHelper::drawText("T", Position(), .1, 1.6, color, signRot);
243 } else {
244 GLHelper::drawText("H", Position(), .1, 1.6, color, signRot);
245 }
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
280/****************************************************************************/
@ 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
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:300
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition GLHelper.cpp:583
static void drawFilledCircle(double width, int steps=8)
Draws a filled circle around (0,0)
Definition GLHelper.cpp:498
static void pushName(unsigned int name)
push Name
Definition GLHelper.cpp:139
static void popMatrix()
pop matrix
Definition GLHelper.cpp:130
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:329
static void drawBoxLine(const Position &beg, double rot, double visLength, double width, double offset=0)
Draws a thick line.
Definition GLHelper.cpp:277
static void popName()
pop Name
Definition GLHelper.cpp:148
static void pushMatrix()
push matrix
Definition GLHelper.cpp:117
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:685
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:716
Position myFGSignPos
The position of the sign.
Definition GUIBusStop.h:154
std::vector< double > myFGShapeRotations2
Definition GUIBusStop.h:143
bool addAccess(MSLane *lane, const double pos, double length)
adds an access point to this stop
double myFGSignRot
The rotation of the sign.
Definition GUIBusStop.h:158
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
double myFGSignRot2
Definition GUIBusStop.h:159
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.
~GUIBusStop()
Destructor.
std::vector< double > myFGShapeLengths
The lengths of the shape parts.
Definition GUIBusStop.h:146
PositionVector myFGShape
The shape.
Definition GUIBusStop.h:150
std::vector< double > myFGShapeLengths2
Definition GUIBusStop.h:147
GUIParameterTableWindow * getParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own parameter window.
double myWidth
The visual width of the stoppling place.
Definition GUIBusStop.h:162
std::vector< double > myFGShapeRotations
The rotations of the shape parts.
Definition GUIBusStop.h:142
const std::string getOptionalName() const
Returns the street name.
PositionVector myAccessCoords
The coordinates of access points.
Definition GUIBusStop.h:165
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:155
PositionVector myFGShape2
Definition GUIBusStop.h:151
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
GUIVisualizationDetailSettings detailSettings
detail settings
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:169
Representation of a lane in the micro simulation.
Definition MSLane.h:84
virtual double getLengthGeometryFactor(bool) const
Definition MSLane.h:289
virtual const PositionVector & getShape(bool) const
Definition MSLane.h:293
double getWidth() const
Returns the lane's width.
Definition MSLane.h:622
const Position geometryPositionAtOffset(double offset, double lateralOffset=0) const
Definition MSLane.h:551
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 tranportables 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.
virtual bool addAccess(MSLane *lane, const double pos, double length)
adds an access point to this stop
const RGBColor & getColor() const
const int myTransportableCapacity
The number of transportables that can wait here.
const std::string & getMyName() const
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:254
double distanceTo(const Position &p2) const
returns the euclidean distance in 3 dimension
Definition Position.h:244
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
Definition Position.h:264
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 ammount
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
static const double stoppingPlaceDetails
details for stopping places
static const double stoppingPlaceText
details for stopping place texts
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