Eclipse SUMO - Simulation of Urban MObility
GNEContainerStop.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3// Copyright (C) 2001-2022 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
68 device.openTag(getTagProperty().getTag());
69 device.writeAttr(SUMO_ATTR_ID, getID());
70 if (!myAdditionalName.empty()) {
72 }
73 device.writeAttr(SUMO_ATTR_LANE, getParentLanes().front()->getID());
76 }
79 }
81 device.writeAttr(SUMO_ATTR_FRIENDLY_POS, "true");
82 }
85 }
88 }
91 }
92 if (getAttribute(SUMO_ATTR_COLOR).size() > 0) {
94 }
95 // write parameters (Always after children to avoid problems with additionals.xsd)
96 writeParams(device);
97 device.closeTag();
98}
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);
112 // Move shape to side
114 // Get position of the sign
115 mySignPos = tmpShape.getLineCenter();
116}
117
118
119void
121 // Obtain exaggeration of the draw
122 const double containerStopExaggeration = getExaggeration(s);
123 // first check if additional has to be drawn
125 // check exaggeration
126 if (s.drawAdditionals(containerStopExaggeration)) {
127 // declare colors
128 RGBColor baseColor, signColor;
129 // set colors
130 if (mySpecialColor) {
131 baseColor = *mySpecialColor;
132 signColor = baseColor.changedBrightness(-32);
133 } else if (drawUsingSelectColor()) {
135 signColor = baseColor.changedBrightness(-32);
136 } else if (myColor != RGBColor::INVISIBLE) {
137 baseColor = myColor;
139 } else {
140 baseColor = s.colorSettings.containerStopColor;
142 }
143 // draw parent and child lines
145 // Start drawing adding an gl identificator
147 // Add a layer matrix
149 // translate to front
151 // set base color
152 GLHelper::setColor(baseColor);
153 // Draw the area using shape, shapeRotations, shapeLengths and value of exaggeration
155 // draw detail
156 if (s.drawDetail(s.detailSettings.stoppingPlaceDetails, containerStopExaggeration)) {
157 // draw lines
158 drawLines(s, myLines, baseColor);
159 // draw sign
160 drawSign(s, containerStopExaggeration, baseColor, signColor, "C");
161 }
162 // draw geometry points
165 }
168 }
169 // pop layer matrix
171 // Pop name
173 // draw lock icon
175 // check if mouse is over element
178 // Inspect contour
181 containerStopExaggeration, true, true);
182 }
183 // front element contour
184 if (myNet->getViewNet()->getFrontAttributeCarrier() == this) {
186 containerStopExaggeration, true, true);
187 }
188 // delete contour
189 if (myNet->getViewNet()->drawDeleteContour(this, this)) {
191 containerStopExaggeration, true, true);
192 }
193 // select contour
194 if (myNet->getViewNet()->drawSelectContour(this, this)) {
196 containerStopExaggeration, true, true);
197 }
198 // draw child demand elements
199 for (const auto& demandElement : getChildDemandElements()) {
200 if (!demandElement->getTagProperty().isPlacedInRTree() &&
201 (!demandElement->getTagProperty().isContainerPlan() || demandElement->getTagProperty().isStopContainer())) {
202 demandElement->drawGL(s);
203 }
204 }
205 }
206 // Draw additional ID
208 // draw additional name
210 }
211}
212
213
214std::string
216 switch (key) {
217 case SUMO_ATTR_ID:
218 return getMicrosimID();
219 case SUMO_ATTR_LANE:
220 return getParentLanes().front()->getID();
224 } else {
225 return "";
226 }
227 case SUMO_ATTR_ENDPOS:
229 return toString(myEndPosition);
230 } else {
231 return "";
232 }
233 case SUMO_ATTR_NAME:
234 return myAdditionalName;
237 case SUMO_ATTR_LINES:
238 return joinToString(myLines, " ");
243 case SUMO_ATTR_COLOR:
245 return "";
246 } else {
247 return toString(myColor);
248 }
252 return getParametersStr();
254 return "";
255 default:
256 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
257 }
258}
259
260
261void
262GNEContainerStop::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
263 switch (key) {
264 case SUMO_ATTR_ID:
265 case SUMO_ATTR_LANE:
267 case SUMO_ATTR_ENDPOS:
268 case SUMO_ATTR_NAME:
270 case SUMO_ATTR_LINES:
273 case SUMO_ATTR_COLOR:
277 undoList->changeAttribute(new GNEChange_Attribute(this, key, value));
278 break;
279 default:
280 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
281 }
282}
283
284
285bool
286GNEContainerStop::isValid(SumoXMLAttr key, const std::string& value) {
287 switch (key) {
288 case SUMO_ATTR_ID:
289 return isValidAdditionalID(value);
290 case SUMO_ATTR_LANE:
291 if (myNet->getAttributeCarriers()->retrieveLane(value, false) != nullptr) {
292 return true;
293 } else {
294 return false;
295 }
297 if (value.empty()) {
298 return true;
299 } else if (canParse<double>(value)) {
300 return SUMORouteHandler::isStopPosValid(parse<double>(value), getAttributeDouble(SUMO_ATTR_ENDPOS), getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength(), POSITION_EPS, myFriendlyPosition);
301 } else {
302 return false;
303 }
304 case SUMO_ATTR_ENDPOS:
305 if (value.empty()) {
306 return true;
307 } else if (canParse<double>(value)) {
308 return SUMORouteHandler::isStopPosValid(getAttributeDouble(SUMO_ATTR_STARTPOS), parse<double>(value), getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength(), POSITION_EPS, myFriendlyPosition);
309 } else {
310 return false;
311 }
312 case SUMO_ATTR_NAME:
315 return canParse<bool>(value);
316 case SUMO_ATTR_LINES:
317 return canParse<std::vector<std::string> >(value);
319 return canParse<int>(value) && (parse<int>(value) > 0 || parse<int>(value) == -1);
321 return canParse<double>(value) && (parse<double>(value) >= 0);
322 case SUMO_ATTR_COLOR:
323 if (value.empty()) {
324 return true;
325 } else {
326 return canParse<RGBColor>(value);
327 }
329 return canParse<bool>(value);
331 return areParametersValid(value);
332 default:
333 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
334 }
335}
336
337// ===========================================================================
338// private
339// ===========================================================================
340
341void
342GNEContainerStop::setAttribute(SumoXMLAttr key, const std::string& value) {
343 switch (key) {
344 case SUMO_ATTR_ID:
345 // update microsimID
346 setMicrosimID(value);
347 // enable save demand elements if there are stops
348 for (const auto& stop : getChildDemandElements()) {
349 if (stop->getTagProperty().isStop() || stop->getTagProperty().isStopPerson()) {
351 }
352 }
353 break;
354 case SUMO_ATTR_LANE:
356 break;
358 if (value == "") {
360 } else {
361 myStartPosition = parse<double>(value);
362 }
363 break;
364 case SUMO_ATTR_ENDPOS:
365 if (value == "") {
367 } else {
368 myEndPosition = parse<double>(value);
369 }
370 break;
371 case SUMO_ATTR_NAME:
372 myAdditionalName = value;
373 break;
375 myFriendlyPosition = parse<bool>(value);
376 break;
377 case SUMO_ATTR_LINES:
378 myLines = GNEAttributeCarrier::parse<std::vector<std::string> >(value);
379 break;
381 myContainerCapacity = GNEAttributeCarrier::parse<int>(value);
382 break;
384 myParkingLength = GNEAttributeCarrier::parse<double>(value);
385 break;
386 case SUMO_ATTR_COLOR:
387 if (value.empty()) {
389 } else {
390 myColor = GNEAttributeCarrier::parse<RGBColor>(value);
391 }
392 break;
394 if (parse<bool>(value)) {
396 } else {
398 }
399 break;
401 setParametersStr(value);
402 break;
405 break;
406 default:
407 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
408 }
409}
410
411
412/****************************************************************************/
@ 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_SELECTED
element is selected
@ 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
Definition: StdDefs.h:60
T MIN2(T a, T b)
Definition: StdDefs.h:71
std::string joinToString(const std::vector< T > &v, const T_BETWEEN &between, std::streamsize accuracy=gPrecision)
Definition: ToString.h:282
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:583
static void pushName(unsigned int name)
push Name
Definition: GLHelper.cpp:139
static void popMatrix()
pop matrix
Definition: GLHelper.cpp:130
static void popName()
pop Name
Definition: GLHelper.cpp:148
static void pushMatrix()
push matrix
Definition: GLHelper.cpp:117
static void drawRightGeometryPoint(const GNEViewNet *viewNet, const Position &pos, const double rot, const RGBColor &baseColor, const bool ignoreShift=false)
draw right geometry point
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
const RGBColor * mySpecialColor
pointer to special color (used for drawing Additional with a certain color, mainly used for selection...
static void drawLeftGeometryPoint(const GNEViewNet *viewNet, const Position &pos, const double rot, const RGBColor &baseColor, const bool ignoreShift=false)
draw left geometry point
bool isValidAdditionalID(const std::string &newID) const
check if a new additional ID is valid
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
friend class GNEChange_Attribute
declare friend class
const std::string & getTagStr() const
get tag assigned to this object in string format
const GNETagProperties & getTagProperty() const
get tagProperty associated with this Attribute Carrier
void unselectAttributeCarrier(const bool changeFlag=true)
unselect attribute carrier using GUIGlobalSelection
bool drawUsingSelectColor() const
check if attribute carrier must be drawn using selecting color.
void resetDefaultValues()
reset attribute carrier to their default values
GNENet * myNet
pointer to net
void selectAttributeCarrier(const bool changeFlag=true)
select attribute carrier using GUIGlobalSelection
const GNETagProperties & myTagProperty
reference to tagProperty associated with this attribute carrier
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
const std::vector< GNEDemandElement * > & getChildDemandElements() const
return child demand elements
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:132
void requireSaveDemandElements(bool value)
inform that demand elements has to be saved
Definition: GNENet.cpp:2083
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:1987
void updateCenteringBoundary(const bool updateGrid)
update centering boundary (implies change in RTREE)
virtual double getAttributeDouble(SumoXMLAttr key) const
static const double myCircleWidth
circle width resolution for all stopping places
bool myFriendlyPosition
Flag for friendly position.
void drawLines(const GUIVisualizationSettings &s, const std::vector< std::string > &lines, const RGBColor &color) const
draw lines
void setStoppingPlaceGeometry(double movingToSide)
set geometry common to all stopping places
double myEndPosition
The position this stopping place is located at (-1 means empty)
void drawSign(const GUIVisualizationSettings &s, const double exaggeration, const RGBColor &baseColor, const RGBColor &signColor, const std::string &word) const
draw sign
Position mySignPos
The position of the sign.
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
void changeAttribute(GNEChange_Attribute *change)
special method for change attributes, avoid empty changes, always execute
const GNEViewNetHelper::DataViewOptions & getDataViewOptions() const
get data view options
Definition: GNEViewNet.cpp:656
const GNEAttributeCarrier * getFrontAttributeCarrier() const
get front attributeCarrier
bool drawSelectContour(const GUIGlObject *GLObject, const GNEAttributeCarrier *AC) const
check if draw select contour
bool drawDeleteContour(const GUIGlObject *GLObject, const GNEAttributeCarrier *AC) const
check if draw delete contour
void drawTranslateFrontAttributeCarrier(const GNEAttributeCarrier *AC, double typeOrLayer, const double extraOffset=0)
draw front attributeCarrier
bool isAttributeCarrierInspected(const GNEAttributeCarrier *AC) const
check if attribute carrier is being inspected
static void drawDottedContourShape(const GUIVisualizationSettings &s, const DottedContourType type, const PositionVector &shape, const double width, const double exaggeration, const bool drawFirstExtrem, const bool drawLastExtrem)
draw dotted contour for the given shape (used by additionals)
const std::vector< double > & getShapeRotations() const
The rotations of the single shape parts.
static void drawGeometry(const GUIVisualizationSettings &s, const Position &mousePos, 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
Definition: GUIGeometry.cpp:58
const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
Definition: GUIGlObject.h:141
virtual void setMicrosimID(const std::string &newID)
Changes the microsimID of the object.
void mouseWithinGeometry(const Position center, const double radius) const
check if mouse is within elements geometry (for circles)
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
Definition: GUIGlObject.h:154
GUIGlID getGlID() const
Returns the numerical id of the object.
Definition: GUIGlObject.h:102
const GUIVisualizationSettings & getVisualisationSettings() const
get visualization settings (read only)
virtual Position getPositionInformation() const
Returns the cursor's x/y position within the network.
Stores the information about how to visualize structures.
GUIVisualizationDetailSettings detailSettings
detail settings
bool drawAdditionals(const double exaggeration) const
check if additionals must be drawn
GUIVisualizationColorSettings colorSettings
color settings
GUIVisualizationStoppingPlaceSettings stoppingPlaceSettings
StoppingPlace settings.
bool drawDetail(const double detail, const double exaggeration) const
check if details can be drawn for the given GUIVisualizationDetailSettings and current scale and exxa...
GUIVisualizationAdditionalSettings additionalSettings
Additional 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.
Definition: OptionsCont.cpp:59
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:61
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:251
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.
Definition: Parameterised.h:41
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
Definition: Parameterised.h:45
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 ammount
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 GNEAttributeCarrier *AC, GUIGlObjectType type, const Position viewPosition, 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 stoppingPlaceDetails
details for stopping places
static const double stoppingPlaceSignOffset
busStop offset
static const double containerStopWidth
containerStop width