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-2021 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>
26 #include <utils/common/RGBColor.h>
28 #include <utils/geom/Boundary.h>
29 #include <utils/gui/div/GLHelper.h>
30 #include <utils/common/ToString.h>
31 #include <microsim/MSNet.h>
32 #include <microsim/MSLane.h>
33 #include <microsim/MSEdge.h>
34 #include "GUINet.h"
35 #include "GUIEdge.h"
36 #include "GUIContainer.h"
37 #include "GUIContainerStop.h"
40 #include <gui/GUIGlobals.h>
45 #include <utils/geom/GeomHelper.h>
49 
50 
51 // ===========================================================================
52 // method definitions
53 // ===========================================================================
54 GUIContainerStop::GUIContainerStop(const std::string& id, const std::vector<std::string>& lines, MSLane& lane,
55  double frompos, double topos, const std::string& name, int containerCapacity,
56  double parkingLength, const RGBColor& color) :
57  MSStoppingPlace(id, lines, lane, frompos, topos, name, containerCapacity, parkingLength, color),
59  const double offsetSign = MSGlobals::gLefthand ? -1 : 1;
60  myFGShape = lane.getShape();
61  myFGShape.move2side(1.65 * offsetSign);
63  lane.interpolateLanePosToGeometryPos(frompos),
65  myFGShapeRotations.reserve(myFGShape.size() - 1);
66  myFGShapeLengths.reserve(myFGShape.size() - 1);
67  int e = (int) myFGShape.size() - 1;
68  for (int i = 0; i < e; ++i) {
69  const Position& f = myFGShape[i];
70  const Position& s = myFGShape[i + 1];
71  myFGShapeLengths.push_back(f.distanceTo(s));
72  myFGShapeRotations.push_back((double) atan2((s.x() - f.x()), (f.y() - s.y())) * (double) 180.0 / (double) M_PI);
73  }
75  tmp.move2side(1.5 * offsetSign);
76  myFGSignPos = tmp.getLineCenter();
77  myFGSignRot = 0;
78  if (tmp.length() != 0) {
80  myFGSignRot -= 90;
81  }
82 }
83 
84 
86 
87 
90  GUISUMOAbstractView& parent) {
91  GUIGLObjectPopupMenu* ret = new GUIGLObjectPopupMenu(app, parent, *this);
92  buildPopupHeader(ret, app);
97  buildPositionCopyEntry(ret, false);
98  return ret;
99 }
100 
101 
106  new GUIParameterTableWindow(app, *this);
107  // add items
108  ret->mkItem("name", false, getMyName());
109  ret->mkItem("begin position [m]", false, myBegPos);
110  ret->mkItem("end position [m]", false, myEndPos);
111  ret->mkItem("container number [#]", true, new FunctionBinding<GUIContainerStop, int>(this, &MSStoppingPlace::getTransportableNumber));
112  ret->mkItem("stopped vehicles[#]", true, new FunctionBinding<GUIContainerStop, int>(this, &MSStoppingPlace::getStoppedVehicleNumber));
113  ret->mkItem("last free pos[m]", true, new FunctionBinding<GUIContainerStop, double>(this, &MSStoppingPlace::getLastFreePos));
114  // close building
115  ret->closeBuilding();
116  return ret;
117 }
118 
119 
120 void
122  glPushName(getGlID());
123  glPushMatrix();
124  // draw the area
125  glTranslated(0, 0, getType());
127  const double exaggeration = s.addSize.getExaggeration(s, this);
129  // draw details unless zoomed out to far
130  if (s.drawDetail(s.detailSettings.stoppingPlaceDetails, exaggeration)) {
131  glPushMatrix();
132  // draw the lines
133  const double rotSign = MSGlobals::gLefthand ? -1 : 1;
134  // Iterate over every line
135  for (int i = 0; i < (int)myLines.size(); ++i) {
136  // push a new matrix for every line
137  glPushMatrix();
138  // traslate and rotate
139  glTranslated(myFGSignPos.x(), myFGSignPos.y(), 0);
140  glRotated(rotSign * myFGSignRot, 0, 0, 1);
141  // draw line
142  GLHelper::drawText(myLines[i].c_str(), Position(1.2, (double)i), .1, 1.f, getColor(), 0, FONS_ALIGN_LEFT);
143  // pop matrix for every line
144  glPopMatrix();
145  }
146  // draw the sign
147  glTranslated(myFGSignPos.x(), myFGSignPos.y(), 0);
148  int noPoints = 9;
149  if (s.scale * exaggeration > 25) {
150  noPoints = MIN2((int)(9.0 + (s.scale * exaggeration) / 10.0), 36);
151  }
152  glScaled(exaggeration, exaggeration, 1);
153  GLHelper::drawFilledCircle((double) 1.1, noPoints);
154  glTranslated(0, 0, .1);
156  GLHelper::drawFilledCircle((double) 0.9, noPoints);
157  if (s.drawDetail(s.detailSettings.stoppingPlaceText, exaggeration)) {
159  }
160  glPopMatrix();
161  }
162  glPopMatrix();
163  glPopName();
164  drawName(getCenteringBoundary().getCenter(), s.scale, s.addName);
165  //for (std::vector<MSTransportable*>::const_iterator i = myWaitingTransportables.begin(); i != myWaitingTransportables.end(); ++i) {
166  // glTranslated(0, 1, 0); // make multiple containers viewable
167  // static_cast<GUIContainer*>(*i)->drawGL(s);
168  //}
169 }
170 
171 
172 Boundary
175  b.grow(20);
176  return b;
177 }
178 
179 const std::string
181  return myName;
182 }
183 
184 
185 /****************************************************************************/
GUIGlObject::getType
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
Definition: GUIGlObject.cpp:202
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:74
GUIParameterTableWindow
A window containing a gl-object's parameter.
Definition: GUIParameterTableWindow.h:60
MSStoppingPlace::myLines
std::vector< std::string > myLines
The list of lines that are assigned to this stop.
Definition: MSStoppingPlace.h:240
GUIContainer.h
GUISUMOAbstractView
Definition: GUISUMOAbstractView.h:70
MSNet.h
GUIVisualizationDetailSettings::stoppingPlaceDetails
static const double stoppingPlaceDetails
details for stopping places
Definition: GUIVisualizationSettings.h:452
MSLane
Representation of a lane in the micro simulation.
Definition: MSLane.h:82
GUIParameterTableWindow.h
GUIVisualizationStoppingPlaceSettings::containerStopColor
static const RGBColor containerStopColor
color for containerStops
Definition: GUIVisualizationSettings.h:356
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:376
GUIGlObject::buildSelectionPopupEntry
void buildSelectionPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to (de)select the object.
Definition: GUIGlObject.cpp:257
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:181
GUIContainerStop::drawGL
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
Definition: GUIContainerStop.cpp:121
PositionVector::getSubpart
PositionVector getSubpart(double beginOffset, double endOffset) const
get subpart of a position vector
Definition: PositionVector.cpp:714
GUIContainerStop::myFGSignPos
Position myFGSignPos
The position of the sign.
Definition: GUIContainerStop.h:138
MsgHandler.h
GUIContainerStop::getPopUpMenu
GUIGLObjectPopupMenu * getPopUpMenu(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own popup-menu.
Definition: GUIContainerStop.cpp:89
GUIGLObjectPopupMenu.h
GUIGlobalSelection.h
FONS_ALIGN_LEFT
@ FONS_ALIGN_LEFT
Definition: fontstash.h:42
PositionVector::length
double length() const
Returns the length.
Definition: PositionVector.cpp:492
MSEdge.h
GLHelper.h
GUIGlObject_AbstractAdd
Definition: GUIGlObject_AbstractAdd.h:37
GUINet.h
PositionVector
A list of positions.
Definition: PositionVector.h:43
GUIGLObjectPopupMenu
The popup menu of a globject.
Definition: GUIGLObjectPopupMenu.h:45
GLHelper::setColor
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:446
PositionVector::getBoxBoundary
Boundary getBoxBoundary() const
Returns a boundary enclosing this list of lines.
Definition: PositionVector.cpp:389
GUIContainerStop::getParameterWindow
GUIParameterTableWindow * getParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own parameter window.
Definition: GUIContainerStop.cpp:103
GUIParameterTableWindow::closeBuilding
void closeBuilding(const Parameterised *p=0)
Closes the building of the table.
Definition: GUIParameterTableWindow.cpp:246
RGBColor.h
GUIAppEnum.h
MSStoppingPlace::myBegPos
const double myBegPos
The begin position this bus stop is located at.
Definition: MSStoppingPlace.h:249
GLHelper::drawFilledCircle
static void drawFilledCircle(double width, int steps=8)
Draws a filled circle around (0,0)
Definition: GLHelper.cpp:347
GUIContainerStop::getCenteringBoundary
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
Definition: GUIContainerStop.cpp:173
RGBColor
Definition: RGBColor.h:37
GUIVisualizationSettings::addName
GUIVisualizationTextSettings addName
Definition: GUIVisualizationSettings.h:761
GUIContainerStop::myFGShapeRotations
std::vector< double > myFGShapeRotations
The rotations of the shape parts.
Definition: GUIContainerStop.h:129
MSGlobals::gLefthand
static bool gLefthand
Whether lefthand-drive is being simulated.
Definition: MSGlobals.h:142
GUIContainerStop::myFGSignRot
double myFGSignRot
The rotation of the sign.
Definition: GUIContainerStop.h:141
GUIVisualizationSettings::detailSettings
GUIVisualizationDetailSettings detailSettings
detail settings
Definition: GUIVisualizationSettings.h:888
MSStoppingPlace::myName
const std::string myName
The name of the stopping place.
Definition: MSStoppingPlace.h:258
GUIContainerStop::myFGShape
PositionVector myFGShape
The shape.
Definition: GUIContainerStop.h:135
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:247
GUIContainerStop::myFGShapeLengths
std::vector< double > myFGShapeLengths
The lengths of the shape parts.
Definition: GUIContainerStop.h:132
MSStoppingPlace::myEndPos
const double myEndPos
The end position this bus stop is located at.
Definition: MSStoppingPlace.h:252
Position::distanceTo
double distanceTo(const Position &p2) const
returns the euclidean distance in 3 dimension
Definition: Position.h:232
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:104
MSStoppingPlace::getColor
const RGBColor & getColor() const
Definition: MSStoppingPlace.cpp:283
GUIGlobals.h
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, double parkingLength, const RGBColor &color)
Constructor.
Definition: GUIContainerStop.cpp:54
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, const int align=0, double width=-1)
Definition: GLHelper.cpp:542
PositionVector::rotationDegreeAtOffset
double rotationDegreeAtOffset(double pos) const
Returns the rotation at the given length.
Definition: PositionVector.cpp:318
GUIGlObject::getGlID
GUIGlID getGlID() const
Returns the numerical id of the object.
Definition: GUIGlObject.cpp:166
MSStoppingPlace::getStoppedVehicleNumber
int getStoppedVehicleNumber() const
Returns the number of stopped vehicles waiting on this stop.
Definition: MSStoppingPlace.h:171
Boundary
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:39
MSLane::interpolateLanePosToGeometryPos
double interpolateLanePosToGeometryPos(double lanePos) const
Definition: MSLane.h:499
GUIContainerStop.h
GUIVisualizationSettings::scale
double scale
information about a lane's width (temporary, used for a single view)
Definition: GUIVisualizationSettings.h:811
GUIApplicationWindow.h
Position
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:37
Position::x
double x() const
Returns the x-position.
Definition: Position.h:55
GUIGlObject::buildPopupHeader
void buildPopupHeader(GUIGLObjectPopupMenu *ret, GUIMainWindow &app, bool addSeparator=true)
Builds the header.
Definition: GUIGlObject.cpp:229
MSStoppingPlace::getMyName
const std::string & getMyName() const
Definition: MSStoppingPlace.cpp:277
GLIncludes.h
MSLane::getShape
const PositionVector & getShape() const
Returns this lane's shape.
Definition: MSLane.h:478
FunctionBinding.h
GUIMainWindow
Definition: GUIMainWindow.h:44
Position::y
double y() const
Returns the y-position.
Definition: Position.h:60
M_PI
#define M_PI
Definition: odrSpiral.cpp:40
GUIEdge.h
GUIGlObject::buildShowParamsPopupEntry
void buildShowParamsPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to open the parameter window.
Definition: GUIGlObject.cpp:270
GUIVisualizationDetailSettings::stoppingPlaceText
static const double stoppingPlaceText
details for stopping place texts
Definition: GUIVisualizationSettings.h:455
GUIGlObject::buildCenterPopupEntry
void buildCenterPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to center to the object.
Definition: GUIGlObject.cpp:238
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:288
MSStoppingPlace::getLastFreePos
double getLastFreePos() const
Definition: MSStoppingPlace.h:175
GUIVisualizationStoppingPlaceSettings::containerStopColorSign
static const RGBColor containerStopColorSign
color for containerStop signs
Definition: GUIVisualizationSettings.h:359
MSStoppingPlace::getTransportableNumber
int getTransportableNumber() const
Returns the number of transportables waiting on this stop.
Definition: MSStoppingPlace.h:161
config.h
GUIVisualizationSettings::addSize
GUIVisualizationSizeSettings addSize
Definition: GUIVisualizationSettings.h:759
GeomHelper.h
Boundary::grow
Boundary & grow(double by)
extends the boundary by the given amount
Definition: Boundary.cpp:299
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:1933
GLO_CONTAINER_STOP
@ GLO_CONTAINER_STOP
a containerStop
Definition: GUIGlObjectTypes.h:83
MSLane.h
GUIVisualizationSettings
Stores the information about how to visualize structures.
Definition: GUIVisualizationSettings.h:499
FunctionBinding
Definition: FunctionBinding.h:37
PositionVector::getLineCenter
Position getLineCenter() const
get line center
Definition: PositionVector.cpp:482
GUIVisualizationSettings::stoppingPlaceSettings
GUIVisualizationStoppingPlaceSettings stoppingPlaceSettings
StoppingPlace settings.
Definition: GUIVisualizationSettings.h:879
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:288
PositionVector::move2side
void move2side(double amount, double maxExtension=100)
move position vector to side using certain ammount
Definition: PositionVector.cpp:1112
GUIContainerStop::~GUIContainerStop
~GUIContainerStop()
Destructor.
Definition: GUIContainerStop.cpp:85
GUIContainerStop::getOptionalName
const std::string getOptionalName() const
Returns the stopping place name.
Definition: GUIContainerStop.cpp:180
fontstash.h