Eclipse SUMO - Simulation of Urban MObility
GUIParkingArea.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 // Copyright (C) 2001-2024 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 area where vehicles can park next to the road (gui version)
21 /****************************************************************************/
22 #include <config.h>
23 
24 #include <string>
27 #include <gui/GUIGlobals.h>
28 #include <guisim/GUIParkingArea.h>
29 #include <guisim/GUIVehicle.h>
30 #include <microsim/MSEdge.h>
31 #include <microsim/MSLane.h>
32 #include <microsim/MSNet.h>
35 #include <utils/common/ToString.h>
36 #include <utils/geom/Boundary.h>
37 #include <utils/geom/GeomHelper.h>
39 #include <utils/gui/div/GLHelper.h>
45 
46 #include "GUINet.h"
47 #include "GUIEdge.h"
48 #include "GUIContainer.h"
49 #include "GUIParkingArea.h"
50 
51 
52 // ===========================================================================
53 // method definitions
54 // ===========================================================================
55 GUIParkingArea::GUIParkingArea(const std::string& id, const std::vector<std::string>& lines,
56  const std::vector<std::string>& badges, MSLane& lane, double frompos, double topos,
57  unsigned int capacity, double width, double length, double angle, const std::string& name,
58  bool onRoad,
59  const std::string& departPos,
60  bool lefthand) :
61  MSParkingArea(id, lines, badges, lane, frompos, topos, capacity, width, length, angle, name, onRoad, departPos, lefthand),
63  const double offsetSign = (MSGlobals::gLefthand || lefthand) ? -1 : 1;
64  myShapeRotations.reserve(myShape.size() - 1);
65  myShapeLengths.reserve(myShape.size() - 1);
66  int e = (int) myShape.size() - 1;
67  for (int i = 0; i < e; ++i) {
68  const Position& f = myShape[i];
69  const Position& s = myShape[i + 1];
70  myShapeLengths.push_back(f.distanceTo(s));
71  myShapeRotations.push_back((double) atan2((s.x() - f.x()), (f.y() - s.y())) * (double) 180.0 / (double) M_PI);
72  }
73  PositionVector tmp = myShape;
74  tmp.move2side((lane.getWidth() + myWidth) * offsetSign);
75  mySignPos = tmp.getLineCenter();
76  mySignRot = 0;
77  if (tmp.length() != 0) {
79  const double rotSign = MSGlobals::gLefthand ? -1 : 1;
80  mySignRot -= 90 * rotSign;
81  }
83  myBoundary.grow(20);
84 }
85 
87 
88 
91  GUISUMOAbstractView& parent) {
92  GUIGLObjectPopupMenu* ret = new GUIGLObjectPopupMenu(app, parent, *this);
93  buildPopupHeader(ret, app);
98  buildPositionCopyEntry(ret, app);
99  return ret;
100 }
101 
102 
107  new GUIParameterTableWindow(app, *this);
108  // add items
109  ret->mkItem(TL("name"), false, getMyName());
110  ret->mkItem(TL("begin position [m]"), false, myBegPos);
111  ret->mkItem(TL("end position [m]"), false, myEndPos);
112  ret->mkItem(TL("occupancy [#]"), true, getOccupancy());
113  ret->mkItem(TL("capacity [#]"), false, getCapacity());
114  ret->mkItem(TL("alternatives [#]"), false, getNumAlternatives());
115  ret->mkItem(TL("access badges"), false, joinToString(myAcceptedBadges, " "));
116  // close building
117  ret->closeBuilding();
118  return ret;
119 }
120 
121 
122 void
126  RGBColor grey(177, 184, 186, 171);
127  RGBColor blue(83, 89, 172, 255);
128  RGBColor red(255, 0, 0, 255);
129  RGBColor green(0, 255, 0, 255);
130  // draw the area
131  glTranslated(0, 0, getType());
132  GLHelper::setColor(blue);
133  const double exaggeration = getExaggeration(s);
135  // draw details unless zoomed out to far
136  if (s.scale * exaggeration >= 1) {
137  // draw the lots
138  glTranslated(0, 0, .1);
139  // calculate shape lengt
140  double ShapeLength = 0;
141  for (const auto& length : myShapeLengths) {
142  ShapeLength += length;
143  }
144  // calculate index Updater
145  int indexUpdater = (int)((double)mySpaceOccupancies.size() / ShapeLength);
146  // check if indexUpdater is 0
147  if (indexUpdater == 0 || (myCapacity != myRoadSideCapacity)) {
148  indexUpdater = 1;
149  }
150  // draw spaceOccupancies
151  for (int i = 0; i < (int)mySpaceOccupancies.size(); i += indexUpdater) {
152  GLHelper::drawSpaceOccupancies(exaggeration, mySpaceOccupancies.at(i).position, mySpaceOccupancies.at(i).rotation,
153  mySpaceOccupancies.at(i).width, mySpaceOccupancies.at(i).length, mySpaceOccupancies.at(i).vehicle ? true : false);
154  }
155  GLHelper::setColor(blue);
156  // draw the lines
157  for (size_t i = 0; i != myLines.size(); ++i) {
158  // push a new matrix for every line
160  // traslate and rotate
161  glTranslated(mySignPos.x(), mySignPos.y(), 0);
162  glRotated(180, 1, 0, 0);
163  glRotated(mySignRot, 0, 0, 1);
164  // draw line
165  GLHelper::drawText(myLines[i].c_str(), Position(1.2, (double)i), .1, 1.f, RGBColor(76, 170, 50), 0, FONS_ALIGN_LEFT);
166  // pop matrix for every line
168 
169  }
170  // draw the sign
171  glTranslated(mySignPos.x(), mySignPos.y(), 0);
172  int noPoints = 9;
173  if (s.scale * exaggeration > 25) {
174  noPoints = MIN2((int)(9.0 + (s.scale * exaggeration) / 10.0), 36);
175  }
176  glScaled(exaggeration, exaggeration, 1);
177  GLHelper::drawFilledCircle((double) 1.1, noPoints);
178  glTranslated(0, 0, .1);
179  GLHelper::setColor(grey);
180  GLHelper::drawFilledCircle((double) 0.9, noPoints);
181  if (s.drawDetail(10, exaggeration)) {
182  GLHelper::drawText("P", Position(), .1, 1.6, blue, mySignRot);
183  }
184  }
186  if (s.addFullName.show(this) && getMyName() != "") {
188  }
190  drawName(getCenteringBoundary().getCenter(), s.scale, s.addName, s.angle);
192  // draw parking vehicles (their lane might not be within drawing range. if it is, they are drawn twice)
194  for (const MSBaseVehicle* const v : myLane.getParkingVehicles()) {
195  static_cast<const GUIVehicle*>(v)->drawGL(s);
196  }
198  }
199 }
200 
201 void
202 GUIParkingArea::addLotEntry(double x, double y, double z,
203  double width, double length,
204  double angle, double slope) {
205  MSParkingArea::addLotEntry(x, y, z, width, length, angle, slope);
206  Boundary b;
207  b.add(Position(x, y));
208  b.grow(MAX2(width, length) + 5);
209  myBoundary.add(b);
210 }
211 
212 
213 double
215  return s.addSize.getExaggeration(s, this);
216 }
217 
218 
219 Boundary
221  return myBoundary;
222 }
223 
224 
225 const std::string
227  return myName;
228 }
229 
230 
231 /****************************************************************************/
@ GLO_MAX
empty max
@ GLO_PARKING_AREA
a ParkingArea
GUIIcon
An enumeration of icons used by the gui applications.
Definition: GUIIcons.h:33
#define TL(string)
Definition: MsgHandler.h:315
T MIN2(T a, T b)
Definition: StdDefs.h:76
T MAX2(T a, T b)
Definition: StdDefs.h:82
std::string joinToString(const std::vector< T > &v, const T_BETWEEN &between, std::streamsize accuracy=gPrecision)
Definition: ToString.h:283
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:39
void add(double x, double y, double z=0)
Makes the boundary include the given coordinate.
Definition: Boundary.cpp:78
Boundary & grow(double by)
extends the boundary by the given amount
Definition: Boundary.cpp:319
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:654
static void pushName(unsigned int name)
push Name
Definition: GLHelper.cpp:139
static void drawFilledCircle(const double widradiusth, const int steps=8)
Draws a filled circle around (0,0)
Definition: GLHelper.cpp:569
static void popMatrix()
pop matrix
Definition: GLHelper.cpp:130
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:347
static void popName()
pop Name
Definition: GLHelper.cpp:148
static void pushMatrix()
push matrix
Definition: GLHelper.cpp:117
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:756
static void drawSpaceOccupancies(const double exaggeration, const Position &pos, const double rotation, const double width, const double length, const bool vehicle)
draw
Definition: GLHelper.cpp:684
static void drawTextSettings(const GUIVisualizationTextSettings &settings, const std::string &text, const Position &pos, const double scale, const double angle=0, const double layer=2048, const int align=0)
Definition: GLHelper.cpp:787
The popup menu of a globject.
void buildShowParamsPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to open the parameter window.
void buildCenterPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to center to the object.
void buildNameCopyPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds entries which allow to copy the name / typed name into the clipboard.
void buildPopupHeader(GUIGLObjectPopupMenu *ret, GUIMainWindow &app, bool addSeparator=true)
Builds the header.
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
Definition: GUIGlObject.h:156
void buildSelectionPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to (de)select the object.
void buildPositionCopyEntry(GUIGLObjectPopupMenu *ret, const GUIMainWindow &app) const
Builds an entry which allows to copy the cursor position if geo projection is used,...
GUIGlID getGlID() const
Returns the numerical id of the object.
Definition: GUIGlObject.h:104
void drawName(const Position &pos, const double scale, const GUIVisualizationTextSettings &settings, const double angle=0, bool forceShow=false) const
draw name of item
A window containing a gl-object's parameter.
void mkItem(const char *name, bool dynamic, ValueSource< T > *src)
Adds a row which obtains its value from a ValueSource.
void closeBuilding(const Parameterised *p=0)
Closes the building of the table.
std::vector< double > myShapeLengths
The lengths of the shape parts.
Boundary myBoundary
the centering boundary
std::vector< double > myShapeRotations
The rotations of the shape parts.
~GUIParkingArea()
Destructor.
GUIParkingArea(const std::string &id, const std::vector< std::string > &lines, const std::vector< std::string > &badges, MSLane &lane, double frompos, double topos, unsigned int capacity, double width, double length, double angle, const std::string &name, bool onRoad, const std::string &departPos, bool lefthand)
Constructor.
void addLotEntry(double x, double y, double z, double width, double length, double angle, double slope)
extend boundary
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
double mySignRot
The rotation of the sign.
double getExaggeration(const GUIVisualizationSettings &s) const
return exaggeration associated with this GLObject
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
GUIParameterTableWindow * getParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own parameter window.
GUIGLObjectPopupMenu * getPopUpMenu(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own popup-menu.
const std::string getOptionalName() const
Returns the stopping place name.
Position mySignPos
The position of the sign.
A MSVehicle extended by some values for usage within the gui.
Definition: GUIVehicle.h:51
Stores the information about how to visualize structures.
GUIVisualizationTextSettings addName
GUIVisualizationSizeSettings addSize
GUIVisualizationTextSettings addFullName
double scale
information about a lane's width (temporary, used for a single view)
bool drawDetail(const double detail, const double exaggeration) const
check if details can be drawn for the given GUIVisualizationDetailSettings and current scale and exxa...
double getTextAngle(double objectAngle) const
return an angle that is suitable for reading text aligned with the given angle (degrees)
double angle
The current view rotation angle.
The base class for microscopic and mesoscopic vehicles.
Definition: MSBaseVehicle.h:57
static bool gLefthand
Whether lefthand-drive is being simulated.
Definition: MSGlobals.h:171
Representation of a lane in the micro simulation.
Definition: MSLane.h:84
virtual const VehCont & getVehiclesSecure() const
Returns the vehicles container; locks it for microsimulation.
Definition: MSLane.h:475
const std::set< const MSBaseVehicle * > & getParkingVehicles() const
retrieve the parking vehicles (see GUIParkingArea)
Definition: MSLane.h:1245
virtual void releaseVehicles() const
Allows to use the container for microsimulation again.
Definition: MSLane.h:505
double getWidth() const
Returns the lane's width.
Definition: MSLane.h:627
A lane area vehicles can halt at.
Definition: MSParkingArea.h:60
int getNumAlternatives() const
get number alternatives
int myCapacity
Stop area total capacity.
int getCapacity() const
Returns the area capacity.
PositionVector myShape
The roadside shape of this parkingArea.
virtual void addLotEntry(double x, double y, double z, double width, double length, double angle, double slope)
Add a lot entry to parking area.
int myRoadSideCapacity
Stop area capacity configured via roadsideCapacity.
double myWidth
The default width of each parking space.
int getOccupancy() const
Returns the area occupancy.
std::vector< LotSpaceDefinition > mySpaceOccupancies
All the spaces in this parking area.
std::set< std::string > myAcceptedBadges
The parking badges to grant access.
const double myBegPos
The begin position this bus stop is located at.
const MSLane & myLane
The lane this bus stop is located at.
const std::string myName
The name of the stopping place.
const double myEndPos
The end position this bus stop is located at.
std::vector< std::string > myLines
The list of lines that are assigned to this stop.
const std::string & getMyName() const
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:37
double distanceTo(const Position &p2) const
returns the euclidean distance in 3 dimensions
Definition: Position.h:266
double x() const
Returns the x-position.
Definition: Position.h:55
double y() const
Returns the y-position.
Definition: Position.h:60
A list of positions.
double length() const
Returns the length.
double rotationDegreeAtOffset(double pos) const
Returns the rotation at the given length.
void move2side(double amount, double maxExtension=100)
move position vector to side using certain amount
Boundary getBoxBoundary() const
Returns a boundary enclosing this list of lines.
Position getLineCenter() const
get line center
@ FONS_ALIGN_LEFT
Definition: fontstash.h:42
#define M_PI
Definition: odrSpiral.cpp:45
double getExaggeration(const GUIVisualizationSettings &s, const GUIGlObject *o, double factor=20) const
return the drawing size including exaggeration and constantSize values
bool show(const GUIGlObject *o) const
whether to show the text