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-2018 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) :
58  MSStoppingPlace(id, lines, lane, frompos, topos, name),
60  const double offsetSign = MSNet::getInstance()->lefthand() ? -1 : 1;
61  myFGShape = lane.getShape();
62  myFGShape.move2side(1.65 * 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(1.5 * 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, 7);
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("person number [#]", true, new FunctionBinding<GUIBusStop, int>(this, &MSStoppingPlace::getTransportableNumber));
123  ret->mkItem("stopped vehicles[#]", true, new FunctionBinding<GUIBusStop, int>(this, &MSStoppingPlace::getStoppedVehicleNumber));
124  ret->mkItem("last free pos[m]", true, new FunctionBinding<GUIBusStop, double>(this, &MSStoppingPlace::getLastFreePos));
125  // close building
126  ret->closeBuilding();
127  return ret;
128 }
129 
130 
131 void
133  glPushName(getGlID());
134  glPushMatrix();
135  // draw the area
136  glTranslated(0, 0, getType());
138  const double exaggeration = s.addSize.getExaggeration(s, this);
140  // draw details unless zoomed out to far
141  if (s.scale * exaggeration >= 10) {
142  glPushMatrix();
143  // draw the lines
144  const double rotSign = MSNet::getInstance()->lefthand() ? 1 : -1;
145  // Iterate over every line
146  for (int i = 0; i < (int)myLines.size(); ++i) {
147  // push a new matrix for every line
148  glPushMatrix();
149  // traslate and rotate
150  glTranslated(myFGSignPos.x(), myFGSignPos.y(), 0);
151  glRotated(rotSign * myFGSignRot, 0, 0, 1);
152  // draw line
153  GLHelper::drawText(myLines[i].c_str(), Position(1.2, (double)i), .1, 1.f, s.SUMO_color_busStop, 0, FONS_ALIGN_LEFT);
154  // pop matrix for every line
155  glPopMatrix();
156  }
157  for (std::vector<Position>::const_iterator i = myAccessCoords.begin(); i != myAccessCoords.end(); ++i) {
159  }
160  // draw the sign
161  glTranslated(myFGSignPos.x(), myFGSignPos.y(), 0);
162  int noPoints = 9;
163  if (s.scale * exaggeration > 25) {
164  noPoints = MIN2((int)(9.0 + (s.scale * exaggeration) / 10.0), 36);
165  }
166  glScaled(exaggeration, exaggeration, 1);
167  GLHelper::drawFilledCircle((double) 1.1, noPoints);
168  glTranslated(0, 0, .1);
170  GLHelper::drawFilledCircle((double) 0.9, noPoints);
171  if (s.scale * exaggeration >= 4.5) {
173  }
174  glPopMatrix();
175  }
176  if (s.addFullName.show && getMyName() != "") {
178  }
179  glPopMatrix();
180  glPopName();
182 }
183 
184 
185 Boundary
189  for (const Position& p : myAccessCoords) {
190  b.add(p);
191  }
192  return b;
193 }
194 
195 
196 /****************************************************************************/
double rotationDegreeAtOffset(double pos) const
Returns the rotation at the given length.
double scale
information about a lane&#39;s width (temporary, used for a single view)
void closeBuilding(const Parameterised *p=0)
Closes the building of the table.
static const RGBColor SUMO_color_busStop_sign
color for busStops signs
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:178
GUIVisualizationTextSettings addName
void buildNameCopyPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds entries which allow to copy the name / typed name into the clipboard.
GUIGLObjectPopupMenu * getPopUpMenu(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own popup-menu.
Definition: GUIBusStop.cpp:100
A lane area vehicles can halt at.
double distanceTo2D(const Position &p2) const
returns the euclidean distance in the x-y-plane
Definition: Position.h:244
const double myEndPos
The end position this bus stop is located at.
Stores the information about how to visualize structures.
Position myFGSignPos
The position of the sign.
Definition: GUIBusStop.h:139
int getStoppedVehicleNumber() const
Returns the number of stopped vehicles waiting on this stop.
const double SUMO_const_laneWidth
Definition: StdDefs.h:51
double y() const
Returns the y-position.
Definition: Position.h:62
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:635
void mkItem(const char *name, bool dynamic, ValueSource< T > *src)
Adds a row which obtains its value from a ValueSource.
double x() const
Returns the x-position.
Definition: Position.h:57
void buildCenterPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to center to the object.
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:611
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
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:165
double myFGSignRot
The rotation of the sign.
Definition: GUIBusStop.h:142
const PositionVector & getShape() const
Returns this lane&#39;s shape.
Definition: MSLane.h:456
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
Definition: GUIBusStop.cpp:186
#define RAD2DEG(x)
Definition: GeomHelper.h:39
int getTransportableNumber() const
Returns the number of transportables waiting on this stop.
void buildShowParamsPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to open the parameter window.
static void drawFilledCircle(double width, int steps=8)
Draws a filled circle around (0,0)
Definition: GLHelper.cpp:344
const std::string & getMyName() const
void buildPositionCopyEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to copy the cursor position if geo projection is used, also builds an entry for copying the geo-position.
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:42
Position getLineCenter() const
get line center
GUIVisualizationSizeSettings addSize
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
double getTextAngle(double objectAngle) const
return an angle that is suitable for reading text aligned with the given angle (degrees) ...
a busStop
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:573
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:39
A list of positions.
PositionVector myFGShape
The shape.
Definition: GUIBusStop.h:136
~GUIBusStop()
Destructor.
Definition: GUIBusStop.cpp:86
bool addAccess(MSLane *lane, const double pos, const double length)
adds an access point to this stop
Definition: GUIBusStop.cpp:90
T MIN2(T a, T b)
Definition: StdDefs.h:70
void drawName(const Position &pos, const double scale, const GUIVisualizationTextSettings &settings, const double angle=0) const
draw name of item
Boundary & grow(double by)
extends the boundary by the given amount
Definition: Boundary.cpp:301
double angle
The current view rotation angle.
PositionVector getSubpart(double beginOffset, double endOffset) const
get subpart of a position vector
static const RGBColor SUMO_color_busStop
color for busStops
bool lefthand() const
return whether the network was built for lefthand traffic
Definition: MSNet.h:615
void move2side(double amount)
move position vector to side using certain ammount
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
Definition: GUIBusStop.cpp:132
virtual bool addAccess(MSLane *lane, const double pos, const double length)
adds an access point to this stop
const double myBegPos
The begin position this bus stop is located at.
double length() const
Returns the length.
#define M_PI
Definition: odrSpiral.cpp:40
GUIVisualizationTextSettings addFullName
PositionVector myAccessCoords
The coordinates of access points.
Definition: GUIBusStop.h:145
double interpolateLanePosToGeometryPos(double lanePos) const
Definition: MSLane.h:472
The popup menu of a globject.
const Position geometryPositionAtOffset(double offset, double lateralOffset=0) const
Definition: MSLane.h:478
void buildSelectionPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to (de)select the object.
GUIParameterTableWindow * getParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own parameter window.
Definition: GUIBusStop.cpp:114
std::vector< double > myFGShapeRotations
The rotations of the shape parts.
Definition: GUIBusStop.h:130
GUIGlID getGlID() const
Returns the numerical id of the object.
double distanceTo(const Position &p2) const
returns the euclidean distance in 3 dimension
Definition: Position.h:234
std::vector< double > myFGShapeLengths
The lengths of the shape parts.
Definition: GUIBusStop.h:133
Boundary getBoxBoundary() const
Returns a boundary enclosing this list of lines.
empty max
static void drawBoxLine(const Position &beg, double rot, double visLength, double width, double offset=0)
Draws a thick line.
Definition: GLHelper.cpp:132
void add(double x, double y, double z=0)
Makes the boundary include the given coordinate.
Definition: Boundary.cpp:79
double getLastFreePos() const
double getExaggeration(const GUIVisualizationSettings &s, const GUIGlObject *o, double factor=20) const
return the drawing size including exaggeration and constantSize values
std::vector< std::string > myLines
The list of lines that are assigned to this stop.
Representation of a lane in the micro simulation.
Definition: MSLane.h:78
A window containing a gl-object&#39;s parameter.
void buildPopupHeader(GUIGLObjectPopupMenu *ret, GUIMainWindow &app, bool addSeparator=true)
Builds the header.
GUIBusStop(const std::string &id, const std::vector< std::string > &lines, MSLane &lane, double frompos, double topos, const std::string name)
Constructor.
Definition: GUIBusStop.cpp:56