SUMO - Simulation of Urban MObility
GUIBusStop.cpp
Go to the documentation of this file.
1 /****************************************************************************/
9 // A lane area vehicles can halt at (gui-version)
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
12 // Copyright (C) 2001-2017 DLR (http://www.dlr.de/) and contributors
13 /****************************************************************************/
14 //
15 // This file is part of SUMO.
16 // SUMO is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
21 /****************************************************************************/
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #ifdef _MSC_VER
28 #include <windows_config.h>
29 #else
30 #include <config.h>
31 #endif
32 
33 #include <string>
36 #include <utils/geom/Boundary.h>
37 #include <utils/gui/div/GLHelper.h>
38 #include <utils/common/ToString.h>
39 #include <microsim/MSNet.h>
40 #include <microsim/MSLane.h>
41 #include <microsim/MSEdge.h>
42 #include "GUINet.h"
43 #include "GUIEdge.h"
44 #include "GUIPerson.h"
45 #include "GUIBusStop.h"
48 #include <gui/GUIGlobals.h>
54 #include <utils/geom/GeomHelper.h>
55 #include <guisim/GUIBusStop.h>
57 
58 
59 
60 // ===========================================================================
61 // method definitions
62 // ===========================================================================
63 GUIBusStop::GUIBusStop(const std::string& id, const std::vector<std::string>& lines, MSLane& lane,
64  double frompos, double topos, const std::string name) :
65  MSStoppingPlace(id, lines, lane, frompos, topos, name),
66  GUIGlObject_AbstractAdd("busStop", GLO_TRIGGER, id) {
67  const double offsetSign = MSNet::getInstance()->lefthand() ? -1 : 1;
68  myFGShape = lane.getShape();
69  myFGShape.move2side(1.65 * offsetSign);
70  myFGShape = myFGShape.getSubpart(frompos, topos);
71  myFGShapeRotations.reserve(myFGShape.size() - 1);
72  myFGShapeLengths.reserve(myFGShape.size() - 1);
73  int e = (int) myFGShape.size() - 1;
74  for (int i = 0; i < e; ++i) {
75  const Position& f = myFGShape[i];
76  const Position& s = myFGShape[i + 1];
77  myFGShapeLengths.push_back(f.distanceTo(s));
78  myFGShapeRotations.push_back((double) atan2((s.x() - f.x()), (f.y() - s.y())) * (double) 180.0 / (double) PI);
79  }
81  tmp.move2side(1.5 * offsetSign);
82  myFGSignPos = tmp.getLineCenter();
83  myFGSignRot = 0;
84  if (tmp.length() != 0) {
86  myFGSignRot -= 90;
87  }
88 }
89 
90 
92 
93 
94 void
95 GUIBusStop::addAccess(MSLane* lane, const double pos) {
96  MSStoppingPlace::addAccess(lane, pos);
97  myAccessCoords.push_back(lane->getShape().positionAtOffset(pos));
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, 4);
120  // add items
121  ret->mkItem("begin position [m]", false, myBegPos);
122  ret->mkItem("end position [m]", false, myEndPos);
123  ret->mkItem("person number [#]", true, new FunctionBinding<GUIBusStop, int>(this, &MSStoppingPlace::getTransportableNumber));
124  // close building
125  ret->closeBuilding();
126  return ret;
127 }
128 
129 
130 void
132  glPushName(getGlID());
133  glPushMatrix();
134  RGBColor green(76, 170, 50, 255);
135  RGBColor yellow(255, 235, 0, 255);
136  RGBColor black(0, 0, 0);
137  // draw the area
138  glTranslated(0, 0, getType());
139  GLHelper::setColor(green);
140  const double exaggeration = s.addSize.getExaggeration(s);
142  // draw details unless zoomed out to far
143  if (s.scale * exaggeration >= 10) {
144  // draw the lines
145  const double rotSign = MSNet::getInstance()->lefthand() ? -1 : 1;
146  for (int i = 0; i != (int)myLines.size(); ++i) {
147  glPushMatrix();
148  glTranslated(myFGSignPos.x(), myFGSignPos.y(), 0);
149  glRotated(180, 1, 0, 0);
150  glRotated(rotSign * myFGSignRot, 0, 0, 1);
151  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
152  pfSetPosition(0, 0);
153  pfSetScale(1.f);
154  glTranslated(1.2, -(double)i, 0);
155  pfDrawString(myLines[i].c_str());
156  glPopMatrix();
157  }
158  for (std::vector<Position>::const_iterator i = myAccessCoords.begin(); i != myAccessCoords.end(); ++i) {
160  }
161  // draw the sign
162  glTranslated(myFGSignPos.x(), myFGSignPos.y(), 0);
163  int noPoints = 9;
164  if (s.scale * exaggeration > 25) {
165  noPoints = MIN2((int)(9.0 + (s.scale * exaggeration) / 10.0), 36);
166  }
167  glScaled(exaggeration, exaggeration, 1);
168  GLHelper::drawFilledCircle((double) 1.1, noPoints);
169  glTranslated(0, 0, .1);
170  GLHelper::setColor(yellow);
171  GLHelper::drawFilledCircle((double) 0.9, noPoints);
172  if (s.scale * exaggeration >= 4.5) {
173  GLHelper::drawText("H", Position(), .1, 1.6, green, myFGSignRot);
174  }
175  //TODO: add pt stop show name options to gui settings [GL Mar '17]
176  if (s.streetName.show && s.scale * exaggeration >= 4.5) {
177  glTranslated(0, -3.1, 0);
178  GLHelper::drawText(getMyName(), Position(), .1, 3, black, myFGSignRot);
179  }
180 
181  }
182  glPopMatrix();
183  glPopName();
184  drawName(getCenteringBoundary().getCenter(), s.scale, s.addName);
185 }
186 
187 
188 Boundary
192  return b;
193 }
194 
195 
196 
197 /****************************************************************************/
198 
int pfDrawString(const char *c)
Definition: polyfonts.c:1074
double rotationDegreeAtOffset(double pos) const
Returns the rotation at the given length.
a lane speed trigger,
double scale
information about a lane&#39;s width (temporary, used for a single view)
GUIVisualizationTextSettings streetName
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:172
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:102
void pfSetScale(double s)
Definition: polyfonts.c:465
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:250
void addAccess(MSLane *lane, const double pos)
adds an access point to this stop
Definition: GUIBusStop.cpp:95
const double myEndPos
The end position this bus stop is located at.
virtual void addAccess(MSLane *lane, const double pos)
adds an access point to this stop
Stores the information about how to visualize structures.
Position myFGSignPos
The position of the sign.
Definition: GUIBusStop.h:147
const double SUMO_const_laneWidth
Definition: StdDefs.h:48
double y() const
Returns the y-position.
Definition: Position.h:68
double x() const
Returns the x-position.
Definition: Position.h:63
void buildCenterPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to center to the object.
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:260
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:158
double myFGSignRot
The rotation of the sign.
Definition: GUIBusStop.h:150
const PositionVector & getShape() const
Returns this lane&#39;s shape.
Definition: MSLane.h:426
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
Definition: GUIBusStop.cpp:189
void pfSetPosition(double x, double y)
Definition: polyfonts.c:480
#define RAD2DEG(x)
Definition: GeomHelper.h:46
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:340
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:48
Position getLineCenter() const
get line center
GUIVisualizationSizeSettings addSize
#define PI
Definition: polyfonts.c:61
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:439
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
A list of positions.
PositionVector myFGShape
The shape.
Definition: GUIBusStop.h:144
~GUIBusStop()
Destructor.
Definition: GUIBusStop.cpp:91
T MIN2(T a, T b)
Definition: StdDefs.h:64
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:234
PositionVector getSubpart(double beginOffset, double endOffset) const
get subpart of a position vector
bool lefthand() const
return whether the network was built for lefthand traffic
Definition: MSNet.h:693
void move2side(double amount)
move position vector to side using certain ammount
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
Definition: GUIBusStop.cpp:131
const double myBegPos
The begin position this bus stop is located at.
double length() const
Returns the length.
PositionVector myAccessCoords
The coordinates of access points.
Definition: GUIBusStop.h:153
The popup menu of a globject.
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:116
std::vector< double > myFGShapeRotations
The rotations of the shape parts.
Definition: GUIBusStop.h:138
GUIGlID getGlID() const
Returns the numerical id of the object.
double getExaggeration(const GUIVisualizationSettings &s, double factor=20) const
return the drawing size including exaggeration and constantSize values
double distanceTo(const Position &p2) const
returns the euclidean distance in 3 dimension
Definition: Position.h:240
std::vector< double > myFGShapeLengths
The lengths of the shape parts.
Definition: GUIBusStop.h:141
Boundary getBoxBoundary() const
Returns a boundary enclosing this list of lines.
static void drawBoxLine(const Position &beg, double rot, double visLength, double width, double offset=0)
Draws a thick line.
Definition: GLHelper.cpp:126
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)
draw Text with given parameters
Definition: GLHelper.cpp:456
std::vector< std::string > myLines
The list of lines that are assigned to this stop.
void mkItem(const char *name, bool dynamic, ValueSource< unsigned > *src)
Adds a row which obtains its value from an unsigned-ValueSource.
Position positionAtOffset(double pos, double lateralOffset=0) const
Returns the position at the given length.
void closeBuilding()
Closes the building of the table.
Representation of a lane in the micro simulation.
Definition: MSLane.h:79
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:63