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-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
17 // A lane area vehicles can halt at (gui-version)
18 /****************************************************************************/
19 
20 
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #include <config.h>
25 
26 #include <string>
29 #include <utils/geom/Boundary.h>
30 #include <utils/gui/div/GLHelper.h>
31 #include <utils/common/ToString.h>
32 #include <microsim/MSNet.h>
33 #include <microsim/MSLane.h>
34 #include <microsim/MSEdge.h>
35 #include "GUINet.h"
36 #include "GUIEdge.h"
37 #include "GUIPerson.h"
38 #include "GUIBusStop.h"
41 #include <gui/GUIGlobals.h>
47 #include <utils/geom/GeomHelper.h>
48 #include <guisim/GUIBusStop.h>
50 
51 
52 
53 // ===========================================================================
54 // method definitions
55 // ===========================================================================
56 GUIBusStop::GUIBusStop(const std::string& id, const std::vector<std::string>& lines, MSLane& lane,
57  double frompos, double topos, const std::string name, int personCapacity) :
58  MSStoppingPlace(id, lines, lane, frompos, topos, name, personCapacity),
60  myPersonExaggeration(1) {
61  const double offsetSign = MSNet::getInstance()->lefthand() ? -1 : 1;
62  myWidth = MAX2(1.0, ceil(personCapacity / getPersonsAbreast()) * SUMO_const_waitingPersonDepth);
63  myFGShape = lane.getShape();
64  myFGShape.move2side((lane.getWidth() + myWidth) * 0.45 * offsetSign);
66  lane.interpolateLanePosToGeometryPos(frompos),
68  myFGShapeRotations.reserve(myFGShape.size() - 1);
69  myFGShapeLengths.reserve(myFGShape.size() - 1);
70  int e = (int) myFGShape.size() - 1;
71  for (int i = 0; i < e; ++i) {
72  const Position& f = myFGShape[i];
73  const Position& s = myFGShape[i + 1];
74  myFGShapeLengths.push_back(f.distanceTo(s));
75  myFGShapeRotations.push_back((double) atan2((s.x() - f.x()), (f.y() - s.y())) * (double) 180.0 / (double) M_PI);
76  }
78  tmp.move2side(myWidth / 2 * offsetSign);
79  myFGSignPos = tmp.getLineCenter();
80  myFGSignRot = 0;
81  if (tmp.length() != 0) {
83  myFGSignRot -= 90;
84  }
85 }
86 
87 
89 
90 
91 bool
92 GUIBusStop::addAccess(MSLane* lane, const double pos, const double length) {
93  bool added = MSStoppingPlace::addAccess(lane, pos, length);
94  if (added) {
95  myAccessCoords.push_back(lane->geometryPositionAtOffset(pos));
96  }
97  return added;
98 }
99 
100 
103  GUISUMOAbstractView& parent) {
104  GUIGLObjectPopupMenu* ret = new GUIGLObjectPopupMenu(app, parent, *this);
105  buildPopupHeader(ret, app);
110  buildPositionCopyEntry(ret, false);
111  return ret;
112 }
113 
114 
119  new GUIParameterTableWindow(app, *this, 7);
120  // add items
121  ret->mkItem("name", false, getMyName());
122  ret->mkItem("begin position [m]", false, myBegPos);
123  ret->mkItem("end position [m]", false, myEndPos);
124  ret->mkItem("person capacity [#]", false, myTransportableCapacity);
125  ret->mkItem("person number [#]", true, new FunctionBinding<GUIBusStop, int>(this, &MSStoppingPlace::getTransportableNumber));
126  ret->mkItem("stopped vehicles[#]", true, new FunctionBinding<GUIBusStop, int>(this, &MSStoppingPlace::getStoppedVehicleNumber));
127  ret->mkItem("last free pos[m]", true, new FunctionBinding<GUIBusStop, double>(this, &MSStoppingPlace::getLastFreePos));
128  // close building
129  ret->closeBuilding();
130  return ret;
131 }
132 
133 
134 void
136  glPushName(getGlID());
137  glPushMatrix();
138  // draw the area
139  glTranslated(0, 0, getType());
141  const double exaggeration = s.addSize.getExaggeration(s, this);
142  const double offset = myWidth * 0.5 * MAX2(0.0, exaggeration - 1);
143  GLHelper::drawBoxLines(myFGShape, myFGShapeRotations, myFGShapeLengths, myWidth * 0.5 * exaggeration, 0, offset);
144  // draw details unless zoomed out to far
145  if (s.drawDetail(s.detailSettings.stoppingPlaceDetails, exaggeration)) {
146  glPushMatrix();
147  // draw the lines
148  const double rotSign = MSNet::getInstance()->lefthand() ? 1 : -1;
149  // Iterate over every line
150  for (int i = 0; i < (int)myLines.size(); ++i) {
151  // push a new matrix for every line
152  glPushMatrix();
153  // traslate and rotate
154  glTranslated(myFGSignPos.x(), myFGSignPos.y(), 0);
155  glRotated(rotSign * myFGSignRot, 0, 0, 1);
156  // draw line
157  GLHelper::drawText(myLines[i].c_str(), Position(1.2, (double)i), .1, 1.f, s.colorSettings.busStop, 0, FONS_ALIGN_LEFT);
158  // pop matrix for every line
159  glPopMatrix();
160  }
161  for (std::vector<Position>::const_iterator i = myAccessCoords.begin(); i != myAccessCoords.end(); ++i) {
163  }
164  // draw the sign
165  glTranslated(myFGSignPos.x(), myFGSignPos.y(), 0);
166  int noPoints = 9;
167  if (s.scale * exaggeration > 25) {
168  noPoints = MIN2((int)(9.0 + (s.scale * exaggeration) / 10.0), 36);
169  }
170  glScaled(exaggeration, exaggeration, 1);
171  GLHelper::drawFilledCircle((double) 1.1, noPoints);
172  glTranslated(0, 0, .1);
174  GLHelper::drawFilledCircle((double) 0.9, noPoints);
175  if (s.drawDetail(s.detailSettings.stoppingPlaceText, exaggeration)) {
177  }
178  glPopMatrix();
179  }
180  if (s.addFullName.show && getMyName() != "") {
182  }
183  if (exaggeration > 1) {
185  }
186  glPopMatrix();
187  glPopName();
189 }
190 
191 
192 Boundary
196  for (const Position& p : myAccessCoords) {
197  b.add(p);
198  }
199  return b;
200 }
201 
202 const std::string
204  return myName;
205 }
206 
207 Position
210  if (myPersonExaggeration > 1) {
212  myLane.getWidth() / 2);
213  result = ref + (result - ref) * myPersonExaggeration;
214  }
215  return result;
216 }
217 
218 /****************************************************************************/
GUIGlObject::getType
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
Definition: GUIGlObject.cpp:181
GUIBusStop::~GUIBusStop
~GUIBusStop()
Destructor.
Definition: GUIBusStop.cpp:88
Boundary.h
GUIBusStop::getOptionalName
const std::string getOptionalName() const
Returns the street name.
Definition: GUIBusStop.cpp:203
GLO_MAX
empty max
Definition: GUIGlObjectTypes.h:166
ToString.h
GLHelper::drawTextSettings
static void drawTextSettings(const GUIVisualizationTextSettings &settings, const std::string &text, const Position &pos, const double scale, const double angle=0, const double layer=2048)
Definition: GLHelper.cpp:701
MSStoppingPlace
A lane area vehicles can halt at.
Definition: MSStoppingPlace.h:60
GUIVisualizationColorSettings::busStop
static const RGBColor busStop
color for busStops
Definition: GUIVisualizationSettings.h:175
MIN2
T MIN2(T a, T b)
Definition: StdDefs.h:74
GUIParameterTableWindow
A window containing a gl-object's parameter.
Definition: GUIParameterTableWindow.h:63
MSStoppingPlace::myLines
std::vector< std::string > myLines
The list of lines that are assigned to this stop.
Definition: MSStoppingPlace.h:217
GUISUMOAbstractView
Definition: GUISUMOAbstractView.h:73
MSNet.h
GUIBusStop::myWidth
double myWidth
The visual width of the stoppling place.
Definition: GUIBusStop.h:152
GUIVisualizationDetailSettings::stoppingPlaceDetails
static const double stoppingPlaceDetails
details for stopping places
Definition: GUIVisualizationSettings.h:299
MSLane
Representation of a lane in the micro simulation.
Definition: MSLane.h:83
GUIVisualizationSettings::getTextAngle
double getTextAngle(double objectAngle) const
return an angle that is suitable for reading text aligned with the given angle (degrees)
Definition: GUIVisualizationSettings.cpp:1605
GUIParameterTableWindow.h
GUIBusStop::getWaitPosition
Position getWaitPosition(MSTransportable *person) const
Returns the next free waiting place for pedestrians / containers.
Definition: GUIBusStop.cpp:208
GUIGlObject::drawName
void drawName(const Position &pos, const double scale, const GUIVisualizationTextSettings &settings, const double angle=0) const
draw name of item
Definition: GUIGlObject.cpp:355
GUIVisualizationSettings::angle
double angle
The current view rotation angle.
Definition: GUIVisualizationSettings.h:403
GUIGlObject::buildSelectionPopupEntry
void buildSelectionPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to (de)select the object.
Definition: GUIGlObject.cpp:236
GLHelper::drawBoxLines
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:182
GUIBusStop::drawGL
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
Definition: GUIBusStop.cpp:135
GUIPerson.h
PositionVector::getSubpart
PositionVector getSubpart(double beginOffset, double endOffset) const
get subpart of a position vector
Definition: PositionVector.cpp:698
MsgHandler.h
GUIGLObjectPopupMenu.h
GUIGlobalSelection.h
FONS_ALIGN_LEFT
Definition: fontstash.h:42
MSStoppingPlace::addAccess
virtual bool addAccess(MSLane *lane, const double pos, const double length)
adds an access point to this stop
Definition: MSStoppingPlace.cpp:272
SUMO_const_waitingPersonDepth
const double SUMO_const_waitingPersonDepth
Definition: StdDefs.h:58
SUMO_const_laneWidth
const double SUMO_const_laneWidth
Definition: StdDefs.h:50
RAD2DEG
#define RAD2DEG(x)
Definition: GeomHelper.h:39
PositionVector::length
double length() const
Returns the length.
Definition: PositionVector.cpp:476
MSEdge.h
GLHelper.h
GUIGlObject_AbstractAdd
Definition: GUIGlObject_AbstractAdd.h:40
MSTransportable
Definition: MSTransportable.h:59
GUINet.h
PositionVector
A list of positions.
Definition: PositionVector.h:46
GUIGLObjectPopupMenu
The popup menu of a globject.
Definition: GUIGLObjectPopupMenu.h:48
GUIBusStop::getParameterWindow
GUIParameterTableWindow * getParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own parameter window.
Definition: GUIBusStop.cpp:116
GLHelper::setColor
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:616
PositionVector::getBoxBoundary
Boundary getBoxBoundary() const
Returns a boundary enclosing this list of lines.
Definition: PositionVector.cpp:382
GUIParameterTableWindow::closeBuilding
void closeBuilding(const Parameterised *p=0)
Closes the building of the table.
Definition: GUIParameterTableWindow.cpp:220
GUIAppEnum.h
MSStoppingPlace::myBegPos
const double myBegPos
The begin position this bus stop is located at.
Definition: MSStoppingPlace.h:226
MAX2
T MAX2(T a, T b)
Definition: StdDefs.h:80
GLHelper::drawFilledCircle
static void drawFilledCircle(double width, int steps=8)
Draws a filled circle around (0,0)
Definition: GLHelper.cpp:348
GLHelper::drawText
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, int align=0, double width=-1)
Definition: GLHelper.cpp:668
GUIVisualizationSettings::addName
GUIVisualizationTextSettings addName
Definition: GUIVisualizationSettings.h:582
GUIVisualizationSettings::detailSettings
GUIVisualizationDetailSettings detailSettings
detail settings
Definition: GUIVisualizationSettings.h:655
MSStoppingPlace::myName
const std::string myName
The name of the stopping place.
Definition: MSStoppingPlace.h:235
GUIBusStop::addAccess
bool addAccess(MSLane *lane, const double pos, const double length)
adds an access point to this stop
Definition: GUIBusStop.cpp:92
GUIGlObject::buildNameCopyPopupEntry
void buildNameCopyPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds entries which allow to copy the name / typed name into the clipboard.
Definition: GUIGlObject.cpp:226
GUIBusStop::myAccessCoords
PositionVector myAccessCoords
The coordinates of access points.
Definition: GUIBusStop.h:155
MSNet::lefthand
bool lefthand() const
return whether the network was built for lefthand traffic
Definition: MSNet.h:662
MSStoppingPlace::myEndPos
const double myEndPos
The end position this bus stop is located at.
Definition: MSStoppingPlace.h:229
Position::distanceTo
double distanceTo(const Position &p2) const
returns the euclidean distance in 3 dimension
Definition: Position.h:234
GUIParameterTableWindow::mkItem
void mkItem(const char *name, bool dynamic, ValueSource< T > *src)
Adds a row which obtains its value from a ValueSource.
Definition: GUIParameterTableWindow.h:109
GUIGlobals.h
PositionVector::positionAtOffset
Position positionAtOffset(double pos, double lateralOffset=0) const
Returns the position at the given length.
Definition: PositionVector.cpp:246
PositionVector::rotationDegreeAtOffset
double rotationDegreeAtOffset(double pos) const
Returns the rotation at the given length.
Definition: PositionVector.cpp:311
GUIGlObject::getGlID
GUIGlID getGlID() const
Returns the numerical id of the object.
Definition: GUIGlObject.cpp:150
MSStoppingPlace::getStoppedVehicleNumber
int getStoppedVehicleNumber() const
Returns the number of stopped vehicles waiting on this stop.
Definition: MSStoppingPlace.h:169
Boundary
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:42
MSLane::interpolateLanePosToGeometryPos
double interpolateLanePosToGeometryPos(double lanePos) const
Definition: MSLane.h:499
GUIVisualizationSettings::scale
double scale
information about a lane's width (temporary, used for a single view)
Definition: GUIVisualizationSettings.h:623
GUIApplicationWindow.h
Position
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:39
Position::x
double x() const
Returns the x-position.
Definition: Position.h:57
Boundary::add
void add(double x, double y, double z=0)
Makes the boundary include the given coordinate.
Definition: Boundary.cpp:79
GUIVisualizationSettings::addFullName
GUIVisualizationTextSettings addFullName
Definition: GUIVisualizationSettings.h:584
GUIVisualizationSettings::personSize
GUIVisualizationSizeSettings personSize
Definition: GUIVisualizationSettings.h:529
GUIBusStop::myFGSignRot
double myFGSignRot
The rotation of the sign.
Definition: GUIBusStop.h:149
GUIVisualizationTextSettings::show
bool show
flag show
Definition: GUIVisualizationSettings.h:69
GLO_BUS_STOP
a busStop
Definition: GUIGlObjectTypes.h:62
GUIBusStop::myPersonExaggeration
double myPersonExaggeration
The current person exaggeration.
Definition: GUIBusStop.h:158
GUIGlObject::buildPopupHeader
void buildPopupHeader(GUIGLObjectPopupMenu *ret, GUIMainWindow &app, bool addSeparator=true)
Builds the header.
Definition: GUIGlObject.cpp:208
MSStoppingPlace::getMyName
const std::string & getMyName() const
Definition: MSStoppingPlace.cpp:266
GUIVisualizationSettings::colorSettings
GUIVisualizationColorSettings colorSettings
color settings
Definition: GUIVisualizationSettings.h:649
Position::angleTo2D
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:254
MSStoppingPlace::myTransportableCapacity
const int myTransportableCapacity
The number of transportables that can wait here.
Definition: MSStoppingPlace.h:238
Position::distanceTo2D
double distanceTo2D(const Position &p2) const
returns the euclidean distance in the x-y-plane
Definition: Position.h:244
GLIncludes.h
MSLane::getShape
const PositionVector & getShape() const
Returns this lane's shape.
Definition: MSLane.h:478
FunctionBinding.h
MSNet::getInstance
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:168
GUIMainWindow
Definition: GUIMainWindow.h:47
Position::y
double y() const
Returns the y-position.
Definition: Position.h:62
M_PI
#define M_PI
Definition: odrSpiral.cpp:40
GLHelper::drawBoxLine
static void drawBoxLine(const Position &beg, double rot, double visLength, double width, double offset=0)
Draws a thick line.
Definition: GLHelper.cpp:136
GUIVisualizationColorSettings::busStop_sign
static const RGBColor busStop_sign
color for busStops signs
Definition: GUIVisualizationSettings.h:178
GUIEdge.h
GUIGlObject::buildShowParamsPopupEntry
void buildShowParamsPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to open the parameter window.
Definition: GUIGlObject.cpp:249
GUIBusStop::GUIBusStop
GUIBusStop(const std::string &id, const std::vector< std::string > &lines, MSLane &lane, double frompos, double topos, const std::string name, int personCapacity)
Constructor.
Definition: GUIBusStop.cpp:56
GUIBusStop::myFGShape
PositionVector myFGShape
The shape.
Definition: GUIBusStop.h:143
GUIVisualizationDetailSettings::stoppingPlaceText
static const double stoppingPlaceText
details for stopping place texts
Definition: GUIVisualizationSettings.h:302
GUIGlObject::buildCenterPopupEntry
void buildCenterPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to center to the object.
Definition: GUIGlObject.cpp:217
GUIGlObject::buildPositionCopyEntry
void buildPositionCopyEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to copy the cursor position if geo projection is used,...
Definition: GUIGlObject.cpp:267
MSStoppingPlace::getLastFreePos
double getLastFreePos() const
Definition: MSStoppingPlace.h:173
GUIBusStop::getPopUpMenu
GUIGLObjectPopupMenu * getPopUpMenu(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own popup-menu.
Definition: GUIBusStop.cpp:102
MSLane::getWidth
double getWidth() const
Returns the lane's width.
Definition: MSLane.h:557
MSStoppingPlace::getTransportableNumber
int getTransportableNumber() const
Returns the number of transportables waiting on this stop.
Definition: MSStoppingPlace.h:159
config.h
GUIVisualizationSettings::addSize
GUIVisualizationSizeSettings addSize
Definition: GUIVisualizationSettings.h:580
GeomHelper.h
MSStoppingPlace::getWaitPosition
virtual Position getWaitPosition(MSTransportable *person) const
Returns the next free waiting place for pedestrians / containers.
Definition: MSStoppingPlace.cpp:144
Boundary::grow
Boundary & grow(double by)
extends the boundary by the given amount
Definition: Boundary.cpp:301
MSLane::geometryPositionAtOffset
const Position geometryPositionAtOffset(double offset, double lateralOffset=0) const
Definition: MSLane.h:505
GUIVisualizationSettings::drawDetail
bool drawDetail(const double detail, const double exaggeration) const
check if details can be drawn for the given GUIVisualizationDetailSettings and current scale and exxa...
Definition: GUIVisualizationSettings.cpp:1621
GUIBusStop::myFGSignPos
Position myFGSignPos
The position of the sign.
Definition: GUIBusStop.h:146
GUIBusStop::myFGShapeRotations
std::vector< double > myFGShapeRotations
The rotations of the shape parts.
Definition: GUIBusStop.h:137
MSStoppingPlace::getPersonsAbreast
int getPersonsAbreast() const
Definition: MSStoppingPlace.cpp:139
MSLane.h
GUIVisualizationSettings
Stores the information about how to visualize structures.
Definition: GUIVisualizationSettings.h:346
FunctionBinding
Definition: FunctionBinding.h:41
PositionVector::getLineCenter
Position getLineCenter() const
get line center
Definition: PositionVector.cpp:466
GUIBusStop.h
GUIBusStop::myFGShapeLengths
std::vector< double > myFGShapeLengths
The lengths of the shape parts.
Definition: GUIBusStop.h:140
PositionVector.h
MSStoppingPlace::myLane
const MSLane & myLane
The lane this bus stop is located at.
Definition: MSStoppingPlace.h:223
GUIBusStop::getCenteringBoundary
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
Definition: GUIBusStop.cpp:193
GUIVisualizationSizeSettings::getExaggeration
double getExaggeration(const GUIVisualizationSettings &s, const GUIGlObject *o, double factor=20) const
return the drawing size including exaggeration and constantSize values
Definition: GUIVisualizationSettings.cpp:212
PositionVector::move2side
void move2side(double amount, double maxExtension=100)
move position vector to side using certain ammount
Definition: PositionVector.cpp:1086
fontstash.h