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-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 halt at (GNE version)
19/****************************************************************************/
20
21#include <netedit/GNENet.h>
27
28#include "GNEContainerStop.h"
29
30// ===========================================================================
31// method definitions
32// ===========================================================================
33
37
38
39GNEContainerStop::GNEContainerStop(const std::string& id, GNENet* net, const std::string& filename, GNELane* lane, const double startPos, const double endPos,
40 const std::string& name, const std::vector<std::string>& lines, int containerCapacity, double parkingLength, const RGBColor& color,
41 bool friendlyPosition, const Parameterised::Map& parameters) :
42 GNEStoppingPlace(id, net, filename, SUMO_TAG_CONTAINER_STOP, lane, startPos, endPos, name, friendlyPosition, color, parameters),
43 myLines(lines),
44 myContainerCapacity(containerCapacity),
45 myParkingLength(parkingLength) {
46 // update centering boundary without updating grid
48}
49
50
52
53
54void
87
88
89void
91 // Get value of option "lefthand"
92 const double offsetSign = OptionsCont::getOptions().getBool("lefthand") ? -1 : 1;
93 // Update common geometry of stopping place
94 setStoppingPlaceGeometry(getParentLanes().front()->getParentEdge()->getNBEdge()->getLaneWidth(getParentLanes().front()->getIndex()) / 2);
95 // Obtain a copy of the shape
97 // move entire shape and update
98 tmpShape.move2side(2 * offsetSign);
100 // Move shape to side
102 // Get position of the sign
103 mySymbolPosition = tmpShape.getLineCenter();
104}
105
106
107void
109 // first check if additional has to be drawn
111 // Obtain exaggeration of the draw
112 const double containerStopExaggeration = getExaggeration(s);
113 // check if draw moving geometry points
114 const bool movingGeometryPoints = drawMovingGeometryPoints(false);
115 // get detail level
116 const auto d = s.getDetailLevel(containerStopExaggeration);
117 // draw geometry only if we'rent in drawForObjectUnderCursor mode
119 // declare colors
120 RGBColor baseColor, signColor;
121 // set colors
122 if (mySpecialColor) {
123 baseColor = *mySpecialColor;
124 signColor = baseColor.changedBrightness(-32);
125 } else if (drawUsingSelectColor()) {
127 signColor = baseColor.changedBrightness(-32);
128 } else if (myColor != RGBColor::INVISIBLE) {
129 baseColor = myColor;
131 } else {
132 baseColor = s.colorSettings.containerStopColor;
134 }
135 // draw parent and child lines
137 // Add a layer matrix
139 // translate to front
141 // set base color
142 GLHelper::setColor(baseColor);
143 // Draw the area using shape, shapeRotations, shapeLengths and value of exaggeration
145 // draw lines
146 drawLines(d, myLines, baseColor);
147 // draw sign
148 drawSign(s, d, containerStopExaggeration, baseColor, signColor, "C");
149 // draw geometry points
150 if (movingGeometryPoints && (myStartPosition != INVALID_DOUBLE)) {
152 }
153 if (movingGeometryPoints && (myEndPosition != INVALID_DOUBLE)) {
155 }
156 // pop layer matrix
158 // draw lock icon
160 // Draw additional ID
162 // draw additional name
164 // draw dotted contours
165 if (movingGeometryPoints) {
168 } else {
171 }
172 }
173 // draw demand element children
175 // calculate contours
176 calculateStoppingPlaceContour(s, d, s.stoppingPlaceSettings.containerStopWidth, containerStopExaggeration, movingGeometryPoints);
177 }
178}
179
180
181std::string
183 switch (key) {
184
185 case SUMO_ATTR_LINES:
186 return joinToString(myLines, " ");
191 default:
192 return getStoppingPlaceAttribute(this, key);
193 }
194}
195
196
197double
201
202
203void
204GNEContainerStop::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
205 switch (key) {
206 case SUMO_ATTR_LINES:
209 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
210 break;
211 default:
212 setStoppingPlaceAttribute(key, value, undoList);
213 break;
214 }
215}
216
217
218bool
219GNEContainerStop::isValid(SumoXMLAttr key, const std::string& value) {
220 switch (key) {
221 case SUMO_ATTR_LINES:
222 return true;
224 return canParse<int>(value) && (parse<int>(value) >= 0);
226 return canParse<double>(value) && (parse<double>(value) >= 0);
227 default:
228 return isStoppingPlaceValid(key, value);
229 }
230}
231
232// ===========================================================================
233// private
234// ===========================================================================
235
236void
237GNEContainerStop::setAttribute(SumoXMLAttr key, const std::string& value) {
238 switch (key) {
239 case SUMO_ATTR_LINES:
240 myLines = GNEAttributeCarrier::parse<std::vector<std::string> >(value);
241 break;
243 myContainerCapacity = GNEAttributeCarrier::parse<int>(value);
244 break;
246 if (value.empty()) {
248 } else {
249 myParkingLength = GNEAttributeCarrier::parse<double>(value);
250 }
251 break;
252 default:
253 setStoppingPlaceAttribute(this, key, value);
254 break;
255 }
256}
257
258
259/****************************************************************************/
@ GLO_CONTAINER_STOP
a 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
@ SUMO_ATTR_CONTAINER_CAPACITY
@ SUMO_ATTR_NAME
@ SUMO_ATTR_FRIENDLY_POS
@ SUMO_ATTR_COLOR
A color information.
@ SUMO_ATTR_ID
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
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
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
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
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
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
double getAttributeDouble(SumoXMLAttr key) const
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 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:2193
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 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
RGBColor myColor
RGB color.
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)
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.
void updateGeometry(const PositionVector &shape)
update entire geometry
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.
std::map< std::string, std::string > Map
parameters map
void writeParams(OutputDevice &device) const
write Params in the given outputdevice
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:198
RGBColor changedBrightness(int change, int toChange=3) const
Returns a new color with altered brightness.
Definition RGBColor.cpp:200
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