Eclipse SUMO - Simulation of Urban MObility
GUIBusStop.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-2022 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 const double offsetSign = MSGlobals::gLefthand ? -1 : 1;
62 // see MSVehicleControl defContainerType
63 myWidth = MAX2(1.0, ceil((double)personCapacity / getTransportablesAbreast()) * myTransportableDepth);
64 myFGShape = lane.getShape();
68 myFGShape.move2side((lane.getWidth() + myWidth) * 0.45 * offsetSign);
69 myFGShapeRotations.reserve(myFGShape.size() - 1);
70 myFGShapeLengths.reserve(myFGShape.size() - 1);
71 int e = (int) myFGShape.size() - 1;
72 for (int i = 0; i < e; ++i) {
73 const Position& f = myFGShape[i];
74 const Position& s = myFGShape[i + 1];
75 myFGShapeLengths.push_back(f.distanceTo(s));
76 myFGShapeRotations.push_back((double) atan2((s.x() - f.x()), (f.y() - s.y())) * (double) 180.0 / (double) M_PI);
77 }
79 tmp.move2side(myWidth / 2 * offsetSign);
81 myFGSignRot = 0;
82 if (tmp.length() != 0) {
84 myFGSignRot -= 90;
85 }
86}
87
88
90
91
92bool
93GUIBusStop::addAccess(MSLane* lane, const double pos, double length) {
94 const bool added = MSStoppingPlace::addAccess(lane, pos, length);
95 if (added) {
96 myAccessCoords.push_back(lane->geometryPositionAtOffset(pos));
97 }
98 return added;
99}
100
101
104 GUISUMOAbstractView& parent) {
105 GUIGLObjectPopupMenu* ret = new GUIGLObjectPopupMenu(app, parent, *this);
106 buildPopupHeader(ret, app);
111 buildPositionCopyEntry(ret, app);
112 return ret;
113}
114
115
120 new GUIParameterTableWindow(app, *this);
121 // add items
122 ret->mkItem("name", false, getMyName());
123 ret->mkItem("begin position [m]", false, myBegPos);
124 ret->mkItem("end position [m]", false, myEndPos);
125 ret->mkItem("lines", false, joinToString(myLines, " "));
126 ret->mkItem("parking length [m]", false, (myEndPos - myBegPos) / myParkingFactor);
127 const std::string transportable = (myElement == SUMO_TAG_CONTAINER_STOP ? "container" : "person");
128 ret->mkItem((transportable + " capacity [#]").c_str(), false, myTransportableCapacity);
129 ret->mkItem((transportable + " number [#]").c_str(), true, new FunctionBinding<GUIBusStop, int>(this, &MSStoppingPlace::getTransportableNumber));
130 ret->mkItem("stopped vehicles[#]", true, new FunctionBinding<GUIBusStop, int>(this, &MSStoppingPlace::getStoppedVehicleNumber));
131 ret->mkItem("last free pos[m]", true, new FunctionBinding<GUIBusStop, double>(this, &MSStoppingPlace::getLastFreePos));
132 // rides-being-waited-on statistic
133 std::map<std::string, int> stats;
134 for (const MSTransportable* t : getTransportables()) {
135 MSStageDriving* s = dynamic_cast<MSStageDriving*>(t->getCurrentStage());
136 if (s != nullptr) {
137 if (s->getIntendedVehicleID() != "") {
138 stats[s->getIntendedVehicleID()] += 1;
139 } else {
140 stats[joinToString(s->getLines(), " ")] += 1;
141 }
142 }
143 }
144 if (stats.size() > 0) {
145 ret->mkItem("waiting for:", false, "[#]");
146 for (auto item : stats) {
147 ret->mkItem(item.first.c_str(), false, toString(item.second));
148 }
149 }
150
151 // close building
152 ret->closeBuilding();
153 return ret;
154}
155
156
157void
159 // get colors
160 RGBColor color, colorSign;
164 } else if (myElement == SUMO_TAG_TRAIN_STOP) {
166 colorSign = s.colorSettings.trainStopColorSign;
167 } else {
168 color = s.colorSettings.busStopColor;
169 colorSign = s.colorSettings.busStopColorSign;
170 }
171 // set color
172 if (getColor() != RGBColor::INVISIBLE) {
173 color = getColor();
174 }
177 // draw the area
178 glTranslated(0, 0, getType());
179 GLHelper::setColor(color);
180 const double exaggeration = getExaggeration(s);
181 // only shrink the box but never enlarge it (only enlarge the sign)
183 // draw details unless zoomed out to far
184 if (s.drawDetail(s.detailSettings.stoppingPlaceDetails, exaggeration)) {
186 // draw the lines
187 const double rotSign = MSGlobals::gLefthand ? 1 : -1;
188 // Iterate over every line
189 const double lineAngle = s.getTextAngle(rotSign * myFGSignRot);
190 RGBColor lineColor = color.changedBrightness(-51);
191 const double textOffset = s.flippedTextAngle(rotSign * myFGSignRot) ? -1 : 1;
192 const double textOffset2 = s.flippedTextAngle(rotSign * myFGSignRot) ? -1 : 0.3;
193 for (int i = 0; i < (int)myLines.size(); ++i) {
194 // push a new matrix for every line
196 // traslate and rotate
197 glTranslated(myFGSignPos.x(), myFGSignPos.y(), 0);
198 glRotated(lineAngle, 0, 0, 1);
199 // draw line
200 GLHelper::drawText(myLines[i].c_str(), Position(1.2, i * textOffset + textOffset2), .1, 1.f, lineColor, 0, FONS_ALIGN_LEFT);
201 // pop matrix for every line
203 }
204 GLHelper::setColor(color);
205 for (std::vector<Position>::const_iterator i = myAccessCoords.begin(); i != myAccessCoords.end(); ++i) {
207 }
208 // draw the sign
209 glTranslated(myFGSignPos.x(), myFGSignPos.y(), 0);
210 int noPoints = 9;
211 if (s.scale * exaggeration > 25) {
212 noPoints = MIN2((int)(9.0 + (s.scale * exaggeration) / 10.0), 36);
213 }
214 glScaled(exaggeration, exaggeration, 1);
215 GLHelper::drawFilledCircle((double) 1.1, noPoints);
216 glTranslated(0, 0, .1);
217 GLHelper::setColor(colorSign);
218 GLHelper::drawFilledCircle((double) 0.9, noPoints);
219 if (s.drawDetail(s.detailSettings.stoppingPlaceText, exaggeration)) {
221 GLHelper::drawText("C", Position(), .1, 1.6, color, myFGSignRot);
222 } else if (myElement == SUMO_TAG_TRAIN_STOP) {
223 GLHelper::drawText("T", Position(), .1, 1.6, color, myFGSignRot);
224 } else {
225 GLHelper::drawText("H", Position(), .1, 1.6, color, myFGSignRot);
226 }
227 }
229 }
230 if (s.addFullName.show(this) && getMyName() != "") {
232 }
236}
237
238
239double
241 return s.addSize.getExaggeration(s, this);
242}
243
244
248 b.grow(myWidth);
249 for (const Position& p : myAccessCoords) {
250 b.add(p);
251 }
252 return b;
253}
254
255const std::string
257 return myName;
258}
259
260/****************************************************************************/
@ 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:71
T MAX2(T a, T b)
Definition: StdDefs.h:77
std::string joinToString(const std::vector< T > &v, const T_BETWEEN &between, std::streamsize accuracy=gPrecision)
Definition: ToString.h:282
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:144
bool addAccess(MSLane *lane, const double pos, double length)
adds an access point to this stop
Definition: GUIBusStop.cpp:93
double myFGSignRot
The rotation of the sign.
Definition: GUIBusStop.h:147
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
Definition: GUIBusStop.cpp:158
GUIGLObjectPopupMenu * getPopUpMenu(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own popup-menu.
Definition: GUIBusStop.cpp:103
~GUIBusStop()
Destructor.
Definition: GUIBusStop.cpp:89
std::vector< double > myFGShapeLengths
The lengths of the shape parts.
Definition: GUIBusStop.h:138
PositionVector myFGShape
The shape.
Definition: GUIBusStop.h:141
GUIParameterTableWindow * getParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own parameter window.
Definition: GUIBusStop.cpp:117
double myWidth
The visual width of the stoppling place.
Definition: GUIBusStop.h:150
std::vector< double > myFGShapeRotations
The rotations of the shape parts.
Definition: GUIBusStop.h:135
const std::string getOptionalName() const
Returns the street name.
Definition: GUIBusStop.cpp:256
PositionVector myAccessCoords
The coordinates of access points.
Definition: GUIBusStop.h:153
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
Definition: GUIBusStop.cpp:246
double getExaggeration(const GUIVisualizationSettings &s) const
return exaggeration associated with this GLObject
Definition: GUIBusStop.cpp:240
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.
Definition: GUIBusStop.cpp:56
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.
Definition: GUIGlObject.h:154
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.
Definition: GUIGlObject.h:102
void drawName(const Position &pos, const double scale, const GUIVisualizationTextSettings &settings, const double angle=0, bool forceShow=false) const
draw name of item
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 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:168
Representation of a lane in the micro simulation.
Definition: MSLane.h:84
const PositionVector & getShape() const
Returns this lane's shape.
Definition: MSLane.h:506
double interpolateLanePosToGeometryPos(double lanePos) const
Definition: MSLane.h:527
double getWidth() const
Returns the lane's width.
Definition: MSLane.h:590
const Position geometryPositionAtOffset(double offset, double lateralOffset=0) const
Definition: MSLane.h:533
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.
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
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:252
double distanceTo(const Position &p2) const
returns the euclidean distance in 3 dimension
Definition: Position.h:242
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:262
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