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-2023 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);
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 // avoid draw invisible elements
144 if (baseColor.alpha() != 0) {
145 // draw parent and child lines
147 // Start drawing adding an gl identificator
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 detail
158 if (s.drawDetail(s.detailSettings.stoppingPlaceDetails, containerStopExaggeration)) {
159 // draw lines
160 drawLines(s, myLines, baseColor);
161 // draw sign
162 drawSign(s, containerStopExaggeration, baseColor, signColor, "C");
163 }
164 // draw geometry points
167 }
170 }
171 // pop layer matrix
173 // Pop name
175 }
176 // draw lock icon
178 // check if mouse is over element
181 // Inspect contour
184 containerStopExaggeration, true, true);
185 }
186 // front element contour
187 if (myNet->getViewNet()->getFrontAttributeCarrier() == this) {
189 containerStopExaggeration, true, true);
190 }
191 // delete contour
192 if (myNet->getViewNet()->drawDeleteContour(this, this)) {
194 containerStopExaggeration, true, true);
195 }
196 // select contour
197 if (myNet->getViewNet()->drawSelectContour(this, this)) {
199 containerStopExaggeration, true, true);
200 }
201 // draw child demand elements
202 for (const auto& demandElement : getChildDemandElements()) {
203 if (!demandElement->getTagProperty().isPlacedInRTree() &&
204 (!demandElement->getTagProperty().isContainerPlan() || demandElement->getTagProperty().isStopContainer())) {
205 demandElement->drawGL(s);
206 }
207 }
208 }
209 // Draw additional ID
211 // draw additional name
213 }
214}
215
216
217std::string
219 switch (key) {
220 case SUMO_ATTR_ID:
221 return getMicrosimID();
222 case SUMO_ATTR_LANE:
223 return getParentLanes().front()->getID();
227 } else {
228 return "";
229 }
230 case SUMO_ATTR_ENDPOS:
232 return toString(myEndPosition);
233 } else {
234 return "";
235 }
236 case SUMO_ATTR_NAME:
237 return myAdditionalName;
240 case SUMO_ATTR_LINES:
241 return joinToString(myLines, " ");
246 case SUMO_ATTR_COLOR:
248 return "";
249 } else {
250 return toString(myColor);
251 }
255 return getParametersStr();
257 return "";
258 default:
259 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
260 }
261}
262
263
264void
265GNEContainerStop::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
266 switch (key) {
267 case SUMO_ATTR_ID:
268 case SUMO_ATTR_LANE:
270 case SUMO_ATTR_ENDPOS:
271 case SUMO_ATTR_NAME:
273 case SUMO_ATTR_LINES:
276 case SUMO_ATTR_COLOR:
280 undoList->changeAttribute(new GNEChange_Attribute(this, key, value));
281 break;
282 default:
283 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
284 }
285}
286
287
288bool
289GNEContainerStop::isValid(SumoXMLAttr key, const std::string& value) {
290 switch (key) {
291 case SUMO_ATTR_ID:
292 return isValidAdditionalID(value);
293 case SUMO_ATTR_LANE:
294 if (myNet->getAttributeCarriers()->retrieveLane(value, false) != nullptr) {
295 return true;
296 } else {
297 return false;
298 }
300 if (value.empty()) {
301 return true;
302 } else if (canParse<double>(value)) {
303 return SUMORouteHandler::isStopPosValid(parse<double>(value), getAttributeDouble(SUMO_ATTR_ENDPOS), getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength(), POSITION_EPS, myFriendlyPosition);
304 } else {
305 return false;
306 }
307 case SUMO_ATTR_ENDPOS:
308 if (value.empty()) {
309 return true;
310 } else if (canParse<double>(value)) {
311 return SUMORouteHandler::isStopPosValid(getAttributeDouble(SUMO_ATTR_STARTPOS), parse<double>(value), getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength(), POSITION_EPS, myFriendlyPosition);
312 } else {
313 return false;
314 }
315 case SUMO_ATTR_NAME:
318 return canParse<bool>(value);
319 case SUMO_ATTR_LINES:
320 return canParse<std::vector<std::string> >(value);
322 return canParse<int>(value) && (parse<int>(value) > 0 || parse<int>(value) == -1);
324 return canParse<double>(value) && (parse<double>(value) >= 0);
325 case SUMO_ATTR_COLOR:
326 if (value.empty()) {
327 return true;
328 } else {
329 return canParse<RGBColor>(value);
330 }
332 return canParse<bool>(value);
334 return areParametersValid(value);
335 default:
336 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
337 }
338}
339
340// ===========================================================================
341// private
342// ===========================================================================
343
344void
345GNEContainerStop::setAttribute(SumoXMLAttr key, const std::string& value) {
346 switch (key) {
347 case SUMO_ATTR_ID:
348 // update microsimID
349 setMicrosimID(value);
350 // enable save demand elements if there are stops
351 for (const auto& stop : getChildDemandElements()) {
352 if (stop->getTagProperty().isStop() || stop->getTagProperty().isStopPerson()) {
354 }
355 }
356 break;
357 case SUMO_ATTR_LANE:
359 break;
361 if (value == "") {
363 } else {
364 myStartPosition = parse<double>(value);
365 }
366 break;
367 case SUMO_ATTR_ENDPOS:
368 if (value == "") {
370 } else {
371 myEndPosition = parse<double>(value);
372 }
373 break;
374 case SUMO_ATTR_NAME:
375 myAdditionalName = value;
376 break;
378 myFriendlyPosition = parse<bool>(value);
379 break;
380 case SUMO_ATTR_LINES:
381 myLines = GNEAttributeCarrier::parse<std::vector<std::string> >(value);
382 break;
384 myContainerCapacity = GNEAttributeCarrier::parse<int>(value);
385 break;
387 myParkingLength = GNEAttributeCarrier::parse<double>(value);
388 break;
389 case SUMO_ATTR_COLOR:
390 if (value.empty()) {
392 } else {
393 myColor = GNEAttributeCarrier::parse<RGBColor>(value);
394 }
395 break;
397 if (parse<bool>(value)) {
399 } else {
401 }
402 break;
404 setParametersStr(value);
405 break;
408 break;
409 default:
410 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
411 }
412}
413
414
415/****************************************************************************/
@ 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
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: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
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
the function-object for an editing operation (abstract base)
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
void requireSaveDemandElements()
inform that demand elements has to be saved
A NBNetBuilder extended by visualisation and editing capabilities.
Definition GNENet.h:42
GNENetHelper::SavingStatus * getSavingStatus() const
get saving status
Definition GNENet.cpp:126
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
get all attribute carriers used in this net
Definition GNENet.cpp:120
GNEViewNet * getViewNet() const
get view net
Definition GNENet.cpp:2030
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
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
const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
virtual void setMicrosimID(const std::string &newID)
Changes the microsimID of the object.
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
bool mouseWithinGeometry(const Position center, const double radius) const
check if mouse is within elements geometry (for circles)
GUIGlID getGlID() const
Returns the numerical id of the object.
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.
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 ammount
Position getLineCenter() const
get line center
Position getCentroid() const
Returns the centroid (closes the polygon if unclosed)
unsigned char alpha() const
Returns the alpha-amount of the color.
Definition RGBColor.cpp:92
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