Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GNEParkingArea.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-2026 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/****************************************************************************/
19// A lane area vehicles can park at (GNE version)
20/****************************************************************************/
21
23
25#include <netedit/GNENet.h>
29
30#include "GNEParkingArea.h"
31
32// ===========================================================================
33// method definitions
34// ===========================================================================
35
39
40
41GNEParkingArea::GNEParkingArea(const std::string& id, GNENet* net, FileBucket* fileBucket, GNELane* lane, const double startPos, const double endPos,
42 const std::string& departPos, const std::string& name, const std::vector<std::string>& badges,
43 const bool friendlyPosition, const int roadSideCapacity, const bool onRoad, const double width,
44 const double length, const double angle, const bool lefthand, const Parameterised::Map& parameters) :
45 GNEStoppingPlace(id, net, fileBucket, SUMO_TAG_PARKING_AREA, lane, startPos,
46 endPos, name, friendlyPosition, RGBColor::INVISIBLE, angle, parameters),
47 myDepartPos(departPos),
48 myRoadSideCapacity(roadSideCapacity),
49 myOnRoad(onRoad),
50 myWidth(width),
51 myLength(length),
52 myLefthand(lefthand),
53 myAcceptedBadges(badges) {
54 // update centering boundary without updating grid
56}
57
58
60
61
62void
64 device.openTag(getTagProperty()->getTag());
65 // write common attributes
67 // write specific attributes
70 }
73 }
76 }
79 }
82 }
85 }
88 }
89 // write all parking spaces
90 for (const auto& space : getChildAdditionals()) {
91 if (space->getTagProperty()->getTag() == SUMO_TAG_PARKING_SPACE) {
92 space->writeAdditional(device);
93 }
94 }
95 // write parameters (Always after children to avoid problems with additionals.xsd)
96 XMLHelpers::writeParams(device, *this);
97 device.closeTag();
98}
99
100
101void
103 // Get value of option "lefthand"
104 const double offsetSign = OptionsCont::getOptions().getBool("lefthand") != myLefthand ? -1 : 1;
105 // calculate spaceDim
106 const double spaceDim = myRoadSideCapacity > 0 ? (getAttributeDouble(SUMO_ATTR_ENDPOS) - getAttributeDouble(SUMO_ATTR_STARTPOS)) / myRoadSideCapacity * getParentLanes().front()->getLengthGeometryFactor() : 7.5;
107 // calculate length
108 const double length = (myLength > 0) ? myLength : spaceDim;
109 // Update common geometry of stopping place
111 // Obtain a copy of the shape
113 // Move shape to side
114 tmpShape.move2side(offsetSign * (1.5 + myWidth));
115 // Get position of the sign
116 mySymbolPosition = tmpShape.getLineCenter();
117 // clear LotSpaceDefinitions
118 myLotSpaceDefinitions.clear();
119 // iterate over
120 for (int i = 0; i < myRoadSideCapacity; ++i) {
121 // calculate pos
123 // calculate angle
124 const double angle = GeomHelper::calculateLotSpaceAngle(myAdditionalGeometry.getShape(), i, spaceDim, myAngle);
125 // add GNElotEntry
126 myLotSpaceDefinitions.push_back(GNELotSpaceDefinition(pos.x(), pos.y(), pos.z(), angle, myWidth, length));
127 }
128}
129
130
131void
133 // first check if additional has to be drawn
135 // Obtain exaggeration of the draw
136 const double parkingAreaExaggeration = getExaggeration(s);
137 // check if draw moving geometry points
138 const bool movingGeometryPoints = drawMovingGeometryPoints();
139 // get detail level
140 const auto d = s.getDetailLevel(parkingAreaExaggeration);
141 // draw geometry only if we'rent in drawForObjectUnderCursor mode
143 // declare colors
144 RGBColor baseColor, signColor;
145 // set colors
146 if (mySpecialColor) {
147 baseColor = *mySpecialColor;
148 signColor = baseColor.changedBrightness(-32);
149 } else if (drawUsingSelectColor()) {
151 signColor = baseColor.changedBrightness(-32);
152 } else {
153 baseColor = s.colorSettings.parkingAreaColor;
155 }
156 // draw parent and child lines
158 // Add a layer matrix
160 // translate to front
162 // set base color
163 GLHelper::setColor(baseColor);
164 // Draw the area using shape, shapeRotations, shapeLengths and value of exaggeration
165 GUIGeometry::drawGeometry(d, myAdditionalGeometry, myWidth * 0.5 * MIN2(1.0, parkingAreaExaggeration));
166 // draw sign
167 drawSign(s, d, parkingAreaExaggeration, baseColor, signColor, "P");
168 // Translate to front
169 glTranslated(0, 0, 0.1);
170 // draw lotSpaceDefinitions
172 for (const auto& lsd : myLotSpaceDefinitions) {
173 GLHelper::drawSpaceOccupancies(parkingAreaExaggeration, lsd.position, lsd.rotation, lsd.width, lsd.length, true);
174 }
175 }
176 // draw geometry points
177 if (movingGeometryPoints && (myStartPosOverLane != INVALID_DOUBLE)) {
179 }
180 if (movingGeometryPoints && (myEndPosPosOverLane != INVALID_DOUBLE)) {
182 }
183 // pop layer matrix
185 // draw lock icon
186 GNEViewNetHelper::LockIcon::drawLockIcon(d, this, getType(), getPositionInView(), parkingAreaExaggeration);
187 // Draw additional ID
189 // draw additional name
191 // draw dotted contours
192 if (movingGeometryPoints) {
195 } else {
198 }
199 }
200 // draw demand element children
202 // calculate contours
203 calculateStoppingPlaceContour(s, d, myWidth * 0.5, parkingAreaExaggeration, movingGeometryPoints);
204 }
205}
206
207
208std::string
210 switch (key) {
212 return myDepartPos;
214 return joinToString(myAcceptedBadges, " ");
217 case SUMO_ATTR_ONROAD:
218 return toString(myOnRoad);
219 case SUMO_ATTR_WIDTH:
220 return toString(myWidth);
221 case SUMO_ATTR_LENGTH:
222 return toString(myLength);
224 return toString(myLefthand);
225 default:
226 return getStoppingPlaceAttribute(key);
227 }
228}
229
230
231double
233 switch (key) {
234 case SUMO_ATTR_WIDTH:
235 return myWidth;
236 case SUMO_ATTR_LENGTH: {
237 // calculate spaceDim
238 const double spaceDim = myRoadSideCapacity > 0 ? (getAttributeDouble(SUMO_ATTR_ENDPOS) - getAttributeDouble(SUMO_ATTR_STARTPOS)) / myRoadSideCapacity * getParentLanes().front()->getLengthGeometryFactor() : 7.5;
239 return (myLength > 0) ? myLength : spaceDim;
240 }
241 default:
243 }
244}
245
246
247void
248GNEParkingArea::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
249 switch (key) {
253 case SUMO_ATTR_ONROAD:
254 case SUMO_ATTR_WIDTH:
255 case SUMO_ATTR_LENGTH:
257 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
258 break;
259 default:
260 setStoppingPlaceAttribute(key, value, undoList);
261 break;
262 }
263}
264
265
266bool
267GNEParkingArea::isValid(SumoXMLAttr key, const std::string& value) {
268 switch (key) {
270 if (value.empty()) {
271 return true;
272 } else if (canParse<double>(value)) {
273 // parse value
274 const double departPos = parse<double>(value);
275 if (departPos >= 0) {
276 if (isTemplate()) {
277 return true;
278 } else {
279 return (departPos <= getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength());
280 }
281 } else {
282 return false;
283 }
284 } else {
285 return false;
286 }
288 return true;
290 return canParse<int>(value) && (parse<int>(value) >= 0);
291 case SUMO_ATTR_ONROAD:
292 return canParse<bool>(value);
293 case SUMO_ATTR_WIDTH:
294 return canParse<double>(value) && (parse<double>(value) > 0);
295 case SUMO_ATTR_LENGTH:
296 if (value.empty()) {
297 return true;
298 } else {
299 return canParse<double>(value) && (parse<double>(value) > 0);
300 }
302 return canParse<bool>(value);
303 default:
304 return isStoppingPlaceValid(key, value);
305 }
306}
307
308// ===========================================================================
309// protected
310// ===========================================================================
311
313 rotation(0),
314 width(0),
315 length(0) {
316}
317
318
319GNEParkingArea::GNELotSpaceDefinition::GNELotSpaceDefinition(double x, double y, double z, double rotation_, double width_, double length_) :
320 position(Position(x, y, z)),
321 rotation(rotation_),
322 width(width_),
323 length(length_) {
324}
325
326// ===========================================================================
327// private
328// ===========================================================================
329
330void
331GNEParkingArea::setAttribute(SumoXMLAttr key, const std::string& value) {
332 switch (key) {
334 myDepartPos = value;
335 break;
337 myAcceptedBadges = GNEAttributeCarrier::parse<std::vector<std::string> >(value);
338 break;
340 myRoadSideCapacity = parse<int>(value);
342 break;
343 case SUMO_ATTR_ONROAD:
344 myOnRoad = parse<bool>(value);
345 break;
346 case SUMO_ATTR_WIDTH:
347 myWidth = parse<double>(value);
348 // update geometry of all spaces
349 for (const auto& space : getChildAdditionals()) {
350 space->updateGeometry();
351 }
353 if (!isTemplate()) {
354 getParentLanes().front()->getParentEdge()->updateCenteringBoundary(true);
355 }
356 break;
357 case SUMO_ATTR_LENGTH:
358 if (value.empty()) {
359 myLength = 0;
360 } else {
361 myLength = parse<double>(value);
362 }
363 // update geometry of all spaces
364 for (const auto& space : getChildAdditionals()) {
365 space->updateGeometry();
366 }
367 break;
369 myLefthand = parse<bool>(value);
370 if (!isTemplate()) {
372 }
373 break;
374 default:
375 setStoppingPlaceAttribute(key, value);
376 break;
377 }
378}
379
380
381/****************************************************************************/
@ GLO_PARKING_AREA
a ParkingArea
@ SUMO_TAG_PARKING_AREA
A parking area.
@ SUMO_TAG_PARKING_SPACE
A parking space for a single vehicle within a parking area.
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ SUMO_ATTR_STARTPOS
@ SUMO_ATTR_ACCEPTED_BADGES
@ SUMO_ATTR_ENDPOS
@ SUMO_ATTR_DEPARTPOS
@ SUMO_ATTR_LEFTHAND
@ SUMO_ATTR_ROADSIDE_CAPACITY
@ SUMO_ATTR_ONROAD
@ SUMO_ATTR_LENGTH
@ SUMO_ATTR_WIDTH
const double INVALID_DOUBLE
invalid double
Definition StdDefs.h:68
T MIN2(T a, T b)
Definition StdDefs.h:80
std::string joinToString(const std::vector< T > &v, const T_BETWEEN &between, std::streamsize accuracy=gPrecision)
Definition ToString.h:322
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:57
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition GLHelper.cpp:649
static void popMatrix()
pop matrix
Definition GLHelper.cpp:131
static void pushMatrix()
push matrix
Definition GLHelper.cpp:118
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:679
double getExaggeration(const GUIVisualizationSettings &s) const override
return exaggeration associated with this GLObject
void drawRightGeometryPoint(const GUIVisualizationSettings &s, const GUIVisualizationSettings::Detail d, const Position &pos, const double rot, const RGBColor &baseColor, const bool ignoreShift=false) const
draw right geometry point
GNEContour myAdditionalContour
variable used for draw additional contours
GUIGeometry myAdditionalGeometry
geometry to be precomputed in updateGeometry(...)
void drawAdditionalID(const GUIVisualizationSettings &s) const
draw additional ID
void drawAdditionalName(const GUIVisualizationSettings &s) const
draw additional name
void drawDemandElementChildren(const GUIVisualizationSettings &s) const
draw demand element children
const RGBColor * mySpecialColor
pointer to special color (used for drawing Additional with a certain color, mainly used for selection...
void drawLeftGeometryPoint(const GUIVisualizationSettings &s, const GUIVisualizationSettings::Detail d, const Position &pos, const double rot, const RGBColor &baseColor, const bool ignoreShift=false) const
draw left geometry point
void drawParentChildLines(const GUIVisualizationSettings &s, const RGBColor &color, const bool onlySymbols=false) const
draw parent and child lines
bool drawMovingGeometryPoints() const
check if draw moving geometry points
bool isAttributeCarrierSelected() const
check if attribute carrier is selected
bool isTemplate() const
check if this AC is template
bool drawUsingSelectColor() const
check if attribute carrier must be drawn using selecting color.
void drawInLayer(const double typeOrLayer, const double extraOffset=0) const
draw element in the given layer, or in front if corresponding flag is enabled
const GNETagProperties * getTagProperty() const
get tagProperty associated with this Attribute Carrier
GNENet * myNet
pointer to net
const GNETagProperties * myTagProperty
reference to tagProperty associated with this attribute carrier
static void changeAttribute(GNEAttributeCarrier *AC, SumoXMLAttr key, const std::string &value, GNEUndoList *undoList, const bool force=false)
change attribute
void drawDottedContourGeometryPoints(const GUIVisualizationSettings &s, const GUIVisualizationSettings::Detail d, const GNEAttributeCarrier *AC, const PositionVector &shape, const double radius, const double scale, const double lineWidth) const
draw dotted contour for geometry points
bool drawDottedContours(const GUIVisualizationSettings &s, const GUIVisualizationSettings::Detail d, const GNEAttributeCarrier *AC, const double lineWidth, const bool addOffset) const
draw dotted contours (basics, select, delete, inspect...)
const GNEHierarchicalContainerChildren< GNEAdditional * > & getChildAdditionals() const
return child additionals
const GNEHierarchicalContainerParents< GNELane * > & getParentLanes() const
get parent lanes
GNEViewNet * getViewNet() const
get view net (used for simplify code)
Definition GNENet.cpp:144
double myLength
Length of Parking Area (by default (endPos - startPos) / roadsideCapacity.
bool myLefthand
lefthand
~GNEParkingArea()
Destructor.
double getAttributeDouble(SumoXMLAttr key) const override
double myWidth
width of Parking Area
void writeAdditional(OutputDevice &device) const override
write additional element into a xml file
std::vector< std::string > myAcceptedBadges
The list of badges that allow accessing the parkingArea.
std::string myDepartPos
departPos
bool myOnRoad
Whether vehicles stay on the road.
std::vector< GNELotSpaceDefinition > myLotSpaceDefinitions
vector with GNELotSpaceDefinition
GNEParkingArea(GNENet *net)
default constructor
std::string getAttribute(SumoXMLAttr key) const override
bool isValid(SumoXMLAttr key, const std::string &value) override
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList) override
void drawGL(const GUIVisualizationSettings &s) const override
Draws the object.
void updateGeometry() override
update pre-computed geometry information
int myRoadSideCapacity
roadside capacity of Parking Area
bool isStoppingPlaceValid(SumoXMLAttr key, const std::string &value) const
void setStoppingPlaceAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
double myEndPosPosOverLane
The end position over lane.
void writeStoppingPlaceAttributes(OutputDevice &device) const
write common stoppingPlace attributes
void drawSign(const GUIVisualizationSettings &s, const GUIVisualizationSettings::Detail d, const double exaggeration, const RGBColor &baseColor, const RGBColor &signColor, const std::string &word) const
draw sign
double getStoppingPlaceAttributeDouble(SumoXMLAttr key) const
void calculateStoppingPlaceContour(const GUIVisualizationSettings &s, const GUIVisualizationSettings::Detail d, const double width, const double exaggeration, const bool movingGeometryPoints) const
check object in view
Position mySymbolPosition
The position of the sign.
double myStartPosOverLane
The start position over lane.
void setStoppingPlaceGeometry(double movingToSide)
set geometry common to all stopping places
GNEContour mySymbolContour
circle contour
Position getPositionInView() const override
Returns position of additional in view.
std::string getStoppingPlaceAttribute(SumoXMLAttr key) const
void updateCenteringBoundary(const bool updateGrid) override
update centering boundary (implies change in RTREE)
bool getDefaultBoolValue(SumoXMLAttr attr) const
get default bool value
double getDefaultDoubleValue(SumoXMLAttr attr) const
get default double value
int getDefaultIntValue(SumoXMLAttr attr) const
get default int value
const std::string & getDefaultStringValue(SumoXMLAttr attr) const
default values
const GNEViewNetHelper::DataViewOptions & getDataViewOptions() const
get data view options
const std::vector< double > & getShapeRotations() const
The rotations of the single shape parts.
static void drawGeometry(const GUIVisualizationSettings::Detail d, const GUIGeometry &geometry, const double width, double offset=0)
draw geometry
const PositionVector & getShape() const
The shape of the additional element.
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
Stores the information about how to visualize structures.
bool checkDrawAdditional(Detail d, const bool selected) const
check if draw additionals
Detail getDetailLevel(const double exaggeration) const
return the detail level
GUIVisualizationColorSettings colorSettings
color settings
GUIVisualizationDottedContourSettings dottedContourSettings
dotted contour settings
GUIVisualizationAdditionalSettings additionalSettings
Additional settings.
GUIVisualizationNeteditSizeSettings neteditSizeSettings
netedit size settings
static const Position calculateLotSpacePosition(const PositionVector &shape, const int index, const double spaceDim, const double angle, const double width, const double length)
calculate lotSpace position
static double calculateLotSpaceAngle(const PositionVector &shape, const int index, const double spaceDim, const double angle)
calculate lotSpace angle
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
static OptionsCont & getOptions()
Retrieves the options.
Static storage of an output device and its base (abstract) implementation.
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
OutputDevice & writeAttr(const ATTR_TYPE &attr, const T &val, const bool isNull=false, const bool escape=false)
writes a named attribute
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
std::map< std::string, std::string > Map
parameters map
A point in 2D or 3D with translation and scaling methods.
Definition Position.h:37
double x() const
Returns the x-position.
Definition Position.h:52
double z() const
Returns the z-position.
Definition Position.h:62
double y() const
Returns the y-position.
Definition Position.h:57
A list of positions.
void move2side(double amount, double maxExtension=100)
move position vector to side using certain amount
RGBColor changedBrightness(int change, int toChange=3) const
Returns a new color with altered brightness.
Definition RGBColor.cpp:228
static OutputDevice & writeParams(OutputDevice &device, const Parameterised &params)
write the parameters of the given object as param tags
Representation of a single lot space in Netedit.
bool showAdditionals() const
check if additionals has to be drawn
static void drawLockIcon(const GUIVisualizationSettings::Detail d, const GNEAttributeCarrier *AC, GUIGlObjectType type, const Position position, const double exaggeration, const double size=0.5, const double offsetx=0, const double offsety=0)
draw lock icon
static const RGBColor connectionColor
connection color
RGBColor selectedAdditionalColor
additional selection color (busStops, Detectors...)
RGBColor parkingAreaColorSign
color for parkingArea sign
RGBColor parkingAreaColor
color for parkingAreas
static const double segmentWidthSmall
width of small dotted contour segments
static const double segmentWidth
width of dotted contour segments
static const double additionalGeometryPointRadius
moving additional geometry point radius