Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GNEStopPlan.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// Representation of Stops in netedit
19/****************************************************************************/
20
23#include <netedit/GNENet.h>
24#include <netedit/GNEUndoList.h>
27
28#include "GNEStopPlan.h"
29
30// ===========================================================================
31// member method definitions
32// ===========================================================================
33#ifdef _MSC_VER
34#pragma warning(push)
35#pragma warning(disable: 4355) // mask warning about "this" in initializers
36#endif
38 GNEDemandElement("", net, "", tag, GNEPathElement::Options::DEMAND_ELEMENT),
39 GNEDemandElementPlan(this, -1, -1) {
40}
41
42
43GNEStopPlan::GNEStopPlan(SumoXMLTag tag, GNEDemandElement* personParent, const GNEPlanParents& planParameters,
44 const double endPos, const SUMOTime duration, const SUMOTime until, const std::string& actType,
45 bool friendlyPos, const int parameterSet) :
46 GNEDemandElement(personParent, tag, GNEPathElement::Options::DEMAND_ELEMENT),
47 GNEDemandElementPlan(this, -1, endPos),
48 myDuration(duration),
49 myUntil(until),
50 myActType(actType),
51 myFriendlyPos(friendlyPos),
52 myParametersSet(parameterSet) {
53 // set parents
54 setParents<GNEJunction*>(planParameters.getJunctions());
55 setParents<GNEEdge*>(planParameters.getEdges());
56 setParents<GNEAdditional*>(planParameters.getAdditionalElements());
57 setParents<GNEDemandElement*>(planParameters.getDemandElements(personParent));
58 // update centering boundary without updating grid
60}
61#ifdef _MSC_VER
62#pragma warning(pop)
63#endif
64
65
67
68
73
74
77 return nullptr;
78}
79
80
81const Parameterised*
83 return nullptr;
84}
85
86
87void
106
107
112
113
114std::string
118
119
120void
122 // currently the only solution is removing stop
123}
124
125
128 return SVC_PASSENGER;
129}
130
131
132const RGBColor&
136
137
138void
140 const auto& viewSettings = myNet->getViewNet()->getVisualisationSettings();
141 PositionVector shape;
142 // update geometry depending of parent
143 if (getParentAdditionals().size() > 0) {
144 const double stopWidth = (getParentAdditionals().front()->getTagProperty()->getTag() == SUMO_TAG_BUS_STOP) ?
145 viewSettings.stoppingPlaceSettings.busStopWidth : viewSettings.stoppingPlaceSettings.trainStopWidth;
146 // get busStop shape
147 const PositionVector& busStopShape = getParentAdditionals().front()->getAdditionalGeometry().getShape();
148 PositionVector shapeA = {busStopShape[-1], busStopShape[-2]};
149 PositionVector shapeB = {busStopShape[-1], busStopShape[-2]};
152 shape = {shapeA.positionAtOffset2D(stopWidth), shapeB.positionAtOffset2D(stopWidth)};
153 } else if (getParentEdges().size() > 0) {
154 // get front and back lane
155 const GNELane* frontLane = getParentEdges().front()->getChildLanes().front();
156 const GNELane* backLane = getParentEdges().front()->getChildLanes().back();
157 // calculate front position
159 frontLane->getDrawingConstants()->getDrawingWidth());
160 // calulate length between both shapes
161 const double length = backLane->getLaneShape().distance2D(frontPosition, true);
162 // calculate back position
164 (length + backLane->getDrawingConstants()->getDrawingWidth() - frontLane->getDrawingConstants()->getDrawingWidth()) * -1);
165 // update demand element geometry using both positions
166 shape = {frontPosition, backPosition};
167 }
168 // extrapolate for sign
169 shape.extrapolate(0.1, true);
171 shape.extrapolate(viewSettings.additionalSettings.stopEdgeSize - 0.1, true);
172 mySignPosition = shape.front();
173}
174
175
180
181
182std::string
184 return getParentDemandElements().front()->getID();
185}
186
187
188double
192
193
198
199
200void
201GNEStopPlan::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
202 // geometry of this element cannot be splitted
203}
204
205
206void
208 // check if stop can be draw
209 if ((getTagProperty()->isPlanStopPerson() && checkDrawPersonPlan()) ||
210 (getTagProperty()->isPlanStopContainer() && checkDrawContainerPlan())) {
211 // Obtain exaggeration of the draw
212 const double exaggeration = getExaggeration(s);
213 // get detail level
214 const auto d = s.getDetailLevel(exaggeration);
215 // draw geometry only if we'rent in drawForObjectUnderCursor mode
217 // declare stop color
219 // Add layer matrix matrix
221 // translate to front
223 // declare stop color
224 // declare central line color
225 const RGBColor centralLineColor = drawUsingSelectColor() ? stopColor.changedBrightness(-32) : RGBColor::WHITE;
226 // set base color
227 GLHelper::setColor(stopColor);
228 // Draw the area using shape, shapeRotations, shapeLengths and value of exaggeration
230 // move to front
231 glTranslated(0, 0, .1);
232 // set central color
233 GLHelper::setColor(centralLineColor);
234 // Draw the area using shape, shapeRotations, shapeLengths and value of exaggeration
235 GUIGeometry::drawGeometry(d, myDemandElementGeometry, 0.05 * exaggeration);
236 // move to icon position and front
237 glTranslated(mySignPosition.x(), mySignPosition.y(), .1);
238 // rotate over lane
240 // draw icon depending of detail level
242 // set color
243 glColor3d(1, 1, 1);
244 // rotate texture
245 glRotated(180, 0, 0, 1);
246 // draw texture
247 if (drawUsingSelectColor()) {
249 } else {
251 }
252 } else {
253 // set stop color
254 GLHelper::setColor(stopColor);
255 // draw filled circle
257 }
258 // pop layer matrix
260 // draw lock icon
262 // draw dotted contour
265 }
266 // calculate contour and draw dotted geometry
267 if (getParentLanes().size() > 0) {
268 myStopContour.calculateContourExtrudedShape(s, d, this, myDemandElementGeometry.getShape(), getType(), 0.3, exaggeration, false, true, 0, nullptr, getParentLanes().front()->getParentEdge());
269 myStopSignContour.calculateContourCircleShape(s, d, this, mySignPosition, s.additionalSettings.stopEdgeSize, getType(), exaggeration, getParentLanes().front()->getParentEdge());
270 } else if (getParentEdges().size() > 0) {
271 myStopContour.calculateContourExtrudedShape(s, d, this, myDemandElementGeometry.getShape(), getType(), 0.3, exaggeration, false, true, 0, nullptr, getParentEdges().front());
273 } else {
274 myStopContour.calculateContourExtrudedShape(s, d, this, myDemandElementGeometry.getShape(), getType(), 0.3, exaggeration, false, true, 0, nullptr, getParentAdditionals().front());
276 }
277 }
278 // check if draw plan parent
279 if (getParentDemandElements().at(0)->getPreviousChildDemandElement(this) == nullptr) {
280 getParentDemandElements().at(0)->drawGL(s);
281 }
282}
283
284
285void
287 // only update geometry
289}
290
291
292void
293GNEStopPlan::drawLanePartialGL(const GUIVisualizationSettings& /*s*/, const GNESegment* /*segment*/, const double /*offsetFront*/) const {
294 // Stops don't use drawJunctionPartialGL
295}
296
297
298void
299GNEStopPlan::drawJunctionPartialGL(const GUIVisualizationSettings& /*s*/, const GNESegment* /*segment*/, const double /*offsetFront*/) const {
300 // Stops don't use drawJunctionPartialGL
301}
302
303
304GNELane*
308
309
310GNELane*
314
315
316std::string
318 switch (key) {
320 if (isAttributeEnabled(key)) {
321 return time2string(myDuration);
322 } else {
323 return "";
324 }
325 case SUMO_ATTR_UNTIL:
326 if (isAttributeEnabled(key)) {
327 return time2string(myUntil);
328 } else {
329 return "";
330 }
332 return myActType;
334 return toString(myFriendlyPos);
335 default:
336 return getPlanAttribute(key);
337 }
338}
339
340
341double
345
346
351
352
353void
354GNEStopPlan::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
355 switch (key) {
357 case SUMO_ATTR_UNTIL:
360 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
361 break;
362 default:
363 setPlanAttribute(key, value, undoList);
364 break;
365 }
366}
367
368
369bool
370GNEStopPlan::isValid(SumoXMLAttr key, const std::string& value) {
371 switch (key) {
373 case SUMO_ATTR_UNTIL:
374 if (canParse<SUMOTime>(value)) {
375 return parse<SUMOTime>(value) >= 0;
376 } else {
377 return false;
378 }
380 return true;
382 return canParse<bool>(value);
383 default:
384 return isPlanValid(key, value);
385 }
386}
387
388
389void
391 switch (key) {
393 case SUMO_ATTR_UNTIL:
394 undoList->add(new GNEChange_ToggleAttribute(this, key, true), true);
395 break;
396 default:
397 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
398 }
399}
400
401
402void
404 switch (key) {
406 case SUMO_ATTR_UNTIL:
407 undoList->add(new GNEChange_ToggleAttribute(this, key, false), true);
408 break;
409 default:
410 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
411 }
412}
413
414
415bool
417 switch (key) {
419 return (myParametersSet & STOP_DURATION_SET) != 0;
420 case SUMO_ATTR_UNTIL:
421 return (myParametersSet & STOP_UNTIL_SET) != 0;
422 default:
423 return isPlanAttributeEnabled(key);
424 }
425}
426
427
428std::string
430 return getTagStr();
431}
432
433
434std::string
438
439// ===========================================================================
440// private
441// ===========================================================================
442
443void
444GNEStopPlan::setAttribute(SumoXMLAttr key, const std::string& value) {
445 switch (key) {
447 if (value.empty()) {
448 toggleAttribute(key, false);
449 } else {
450 toggleAttribute(key, true);
451 myDuration = string2time(value);
452 }
453 break;
454 case SUMO_ATTR_UNTIL:
455 if (value.empty()) {
456 toggleAttribute(key, false);
457 } else {
458 toggleAttribute(key, true);
459 myUntil = string2time(value);
460 }
461 break;
463 myActType = value;
464 break;
466 myFriendlyPos = parse<bool>(value);
467 break;
468 default:
469 setPlanAttribute(key, value);
470 break;
471 }
472}
473
474
475void
477 switch (key) {
479 if (value) {
481 } else {
482 myParametersSet &= ~STOP_DURATION_SET;
483 }
484 break;
485 case SUMO_ATTR_UNTIL:
486 if (value) {
488 } else {
489 myParametersSet &= ~STOP_UNTIL_SET;
490 }
491 break;
492 default:
493 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
494 }
495}
496
497/****************************************************************************/
long long int SUMOTime
Definition GUI.h:36
@ STOPPERSON_SELECTED
#define DEG2RAD(x)
Definition GeomHelper.h:35
SUMOTime string2time(const std::string &r)
convert string to SUMOTime
Definition SUMOTime.cpp:46
std::string time2string(SUMOTime t, bool humanReadable)
convert SUMOTime to string (independently of global format setting)
Definition SUMOTime.cpp:91
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types.
@ SVC_PASSENGER
vehicle is a passenger car (a "normal" car)
const int STOP_DURATION_SET
const int STOP_UNTIL_SET
SumoXMLTag
Numbers representing SUMO-XML - element names.
@ SUMO_TAG_BUS_STOP
A bus stop.
@ SUMO_TAG_STOP
stop for vehicles
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ SUMO_ATTR_ACTTYPE
@ SUMO_ATTR_FRIENDLY_POS
@ GNE_ATTR_PLAN_GEOMETRY_ENDPOS
person/container geometry end position
@ SUMO_ATTR_UNTIL
@ SUMO_ATTR_DURATION
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:46
A class that stores a 2D geometrical boundary.
Definition Boundary.h:39
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 drawFilledCircleDetailled(const GUIVisualizationSettings::Detail d, const double radius)
Draws a filled circle around (0,0) depending of level of detail.
Definition GLHelper.cpp:534
static void pushMatrix()
push matrix
Definition GLHelper.cpp:118
bool isAttributeCarrierSelected() const
check if attribute carrier is selected
const std::string & getTagStr() const
get tag assigned to this object in string format
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
friend class GNEChange_ToggleAttribute
const GNETagProperties * getTagProperty() const
get tagProperty associated with this Attribute Carrier
GNENet * myNet
pointer to net
static void changeAttribute(GNEAttributeCarrier *AC, SumoXMLAttr key, const std::string &value, GNEUndoList *undoList, const bool force=false)
change attribute
void calculateContourExtrudedShape(const GUIVisualizationSettings &s, const GUIVisualizationSettings::Detail d, const GUIGlObject *glObject, const PositionVector &shape, const double layer, const double extrusionWidth, const double scale, const bool closeFirstExtrem, const bool closeLastExtrem, const double offset, const GNESegment *segment, const GUIGlObject *boundaryParent, const bool addToSelectedObjects=true) const
calculate contour extruded (used in elements formed by a central shape)
void calculateContourCircleShape(const GUIVisualizationSettings &s, const GUIVisualizationSettings::Detail d, const GUIGlObject *glObject, const Position &pos, double radius, const double layer, const double scale, const GUIGlObject *boundaryParent) const
calculate contour (circle elements)
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...)
GUIGeometry myDemandElementGeometry
demand element geometry (also called "stacked geometry")
Problem
enum class for demandElement problems
GNEDemandElement * getPreviousChildDemandElement(const GNEDemandElement *demandElement) const
get previous child demand element to the given demand element
bool isPlanValid(SumoXMLAttr key, const std::string &value)
check if plan attribute is valid
Boundary getPlanCenteringBoundary() const
get plan centering boundary
Position getPlanPositionInView() const
Returns position of additional in view.
std::string getPersonPlanProblem() const
get plan problem
Position getPlanAttributePosition(SumoXMLAttr key) const
get plan attribute position
GNEDemandElement::Problem isPlanPersonValid() const
check if plan is valid
GNEMoveElementPlan * myMoveElementPlan
move element plan
std::string getPlanHierarchyName() const
get plan Hierarchy Name (Used in AC Hierarchy)
void writeLocationAttributes(OutputDevice &device) const
write plan element common attributes
bool checkDrawPersonPlan() const
check if person plan can be drawn
double getPlanAttributeDouble(SumoXMLAttr key) const
get plan attribute double
void setPlanAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
set plan attribute
std::string getPlanAttribute(SumoXMLAttr key) const
get plan attribute string
bool isPlanAttributeEnabled(SumoXMLAttr key) const
check if plan attribute is enabled
bool checkDrawContainerPlan() const
check if container plan can be drawn
GNELane * getLastPlanPathLane() const
get last plan path lane
void updatePlanCenteringBoundary(const bool updateGrid)
update plan centering boundary
GNELane * getFirstPlanPathLane() const
get first plan path lane
const GNEHierarchicalContainerParents< GNEAdditional * > & getParentAdditionals() const
get parent additionals
const GNEHierarchicalContainerParents< GNEDemandElement * > & getParentDemandElements() const
get parent demand elements
const GNEHierarchicalContainerParents< GNEEdge * > & getParentEdges() const
get parent edges
const GNEHierarchicalContainerChildren< GNELane * > & getChildLanes() const
get child lanes
const GNEHierarchicalContainerParents< GNELane * > & getParentLanes() const
get parent lanes
double getDrawingWidth() const
get lane drawing width
Definition GNELane.cpp:118
const PositionVector & getLaneShape() const
get elements shape
Definition GNELane.cpp:232
const DrawingConstants * getDrawingConstants() const
get lane drawing constants (previously calculated in drawGL())
Definition GNELane.cpp:254
A NBNetBuilder extended by visualisation and editing capabilities.
Definition GNENet.h:42
GNEViewNet * getViewNet() const
get view net
Definition GNENet.cpp:2193
GNEPlanParents (used for group all plan parents)
std::vector< GNEDemandElement * > getDemandElements(GNEDemandElement *parent) const
get demand elements (used in plan constructors)
std::vector< GNEAdditional * > getAdditionalElements() const
get additionalElements (used in plan constructors)
std::vector< GNEEdge * > getEdges() const
get edges (used in plan constructors)
std::vector< GNEJunction * > getJunctions() const
get junctions (used in plan constructors)
GNEContour myStopContour
variable used for draw contours
GNEStopPlan(SumoXMLTag tag, GNENet *net)
default constructor
bool isAttributeEnabled(SumoXMLAttr key) const
std::string getPopUpID() const override
get PopPup ID (Used in AC Hierarchy)
double getAttributeDouble(SumoXMLAttr key) const override
std::string getParentName() const
Returns the name of the parent object.
void drawLanePartialGL(const GUIVisualizationSettings &s, const GNESegment *segment, const double offsetFront) const
Draws partial object over lane.
SUMOTime myDuration
duration
GNEContour myStopSignContour
variable used for draw sign contours
bool myFriendlyPos
friendly pos
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList) override
void toggleAttribute(SumoXMLAttr key, const bool value)
method for enable or disable the attribute and nothing else (used in GNEChange_ToggleAttribute)
std::string getHierarchyName() const override
get Hierarchy Name (Used in AC Hierarchy)
SUMOVehicleClass getVClass() const
obtain VClass related with this demand element
void enableAttribute(SumoXMLAttr key, GNEUndoList *undoList)
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
GNEMoveElement * getMoveElement() const override
methods to retrieve the elements linked to this stopPlan
SUMOTime myUntil
until
Problem isDemandElementValid() const
check if current demand element is valid to be written into XML (by default true, can be reimplemente...
GNELane * getLastPathLane() const
get last path lane
void computePathElement()
compute pathElement
Position mySignPosition
sign position
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
Position getAttributePosition(SumoXMLAttr key) const override
void splitEdgeGeometry(const double splitPosition, const GNENetworkElement *originalElement, const GNENetworkElement *newElement, GNEUndoList *undoList)
split geometry
void updateGeometry() override
update pre-computed geometry information
void fixDemandElementProblem()
fix demand element problem (by default throw an exception, has to be reimplemented in children)
std::string getDemandElementProblem() const
return a string with the current demand element problem (by default empty, can be reimplemented in ch...
std::string myActType
act type
Position getPositionInView() const
Returns position of demand element in view.
bool isValid(SumoXMLAttr key, const std::string &value) override
std::string getAttribute(SumoXMLAttr key) const override
inherited from GNEAttributeCarrier
GNELane * getFirstPathLane() const
get first path lane
void disableAttribute(SumoXMLAttr key, GNEUndoList *undoList)
~GNEStopPlan()
destructor
const RGBColor & getColor() const
get color
Parameterised * getParameters() override
get parameters associated with this stopPlan
void writeDemandElement(OutputDevice &device) const
write demand element element into a xml file
double getExaggeration(const GUIVisualizationSettings &s) const
return exaggeration associated with this GLObject
int myParametersSet
parameter set
void drawJunctionPartialGL(const GUIVisualizationSettings &s, const GNESegment *segment, const double offsetFront) const
Draws partial object over junction.
void add(GNEChange *command, bool doit=false, bool merge=true)
Add new command, executing it if desired. The new command will be merged with the previous command if...
static void rotateOverLane(const double rot)
rotate over lane (used by Lock icons, detector logos, etc.)
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)
static GUIGlID getTexture(GUITexture which)
returns a texture previously defined in the enum GUITexture
static void drawTexturedBox(int which, double size)
Draws a named texture as a box with the given size.
Stores the information about how to visualize structures.
GUIVisualizationSizeSettings addSize
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.
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.
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 y() const
Returns the y-position.
Definition Position.h:57
A list of positions.
double distance2D(const Position &p, bool perpendicular=false) const
closest 2D-distance to point p (or -1 if perpendicular is true and the point is beyond this vector)
void extrapolate(const double val, const bool onlyFirst=false, const bool onlyLast=false)
extrapolate position vector
void rotateAroundFirstElement2D(double angle)
Position positionAtOffset2D(double pos, double lateralOffset=0, bool extrapolateBeyond=false) const
Returns the position at the given length.
static const RGBColor WHITE
Definition RGBColor.h:195
RGBColor changedBrightness(int change, int toChange=3) const
Returns a new color with altered brightness.
Definition RGBColor.cpp:200
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 double stopEdgeSize
stopEdges size
RGBColor selectedPersonPlanColor
person plan selection color (Rides, Walks, stopPersons...)
RGBColor stopPersonColor
color for stopPersons
static const double segmentWidthSmall
width of small dotted contour segments
static const double segmentWidth
width of dotted contour segments
double getExaggeration(const GUIVisualizationSettings &s, const GUIGlObject *o, double factor=20) const
return the drawing size including exaggeration and constantSize values