Eclipse SUMO - Simulation of Urban MObility
GUIContainerStop.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 /****************************************************************************/
15 // A lane area vehicles can halt at (gui-version)
16 /****************************************************************************/
17 
18 
19 // ===========================================================================
20 // included modules
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 "GUIContainer.h"
36 #include "GUIContainerStop.h"
39 #include <gui/GUIGlobals.h>
44 #include <utils/geom/GeomHelper.h>
48 
49 
50 // ===========================================================================
51 // method definitions
52 // ===========================================================================
53 GUIContainerStop::GUIContainerStop(const std::string& id, const std::vector<std::string>& lines, MSLane& lane,
54  double frompos, double topos, const std::string& name, int containerCapacity) :
55  MSStoppingPlace(id, lines, lane, frompos, topos, name, containerCapacity),
57  const double offsetSign = MSNet::getInstance()->lefthand() ? -1 : 1;
58  myFGShape = lane.getShape();
59  myFGShape.move2side(1.65 * offsetSign);
61  lane.interpolateLanePosToGeometryPos(frompos),
63  myFGShapeRotations.reserve(myFGShape.size() - 1);
64  myFGShapeLengths.reserve(myFGShape.size() - 1);
65  int e = (int) myFGShape.size() - 1;
66  for (int i = 0; i < e; ++i) {
67  const Position& f = myFGShape[i];
68  const Position& s = myFGShape[i + 1];
69  myFGShapeLengths.push_back(f.distanceTo(s));
70  myFGShapeRotations.push_back((double) atan2((s.x() - f.x()), (f.y() - s.y())) * (double) 180.0 / (double) M_PI);
71  }
73  tmp.move2side(1.5 * offsetSign);
74  myFGSignPos = tmp.getLineCenter();
75  myFGSignRot = 0;
76  if (tmp.length() != 0) {
78  myFGSignRot -= 90;
79  }
80 }
81 
82 
84 
85 
88  GUISUMOAbstractView& parent) {
89  GUIGLObjectPopupMenu* ret = new GUIGLObjectPopupMenu(app, parent, *this);
90  buildPopupHeader(ret, app);
95  buildPositionCopyEntry(ret, false);
96  return ret;
97 }
98 
99 
104  new GUIParameterTableWindow(app, *this, 7);
105  // add items
106  ret->mkItem("name", false, getMyName());
107  ret->mkItem("begin position [m]", false, myBegPos);
108  ret->mkItem("end position [m]", false, myEndPos);
109  ret->mkItem("container number [#]", true, new FunctionBinding<GUIContainerStop, int>(this, &MSStoppingPlace::getTransportableNumber));
110  ret->mkItem("stopped vehicles[#]", true, new FunctionBinding<GUIContainerStop, int>(this, &MSStoppingPlace::getStoppedVehicleNumber));
111  ret->mkItem("last free pos[m]", true, new FunctionBinding<GUIContainerStop, double>(this, &MSStoppingPlace::getLastFreePos));
112  // close building
113  ret->closeBuilding();
114  return ret;
115 }
116 
117 
118 void
120  glPushName(getGlID());
121  glPushMatrix();
122  // draw the area
123  glTranslated(0, 0, getType());
125  const double exaggeration = s.addSize.getExaggeration(s, this);
127  // draw details unless zoomed out to far
128  if (s.drawDetail(s.detailSettings.stoppingPlaceDetails, exaggeration)) {
129  glPushMatrix();
130  // draw the lines
131  const double rotSign = MSNet::getInstance()->lefthand() ? -1 : 1;
132  // Iterate over every line
133  for (int i = 0; i < (int)myLines.size(); ++i) {
134  // push a new matrix for every line
135  glPushMatrix();
136  // traslate and rotate
137  glTranslated(myFGSignPos.x(), myFGSignPos.y(), 0);
138  glRotated(rotSign * myFGSignRot, 0, 0, 1);
139  // draw line
140  GLHelper::drawText(myLines[i].c_str(), Position(1.2, (double)i), .1, 1.f, s.colorSettings.containerStop, 0, FONS_ALIGN_LEFT);
141  // pop matrix for every line
142  glPopMatrix();
143  }
144  // draw the sign
145  glTranslated(myFGSignPos.x(), myFGSignPos.y(), 0);
146  int noPoints = 9;
147  if (s.scale * exaggeration > 25) {
148  noPoints = MIN2((int)(9.0 + (s.scale * exaggeration) / 10.0), 36);
149  }
150  glScaled(exaggeration, exaggeration, 1);
151  GLHelper::drawFilledCircle((double) 1.1, noPoints);
152  glTranslated(0, 0, .1);
154  GLHelper::drawFilledCircle((double) 0.9, noPoints);
155  if (s.drawDetail(s.detailSettings.stoppingPlaceText, exaggeration)) {
157  }
158  glPopMatrix();
159  }
160  glPopMatrix();
161  glPopName();
162  drawName(getCenteringBoundary().getCenter(), s.scale, s.addName);
163  //for (std::vector<MSTransportable*>::const_iterator i = myWaitingTransportables.begin(); i != myWaitingTransportables.end(); ++i) {
164  // glTranslated(0, 1, 0); // make multiple containers viewable
165  // static_cast<GUIContainer*>(*i)->drawGL(s);
166  //}
167 }
168 
169 
170 Boundary
173  b.grow(20);
174  return b;
175 }
176 
177 const std::string
179  return myName;
180 }
181 
182 
183 
184 /****************************************************************************/
185 
GUIGlObject::getType
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
Definition: GUIGlObject.cpp:180
Boundary.h
ToString.h
MSStoppingPlace
A lane area vehicles can halt at.
Definition: MSStoppingPlace.h:59
MIN2
T MIN2(T a, T b)
Definition: StdDefs.h:73
GUIParameterTableWindow
A window containing a gl-object's parameter.
Definition: GUIParameterTableWindow.h:62
MSStoppingPlace::myLines
std::vector< std::string > myLines
The list of lines that are assigned to this stop.
Definition: MSStoppingPlace.h:216
GUIContainer.h
GUISUMOAbstractView
Definition: GUISUMOAbstractView.h:72
MSNet.h
GUIVisualizationDetailSettings::stoppingPlaceDetails
static const double stoppingPlaceDetails
details for stopping places
Definition: GUIVisualizationSettings.h:298
MSLane
Representation of a lane in the micro simulation.
Definition: MSLane.h:82
GUIParameterTableWindow.h
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:354
GUIGlObject::buildSelectionPopupEntry
void buildSelectionPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to (de)select the object.
Definition: GUIGlObject.cpp:235
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
GUIContainerStop::drawGL
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
Definition: GUIContainerStop.cpp:119
PositionVector::getSubpart
PositionVector getSubpart(double beginOffset, double endOffset) const
get subpart of a position vector
Definition: PositionVector.cpp:706
GUIContainerStop::myFGSignPos
Position myFGSignPos
The position of the sign.
Definition: GUIContainerStop.h:137
MsgHandler.h
GUIContainerStop::getPopUpMenu
GUIGLObjectPopupMenu * getPopUpMenu(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own popup-menu.
Definition: GUIContainerStop.cpp:87
GUIGLObjectPopupMenu.h
GUIGlobalSelection.h
FONS_ALIGN_LEFT
Definition: fontstash.h:42
PositionVector::length
double length() const
Returns the length.
Definition: PositionVector.cpp:484
MSEdge.h
GLHelper.h
GUIGlObject_AbstractAdd
Definition: GUIGlObject_AbstractAdd.h:39
GUINet.h
GUIVisualizationColorSettings::containerStop
static const RGBColor containerStop
color for containerStops
Definition: GUIVisualizationSettings.h:180
PositionVector
A list of positions.
Definition: PositionVector.h:45
GUIGLObjectPopupMenu
The popup menu of a globject.
Definition: GUIGLObjectPopupMenu.h:47
GLHelper::setColor
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:621
PositionVector::getBoxBoundary
Boundary getBoxBoundary() const
Returns a boundary enclosing this list of lines.
Definition: PositionVector.cpp:390
GUIContainerStop::getParameterWindow
GUIParameterTableWindow * getParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own parameter window.
Definition: GUIContainerStop.cpp:101
GUIParameterTableWindow::closeBuilding
void closeBuilding(const Parameterised *p=0)
Closes the building of the table.
Definition: GUIParameterTableWindow.cpp:219
GUIAppEnum.h
MSStoppingPlace::myBegPos
const double myBegPos
The begin position this bus stop is located at.
Definition: MSStoppingPlace.h:225
GLHelper::drawFilledCircle
static void drawFilledCircle(double width, int steps=8)
Draws a filled circle around (0,0)
Definition: GLHelper.cpp:348
GUIContainerStop::getCenteringBoundary
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
Definition: GUIContainerStop.cpp:171
GUIVisualizationColorSettings::containerStop_sign
static const RGBColor containerStop_sign
color for containerStop signs
Definition: GUIVisualizationSettings.h:183
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:673
GUIVisualizationSettings::addName
GUIVisualizationTextSettings addName
Definition: GUIVisualizationSettings.h:591
GUIContainerStop::myFGShapeRotations
std::vector< double > myFGShapeRotations
The rotations of the shape parts.
Definition: GUIContainerStop.h:128
GUIContainerStop::myFGSignRot
double myFGSignRot
The rotation of the sign.
Definition: GUIContainerStop.h:140
GUIVisualizationSettings::detailSettings
GUIVisualizationDetailSettings detailSettings
detail settings
Definition: GUIVisualizationSettings.h:683
MSStoppingPlace::myName
const std::string myName
The name of the stopping place.
Definition: MSStoppingPlace.h:234
GUIContainerStop::myFGShape
PositionVector myFGShape
The shape.
Definition: GUIContainerStop.h:134
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:225
GUIContainerStop::myFGShapeLengths
std::vector< double > myFGShapeLengths
The lengths of the shape parts.
Definition: GUIContainerStop.h:131
MSNet::lefthand
bool lefthand() const
return whether the network was built for lefthand traffic
Definition: MSNet.h:663
MSStoppingPlace::myEndPos
const double myEndPos
The end position this bus stop is located at.
Definition: MSStoppingPlace.h:228
Position::distanceTo
double distanceTo(const Position &p2) const
returns the euclidean distance in 3 dimension
Definition: Position.h:233
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:108
GUIGlobals.h
PositionVector::rotationDegreeAtOffset
double rotationDegreeAtOffset(double pos) const
Returns the rotation at the given length.
Definition: PositionVector.cpp:319
GUIGlObject::getGlID
GUIGlID getGlID() const
Returns the numerical id of the object.
Definition: GUIGlObject.cpp:149
MSStoppingPlace::getStoppedVehicleNumber
int getStoppedVehicleNumber() const
Returns the number of stopped vehicles waiting on this stop.
Definition: MSStoppingPlace.h:168
Boundary
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:41
MSLane::interpolateLanePosToGeometryPos
double interpolateLanePosToGeometryPos(double lanePos) const
Definition: MSLane.h:498
GUIContainerStop.h
GUIVisualizationSettings::scale
double scale
information about a lane's width (temporary, used for a single view)
Definition: GUIVisualizationSettings.h:632
GUIApplicationWindow.h
Position
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:38
Position::x
double x() const
Returns the x-position.
Definition: Position.h:56
GUIGlObject::buildPopupHeader
void buildPopupHeader(GUIGLObjectPopupMenu *ret, GUIMainWindow &app, bool addSeparator=true)
Builds the header.
Definition: GUIGlObject.cpp:207
MSStoppingPlace::getMyName
const std::string & getMyName() const
Definition: MSStoppingPlace.cpp:265
GUIVisualizationSettings::colorSettings
GUIVisualizationColorSettings colorSettings
color settings
Definition: GUIVisualizationSettings.h:677
GLIncludes.h
MSLane::getShape
const PositionVector & getShape() const
Returns this lane's shape.
Definition: MSLane.h:477
FunctionBinding.h
MSNet::getInstance
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:167
GUIMainWindow
Definition: GUIMainWindow.h:46
Position::y
double y() const
Returns the y-position.
Definition: Position.h:61
M_PI
#define M_PI
Definition: odrSpiral.cpp:40
GUIContainerStop::GUIContainerStop
GUIContainerStop(const std::string &id, const std::vector< std::string > &lines, MSLane &lane, double frompos, double topos, const std::string &name, int containerCapacity)
Constructor.
Definition: GUIContainerStop.cpp:53
GUIEdge.h
GUIGlObject::buildShowParamsPopupEntry
void buildShowParamsPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to open the parameter window.
Definition: GUIGlObject.cpp:248
GUIVisualizationDetailSettings::stoppingPlaceText
static const double stoppingPlaceText
details for stopping place texts
Definition: GUIVisualizationSettings.h:301
GUIGlObject::buildCenterPopupEntry
void buildCenterPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to center to the object.
Definition: GUIGlObject.cpp:216
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:266
MSStoppingPlace::getLastFreePos
double getLastFreePos() const
Definition: MSStoppingPlace.h:172
MSStoppingPlace::getTransportableNumber
int getTransportableNumber() const
Returns the number of transportables waiting on this stop.
Definition: MSStoppingPlace.h:158
config.h
GUIVisualizationSettings::addSize
GUIVisualizationSizeSettings addSize
Definition: GUIVisualizationSettings.h:589
GeomHelper.h
Boundary::grow
Boundary & grow(double by)
extends the boundary by the given amount
Definition: Boundary.cpp:300
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:1669
GLO_CONTAINER_STOP
a containerStop
Definition: GUIGlObjectTypes.h:63
MSLane.h
GUIVisualizationSettings
Stores the information about how to visualize structures.
Definition: GUIVisualizationSettings.h:345
FunctionBinding
Definition: FunctionBinding.h:40
PositionVector::getLineCenter
Position getLineCenter() const
get line center
Definition: PositionVector.cpp:474
PositionVector.h
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:1103
GUIContainerStop::~GUIContainerStop
~GUIContainerStop()
Destructor.
Definition: GUIContainerStop.cpp:83
GUIContainerStop::getOptionalName
const std::string getOptionalName() const
Returns the stopping place name.
Definition: GUIContainerStop.cpp:178
fontstash.h