Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GNEWalk.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2001-2025 German Aerospace Center (DLR) and others.
4// This program and the accompanying materials are made available under the
5// terms of the Eclipse Public License 2.0 which is available at
6// https://www.eclipse.org/legal/epl-2.0/
7// This Source Code may also be made available under the following Secondary
8// Licenses when the conditions for such availability set forth in the Eclipse
9// Public License 2.0 are satisfied: GNU General Public License, version 2
10// or later which is available at
11// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13/****************************************************************************/
18// A class for visualizing walks in Netedit
19/****************************************************************************/
20
22#include <netedit/GNENet.h>
23
24#include "GNEWalk.h"
25
26// ===========================================================================
27// method definitions
28// ===========================================================================
29#ifdef _MSC_VER
30#pragma warning(push)
31#pragma warning(disable: 4355) // mask warning about "this" in initializers
32#endif
34 GNEDemandElement("", net, "", tag, GNEPathElement::Options::DEMAND_ELEMENT),
35 GNEDemandElementPlan(this, -1, -1) {
36}
37
38
39GNEWalk::GNEWalk(SumoXMLTag tag, GNEDemandElement* personParent, const GNEPlanParents& planParameters,
40 const double arrivalPosition, const double speed, const SUMOTime duration) :
41 GNEDemandElement(personParent, tag, GNEPathElement::Options::DEMAND_ELEMENT),
42 GNEDemandElementPlan(this, -1, arrivalPosition),
43 mySpeed(speed),
44 myDuration(duration) {
45 // set parents
46 setParents<GNEJunction*>(planParameters.getJunctions());
47 setParents<GNEEdge*>(planParameters.getEdges());
48 setParents<GNEAdditional*>(planParameters.getAdditionalElements());
49 setParents<GNEDemandElement*>(planParameters.getDemandElements(personParent));
50 // update centering boundary without updating grid
52}
53#ifdef _MSC_VER
54#pragma warning(pop)
55#endif
56
58
59
64
65
68 return nullptr;
69}
70
71
72const Parameterised*
74 return nullptr;
75}
76
77
80 return getPlanPopUpMenu(app, parent);
81}
82
83
84void
86 // first write origin stop (if this element starts in a stoppingPlace)
87 writeOriginStop(device);
88 // write rest of attributes
89 device.openTag(SUMO_TAG_WALK);
91 // speed
94 }
95 // duration
98 }
99 device.closeTag();
100}
101
102
107
108
109std::string
113
114
115void
117 // currently the only solution is removing Walk
118}
119
120
123 return SVC_PEDESTRIAN;
124}
125
126
127const RGBColor&
131
132
133void
137
138
143
144
145std::string
147 return getParentDemandElements().front()->getID();
148}
149
150
155
156
157void
158GNEWalk::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* originalElement, const GNENetworkElement* newElement, GNEUndoList* undoList) {
159 // only split geometry of WalkEdges
161 // obtain new list of walk edges
162 std::string newWalkEdges = getNewListOfParents(originalElement, newElement);
163 // update walk edges
164 if (newWalkEdges.size() > 0) {
165 setAttribute(SUMO_ATTR_EDGES, newWalkEdges, undoList);
166 }
167 }
168}
169
170
171void
175
176
177void
181
182
183void
187
188
189void
193
194
195GNELane*
199
200
201GNELane*
205
206
207std::string
209 switch (key) {
210 case SUMO_ATTR_SPEED:
212 return "";
213 } else {
214 return toString(mySpeed);
215 }
218 return "";
219 } else {
220 return time2string(myDuration);
221 }
222 default:
223 return getPlanAttribute(key);
224 }
225}
226
227
228double
230 switch (key) {
231 case SUMO_ATTR_SPEED:
232 return mySpeed;
233 default:
234 return getPlanAttributeDouble(key);
235 }
236}
237
238
243
244
245void
246GNEWalk::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
247 switch (key) {
248 case SUMO_ATTR_SPEED:
250 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
251 break;
252 default:
253 setPlanAttribute(key, value, undoList);
254 break;
255 }
256}
257
258
259bool
260GNEWalk::isValid(SumoXMLAttr key, const std::string& value) {
261 switch (key) {
262 case SUMO_ATTR_SPEED:
263 return canParse<double>(value) && (parse<double>(value) >= 0);
265 return canParse<SUMOTime>(value) && (parse<SUMOTime>(value) >= 0);
266 default:
267 return isPlanValid(key, value);
268 }
269}
270
271
272bool
276
277
278std::string
280 return getTagStr();
281}
282
283
284std::string
288
289// ===========================================================================
290// private
291// ===========================================================================
292
293void
294GNEWalk::setAttribute(SumoXMLAttr key, const std::string& value) {
295 switch (key) {
296 case SUMO_ATTR_SPEED:
297 if (value.empty()) {
299 } else {
300 mySpeed = GNEAttributeCarrier::parse<double>(value);
301 }
302 break;
304 if (value.empty()) {
306 } else {
307 myDuration = GNEAttributeCarrier::parse<SUMOTime>(value);
308 }
309 break;
310 default:
311 setPlanAttribute(key, value);
312 break;
313 }
314}
315
316/****************************************************************************/
long long int SUMOTime
Definition GUI.h:36
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_PEDESTRIAN
pedestrian
SumoXMLTag
Numbers representing SUMO-XML - element names.
@ SUMO_TAG_WALK
@ GNE_TAG_WALK_EDGES
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ SUMO_ATTR_SPEED
@ SUMO_ATTR_EDGES
the edges of a route
@ 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
const std::string & getTagStr() const
get tag assigned to this object in string format
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
Problem
enum class for demandElement problems
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
void computePlanPathElement()
compute plan pathElement
Position getPlanAttributePosition(SumoXMLAttr key) const
get plan attribute position
GNEDemandElement::Problem isPlanPersonValid() const
check if plan is valid
GUIGLObjectPopupMenu * getPlanPopUpMenu(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own popup-menu.
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
GNELane * getLastPlanPathLane() const
get last plan path lane
void updatePlanCenteringBoundary(const bool updateGrid)
update plan centering boundary
void drawPlanGL(const bool drawPlan, const GUIVisualizationSettings &s, const RGBColor &planColor, const RGBColor &planSelectedColor) const
draw plan
void updatePlanGeometry()
update pre-computed geometry information
GNELane * getFirstPlanPathLane() const
get first plan path lane
void drawPlanLanePartial(const bool drawPlan, const GUIVisualizationSettings &s, const GNESegment *segment, const double offsetFront, const double planWidth, const RGBColor &planColor, const RGBColor &planSelectedColor) const
draw plan partial lane
void drawPlanJunctionPartial(const bool drawPlan, const GUIVisualizationSettings &s, const GNESegment *segment, const double offsetFront, const double planWidth, const RGBColor &planColor, const RGBColor &planSelectedColor) const
draw plan partial junction
void writeOriginStop(OutputDevice &device) const
write initial stop stage if plan starts at a stopping place
const GNEHierarchicalContainerParents< GNEDemandElement * > & getParentDemandElements() const
get parent demand elements
std::string getNewListOfParents(const GNENetworkElement *currentElement, const GNENetworkElement *newNextElement) const
if use edge/parent lanes as a list of consecutive elements, obtain a list of IDs of elements after in...
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)
double getDefaultDoubleValue(SumoXMLAttr attr) const
get default double value
SUMOTime getDefaultTimeValue(SumoXMLAttr attr) const
get default time value
SumoXMLTag getTag() const
get Tag vinculated with this attribute Property
Position getPositionInView() const
Returns position of additional in view.
Definition GNEWalk.cpp:140
std::string getHierarchyName() const override
get Hierarchy Name (Used in AC Hierarchy)
Definition GNEWalk.cpp:285
std::string getPopUpID() const override
get PopPup ID (Used in AC Hierarchy)
Definition GNEWalk.cpp:279
SUMOVehicleClass getVClass() const
obtain VClass related with this demand element
Definition GNEWalk.cpp:122
bool isAttributeEnabled(SumoXMLAttr key) const
Definition GNEWalk.cpp:273
double getAttributeDouble(SumoXMLAttr key) const override
Definition GNEWalk.cpp:229
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
Definition GNEWalk.cpp:152
void splitEdgeGeometry(const double splitPosition, const GNENetworkElement *originalElement, const GNENetworkElement *newElement, GNEUndoList *undoList)
split geometry
Definition GNEWalk.cpp:158
SUMOTime myDuration
duration
Definition GNEWalk.h:218
void updateGeometry() override
update pre-computed geometry information
Definition GNEWalk.cpp:134
GNELane * getFirstPathLane() const
get first path lane
Definition GNEWalk.cpp:196
GUIGLObjectPopupMenu * getPopUpMenu(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own popup-menu.
Definition GNEWalk.cpp:79
void fixDemandElementProblem()
fix demand element problem (by default throw an exception, has to be reimplemented in children)
Definition GNEWalk.cpp:116
GNEMoveElement * getMoveElement() const override
methods to retrieve the elements linked to this walk
Definition GNEWalk.cpp:61
void drawJunctionPartialGL(const GUIVisualizationSettings &s, const GNESegment *segment, const double offsetFront) const
Draws partial object over junction.
Definition GNEWalk.cpp:190
double mySpeed
speed
Definition GNEWalk.h:215
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
Definition GNEWalk.cpp:172
bool isValid(SumoXMLAttr key, const std::string &value) override
Definition GNEWalk.cpp:260
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList) override
Definition GNEWalk.cpp:246
Problem isDemandElementValid() const
check if current demand element is valid to be written into XML (by default true, can be reimplemente...
Definition GNEWalk.cpp:104
~GNEWalk()
destructor
Definition GNEWalk.cpp:57
std::string getParentName() const
Returns the name of the parent object.
Definition GNEWalk.cpp:146
void drawLanePartialGL(const GUIVisualizationSettings &s, const GNESegment *segment, const double offsetFront) const
Draws partial object over lane.
Definition GNEWalk.cpp:184
Parameterised * getParameters() override
get parameters associated with this walk
Definition GNEWalk.cpp:67
const RGBColor & getColor() const
get color
Definition GNEWalk.cpp:128
void computePathElement()
compute pathElement
Definition GNEWalk.cpp:178
GNELane * getLastPathLane() const
get last path lane
Definition GNEWalk.cpp:202
std::string getDemandElementProblem() const
return a string with the current demand element problem (by default empty, can be reimplemented in ch...
Definition GNEWalk.cpp:110
Position getAttributePosition(SumoXMLAttr key) const override
Definition GNEWalk.cpp:240
GNEWalk(SumoXMLTag tag, GNENet *net)
default constructor
Definition GNEWalk.cpp:33
std::string getAttribute(SumoXMLAttr key) const override
inherited from GNEAttributeCarrier
Definition GNEWalk.cpp:208
void writeDemandElement(OutputDevice &device) const
write demand element element into a xml file
Definition GNEWalk.cpp:85
The popup menu of a globject.
const GUIVisualizationSettings & getVisualisationSettings() const
get visualization settings (read only)
Stores the information about how to visualize structures.
GUIVisualizationWidthSettings widthSettings
width settings
GUIVisualizationColorSettings colorSettings
color 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
RGBColor selectedPersonPlanColor
person plan selection color (Rides, Walks, stopPersons...)