Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GNEContainerStop.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/****************************************************************************/
18// A lane area vehicles can halt at (GNE version)
19/****************************************************************************/
20#include <config.h>
21
23#include <netedit/GNENet.h>
24#include <netedit/GNEUndoList.h>
25#include <netedit/GNEViewNet.h>
31
32#include "GNEContainerStop.h"
33
34// ===========================================================================
35// method definitions
36// ===========================================================================
37
40 nullptr, 0, 0, "", false, Parameterised::Map()),
41 myContainerCapacity(0),
42 myParkingLength(0),
43 myColor(RGBColor::BLACK) {
44 // reset default values
46}
47
48
49GNEContainerStop::GNEContainerStop(const std::string& id, GNELane* lane, GNENet* net, const double startPos, const double endPos,
50 const std::string& name, const std::vector<std::string>& lines, int containerCapacity, double parkingLength, const RGBColor& color,
51 bool friendlyPosition, const Parameterised::Map& parameters) :
53 lane, startPos, endPos, name, friendlyPosition, parameters),
54 myLines(lines),
55 myContainerCapacity(containerCapacity),
56 myParkingLength(parkingLength),
57 myColor(color) {
58 // update centering boundary without updating grid
60}
61
62
64
65
66void
99
100
101void
103 // Get value of option "lefthand"
104 const double offsetSign = OptionsCont::getOptions().getBool("lefthand") ? -1 : 1;
105 // Update common geometry of stopping place
106 setStoppingPlaceGeometry(getParentLanes().front()->getParentEdge()->getNBEdge()->getLaneWidth(getParentLanes().front()->getIndex()) / 2);
107 // Obtain a copy of the shape
109 // move entire shape and update
110 tmpShape.move2side(2 * offsetSign);
112 // Move shape to side
114 // Get position of the sign
115 mySymbolPosition = tmpShape.getLineCenter();
116}
117
118
119void
121 // first check if additional has to be drawn
123 // Obtain exaggeration of the draw
124 const double containerStopExaggeration = getExaggeration(s);
125 // check if draw moving geometry points
126 const bool movingGeometryPoints = drawMovingGeometryPoints(false);
127 // get detail level
128 const auto d = s.getDetailLevel(containerStopExaggeration);
129 // draw geometry only if we'rent in drawForObjectUnderCursor mode
131 // declare colors
132 RGBColor baseColor, signColor;
133 // set colors
134 if (mySpecialColor) {
135 baseColor = *mySpecialColor;
136 signColor = baseColor.changedBrightness(-32);
137 } else if (drawUsingSelectColor()) {
139 signColor = baseColor.changedBrightness(-32);
140 } else if (myColor != RGBColor::INVISIBLE) {
141 baseColor = myColor;
143 } else {
144 baseColor = s.colorSettings.containerStopColor;
146 }
147 // draw parent and child lines
149 // Add a layer matrix
151 // translate to front
153 // set base color
154 GLHelper::setColor(baseColor);
155 // Draw the area using shape, shapeRotations, shapeLengths and value of exaggeration
157 // draw lines
158 drawLines(d, myLines, baseColor);
159 // draw sign
160 drawSign(s, d, containerStopExaggeration, baseColor, signColor, "C");
161 // draw geometry points
162 if (movingGeometryPoints && (myStartPosition != INVALID_DOUBLE)) {
164 }
165 if (movingGeometryPoints && (myEndPosition != INVALID_DOUBLE)) {
167 }
168 // pop layer matrix
170 // draw lock icon
172 // Draw additional ID
174 // draw additional name
176 // draw dotted contours
177 if (movingGeometryPoints) {
180 } else {
183 }
184 }
185 // draw demand element children
187 // calculate contours
188 calculateStoppingPlaceContour(s, d, s.stoppingPlaceSettings.containerStopWidth, containerStopExaggeration, movingGeometryPoints);
189 }
190}
191
192
193std::string
195 switch (key) {
196 case SUMO_ATTR_ID:
197 return getMicrosimID();
198 case SUMO_ATTR_LANE:
199 return getParentLanes().front()->getID();
203 } else {
204 return "";
205 }
206 case SUMO_ATTR_ENDPOS:
208 return toString(myEndPosition);
209 } else {
210 return "";
211 }
212 case SUMO_ATTR_NAME:
213 return myAdditionalName;
216 case SUMO_ATTR_LINES:
217 return joinToString(myLines, " ");
222 case SUMO_ATTR_COLOR:
224 return "";
225 } else {
226 return toString(myColor);
227 }
229 return getParametersStr();
231 return "";
232 default:
233 return getCommonAttribute(key);
234 }
235}
236
237
238void
239GNEContainerStop::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
240 switch (key) {
241 case SUMO_ATTR_ID:
242 case SUMO_ATTR_LANE:
244 case SUMO_ATTR_ENDPOS:
245 case SUMO_ATTR_NAME:
247 case SUMO_ATTR_LINES:
250 case SUMO_ATTR_COLOR:
253 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
254 break;
255 default:
256 setCommonAttribute(key, value, undoList);
257 break;
258 }
259}
260
261
262bool
263GNEContainerStop::isValid(SumoXMLAttr key, const std::string& value) {
264 switch (key) {
265 case SUMO_ATTR_ID:
266 return isValidAdditionalID(value);
267 case SUMO_ATTR_LANE:
268 if (myNet->getAttributeCarriers()->retrieveLane(value, false) != nullptr) {
269 return true;
270 } else {
271 return false;
272 }
274 if (value.empty()) {
275 return true;
276 } else if (canParse<double>(value)) {
277 return SUMORouteHandler::isStopPosValid(parse<double>(value), getAttributeDouble(SUMO_ATTR_ENDPOS), getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength(), POSITION_EPS, myFriendlyPosition);
278 } else {
279 return false;
280 }
281 case SUMO_ATTR_ENDPOS:
282 if (value.empty()) {
283 return true;
284 } else if (canParse<double>(value)) {
285 return SUMORouteHandler::isStopPosValid(getAttributeDouble(SUMO_ATTR_STARTPOS), parse<double>(value), getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength(), POSITION_EPS, myFriendlyPosition);
286 } else {
287 return false;
288 }
289 case SUMO_ATTR_NAME:
292 return canParse<bool>(value);
293 case SUMO_ATTR_LINES:
294 return canParse<std::vector<std::string> >(value);
296 return canParse<int>(value) && (parse<int>(value) > 0 || parse<int>(value) == -1);
298 return canParse<double>(value) && (parse<double>(value) >= 0);
299 case SUMO_ATTR_COLOR:
300 if (value.empty()) {
301 return true;
302 } else {
303 return canParse<RGBColor>(value);
304 }
306 return areParametersValid(value);
307 default:
308 return isCommonValid(key, value);
309 }
310}
311
312// ===========================================================================
313// private
314// ===========================================================================
315
316void
317GNEContainerStop::setAttribute(SumoXMLAttr key, const std::string& value) {
318 switch (key) {
319 case SUMO_ATTR_ID:
320 // update microsimID
321 setAdditionalID(value);
322 break;
323 case SUMO_ATTR_LANE:
325 break;
327 if (value == "") {
329 } else {
330 myStartPosition = parse<double>(value);
331 }
332 break;
333 case SUMO_ATTR_ENDPOS:
334 if (value == "") {
336 } else {
337 myEndPosition = parse<double>(value);
338 }
339 break;
340 case SUMO_ATTR_NAME:
341 myAdditionalName = value;
342 break;
344 myFriendlyPosition = parse<bool>(value);
345 break;
346 case SUMO_ATTR_LINES:
347 myLines = GNEAttributeCarrier::parse<std::vector<std::string> >(value);
348 break;
350 myContainerCapacity = GNEAttributeCarrier::parse<int>(value);
351 break;
353 myParkingLength = GNEAttributeCarrier::parse<double>(value);
354 break;
355 case SUMO_ATTR_COLOR:
356 if (value.empty()) {
358 } else {
359 myColor = GNEAttributeCarrier::parse<RGBColor>(value);
360 }
361 break;
363 setParametersStr(value);
364 break;
367 break;
368 default:
369 setCommonAttribute(key, value);
370 break;
371 }
372}
373
374
375/****************************************************************************/
@ GLO_CONTAINER_STOP
a containerStop
GUIIcon
An enumeration of icons used by the gui applications.
Definition GUIIcons.h:33
@ CONTAINERSTOP
@ SUMO_TAG_CONTAINER_STOP
A container stop.
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ SUMO_ATTR_STARTPOS
@ SUMO_ATTR_LINES
@ SUMO_ATTR_LANE
@ SUMO_ATTR_PARKING_LENGTH
@ SUMO_ATTR_ENDPOS
@ GNE_ATTR_PARAMETERS
parameters "key1=value1|key2=value2|...|keyN=valueN"
@ SUMO_ATTR_CONTAINER_CAPACITY
@ SUMO_ATTR_NAME
@ SUMO_ATTR_FRIENDLY_POS
@ SUMO_ATTR_COLOR
A color information.
@ SUMO_ATTR_ID
@ GNE_ATTR_SHIFTLANEINDEX
shift lane index (only used by elements over lanes)
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
bool isValidAdditionalID(const std::string &value) const
check if a new additional ID is valid
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
void setAdditionalID(const std::string &newID)
set additional ID
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 replaceAdditionalParentLanes(const std::string &value)
replace additional parent lanes
void shiftLaneIndex()
shift lane index
double getExaggeration(const GUIVisualizationSettings &s) const
return exaggeration associated with this GLObject
std::string myAdditionalName
name of additional
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
const std::string getID() const
get ID (all Attribute Carriers have one)
bool isAttributeCarrierSelected() const
check if attribute carrier is selected
void setCommonAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
const GNETagProperties & getTagProperty() const
get tagProperty associated with this Attribute Carrier
bool drawUsingSelectColor() const
check if attribute carrier must be drawn using selecting color.
bool isCommonValid(SumoXMLAttr key, const std::string &value)
void drawInLayer(const double typeOrLayer, const double extraOffset=0) const
draw element in the given layer, or in front if corresponding flag is enabled
void resetDefaultValues()
reset attribute carrier to their default values
GNENet * myNet
pointer to net
std::string getCommonAttribute(SumoXMLAttr key) const
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
std::vector< std::string > myLines
The list of lines that are assigned to this stop.
int myContainerCapacity
maximum number of container that can wait at this stop
RGBColor myColor
RGB color.
GNEContainerStop(GNENet *net)
default constructor
std::string getAttribute(SumoXMLAttr key) const
void writeAdditional(OutputDevice &device) const
write additional element into a xml file
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
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
~GNEContainerStop()
Destructor.
double myParkingLength
custom space for vehicles that park at this stop
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their correspondent attribute are valids
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 std::vector< 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
GNELane * retrieveLane(const std::string &id, bool hardFail=true, bool checkVolatileChange=false) const
get lane by id
A NBNetBuilder extended by visualisation and editing capabilities.
Definition GNENet.h:42
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
get all attribute carriers used in this net
Definition GNENet.cpp:127
GNEViewNet * getViewNet() const
get view net
Definition GNENet.cpp:2163
void updateCenteringBoundary(const bool updateGrid)
update centering boundary (implies change in RTREE)
virtual double getAttributeDouble(SumoXMLAttr key) const
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
void calculateStoppingPlaceContour(const GUIVisualizationSettings &s, const GUIVisualizationSettings::Detail d, const double width, const double exaggeration, const bool movingGeometryPoints) const
check object in view
bool myFriendlyPosition
Flag for friendly position.
void drawLines(const GUIVisualizationSettings::Detail d, const std::vector< std::string > &lines, const RGBColor &color) const
draw lines
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)
const std::string & getDefaultValue(SumoXMLAttr attr) const
return the default value of the attribute of an element
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.
void updateGeometry(const PositionVector &shape)
update entire geometry
const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
const GUIVisualizationSettings & getVisualisationSettings() const
get visualization settings (read only)
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
GUIVisualizationStoppingPlaceSettings stoppingPlaceSettings
StoppingPlace settings.
GUIVisualizationAdditionalSettings additionalSettings
Additional settings.
GUIVisualizationNeteditSizeSettings neteditSizeSettings
netedit size settings
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.
An upper class for objects with additional parameters.
static bool areParametersValid(const std::string &value, bool report=false, const std::string kvsep="=", const std::string sep="|")
check if given string can be parsed to a parameters map "key1=value1|key2=value2|....
std::map< std::string, std::string > Map
parameters map
void setParametersStr(const std::string &paramsString, const std::string kvsep="=", const std::string sep="|")
set the inner key/value map in string format "key1=value1|key2=value2|...|keyN=valueN"
void writeParams(OutputDevice &device) const
write Params in the given outputdevice
std::string getParametersStr(const std::string kvsep="=", const std::string sep="|") const
Returns the inner key/value map in string format "key1=value1|key2=value2|...|keyN=valueN".
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
Position getCentroid() const
Returns the centroid (closes the polygon if unclosed)
static const RGBColor INVISIBLE
Definition RGBColor.h:195
RGBColor changedBrightness(int change, int toChange=3) const
Returns a new color with altered brightness.
Definition RGBColor.cpp:200
static bool isStopPosValid(const double startPos, const double endPos, const double laneLength, const double minLength, const bool friendlyPos)
check if start and end position of a stop is valid
static bool isValidAttribute(const std::string &value)
whether the given string is a valid attribute for a certain key (for example, a name)
static std::string escapeXML(const std::string &orig, const bool maskDoubleHyphen=false)
Replaces the standard escapes by their XML entities.
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 containerStopColor
color for containerStops
RGBColor containerStopColorSign
color for containerStop signs
RGBColor selectedAdditionalColor
additional selection color (busStops, Detectors...)
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
static const double stoppingPlaceSignOffset
busStop offset
static const double containerStopWidth
containerStop width