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#include <netedit/GNENet.h>
27
28#include "GNEParkingArea.h"
29
30// ===========================================================================
31// method definitions
32// ===========================================================================
33
37
38
39GNEParkingArea::GNEParkingArea(const std::string& id, GNENet* net, FileBucket* fileBucket, GNELane* lane, const double startPos, const double endPos,
40 const std::string& departPos, const std::string& name, const std::vector<std::string>& badges,
41 const bool friendlyPosition, const int roadSideCapacity, const bool onRoad, const double width,
42 const double length, const double angle, const bool lefthand, const Parameterised::Map& parameters) :
43 GNEStoppingPlace(id, net, fileBucket, SUMO_TAG_PARKING_AREA, lane, startPos,
44 endPos, name, friendlyPosition, RGBColor::INVISIBLE, angle, parameters),
45 myDepartPos(departPos),
46 myRoadSideCapacity(roadSideCapacity),
47 myOnRoad(onRoad),
48 myWidth(width),
49 myLength(length),
50 myLefthand(lefthand),
51 myAcceptedBadges(badges) {
52 // update centering boundary without updating grid
54}
55
56
58
59
60void
62 device.openTag(getTagProperty()->getTag());
63 // write common attributes
65 // write specific attributes
68 }
71 }
74 }
77 }
80 }
83 }
86 }
87 // write all parking spaces
88 for (const auto& space : getChildAdditionals()) {
89 if (space->getTagProperty()->getTag() == SUMO_TAG_PARKING_SPACE) {
90 space->writeAdditional(device);
91 }
92 }
93 // write parameters (Always after children to avoid problems with additionals.xsd)
94 writeParams(device);
95 device.closeTag();
96}
97
98
99void
101 // Get value of option "lefthand"
102 const double offsetSign = OptionsCont::getOptions().getBool("lefthand") != myLefthand ? -1 : 1;
103 // calculate spaceDim
104 const double spaceDim = myRoadSideCapacity > 0 ? (getAttributeDouble(SUMO_ATTR_ENDPOS) - getAttributeDouble(SUMO_ATTR_STARTPOS)) / myRoadSideCapacity * getParentLanes().front()->getLengthGeometryFactor() : 7.5;
105 // calculate length
106 const double length = (myLength > 0) ? myLength : spaceDim;
107 // Update common geometry of stopping place
109 // Obtain a copy of the shape
111 // Move shape to side
112 tmpShape.move2side(offsetSign * (1.5 + myWidth));
113 // Get position of the sign
114 mySymbolPosition = tmpShape.getLineCenter();
115 // clear LotSpaceDefinitions
116 myLotSpaceDefinitions.clear();
117 // iterate over
118 for (int i = 0; i < myRoadSideCapacity; ++i) {
119 // calculate pos
121 // calculate angle
122 const double angle = GeomHelper::calculateLotSpaceAngle(myAdditionalGeometry.getShape(), i, spaceDim, myAngle);
123 // add GNElotEntry
124 myLotSpaceDefinitions.push_back(GNELotSpaceDefinition(pos.x(), pos.y(), pos.z(), angle, myWidth, length));
125 }
126}
127
128
129void
131 // first check if additional has to be drawn
133 // Obtain exaggeration of the draw
134 const double parkingAreaExaggeration = getExaggeration(s);
135 // check if draw moving geometry points
136 const bool movingGeometryPoints = drawMovingGeometryPoints();
137 // get detail level
138 const auto d = s.getDetailLevel(parkingAreaExaggeration);
139 // draw geometry only if we'rent in drawForObjectUnderCursor mode
141 // declare colors
142 RGBColor baseColor, signColor;
143 // set colors
144 if (mySpecialColor) {
145 baseColor = *mySpecialColor;
146 signColor = baseColor.changedBrightness(-32);
147 } else if (drawUsingSelectColor()) {
149 signColor = baseColor.changedBrightness(-32);
150 } else {
151 baseColor = s.colorSettings.parkingAreaColor;
153 }
154 // draw parent and child lines
156 // Add a layer matrix
158 // translate to front
160 // set base color
161 GLHelper::setColor(baseColor);
162 // Draw the area using shape, shapeRotations, shapeLengths and value of exaggeration
163 GUIGeometry::drawGeometry(d, myAdditionalGeometry, myWidth * 0.5 * MIN2(1.0, parkingAreaExaggeration));
164 // draw sign
165 drawSign(s, d, parkingAreaExaggeration, baseColor, signColor, "P");
166 // Traslate to front
167 glTranslated(0, 0, 0.1);
168 // draw lotSpaceDefinitions
170 for (const auto& lsd : myLotSpaceDefinitions) {
171 GLHelper::drawSpaceOccupancies(parkingAreaExaggeration, lsd.position, lsd.rotation, lsd.width, lsd.length, true);
172 }
173 }
174 // draw geometry points
175 if (movingGeometryPoints && (myStartPosOverLane != INVALID_DOUBLE)) {
177 }
178 if (movingGeometryPoints && (myEndPosPosOverLane != INVALID_DOUBLE)) {
180 }
181 // pop layer matrix
183 // draw lock icon
184 GNEViewNetHelper::LockIcon::drawLockIcon(d, this, getType(), getPositionInView(), parkingAreaExaggeration);
185 // Draw additional ID
187 // draw additional name
189 // draw dotted contours
190 if (movingGeometryPoints) {
193 } else {
196 }
197 }
198 // draw demand element children
200 // calculate contours
201 calculateStoppingPlaceContour(s, d, myWidth * 0.5, parkingAreaExaggeration, movingGeometryPoints);
202 }
203}
204
205
206std::string
208 switch (key) {
210 return myDepartPos;
212 return joinToString(myAcceptedBadges, " ");
215 case SUMO_ATTR_ONROAD:
216 return toString(myOnRoad);
217 case SUMO_ATTR_WIDTH:
218 return toString(myWidth);
219 case SUMO_ATTR_LENGTH:
220 return toString(myLength);
222 return toString(myLefthand);
223 default:
224 return getStoppingPlaceAttribute(key);
225 }
226}
227
228
229double
231 switch (key) {
232 case SUMO_ATTR_WIDTH:
233 return myWidth;
234 case SUMO_ATTR_LENGTH: {
235 // calculate spaceDim
236 const double spaceDim = myRoadSideCapacity > 0 ? (getAttributeDouble(SUMO_ATTR_ENDPOS) - getAttributeDouble(SUMO_ATTR_STARTPOS)) / myRoadSideCapacity * getParentLanes().front()->getLengthGeometryFactor() : 7.5;
237 return (myLength > 0) ? myLength : spaceDim;
238 }
239 default:
241 }
242}
243
244
245void
246GNEParkingArea::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
247 switch (key) {
251 case SUMO_ATTR_ONROAD:
252 case SUMO_ATTR_WIDTH:
253 case SUMO_ATTR_LENGTH:
255 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
256 break;
257 default:
258 setStoppingPlaceAttribute(key, value, undoList);
259 break;
260 }
261}
262
263
264bool
265GNEParkingArea::isValid(SumoXMLAttr key, const std::string& value) {
266 switch (key) {
268 if (value.empty()) {
269 return true;
270 } else if (canParse<double>(value)) {
271 // parse value
272 const double departPos = parse<double>(value);
273 if (departPos >= 0) {
274 if (isTemplate()) {
275 return true;
276 } else {
277 return (departPos <= getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength());
278 }
279 } else {
280 return false;
281 }
282 } else {
283 return false;
284 }
286 return true;
288 return canParse<int>(value) && (parse<int>(value) >= 0);
289 case SUMO_ATTR_ONROAD:
290 return canParse<bool>(value);
291 case SUMO_ATTR_WIDTH:
292 return canParse<double>(value) && (parse<double>(value) > 0);
293 case SUMO_ATTR_LENGTH:
294 if (value.empty()) {
295 return true;
296 } else {
297 return canParse<double>(value) && (parse<double>(value) > 0);
298 }
300 return canParse<bool>(value);
301 default:
302 return isStoppingPlaceValid(key, value);
303 }
304}
305
306// ===========================================================================
307// protected
308// ===========================================================================
309
311 rotation(0),
312 width(0),
313 length(0) {
314}
315
316
317GNEParkingArea::GNELotSpaceDefinition::GNELotSpaceDefinition(double x, double y, double z, double rotation_, double width_, double length_) :
318 position(Position(x, y, z)),
319 rotation(rotation_),
320 width(width_),
321 length(length_) {
322}
323
324// ===========================================================================
325// private
326// ===========================================================================
327
328void
329GNEParkingArea::setAttribute(SumoXMLAttr key, const std::string& value) {
330 switch (key) {
332 myDepartPos = value;
333 break;
335 myAcceptedBadges = GNEAttributeCarrier::parse<std::vector<std::string> >(value);
336 break;
338 myRoadSideCapacity = parse<int>(value);
340 break;
341 case SUMO_ATTR_ONROAD:
342 myOnRoad = parse<bool>(value);
343 break;
344 case SUMO_ATTR_WIDTH:
345 myWidth = parse<double>(value);
346 // update geometry of all spaces
347 for (const auto& space : getChildAdditionals()) {
348 space->updateGeometry();
349 }
351 if (!isTemplate()) {
352 getParentLanes().front()->getParentEdge()->updateCenteringBoundary(true);
353 }
354 break;
355 case SUMO_ATTR_LENGTH:
356 if (value.empty()) {
357 myLength = 0;
358 } else {
359 myLength = parse<double>(value);
360 }
361 // update geometry of all spaces
362 for (const auto& space : getChildAdditionals()) {
363 space->updateGeometry();
364 }
365 break;
367 myLefthand = parse<bool>(value);
368 if (!isTemplate()) {
370 }
371 break;
372 default:
373 setStoppingPlaceAttribute(key, value);
374 break;
375 }
376}
377
378
379/****************************************************************************/
@ 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:289
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:46
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 & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
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
void writeParams(OutputDevice &device) const
write Params in the given outputdevice
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:200
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