Eclipse SUMO - Simulation of Urban MObility
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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-2025 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/****************************************************************************/
18// A lane area vehicles can park at (GNE version)
19/****************************************************************************/
20
21#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, const std::string& filename, 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, filename, SUMO_TAG_PARKING_AREA, lane, startPos,
44 endPos, name, friendlyPosition, RGBColor::INVISIBLE, parameters),
45 myDepartPos(departPos),
46 myRoadSideCapacity(roadSideCapacity),
47 myOnRoad(onRoad),
48 myWidth(width),
49 myLength(length),
50 myAngle(angle),
51 myLefthand(lefthand),
52 myAcceptedBadges(badges) {
53 // update centering boundary without updating grid
55}
56
57
59
60
61void
63 device.openTag(getTagProperty()->getTag());
64 // write common attributes
66 // write specific attributes
69 }
72 }
75 }
78 }
81 }
84 }
87 }
90 }
91 // write all parking spaces
92 for (const auto& space : getChildAdditionals()) {
93 if (space->getTagProperty()->getTag() == SUMO_TAG_PARKING_SPACE) {
94 space->writeAdditional(device);
95 }
96 }
97 // write parameters (Always after children to avoid problems with additionals.xsd)
98 writeParams(device);
99 device.closeTag();
100}
101
102
103void
105 // Get value of option "lefthand"
106 const double offsetSign = OptionsCont::getOptions().getBool("lefthand") != myLefthand ? -1 : 1;
107 // calculate spaceDim
108 const double spaceDim = myRoadSideCapacity > 0 ? (getAttributeDouble(SUMO_ATTR_ENDPOS) - getAttributeDouble(SUMO_ATTR_STARTPOS)) / myRoadSideCapacity * getParentLanes().front()->getLengthGeometryFactor() : 7.5;
109 // calculate length
110 const double length = (myLength > 0) ? myLength : spaceDim;
111 // Update common geometry of stopping place
113 // Obtain a copy of the shape
115 // Move shape to side
116 tmpShape.move2side(1.5 * offsetSign + myWidth);
117 // Get position of the sign
118 mySymbolPosition = tmpShape.getLineCenter();
119 // clear LotSpaceDefinitions
120 myLotSpaceDefinitions.clear();
121 // iterate over
122 for (int i = 0; i < myRoadSideCapacity; ++i) {
123 // calculate pos
125 // calculate angle
126 const double angle = GeomHelper::calculateLotSpaceAngle(myAdditionalGeometry.getShape(), i, spaceDim, myAngle);
127 // add GNElotEntry
128 myLotSpaceDefinitions.push_back(GNELotSpaceDefinition(pos.x(), pos.y(), pos.z(), angle, myWidth, length));
129 }
130}
131
132
133void
135 // first check if additional has to be drawn
137 // Obtain exaggeration of the draw
138 const double parkingAreaExaggeration = getExaggeration(s);
139 // check if draw moving geometry points
140 const bool movingGeometryPoints = drawMovingGeometryPoints(false);
141 // get detail level
142 const auto d = s.getDetailLevel(parkingAreaExaggeration);
143 // draw geometry only if we'rent in drawForObjectUnderCursor mode
145 // declare colors
146 RGBColor baseColor, signColor;
147 // set colors
148 if (mySpecialColor) {
149 baseColor = *mySpecialColor;
150 signColor = baseColor.changedBrightness(-32);
151 } else if (drawUsingSelectColor()) {
153 signColor = baseColor.changedBrightness(-32);
154 } else {
155 baseColor = s.colorSettings.parkingAreaColor;
157 }
158 // draw parent and child lines
160 // Add a layer matrix
162 // translate to front
164 // set base color
165 GLHelper::setColor(baseColor);
166 // Draw the area using shape, shapeRotations, shapeLengths and value of exaggeration
167 GUIGeometry::drawGeometry(d, myAdditionalGeometry, myWidth * 0.5 * MIN2(1.0, parkingAreaExaggeration));
168 // draw sign
169 drawSign(s, d, parkingAreaExaggeration, baseColor, signColor, "P");
170 // Traslate to front
171 glTranslated(0, 0, 0.1);
172 // draw lotSpaceDefinitions
174 for (const auto& lsd : myLotSpaceDefinitions) {
175 GLHelper::drawSpaceOccupancies(parkingAreaExaggeration, lsd.position, lsd.rotation, lsd.width, lsd.length, true);
176 }
177 }
178 // draw geometry points
179 if (movingGeometryPoints && (myStartPosition != INVALID_DOUBLE)) {
181 }
182 if (movingGeometryPoints && (myEndPosition != INVALID_DOUBLE)) {
184 }
185 // pop layer matrix
187 // draw lock icon
188 GNEViewNetHelper::LockIcon::drawLockIcon(d, this, getType(), getPositionInView(), parkingAreaExaggeration);
189 // Draw additional ID
191 // draw additional name
193 // draw dotted contours
194 if (movingGeometryPoints) {
197 } else {
200 }
201 }
202 // draw demand element children
204 // calculate contours
205 calculateStoppingPlaceContour(s, d, myWidth * 0.5, parkingAreaExaggeration, movingGeometryPoints);
206 }
207}
208
209
210std::string
212 switch (key) {
214 return myDepartPos;
216 return joinToString(myAcceptedBadges, " ");
219 case SUMO_ATTR_ONROAD:
220 return toString(myOnRoad);
221 case SUMO_ATTR_WIDTH:
222 return toString(myWidth);
223 case SUMO_ATTR_LENGTH:
224 return toString(myLength);
225 case SUMO_ATTR_ANGLE:
226 return toString(myAngle);
228 return toString(myLefthand);
229 default:
230 return getStoppingPlaceAttribute(this, key);
231 }
232}
233
234
235double
237 switch (key) {
238 case SUMO_ATTR_WIDTH:
239 return myWidth;
240 case SUMO_ATTR_LENGTH: {
241 // calculate spaceDim
242 const double spaceDim = myRoadSideCapacity > 0 ? (getAttributeDouble(SUMO_ATTR_ENDPOS) - getAttributeDouble(SUMO_ATTR_STARTPOS)) / myRoadSideCapacity * getParentLanes().front()->getLengthGeometryFactor() : 7.5;
243 return (myLength > 0) ? myLength : spaceDim;
244 }
245 case SUMO_ATTR_ANGLE:
246 return myAngle;
247 default:
249 }
250}
251
252
253void
254GNEParkingArea::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
255 switch (key) {
259 case SUMO_ATTR_ONROAD:
260 case SUMO_ATTR_WIDTH:
261 case SUMO_ATTR_LENGTH:
262 case SUMO_ATTR_ANGLE:
264 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
265 break;
266 default:
267 setStoppingPlaceAttribute(key, value, undoList);
268 break;
269 }
270}
271
272
273bool
274GNEParkingArea::isValid(SumoXMLAttr key, const std::string& value) {
275 switch (key) {
277 if (value.empty()) {
278 return true;
279 } else if (canParse<double>(value)) {
280 // parse value
281 const double departPos = parse<double>(value);
282 if (departPos >= 0) {
283 if (isTemplate()) {
284 return true;
285 } else {
286 return (departPos <= getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength());
287 }
288 } else {
289 return false;
290 }
291 } else {
292 return false;
293 }
295 return true;
297 return canParse<int>(value) && (parse<int>(value) >= 0);
298 case SUMO_ATTR_ONROAD:
299 return canParse<bool>(value);
300 case SUMO_ATTR_WIDTH:
301 return canParse<double>(value) && (parse<double>(value) > 0);
302 case SUMO_ATTR_LENGTH:
303 if (value.empty()) {
304 return true;
305 } else {
306 return canParse<double>(value) && (parse<double>(value) > 0);
307 }
308 case SUMO_ATTR_ANGLE:
309 return canParse<double>(value);
311 return canParse<bool>(value);
312 default:
313 return isStoppingPlaceValid(key, value);
314 }
315}
316
317// ===========================================================================
318// protected
319// ===========================================================================
320
322 rotation(0),
323 width(0),
324 length(0) {
325}
326
327
328GNEParkingArea::GNELotSpaceDefinition::GNELotSpaceDefinition(double x, double y, double z, double rotation_, double width_, double length_) :
329 position(Position(x, y, z)),
330 rotation(rotation_),
331 width(width_),
332 length(length_) {
333}
334
335// ===========================================================================
336// private
337// ===========================================================================
338
339void
340GNEParkingArea::setAttribute(SumoXMLAttr key, const std::string& value) {
341 switch (key) {
343 myDepartPos = value;
344 break;
346 myAcceptedBadges = GNEAttributeCarrier::parse<std::vector<std::string> >(value);
347 break;
349 myRoadSideCapacity = parse<int>(value);
351 break;
352 case SUMO_ATTR_ONROAD:
353 myOnRoad = parse<bool>(value);
354 break;
355 case SUMO_ATTR_WIDTH:
356 myWidth = parse<double>(value);
357 // update geometry of all spaces
358 for (const auto& space : getChildAdditionals()) {
359 space->updateGeometry();
360 }
362 if (!isTemplate()) {
363 getParentLanes().front()->getParentEdge()->updateCenteringBoundary(true);
364 }
365 break;
366 case SUMO_ATTR_LENGTH:
367 if (value.empty()) {
368 myLength = 0;
369 } else {
370 myLength = parse<double>(value);
371 }
372 // update geometry of all spaces
373 for (const auto& space : getChildAdditionals()) {
374 space->updateGeometry();
375 }
376 break;
377 case SUMO_ATTR_ANGLE:
378 myAngle = parse<double>(value);
379 break;
381 myLefthand = parse<bool>(value);
382 if (!isTemplate()) {
384 }
385 break;
386 default:
387 setStoppingPlaceAttribute(this, key, value);
388 break;
389 }
390}
391
392
393/****************************************************************************/
@ 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_ANGLE
@ SUMO_ATTR_ROADSIDE_CAPACITY
@ SUMO_ATTR_ONROAD
@ SUMO_ATTR_LENGTH
@ SUMO_ATTR_WIDTH
const double INVALID_DOUBLE
invalid double
Definition StdDefs.h:64
T MIN2(T a, T b)
Definition StdDefs.h:76
std::string joinToString(const std::vector< T > &v, const T_BETWEEN &between, std::streamsize accuracy=gPrecision)
Definition ToString.h:283
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
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
double getExaggeration(const GUIVisualizationSettings &s) const
return exaggeration associated with this GLObject
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...
bool drawMovingGeometryPoints(const bool ignoreShift) const
check if draw additional extrem geometry points
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 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
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
Definition GNELane.h:46
A NBNetBuilder extended by visualisation and editing capabilities.
Definition GNENet.h:42
GNEViewNet * getViewNet() const
get view net
Definition GNENet.cpp:2194
double myLength
Length of Parking Area (by default (endPos - startPos) / roadsideCapacity.
bool myLefthand
lefthand
void writeAdditional(OutputDevice &device) const
write additional element into a xml file
std::string getAttribute(SumoXMLAttr key) const
~GNEParkingArea()
Destructor.
double myAngle
Angle of Parking Area.
double myWidth
width of Parking Area
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
std::vector< std::string > myAcceptedBadges
The list of badges that allow accessing the parkingArea.
double getAttributeDouble(SumoXMLAttr key) const
std::string myDepartPos
departPos
bool myOnRoad
Whether vehicles stay on the road.
std::vector< GNELotSpaceDefinition > myLotSpaceDefinitions
vector with GNELotSpaceDefinition
GNEParkingArea(GNENet *net)
default constructor
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform additional changes
void updateGeometry()
update pre-computed geometry information
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their correspondent attribute are valids
int myRoadSideCapacity
roadside capacity of Parking Area
void updateCenteringBoundary(const bool updateGrid)
update centering boundary (implies change in RTREE)
bool isStoppingPlaceValid(SumoXMLAttr key, const std::string &value) const
void setStoppingPlaceAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
void writeStoppingPlaceAttributes(OutputDevice &device) const
write common stoppingPlace attributes
Position getPositionInView() const
Returns position of additional in view.
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
std::string getStoppingPlaceAttribute(const Parameterised *parameterised, SumoXMLAttr key) const
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.
void setStoppingPlaceGeometry(double movingToSide)
set geometry common to all stopping places
double myEndPosition
The position this stopping place is located at (-1 means empty)
GNEContour mySymbolContour
circle contour
double myStartPosition
The relative start position this stopping place is located at (-1 means empty)
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
Position getLineCenter() const
get line center
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