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-2020 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 /****************************************************************************/
20 // A lane area vehicles can halt at (gui-version)
21 /****************************************************************************/
22 #include <config.h>
23 
24 #include <string>
27 #include <utils/geom/Boundary.h>
28 #include <utils/gui/div/GLHelper.h>
29 #include <utils/common/ToString.h>
30 #include <microsim/MSNet.h>
31 #include <microsim/MSLane.h>
32 #include <microsim/MSEdge.h>
33 #include "GUINet.h"
34 #include "GUIEdge.h"
35 #include "GUIPerson.h"
36 #include "GUIBusStop.h"
39 #include <gui/GUIGlobals.h>
45 #include <utils/geom/GeomHelper.h>
46 #include <guisim/GUIBusStop.h>
48 
49 
50 
51 // ===========================================================================
52 // method definitions
53 // ===========================================================================
54 GUIBusStop::GUIBusStop(const std::string& id, const std::vector<std::string>& lines, MSLane& lane,
55  double frompos, double topos, const std::string name, int personCapacity, double parkingLength) :
56  MSStoppingPlace(id, lines, lane, frompos, topos, name, personCapacity, parkingLength),
58  myPersonExaggeration(1) {
59  const double offsetSign = MSGlobals::gLefthand ? -1 : 1;
60  myWidth = MAX2(1.0, ceil(personCapacity / getPersonsAbreast()) * SUMO_const_waitingPersonDepth);
61  myFGShape = lane.getShape();
62  myFGShape.move2side((lane.getWidth() + myWidth) * 0.45 * offsetSign);
64  lane.interpolateLanePosToGeometryPos(frompos),
66  myFGShapeRotations.reserve(myFGShape.size() - 1);
67  myFGShapeLengths.reserve(myFGShape.size() - 1);
68  int e = (int) myFGShape.size() - 1;
69  for (int i = 0; i < e; ++i) {
70  const Position& f = myFGShape[i];
71  const Position& s = myFGShape[i + 1];
72  myFGShapeLengths.push_back(f.distanceTo(s));
73  myFGShapeRotations.push_back((double) atan2((s.x() - f.x()), (f.y() - s.y())) * (double) 180.0 / (double) M_PI);
74  }
76  tmp.move2side(myWidth / 2 * offsetSign);
77  myFGSignPos = tmp.getLineCenter();
78  myFGSignRot = 0;
79  if (tmp.length() != 0) {
81  myFGSignRot -= 90;
82  }
83 }
84 
85 
87 
88 
89 bool
90 GUIBusStop::addAccess(MSLane* lane, const double pos, const double length) {
91  bool added = MSStoppingPlace::addAccess(lane, pos, length);
92  if (added) {
93  myAccessCoords.push_back(lane->geometryPositionAtOffset(pos));
94  }
95  return added;
96 }
97 
98 
101  GUISUMOAbstractView& parent) {
102  GUIGLObjectPopupMenu* ret = new GUIGLObjectPopupMenu(app, parent, *this);
103  buildPopupHeader(ret, app);
108  buildPositionCopyEntry(ret, false);
109  return ret;
110 }
111 
112 
117  new GUIParameterTableWindow(app, *this);
118  // add items
119  ret->mkItem("name", false, getMyName());
120  ret->mkItem("begin position [m]", false, myBegPos);
121  ret->mkItem("end position [m]", false, myEndPos);
122  ret->mkItem("lines", false, joinToString(myLines, " "));
123  ret->mkItem("parking length [m]", false, (myEndPos - myBegPos) / myParkingFactor);
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 = MSGlobals::gLefthand ? 1 : -1;
149  // Iterate over every line
150  const double lineAngle = s.getTextAngle(rotSign * myFGSignRot);
152  const double textOffset = s.flippedTextAngle(rotSign * myFGSignRot) ? -1 : 1;
153  const double textOffset2 = s.flippedTextAngle(rotSign * myFGSignRot) ? -1 : 0.3;
154  for (int i = 0; i < (int)myLines.size(); ++i) {
155  // push a new matrix for every line
156  glPushMatrix();
157  // traslate and rotate
158  glTranslated(myFGSignPos.x(), myFGSignPos.y(), 0);
159  glRotated(lineAngle, 0, 0, 1);
160  // draw line
161  GLHelper::drawText(myLines[i].c_str(), Position(1.2, i * textOffset + textOffset2), .1, 1.f, lineColor, 0, FONS_ALIGN_LEFT);
162  // pop matrix for every line
163  glPopMatrix();
164  }
166  for (std::vector<Position>::const_iterator i = myAccessCoords.begin(); i != myAccessCoords.end(); ++i) {
168  }
169  // draw the sign
170  glTranslated(myFGSignPos.x(), myFGSignPos.y(), 0);
171  int noPoints = 9;
172  if (s.scale * exaggeration > 25) {
173  noPoints = MIN2((int)(9.0 + (s.scale * exaggeration) / 10.0), 36);
174  }
175  glScaled(exaggeration, exaggeration, 1);
176  GLHelper::drawFilledCircle((double) 1.1, noPoints);
177  glTranslated(0, 0, .1);
179  GLHelper::drawFilledCircle((double) 0.9, noPoints);
180  if (s.drawDetail(s.detailSettings.stoppingPlaceText, exaggeration)) {
182  }
183  glPopMatrix();
184  }
185  if (s.addFullName.show && getMyName() != "") {
187  }
188  if (exaggeration > 1) {
190  }
191  glPopMatrix();
192  glPopName();
194 }
195 
196 
197 Boundary
201  for (const Position& p : myAccessCoords) {
202  b.add(p);
203  }
204  return b;
205 }
206 
207 const std::string
209  return myName;
210 }
211 
212 Position
215  if (myPersonExaggeration > 1) {
217  myLane.getWidth() / 2);
218  result = ref + (result - ref) * myPersonExaggeration;
219  }
220  return result;
221 }
222 
223 
224 /****************************************************************************/
@ GLO_BUS_STOP
a busStop
@ GLO_MAX
empty max
#define RAD2DEG(x)
Definition: GeomHelper.h:36
const double SUMO_const_laneWidth
Definition: StdDefs.h:47
const double SUMO_const_waitingPersonDepth
Definition: StdDefs.h:55
T MIN2(T a, T b)
Definition: StdDefs.h:73
T MAX2(T a, T b)
Definition: StdDefs.h:79
std::string joinToString(const std::vector< T > &v, const T_BETWEEN &between, std::streamsize accuracy=gPrecision)
Definition: ToString.h:250
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:77
Boundary & grow(double by)
extends the boundary by the given amount
Definition: Boundary.cpp:299
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:446
static void drawFilledCircle(double width, int steps=8)
Draws a filled circle around (0,0)
Definition: GLHelper.cpp:347
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:181
static void drawBoxLine(const Position &beg, double rot, double visLength, double width, double offset=0)
Draws a thick line.
Definition: GLHelper.cpp:135
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:498
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:529
Position myFGSignPos
The position of the sign.
Definition: GUIBusStop.h:144
double myFGSignRot
The rotation of the sign.
Definition: GUIBusStop.h:147
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
Definition: GUIBusStop.cpp:135
double myPersonExaggeration
The current person exaggeration.
Definition: GUIBusStop.h:156
GUIGLObjectPopupMenu * getPopUpMenu(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own popup-menu.
Definition: GUIBusStop.cpp:100
~GUIBusStop()
Destructor.
Definition: GUIBusStop.cpp:86
std::vector< double > myFGShapeLengths
The lengths of the shape parts.
Definition: GUIBusStop.h:138
PositionVector myFGShape
The shape.
Definition: GUIBusStop.h:141
bool addAccess(MSLane *lane, const double pos, const double length)
adds an access point to this stop
Definition: GUIBusStop.cpp:90
GUIBusStop(const std::string &id, const std::vector< std::string > &lines, MSLane &lane, double frompos, double topos, const std::string name, int personCapacity, double parkingLength)
Constructor.
Definition: GUIBusStop.cpp:54
GUIParameterTableWindow * getParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own parameter window.
Definition: GUIBusStop.cpp:114
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:208
Position getWaitPosition(MSTransportable *person) const
Returns the next free waiting place for pedestrians / containers.
Definition: GUIBusStop.cpp:213
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:198
The popup menu of a globject.
void buildPositionCopyEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to copy the cursor position if geo projection is used,...
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.
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) 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
GUIVisualizationSizeSettings personSize
double scale
information about a lane's width (temporary, used for a single view)
GUIVisualizationStoppingPlaceSettings stoppingPlaceSettings
StoppingPlace settings.
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:136
Representation of a lane in the micro simulation.
Definition: MSLane.h:82
const PositionVector & getShape() const
Returns this lane's shape.
Definition: MSLane.h:476
double interpolateLanePosToGeometryPos(double lanePos) const
Definition: MSLane.h:497
double getWidth() const
Returns the lane's width.
Definition: MSLane.h:555
const Position geometryPositionAtOffset(double offset, double lateralOffset=0) const
Definition: MSLane.h:503
A lane area vehicles can halt at.
int getStoppedVehicleNumber() const
Returns the number of stopped vehicles waiting on this stop.
const double myBegPos
The begin position this bus stop is located at.
const MSLane & myLane
The lane this bus stop is located at.
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.
int getPersonsAbreast() const
std::vector< std::string > myLines
The list of lines that are assigned to this stop.
const int myTransportableCapacity
The number of transportables that can wait here.
const std::string & getMyName() const
virtual Position getWaitPosition(MSTransportable *person) const
Returns the next free waiting place for pedestrians / containers.
double getLastFreePos() const
virtual bool addAccess(MSLane *lane, const double pos, const double length)
adds an access point to this stop
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:36
double distanceTo2D(const Position &p2) const
returns the euclidean distance in the x-y-plane
Definition: Position.h:241
double distanceTo(const Position &p2) const
returns the euclidean distance in 3 dimension
Definition: Position.h:231
double x() const
Returns the x-position.
Definition: Position.h:54
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:251
double y() const
Returns the y-position.
Definition: Position.h:59
A list of positions.
double length() const
Returns the length.
double rotationDegreeAtOffset(double pos) const
Returns the rotation at the given length.
Position positionAtOffset(double pos, double lateralOffset=0) const
Returns the position 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
RGBColor changedBrightness(int change, int toChange=3) const
Returns a new color with altered brightness.
Definition: RGBColor.cpp:145
@ FONS_ALIGN_LEFT
Definition: fontstash.h:42
#define M_PI
Definition: odrSpiral.cpp:40
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
static const RGBColor busStopColorSign
color for busStops signs
static const RGBColor busStopColor
color for busStops