SUMO - Simulation of Urban MObility
GUIParkingArea.cpp
Go to the documentation of this file.
1 /****************************************************************************/
8 // A area where vehicles can park next to the road (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 "GUIParkingArea.h"
47 #include <gui/GUIGlobals.h>
53 #include <utils/geom/GeomHelper.h>
54 #include <guisim/GUIParkingArea.h>
56 
57 
58 // ===========================================================================
59 // method definitions
60 // ===========================================================================
61 GUIParkingArea::GUIParkingArea(const std::string& id, const std::vector<std::string>& lines, MSLane& lane,
62  double frompos, double topos, unsigned int capacity,
63  double width, double length, double angle)
64  : MSParkingArea(id, lines, lane, frompos, topos, capacity, width, length, angle),
65  GUIGlObject_AbstractAdd("parkingArea", GLO_TRIGGER, id) {
66 
67  myShapeRotations.reserve(myShape.size() - 1);
68  myShapeLengths.reserve(myShape.size() - 1);
69  int e = (int) myShape.size() - 1;
70  for (int i = 0; i < e; ++i) {
71  const Position& f = myShape[i];
72  const Position& s = myShape[i + 1];
73  myShapeLengths.push_back(f.distanceTo(s));
74  myShapeRotations.push_back((double) atan2((s.x() - f.x()), (f.y() - s.y())) * (double) 180.0 / (double) PI);
75  }
76  PositionVector tmp = myShape;
77  tmp.move2side(lane.getWidth() + myWidth);
78  mySignPos = tmp.getLineCenter();
79  mySignRot = 0;
80  if (tmp.length() != 0) {
82  mySignRot -= 90;
83  }
84 }
85 
87 
88 
91  GUISUMOAbstractView& parent) {
92  GUIGLObjectPopupMenu* ret = new GUIGLObjectPopupMenu(app, parent, *this);
93  buildPopupHeader(ret, app);
98  buildPositionCopyEntry(ret, false);
99  return ret;
100 }
101 
102 
107  new GUIParameterTableWindow(app, *this, 4);
108  // add items
109  ret->mkItem("begin position [m]", false, myBegPos);
110  ret->mkItem("end position [m]", false, myEndPos);
111  ret->mkItem("occupancy [#]", true, getOccupancy());
112  ret->mkItem("capacity [#]", false, getCapacity());
113  // close building
114  ret->closeBuilding();
115  return ret;
116 }
117 
118 
119 void
121  glPushName(getGlID());
122  glPushMatrix();
123  RGBColor grey(177, 184, 186, 171);
124  RGBColor blue(83, 89, 172, 255);
125  RGBColor red(255, 0, 0, 255);
126  RGBColor green(0, 255, 0, 255);
127  // draw the area
128  glTranslated(0, 0, getType());
129  GLHelper::setColor(blue);
131  // draw details unless zoomed out to far
132  const double exaggeration = s.addSize.getExaggeration(s);
133  if (s.scale * exaggeration >= 10) {
134  // draw the lots
135  glTranslated(0, 0, .1);
136  std::map<unsigned int, LotSpaceDefinition >::const_iterator i;
137  for (i = mySpaceOccupancies.begin(); i != mySpaceOccupancies.end(); i++) {
138  glPushMatrix();
139  glTranslated((*i).second.myPosition.x(), (*i).second.myPosition.y(), (*i).second.myPosition.z());
140  glRotated((*i).second.myRotation, 0, 0, 1);
141  Position pos = (*i).second.myPosition;
142  PositionVector geom;
143  double w = (*i).second.myWidth / 2.;
144  double h = (*i).second.myLength;
145  geom.push_back(Position(- w, + 0, 0.));
146  geom.push_back(Position(+ w, + 0, 0.));
147  geom.push_back(Position(+ w, + h, 0.));
148  geom.push_back(Position(- w, + h, 0.));
149  geom.push_back(Position(- w, + 0, 0.));
150  /*
151  geom.push_back(Position(pos.x(), pos.y(), pos.z()));
152  geom.push_back(Position(pos.x() + (*l).second.myWidth, pos.y(), pos.z()));
153  geom.push_back(Position(pos.x() + (*l).second.myWidth, pos.y() - (*l).second.myLength, pos.z()));
154  geom.push_back(Position(pos.x(), pos.y() - (*l).second.myLength, pos.z()));
155  geom.push_back(Position(pos.x(), pos.y(), pos.z()));
156  */
157  GLHelper::setColor((*i).second.vehicle == 0 ? green : red);
158  GLHelper::drawBoxLines(geom, 0.1);
159  glPopMatrix();
160  }
161  GLHelper::setColor(blue);
162  // draw the lines
163  for (size_t i = 0; i != myLines.size(); ++i) {
164  glPushMatrix();
165  glTranslated(mySignPos.x(), mySignPos.y(), 0);
166  glRotated(180, 1, 0, 0);
167  glRotated(mySignRot, 0, 0, 1);
168  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
169  pfSetPosition(0, 0);
170  pfSetScale(1.f);
171  glScaled(exaggeration, exaggeration, 1);
172  glTranslated(1.2, -(double)i, 0);
173  pfDrawString(myLines[i].c_str());
174  glPopMatrix();
175  }
176  // draw the sign
177  glTranslated(mySignPos.x(), mySignPos.y(), 0);
178  int noPoints = 9;
179  if (s.scale * exaggeration > 25) {
180  noPoints = MIN2((int)(9.0 + (s.scale * exaggeration) / 10.0), 36);
181  }
182  glScaled(exaggeration, exaggeration, 1);
183  GLHelper::drawFilledCircle((double) 1.1, noPoints);
184  glTranslated(0, 0, .1);
185  GLHelper::setColor(grey);
186  GLHelper::drawFilledCircle((double) 0.9, noPoints);
187  if (s.scale * exaggeration >= 4.5) {
188  GLHelper::drawText("P", Position(), .1, 1.6 * exaggeration, blue, mySignRot);
189  }
190  }
191  glPopMatrix();
192  glPopName();
193  drawName(getCenteringBoundary().getCenter(), s.scale, s.addName);
194  for (std::vector<MSTransportable*>::const_iterator i = myWaitingTransportables.begin(); i != myWaitingTransportables.end(); ++i) {
195  glTranslated(0, 1, 0); // make multiple containers viewable
196  static_cast<GUIContainer*>(*i)->drawGL(s);
197  }
198 }
199 
200 
201 Boundary
204  b.grow(20);
205  return b;
206 }
207 
208 
209 
210 /****************************************************************************/
211 
A lane area vehicles can halt at.
Definition: MSParkingArea.h:66
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)
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
const double myEndPos
The end position this bus stop is located at.
Stores the information about how to visualize structures.
GUIParkingArea(const std::string &id, const std::vector< std::string > &lines, MSLane &lane, double frompos, double topos, unsigned int capacity, double width, double length, double angle)
Constructor.
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.
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:340
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.
double getWidth() const
Returns the lane&#39;s width.
Definition: MSLane.h:500
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:48
Position getLineCenter() const
get line center
GUIVisualizationSizeSettings addSize
std::vector< double > myShapeLengths
The lengths of the shape parts.
#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.
GUIGLObjectPopupMenu * getPopUpMenu(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own popup-menu.
std::vector< double > myShapeRotations
The rotations of the shape parts.
PositionVector myShape
The roadside shape of this parkingArea.
int getCapacity() const
Returns the area capacity.
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
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
Boundary & grow(double by)
extends the boundary by the given amount
Definition: Boundary.cpp:234
int getOccupancy() const
Returns the area occupancy.
void move2side(double amount)
move position vector to side using certain ammount
const double myBegPos
The begin position this bus stop is located at.
double length() const
Returns the length.
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
The popup menu of a globject.
void buildSelectionPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to (de)select the object.
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
Boundary getBoxBoundary() const
Returns a boundary enclosing this list of lines.
~GUIParkingArea()
Destructor.
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::map< unsigned int, LotSpaceDefinition > mySpaceOccupancies
A map from objects (vehicles) to the areas they acquire after entering the stop.
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.
double myWidth
The default width of each parking space.
void closeBuilding()
Closes the building of the table.
GUIParameterTableWindow * getParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own parameter window.
Representation of a lane in the micro simulation.
Definition: MSLane.h:79
A window containing a gl-object&#39;s parameter.
Position mySignPos
The position of the sign.
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
double mySignRot
The rotation of the sign.
void buildPopupHeader(GUIGLObjectPopupMenu *ret, GUIMainWindow &app, bool addSeparator=true)
Builds the header.