SUMO - Simulation of Urban MObility
GUIContainerStop.cpp
Go to the documentation of this file.
1 /****************************************************************************/
8 // A lane area vehicles can halt at (gui-version)
9 /****************************************************************************/
10 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
11 // Copyright (C) 2001-2017 DLR (http://www.dlr.de/) and contributors
12 /****************************************************************************/
13 //
14 // This file is part of SUMO.
15 // SUMO is free software: you can redistribute it and/or modify
16 // it under the terms of the GNU General Public License as published by
17 // the Free Software Foundation, either version 3 of the License, or
18 // (at your option) any later version.
19 //
20 /****************************************************************************/
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #ifdef _MSC_VER
27 #include <windows_config.h>
28 #else
29 #include <config.h>
30 #endif
31 
32 #include <string>
35 #include <utils/geom/Boundary.h>
36 #include <utils/gui/div/GLHelper.h>
37 #include <utils/common/ToString.h>
38 #include <microsim/MSNet.h>
39 #include <microsim/MSLane.h>
40 #include <microsim/MSEdge.h>
41 #include "GUINet.h"
42 #include "GUIEdge.h"
43 #include "GUIContainer.h"
44 #include "GUIContainerStop.h"
47 #include <gui/GUIGlobals.h>
53 #include <utils/geom/GeomHelper.h>
56 
57 
58 // ===========================================================================
59 // method definitions
60 // ===========================================================================
61 GUIContainerStop::GUIContainerStop(const std::string& id, const std::vector<std::string>& lines, MSLane& lane,
62  double frompos, double topos)
63  : MSStoppingPlace(id, lines, lane, frompos, topos),
64  GUIGlObject_AbstractAdd("containerStop", GLO_TRIGGER, id) {
65  const double offsetSign = MSNet::getInstance()->lefthand() ? -1 : 1;
66  myFGShape = lane.getShape();
67  myFGShape.move2side(1.65 * offsetSign);
69  lane.interpolateLanePosToGeometryPos(frompos),
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) M_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 
96  GUISUMOAbstractView& parent) {
97  GUIGLObjectPopupMenu* ret = new GUIGLObjectPopupMenu(app, parent, *this);
98  buildPopupHeader(ret, app);
103  buildPositionCopyEntry(ret, false);
104  return ret;
105 }
106 
107 
112  new GUIParameterTableWindow(app, *this, 4);
113  // add items
114  ret->mkItem("begin position [m]", false, myBegPos);
115  ret->mkItem("end position [m]", false, myEndPos);
116  ret->mkItem("container number [#]", true, new FunctionBinding<GUIContainerStop, int>(this, &MSStoppingPlace::getTransportableNumber));
117  // close building
118  ret->closeBuilding();
119  return ret;
120 }
121 
122 
123 void
125  glPushName(getGlID());
126  glPushMatrix();
127  RGBColor grey(177, 184, 186, 171);
128  RGBColor blue(83, 89, 172, 255);
129  // draw the area
130  glTranslated(0, 0, getType());
131  GLHelper::setColor(blue);
132  const double exaggeration = s.addSize.getExaggeration(s);
134  // draw details unless zoomed out to far
135  if (s.scale * exaggeration >= 10) {
136  glPushMatrix();
137  // draw the lines
138  const double rotSign = MSNet::getInstance()->lefthand() ? -1 : 1;
139  for (int i = 0; i != (int)myLines.size(); ++i) {
140  glPushMatrix();
141  glTranslated(myFGSignPos.x(), myFGSignPos.y(), 0);
142  glRotated(180, 1, 0, 0);
143  glRotated(rotSign * myFGSignRot, 0, 0, 1);
144  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
145  pfSetPosition(0, 0);
146  pfSetScale(1.f);
147  glTranslated(1.2, -(double)i, 0);
148  pfDrawString(myLines[i].c_str());
149  glPopMatrix();
150  }
151 
152 
153 
154  // draw the sign
155  glTranslated(myFGSignPos.x(), myFGSignPos.y(), 0);
156  int noPoints = 9;
157  if (s.scale * exaggeration > 25) {
158  noPoints = MIN2((int)(9.0 + (s.scale * exaggeration) / 10.0), 36);
159  }
160  glScaled(exaggeration, exaggeration, 1);
161  GLHelper::drawFilledCircle((double) 1.1, noPoints);
162  glTranslated(0, 0, .1);
163  GLHelper::setColor(grey);
164  GLHelper::drawFilledCircle((double) 0.9, noPoints);
165  if (s.scale * exaggeration >= 4.5) {
166  GLHelper::drawText("C", Position(), .1, 1.6, blue, myFGSignRot);
167  }
168  glPopMatrix();
169  }
170  glPopMatrix();
171  glPopName();
172  drawName(getCenteringBoundary().getCenter(), s.scale, s.addName);
173  for (std::vector<MSTransportable*>::const_iterator i = myWaitingTransportables.begin(); i != myWaitingTransportables.end(); ++i) {
174  glTranslated(0, 1, 0); // make multiple containers viewable
175  static_cast<GUIContainer*>(*i)->drawGL(s);
176  }
177 }
178 
179 
180 Boundary
183  b.grow(20);
184  return b;
185 }
186 
187 
188 
189 /****************************************************************************/
190 
PositionVector myFGShape
The shape.
int pfDrawString(const char *c)
Definition: polyfonts.c:1074
void drawName(const Position &pos, const double scale, const GUIVisualizationTextSettings &settings, const double angle=0) const
draw name of item
bool lefthand() const
return whether the network was built for lefthand traffic
Definition: MSNet.h:688
a lane speed trigger,
std::vector< double > myFGShapeLengths
The lengths of the shape parts.
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 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
std::vector< MSTransportable * > myWaitingTransportables
Persons waiting at this stop.
void buildNameCopyPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds entries which allow to copy the name / typed name into the clipboard.
void pfSetScale(double s)
Definition: polyfonts.c:465
A lane area vehicles can halt at.
const double myEndPos
The end position this bus stop is located at.
double x() const
Returns the x-position.
Definition: Position.h:63
Stores the information about how to visualize structures.
~GUIContainerStop()
Destructor.
double interpolateLanePosToGeometryPos(double lanePos) const
Definition: MSLane.h:442
void buildCenterPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to center to the object.
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:169
void pfSetPosition(double x, double y)
Definition: polyfonts.c:480
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:339
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.
GUIGlID getGlID() const
Returns the numerical id of the object.
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:48
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
GUIVisualizationSizeSettings addSize
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
double getExaggeration(const GUIVisualizationSettings &s, double factor=20) const
return the drawing size including exaggeration and constantSize values
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:438
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
A list of positions.
double rotationDegreeAtOffset(double pos) const
Returns the rotation at the given length.
double y() const
Returns the y-position.
Definition: Position.h:68
GUIParameterTableWindow * getParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own parameter window.
Position myFGSignPos
The position of the sign.
double length() const
Returns the length.
T MIN2(T a, T b)
Definition: StdDefs.h:68
GUIGLObjectPopupMenu * getPopUpMenu(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own popup-menu.
Boundary & grow(double by)
extends the boundary by the given amount
Definition: Boundary.cpp:302
double myFGSignRot
The rotation of the sign.
void move2side(double amount)
move position vector to side using certain ammount
double distanceTo(const Position &p2) const
returns the euclidean distance in 3 dimension
Definition: Position.h:240
const double myBegPos
The begin position this bus stop is located at.
GUIContainerStop(const std::string &id, const std::vector< std::string > &lines, MSLane &lane, double frompos, double topos)
Constructor.
int getTransportableNumber() const
Returns the number of transportables waiting on this stop.
#define M_PI
Definition: odrSpiral.cpp:40
The popup menu of a globject.
void buildSelectionPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to (de)select the object.
std::vector< double > myFGShapeRotations
The rotations of the shape parts.
Position getLineCenter() const
get line center
const PositionVector & getShape() const
Returns this lane&#39;s shape.
Definition: MSLane.h:426
PositionVector getSubpart(double beginOffset, double endOffset) const
get subpart of a position vector
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:455
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
std::vector< std::string > myLines
The list of lines that are assigned to this stop.
Boundary getBoxBoundary() const
Returns a boundary enclosing this list of lines.
void mkItem(const char *name, bool dynamic, ValueSource< unsigned > *src)
Adds a row which obtains its value from an unsigned-ValueSource.
Representation of a lane in the micro simulation.
Definition: MSLane.h:79
A window containing a gl-object&#39;s parameter.
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
void buildPopupHeader(GUIGLObjectPopupMenu *ret, GUIMainWindow &app, bool addSeparator=true)
Builds the header.