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-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// Representation of Stops in netedit
19/****************************************************************************/
20#include <netedit/GNENet.h>
21#include <netedit/GNEUndoList.h>
22#include <netedit/GNEViewNet.h>
29
30#include "GNEStopPlan.h"
31
32// ===========================================================================
33// member method definitions
34// ===========================================================================
35
38 GNEPathManager::PathElement::Options::DEMAND_ELEMENT, {}, {}, {}, {}, {}, {}),
39GNEDemandElementPlan(this, -1, -1) {
40 // reset default values
42}
43
44
45GNEStopPlan::GNEStopPlan(GNENet* net, SumoXMLTag tag, GUIIcon icon, GNEDemandElement* personParent, const GNEPlanParents& planParameters,
46 const double endPos, const SUMOTime duration, const SUMOTime until, const std::string& actType, bool friendlyPos, const int parameterSet) :
47 GNEDemandElement(personParent, net, GLO_STOP_PLAN, tag, GUIIconSubSys::getIcon(icon),
48 GNEPathManager::PathElement::Options::DEMAND_ELEMENT,
49 planParameters.getJunctions(), planParameters.getEdges(), {},
50planParameters.getAdditionalElements(), planParameters.getDemandElements(personParent), {}),
51GNEDemandElementPlan(this, -1, endPos),
52myDuration(duration),
53myUntil(until),
54myActType(actType),
55myFriendlyPos(friendlyPos),
56myParametersSet(parameterSet) {
57}
58
59
61
62
67
68
69void
88
89
94
95
96std::string
100
101
102void
104 // currently the only solution is removing stop
105}
106
107
110 return SVC_PASSENGER;
111}
112
113
114const RGBColor&
118
119
120void
122 const auto& viewSettings = myNet->getViewNet()->getVisualisationSettings();
123 PositionVector shape;
124 // update geometry depending of parent
125 if (getParentAdditionals().size() > 0) {
126 const double stopWidth = (getParentAdditionals().front()->getTagProperty().getTag() == SUMO_TAG_BUS_STOP) ?
127 viewSettings.stoppingPlaceSettings.busStopWidth : viewSettings.stoppingPlaceSettings.trainStopWidth;
128 // get busStop shape
129 const PositionVector& busStopShape = getParentAdditionals().front()->getAdditionalGeometry().getShape();
130 PositionVector shapeA = {busStopShape[-1], busStopShape[-2]};
131 PositionVector shapeB = {busStopShape[-1], busStopShape[-2]};
134 shape = {shapeA.positionAtOffset2D(stopWidth), shapeB.positionAtOffset2D(stopWidth)};
135 } else if (getParentEdges().size() > 0) {
136 // get front and back lane
137 const GNELane* frontLane = getParentEdges().front()->getLanes().front();
138 const GNELane* backLane = getParentEdges().front()->getLanes().back();
139 // calculate front position
141 frontLane->getDrawingConstants()->getDrawingWidth());
142 // calulate length between both shapes
143 const double length = backLane->getLaneShape().distance2D(frontPosition, true);
144 // calculate back position
146 (length + backLane->getDrawingConstants()->getDrawingWidth() - frontLane->getDrawingConstants()->getDrawingWidth()) * -1);
147 // update demand element geometry using both positions
148 shape = {frontPosition, backPosition};
149 }
150 // extrapolate for sign
151 shape.extrapolate(0.1, true);
153 shape.extrapolate(viewSettings.additionalSettings.stopEdgeSize - 0.1, true);
154 mySignPosition = shape.front();
155}
156
157
162
163
164std::string
166 return getParentDemandElements().front()->getID();
167}
168
169
170double
174
175
180
181
182void
183GNEStopPlan::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
184 // geometry of this element cannot be splitted
185}
186
187
188void
190 // check if stop can be draw
191 if ((getTagProperty().isPlanStopPerson() && checkDrawPersonPlan()) ||
192 (getTagProperty().isPlanStopContainer() && checkDrawContainerPlan())) {
193 // Obtain exaggeration of the draw
194 const double exaggeration = getExaggeration(s);
195 // get detail level
196 const auto d = s.getDetailLevel(exaggeration);
197 // draw geometry only if we'rent in drawForObjectUnderCursor mode
199 // declare stop color
201 // Add layer matrix matrix
203 // translate to front
205 // declare stop color
206 // declare central line color
207 const RGBColor centralLineColor = drawUsingSelectColor() ? stopColor.changedBrightness(-32) : RGBColor::WHITE;
208 // set base color
209 GLHelper::setColor(stopColor);
210 // Draw the area using shape, shapeRotations, shapeLengths and value of exaggeration
212 // move to front
213 glTranslated(0, 0, .1);
214 // set central color
215 GLHelper::setColor(centralLineColor);
216 // Draw the area using shape, shapeRotations, shapeLengths and value of exaggeration
217 GUIGeometry::drawGeometry(d, myDemandElementGeometry, 0.05 * exaggeration);
218 // move to icon position and front
219 glTranslated(mySignPosition.x(), mySignPosition.y(), .1);
220 // rotate over lane
222 // draw icon depending of detail level
224 // set color
225 glColor3d(1, 1, 1);
226 // rotate texture
227 glRotated(180, 0, 0, 1);
228 // draw texture
229 if (drawUsingSelectColor()) {
231 } else {
233 }
234 } else {
235 // set stop color
236 GLHelper::setColor(stopColor);
237 // draw filled circle
239 }
240 // pop layer matrix
242 // draw lock icon
244 // draw dotted contour
247 }
248 // calculate contour and draw dotted geometry
249 myStopContour.calculateContourExtrudedShape(s, d, this, myDemandElementGeometry.getShape(), getType(), 0.3, exaggeration, false, true, 0);
251 }
252 // check if draw plan parent
253 if (getParentDemandElements().at(0)->getPreviousChildDemandElement(this) == nullptr) {
254 getParentDemandElements().at(0)->drawGL(s);
255 }
256}
257
258
259void
261 // only update geometry
263}
264
265
266void
267GNEStopPlan::drawLanePartialGL(const GUIVisualizationSettings& /*s*/, const GNEPathManager::Segment* /*segment*/, const double /*offsetFront*/) const {
268 // Stops don't use drawJunctionPartialGL
269}
270
271
272void
273GNEStopPlan::drawJunctionPartialGL(const GUIVisualizationSettings& /*s*/, const GNEPathManager::Segment* /*segment*/, const double /*offsetFront*/) const {
274 // Stops don't use drawJunctionPartialGL
275}
276
277
278GNELane*
282
283
284GNELane*
288
289
290std::string
292 switch (key) {
294 if (isAttributeEnabled(key)) {
295 return time2string(myDuration);
296 } else {
297 return "";
298 }
299 case SUMO_ATTR_UNTIL:
300 if (isAttributeEnabled(key)) {
301 return time2string(myUntil);
302 } else {
303 return "";
304 }
306 return myActType;
308 return toString(myFriendlyPos);
309 default:
310 return getPlanAttribute(key);
311 }
312}
313
314
315double
319
320
325
326
327void
328GNEStopPlan::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
329 switch (key) {
331 case SUMO_ATTR_UNTIL:
334 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
335 break;
336 default:
337 setPlanAttribute(key, value, undoList);
338 break;
339 }
340}
341
342
343bool
344GNEStopPlan::isValid(SumoXMLAttr key, const std::string& value) {
345 switch (key) {
347 case SUMO_ATTR_UNTIL:
348 if (canParse<SUMOTime>(value)) {
349 return parse<SUMOTime>(value) >= 0;
350 } else {
351 return false;
352 }
354 return true;
356 return canParse<bool>(value);
357 default:
358 return isPlanValid(key, value);
359 }
360}
361
362
363void
365 switch (key) {
367 case SUMO_ATTR_UNTIL:
368 undoList->add(new GNEChange_ToggleAttribute(this, key, true), true);
369 break;
370 default:
371 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
372 }
373}
374
375
376void
378 switch (key) {
380 case SUMO_ATTR_UNTIL:
381 undoList->add(new GNEChange_ToggleAttribute(this, key, false), true);
382 break;
383 default:
384 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
385 }
386}
387
388
389bool
391 switch (key) {
393 return (myParametersSet & STOP_DURATION_SET) != 0;
394 case SUMO_ATTR_UNTIL:
395 return (myParametersSet & STOP_UNTIL_SET) != 0;
396 default:
397 return isPlanAttributeEnabled(key);
398 }
399}
400
401
402std::string
404 return getTagStr();
405}
406
407
408std::string
412
413
418
419// ===========================================================================
420// private
421// ===========================================================================
422
423void
424GNEStopPlan::setAttribute(SumoXMLAttr key, const std::string& value) {
425 switch (key) {
427 if (value.empty()) {
428 toggleAttribute(key, false);
429 } else {
430 toggleAttribute(key, true);
431 myDuration = string2time(value);
432 }
433 break;
434 case SUMO_ATTR_UNTIL:
435 if (value.empty()) {
436 toggleAttribute(key, false);
437 } else {
438 toggleAttribute(key, true);
439 myUntil = string2time(value);
440 }
441 break;
443 myActType = value;
444 break;
446 myFriendlyPos = parse<bool>(value);
447 break;
448 default:
449 setPlanAttribute(key, value);
450 break;
451 }
452}
453
454
455void
457 switch (key) {
459 if (value) {
461 } else {
462 myParametersSet &= ~STOP_DURATION_SET;
463 }
464 break;
465 case SUMO_ATTR_UNTIL:
466 if (value) {
468 } else {
469 myParametersSet &= ~STOP_UNTIL_SET;
470 }
471 break;
472 default:
473 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
474 }
475}
476
477
478void
480 // change endPos
481 myArrivalPosition = moveResult.newFirstPos;
482 // update geometry
484}
485
486
487void
489 undoList->begin(this, "endPos of " + getTagStr());
490 // now adjust start position
491 setAttribute(SUMO_ATTR_ENDPOS, toString(moveResult.newFirstPos), undoList);
492 undoList->end();
493}
494
495/****************************************************************************/
long long int SUMOTime
Definition GUI.h:36
@ GLO_STOP_PLAN
a stop plan stop
GUIIcon
An enumeration of icons used by the gui applications.
Definition GUIIcons.h:33
@ 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:69
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_ENDPOS
@ 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:654
static void popMatrix()
pop matrix
Definition GLHelper.cpp:130
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:539
static void pushMatrix()
push matrix
Definition GLHelper.cpp:117
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
bool drawUsingSelectColor() const
check if attribute carrier must be drawn using selecting color.
friend class GNEChange_ToggleAttribute
void resetDefaultValues()
reset attribute carrier to their default values
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
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
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
calculate contour (circle elements)
void 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
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
GNEMoveOperation * getPlanMoveOperation()
get move operation
double getPlanAttributeDouble(SumoXMLAttr key) const
get plan attribute double
void setPlanAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
set plan attribute
double myArrivalPosition
arrival position (used in all plans over edges)
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
GNELane * getFirstPlanPathLane() const
get first plan path lane
const std::vector< GNEDemandElement * > & getParentDemandElements() const
get parent demand elements
const std::vector< GNEAdditional * > & getParentAdditionals() const
get parent additionals
const std::vector< GNEEdge * > & getParentEdges() const
get parent edges
double getDrawingWidth() const
get lane drawing width
Definition GNELane.cpp:124
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
Definition GNELane.h:46
const PositionVector & getLaneShape() const
get elements shape
Definition GNELane.cpp:214
const DrawingConstants * getDrawingConstants() const
get lane drawing constants (previously calculated in drawGL())
Definition GNELane.cpp:236
move operation
move result
double newFirstPos
new first position
A NBNetBuilder extended by visualisation and editing capabilities.
Definition GNENet.h:42
GNEViewNet * getViewNet() const
get view net
Definition GNENet.cpp:2147
GNEPlanParents (used for group all plan parents)
std::vector< GNEAdditional * > getAdditionalElements() const
get additionalElements (used in plan constructors)
GNEContour myStopContour
variable used for draw contours
GNEStopPlan(SumoXMLTag tag, GNENet *net)
default constructor
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
bool isAttributeEnabled(SumoXMLAttr key) const
std::string getParentName() const
Returns the name of the parent object.
void drawLanePartialGL(const GUIVisualizationSettings &s, const GNEPathManager::Segment *segment, const double offsetFront) const
Draws partial object over lane.
SUMOTime myDuration
duration
GNEContour myStopSignContour
variable used for draw sign contours
std::string getAttribute(SumoXMLAttr key) const
inherited from GNEAttributeCarrier
bool myFriendlyPos
friendly pos
void toggleAttribute(SumoXMLAttr key, const bool value)
method for enable or disable the attribute and nothing else (used in GNEChange_ToggleAttribute)
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform demand element changes
SUMOVehicleClass getVClass() const
obtain VClass related with this demand element
void enableAttribute(SumoXMLAttr key, GNEUndoList *undoList)
GNEMoveOperation * getMoveOperation()
get move operation
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
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 updateGeometry()
update pre-computed geometry information
void computePathElement()
compute pathElement
Position mySignPosition
sign position
double getAttributeDouble(SumoXMLAttr key) const
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
void splitEdgeGeometry(const double splitPosition, const GNENetworkElement *originalElement, const GNENetworkElement *newElement, GNEUndoList *undoList)
split geometry
void fixDemandElementProblem()
fix demand element problem (by default throw an exception, has to be reimplemented in children)
const Parameterised::Map & getACParametersMap() const
get parameters map
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.
GNELane * getFirstPathLane() const
get first path lane
void disableAttribute(SumoXMLAttr key, GNEUndoList *undoList)
~GNEStopPlan()
destructor
const RGBColor & getColor() const
get color
void commitMoveShape(const GNEMoveResult &moveResult, GNEUndoList *undoList)
commit move shape
void writeDemandElement(OutputDevice &device) const
write demand element element into a xml file
Position getAttributePosition(SumoXMLAttr key) const
double getExaggeration(const GUIVisualizationSettings &s) const
return exaggeration associated with this GLObject
void setMoveShape(const GNEMoveResult &moveResult)
set move shape
int myParametersSet
parameter set
void drawJunctionPartialGL(const GUIVisualizationSettings &s, const GNEPathManager::Segment *segment, const double offsetFront) const
Draws partial object over junction.
bool hasAttribute(SumoXMLAttr attr) const
check if current TagProperties owns the attribute "attr"
void end()
End undo command sub-group. If the sub-group is still empty, it will be deleted; otherwise,...
void begin(GUIIcon icon, const std::string &description)
Begin undo command sub-group with current supermode. This begins a new group of commands that are tre...
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...
void drawTranslateFrontAttributeCarrier(const GNEAttributeCarrier *AC, double typeOrLayer, const double extraOffset=0)
draw front attributeCarrier
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.
std::map< std::string, std::string > Map
parameters map
const Parameterised::Map & getParametersMap() const
Returns the inner key/value map.
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:55
double y() const
Returns the y-position.
Definition Position.h:60
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) const
Returns the position at the given length.
static const RGBColor WHITE
Definition RGBColor.h:192
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