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-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
22#include <netedit/GNENet.h>
26
27#include "GNEParkingArea.h"
28
29// ===========================================================================
30// method definitions
31// ===========================================================================
32
36
37
38GNEParkingArea::GNEParkingArea(const std::string& id, GNENet* net, const std::string& filename, GNELane* lane, const double startPos, const double endPos,
39 const std::string& departPos, const std::string& name, const std::vector<std::string>& badges,
40 const bool friendlyPosition, const int roadSideCapacity, const bool onRoad, const double width,
41 const double length, const double angle, const bool lefthand, const Parameterised::Map& parameters) :
42 GNEStoppingPlace(id, net, filename, SUMO_TAG_PARKING_AREA, lane, startPos,
43 endPos, name, friendlyPosition, RGBColor::INVISIBLE, angle, parameters),
44 myDepartPos(departPos),
45 myRoadSideCapacity(roadSideCapacity),
46 myOnRoad(onRoad),
47 myWidth(width),
48 myLength(length),
49 myLefthand(lefthand),
50 myAcceptedBadges(badges) {
51 // update centering boundary without updating grid
53}
54
55
57
58
59void
61 device.openTag(getTagProperty()->getTag());
62 // write common attributes
64 // write specific attributes
67 }
70 }
73 }
76 }
79 }
82 }
85 }
86 // write all parking spaces
87 for (const auto& space : getChildAdditionals()) {
88 if (space->getTagProperty()->getTag() == SUMO_TAG_PARKING_SPACE) {
89 space->writeAdditional(device);
90 }
91 }
92 // write parameters (Always after children to avoid problems with additionals.xsd)
93 writeParams(device);
94 device.closeTag();
95}
96
97
98void
100 // Get value of option "lefthand"
101 const double offsetSign = OptionsCont::getOptions().getBool("lefthand") != myLefthand ? -1 : 1;
102 // calculate spaceDim
103 const double spaceDim = myRoadSideCapacity > 0 ? (getAttributeDouble(SUMO_ATTR_ENDPOS) - getAttributeDouble(SUMO_ATTR_STARTPOS)) / myRoadSideCapacity * getParentLanes().front()->getLengthGeometryFactor() : 7.5;
104 // calculate length
105 const double length = (myLength > 0) ? myLength : spaceDim;
106 // Update common geometry of stopping place
108 // Obtain a copy of the shape
110 // Move shape to side
111 tmpShape.move2side(1.5 * offsetSign + myWidth);
112 // Get position of the sign
113 mySymbolPosition = tmpShape.getLineCenter();
114 // clear LotSpaceDefinitions
115 myLotSpaceDefinitions.clear();
116 // iterate over
117 for (int i = 0; i < myRoadSideCapacity; ++i) {
118 // calculate pos
120 // calculate angle
121 const double angle = GeomHelper::calculateLotSpaceAngle(myAdditionalGeometry.getShape(), i, spaceDim, myAngle);
122 // add GNElotEntry
123 myLotSpaceDefinitions.push_back(GNELotSpaceDefinition(pos.x(), pos.y(), pos.z(), angle, myWidth, length));
124 }
125}
126
127
128void
130 // first check if additional has to be drawn
132 // Obtain exaggeration of the draw
133 const double parkingAreaExaggeration = getExaggeration(s);
134 // check if draw moving geometry points
135 const bool movingGeometryPoints = drawMovingGeometryPoints();
136 // get detail level
137 const auto d = s.getDetailLevel(parkingAreaExaggeration);
138 // draw geometry only if we'rent in drawForObjectUnderCursor mode
140 // declare colors
141 RGBColor baseColor, signColor;
142 // set colors
143 if (mySpecialColor) {
144 baseColor = *mySpecialColor;
145 signColor = baseColor.changedBrightness(-32);
146 } else if (drawUsingSelectColor()) {
148 signColor = baseColor.changedBrightness(-32);
149 } else {
150 baseColor = s.colorSettings.parkingAreaColor;
152 }
153 // draw parent and child lines
155 // Add a layer matrix
157 // translate to front
159 // set base color
160 GLHelper::setColor(baseColor);
161 // Draw the area using shape, shapeRotations, shapeLengths and value of exaggeration
162 GUIGeometry::drawGeometry(d, myAdditionalGeometry, myWidth * 0.5 * MIN2(1.0, parkingAreaExaggeration));
163 // draw sign
164 drawSign(s, d, parkingAreaExaggeration, baseColor, signColor, "P");
165 // Traslate to front
166 glTranslated(0, 0, 0.1);
167 // draw lotSpaceDefinitions
169 for (const auto& lsd : myLotSpaceDefinitions) {
170 GLHelper::drawSpaceOccupancies(parkingAreaExaggeration, lsd.position, lsd.rotation, lsd.width, lsd.length, true);
171 }
172 }
173 // draw geometry points
174 if (movingGeometryPoints && (myStartPosOverLane != INVALID_DOUBLE)) {
176 }
177 if (movingGeometryPoints && (myEndPosPosOverLane != INVALID_DOUBLE)) {
179 }
180 // pop layer matrix
182 // draw lock icon
183 GNEViewNetHelper::LockIcon::drawLockIcon(d, this, getType(), getPositionInView(), parkingAreaExaggeration);
184 // Draw additional ID
186 // draw additional name
188 // draw dotted contours
189 if (movingGeometryPoints) {
192 } else {
195 }
196 }
197 // draw demand element children
199 // calculate contours
200 calculateStoppingPlaceContour(s, d, myWidth * 0.5, parkingAreaExaggeration, movingGeometryPoints);
201 }
202}
203
204
205std::string
207 switch (key) {
209 return myDepartPos;
211 return joinToString(myAcceptedBadges, " ");
214 case SUMO_ATTR_ONROAD:
215 return toString(myOnRoad);
216 case SUMO_ATTR_WIDTH:
217 return toString(myWidth);
218 case SUMO_ATTR_LENGTH:
219 return toString(myLength);
221 return toString(myLefthand);
222 default:
223 return getStoppingPlaceAttribute(key);
224 }
225}
226
227
228double
230 switch (key) {
231 case SUMO_ATTR_WIDTH:
232 return myWidth;
233 case SUMO_ATTR_LENGTH: {
234 // calculate spaceDim
235 const double spaceDim = myRoadSideCapacity > 0 ? (getAttributeDouble(SUMO_ATTR_ENDPOS) - getAttributeDouble(SUMO_ATTR_STARTPOS)) / myRoadSideCapacity * getParentLanes().front()->getLengthGeometryFactor() : 7.5;
236 return (myLength > 0) ? myLength : spaceDim;
237 }
238 default:
240 }
241}
242
243
244void
245GNEParkingArea::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
246 switch (key) {
250 case SUMO_ATTR_ONROAD:
251 case SUMO_ATTR_WIDTH:
252 case SUMO_ATTR_LENGTH:
254 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
255 break;
256 default:
257 setStoppingPlaceAttribute(key, value, undoList);
258 break;
259 }
260}
261
262
263bool
264GNEParkingArea::isValid(SumoXMLAttr key, const std::string& value) {
265 switch (key) {
267 if (value.empty()) {
268 return true;
269 } else if (canParse<double>(value)) {
270 // parse value
271 const double departPos = parse<double>(value);
272 if (departPos >= 0) {
273 if (isTemplate()) {
274 return true;
275 } else {
276 return (departPos <= getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength());
277 }
278 } else {
279 return false;
280 }
281 } else {
282 return false;
283 }
285 return true;
287 return canParse<int>(value) && (parse<int>(value) >= 0);
288 case SUMO_ATTR_ONROAD:
289 return canParse<bool>(value);
290 case SUMO_ATTR_WIDTH:
291 return canParse<double>(value) && (parse<double>(value) > 0);
292 case SUMO_ATTR_LENGTH:
293 if (value.empty()) {
294 return true;
295 } else {
296 return canParse<double>(value) && (parse<double>(value) > 0);
297 }
299 return canParse<bool>(value);
300 default:
301 return isStoppingPlaceValid(key, value);
302 }
303}
304
305// ===========================================================================
306// protected
307// ===========================================================================
308
310 rotation(0),
311 width(0),
312 length(0) {
313}
314
315
316GNEParkingArea::GNELotSpaceDefinition::GNELotSpaceDefinition(double x, double y, double z, double rotation_, double width_, double length_) :
317 position(Position(x, y, z)),
318 rotation(rotation_),
319 width(width_),
320 length(length_) {
321}
322
323// ===========================================================================
324// private
325// ===========================================================================
326
327void
328GNEParkingArea::setAttribute(SumoXMLAttr key, const std::string& value) {
329 switch (key) {
331 myDepartPos = value;
332 break;
334 myAcceptedBadges = GNEAttributeCarrier::parse<std::vector<std::string> >(value);
335 break;
337 myRoadSideCapacity = parse<int>(value);
339 break;
340 case SUMO_ATTR_ONROAD:
341 myOnRoad = parse<bool>(value);
342 break;
343 case SUMO_ATTR_WIDTH:
344 myWidth = parse<double>(value);
345 // update geometry of all spaces
346 for (const auto& space : getChildAdditionals()) {
347 space->updateGeometry();
348 }
350 if (!isTemplate()) {
351 getParentLanes().front()->getParentEdge()->updateCenteringBoundary(true);
352 }
353 break;
354 case SUMO_ATTR_LENGTH:
355 if (value.empty()) {
356 myLength = 0;
357 } else {
358 myLength = parse<double>(value);
359 }
360 // update geometry of all spaces
361 for (const auto& space : getChildAdditionals()) {
362 space->updateGeometry();
363 }
364 break;
366 myLefthand = parse<bool>(value);
367 if (!isTemplate()) {
369 }
370 break;
371 default:
372 setStoppingPlaceAttribute(key, value);
373 break;
374 }
375}
376
377
378/****************************************************************************/
@ 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: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
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
A NBNetBuilder extended by visualisation and editing capabilities.
Definition GNENet.h:42
GNEViewNet * getViewNet() const
get view net
Definition GNENet.cpp:2193
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
~GNEParkingArea()
Destructor.
double getAttributeDouble(SumoXMLAttr key) const override
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.
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 updateGeometry() override
update pre-computed geometry information
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)
double myEndPosPosOverLane
The end position over lane.
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
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
std::string getStoppingPlaceAttribute(SumoXMLAttr key) const
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