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-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// A class for visualizing walks in Netedit
19/****************************************************************************/
20
23#include <netedit/GNENet.h>
24#include <netedit/GNEUndoList.h>
25#include <netedit/GNEViewNet.h>
28
29#include "GNEWalk.h"
30#include "GNERoute.h"
31
32// ===========================================================================
33// method definitions
34// ===========================================================================
35
38 GNEPathElement::Options::DEMAND_ELEMENT, {}, {}, {}, {}, {}, {}),
39GNEDemandElementPlan(this, -1, -1) {
40 // reset default values
42}
43
44
45GNEWalk::GNEWalk(GNENet* net, SumoXMLTag tag, GUIIcon icon, GNEDemandElement* personParent, const GNEPlanParents& planParameters,
46 const double arrivalPosition, const double speed, const SUMOTime duration) :
47 GNEDemandElement(personParent, net, GLO_WALK, tag, GUIIconSubSys::getIcon(icon),
48 GNEPathElement::Options::DEMAND_ELEMENT,
49 planParameters.getJunctions(), planParameters.getEdges(), {},
50planParameters.getAdditionalElements(), planParameters.getDemandElements(personParent), {}),
51GNEDemandElementPlan(this, -1, arrivalPosition),
52mySpeed(speed),
53myDuration(duration) {
54}
55
56
58
59
64
65
68 return getPlanPopUpMenu(app, parent);
69}
70
71
72void
74 // first write origin stop (if this element starts in a stoppingPlace)
75 writeOriginStop(device);
76 // write rest of attributes
77 device.openTag(SUMO_TAG_WALK);
79 // speed
82 }
83 // duration
86 }
87 device.closeTag();
88}
89
90
95
96
97std::string
101
102
103void
105 // currently the only solution is removing Walk
106}
107
108
111 return SVC_PEDESTRIAN;
112}
113
114
115const RGBColor&
119
120
121void
125
126
131
132
133std::string
135 return getParentDemandElements().front()->getID();
136}
137
138
143
144
145void
146GNEWalk::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* originalElement, const GNENetworkElement* newElement, GNEUndoList* undoList) {
147 // only split geometry of WalkEdges
149 // obtain new list of walk edges
150 std::string newWalkEdges = getNewListOfParents(originalElement, newElement);
151 // update walk edges
152 if (newWalkEdges.size() > 0) {
153 setAttribute(SUMO_ATTR_EDGES, newWalkEdges, undoList);
154 }
155 }
156}
157
158
159void
163
164
165void
169
170
171void
175
176
177void
181
182
183GNELane*
187
188
189GNELane*
193
194
195std::string
197 switch (key) {
198 case SUMO_ATTR_SPEED:
199 if (mySpeed == 0) {
200 return "";
201 } else {
202 return toString(mySpeed);
203 }
205 if (myDuration == 0) {
206 return "";
207 } else {
208 return time2string(myDuration);
209 }
210 default:
211 return getPlanAttribute(key);
212 }
213}
214
215
216double
218 switch (key) {
219 case SUMO_ATTR_SPEED:
220 return mySpeed;
221 default:
222 return getPlanAttributeDouble(key);
223 }
224}
225
226
231
232
233void
234GNEWalk::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
235 switch (key) {
236 case SUMO_ATTR_SPEED:
238 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
239 break;
240 default:
241 setPlanAttribute(key, value, undoList);
242 break;
243 }
244}
245
246
247bool
248GNEWalk::isValid(SumoXMLAttr key, const std::string& value) {
249 switch (key) {
250 case SUMO_ATTR_SPEED:
251 return canParse<double>(value) && (parse<double>(value) >= 0);
253 return canParse<SUMOTime>(value) && (parse<SUMOTime>(value) >= 0);
254 default:
255 return isPlanValid(key, value);
256 }
257}
258
259
260bool
264
265
266std::string
268 return getTagStr();
269}
270
271
272std::string
276
277
282
283// ===========================================================================
284// private
285// ===========================================================================
286
287void
288GNEWalk::setAttribute(SumoXMLAttr key, const std::string& value) {
289 switch (key) {
290 case SUMO_ATTR_SPEED:
291 if (value.empty()) {
292 mySpeed = 0;
293 } else {
294 mySpeed = GNEAttributeCarrier::parse<double>(value);
295 }
296 break;
298 if (value.empty()) {
299 mySpeed = 0;
300 } else {
301 myDuration = GNEAttributeCarrier::parse<SUMOTime>(value);
302 }
303 break;
304 default:
305 setPlanAttribute(key, value);
306 break;
307 }
308}
309
310
311void
313 // change both position
314 myArrivalPosition = moveResult.newFirstPos;
315 // update geometry
317}
318
319
320void
322 undoList->begin(this, "arrivalPos of " + getTagStr());
323 // now adjust start position
325 undoList->end();
326}
327
328/****************************************************************************/
long long int SUMOTime
Definition GUI.h:36
@ GLO_WALK
a walk
GUIIcon
An enumeration of icons used by the gui applications.
Definition GUIIcons.h:33
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_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_ARRIVALPOS
@ 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
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
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.
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
GNELane * getLastPlanPathLane() const
get last plan path lane
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 std::vector< 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...
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
Definition GNELane.h:46
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:2155
GNEPlanParents (used for group all plan parents)
std::vector< GNEAdditional * > getAdditionalElements() const
get additionalElements (used in plan constructors)
SumoXMLTag getTag() const
get Tag vinculated with this attribute Property
const std::string & getDefaultValue(SumoXMLAttr attr) const
return the default value of the attribute of an element
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...
Position getPositionInView() const
Returns position of additional in view.
Definition GNEWalk.cpp:128
SUMOVehicleClass getVClass() const
obtain VClass related with this demand element
Definition GNEWalk.cpp:110
bool isAttributeEnabled(SumoXMLAttr key) const
Definition GNEWalk.cpp:261
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
Definition GNEWalk.cpp:140
void splitEdgeGeometry(const double splitPosition, const GNENetworkElement *originalElement, const GNENetworkElement *newElement, GNEUndoList *undoList)
split geometry
Definition GNEWalk.cpp:146
SUMOTime myDuration
duration
Definition GNEWalk.h:214
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
Definition GNEWalk.cpp:267
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
Definition GNEWalk.cpp:273
GNELane * getFirstPathLane() const
get first path lane
Definition GNEWalk.cpp:184
void updateGeometry()
update pre-computed geometry information
Definition GNEWalk.cpp:122
Position getAttributePosition(SumoXMLAttr key) const
Definition GNEWalk.cpp:228
GUIGLObjectPopupMenu * getPopUpMenu(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own popup-menu.
Definition GNEWalk.cpp:67
void fixDemandElementProblem()
fix demand element problem (by default throw an exception, has to be reimplemented in children)
Definition GNEWalk.cpp:104
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
Definition GNEWalk.cpp:248
GNEMoveOperation * getMoveOperation()
get move operation
Definition GNEWalk.cpp:61
void drawJunctionPartialGL(const GUIVisualizationSettings &s, const GNESegment *segment, const double offsetFront) const
Draws partial object over junction.
Definition GNEWalk.cpp:178
double mySpeed
speed
Definition GNEWalk.h:211
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
Definition GNEWalk.cpp:160
void setMoveShape(const GNEMoveResult &moveResult)
set move shape
Definition GNEWalk.cpp:312
double getAttributeDouble(SumoXMLAttr key) const
Definition GNEWalk.cpp:217
Problem isDemandElementValid() const
check if current demand element is valid to be written into XML (by default true, can be reimplemente...
Definition GNEWalk.cpp:92
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform demand element changes
Definition GNEWalk.cpp:234
~GNEWalk()
destructor
Definition GNEWalk.cpp:57
const Parameterised::Map & getACParametersMap() const
get parameters map
Definition GNEWalk.cpp:279
std::string getParentName() const
Returns the name of the parent object.
Definition GNEWalk.cpp:134
std::string getAttribute(SumoXMLAttr key) const
inherited from GNEAttributeCarrier
Definition GNEWalk.cpp:196
void drawLanePartialGL(const GUIVisualizationSettings &s, const GNESegment *segment, const double offsetFront) const
Draws partial object over lane.
Definition GNEWalk.cpp:172
void commitMoveShape(const GNEMoveResult &moveResult, GNEUndoList *undoList)
commit move shape
Definition GNEWalk.cpp:321
const RGBColor & getColor() const
get color
Definition GNEWalk.cpp:116
void computePathElement()
compute pathElement
Definition GNEWalk.cpp:166
GNELane * getLastPathLane() const
get last path lane
Definition GNEWalk.cpp:190
std::string getDemandElementProblem() const
return a string with the current demand element problem (by default empty, can be reimplemented in ch...
Definition GNEWalk.cpp:98
GNEWalk(SumoXMLTag tag, GNENet *net)
default constructor
Definition GNEWalk.cpp:36
void writeDemandElement(OutputDevice &device) const
write demand element element into a xml file
Definition GNEWalk.cpp:73
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.
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
RGBColor selectedPersonPlanColor
person plan selection color (Rides, Walks, stopPersons...)