Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netedit/elements/demand/GNEWalk.cpp
185790 views
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
/****************************************************************************/
14
/// @file GNEWalk.cpp
15
/// @author Pablo Alvarez Lopez
16
/// @date Jun 2019
17
///
18
// A class for visualizing walks in Netedit
19
/****************************************************************************/
20
21
#include <netedit/changes/GNEChange_Attribute.h>
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
33
GNEWalk::GNEWalk(SumoXMLTag tag, GNENet* net) :
34
GNEDemandElement(net, tag),
35
GNEDemandElementPlan(this, -1, -1) {
36
}
37
38
39
GNEWalk::GNEWalk(SumoXMLTag tag, GNEDemandElement* personParent, const GNEPlanParents& planParameters,
40
const double arrivalPosition, const double speed, const SUMOTime duration) :
41
GNEDemandElement(personParent, tag),
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
51
updatePlanCenteringBoundary(false);
52
}
53
#ifdef _MSC_VER
54
#pragma warning(pop)
55
#endif
56
57
GNEWalk::~GNEWalk() {}
58
59
60
GNEMoveElement*
61
GNEWalk::getMoveElement() const {
62
return myMoveElementPlan;
63
}
64
65
66
Parameterised*
67
GNEWalk::getParameters() {
68
return nullptr;
69
}
70
71
72
const Parameterised*
73
GNEWalk::getParameters() const {
74
return nullptr;
75
}
76
77
78
GUIGLObjectPopupMenu*
79
GNEWalk::getPopUpMenu(GUIMainWindow& app, GUISUMOAbstractView& parent) {
80
return getPlanPopUpMenu(app, parent);
81
}
82
83
84
void
85
GNEWalk::writeDemandElement(OutputDevice& device) const {
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);
90
writeLocationAttributes(device);
91
// speed
92
if (mySpeed != myTagProperty->getDefaultDoubleValue(SUMO_ATTR_SPEED)) {
93
device.writeAttr(SUMO_ATTR_SPEED, mySpeed);
94
}
95
// duration
96
if (myDuration != myTagProperty->getDefaultTimeValue(SUMO_ATTR_DURATION)) {
97
device.writeAttr(SUMO_ATTR_DURATION, time2string(myDuration));
98
}
99
device.closeTag();
100
}
101
102
103
GNEDemandElement::Problem
104
GNEWalk::isDemandElementValid() const {
105
return isPlanPersonValid();
106
}
107
108
109
std::string
110
GNEWalk::getDemandElementProblem() const {
111
return getPersonPlanProblem();
112
}
113
114
115
void
116
GNEWalk::fixDemandElementProblem() {
117
// currently the only solution is removing Walk
118
}
119
120
121
SUMOVehicleClass
122
GNEWalk::getVClass() const {
123
return SVC_PEDESTRIAN;
124
}
125
126
127
const RGBColor&
128
GNEWalk::getColor() const {
129
return myNet->getViewNet()->getVisualisationSettings().colorSettings.walkColor;
130
}
131
132
133
void
134
GNEWalk::updateGeometry() {
135
updatePlanGeometry();
136
}
137
138
139
Position
140
GNEWalk::getPositionInView() const {
141
return getPlanPositionInView();
142
}
143
144
145
std::string
146
GNEWalk::getParentName() const {
147
return getParentDemandElements().front()->getID();
148
}
149
150
151
Boundary
152
GNEWalk::getCenteringBoundary() const {
153
return getPlanCenteringBoundary();
154
}
155
156
157
void
158
GNEWalk::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* originalElement, const GNENetworkElement* newElement, GNEUndoList* undoList) {
159
// only split geometry of WalkEdges
160
if (myTagProperty->getTag() == GNE_TAG_WALK_EDGES) {
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
171
void
172
GNEWalk::drawGL(const GUIVisualizationSettings& s) const {
173
drawPlanGL(checkDrawPersonPlan(), s, s.colorSettings.walkColor, s.colorSettings.selectedPersonPlanColor);
174
}
175
176
177
void
178
GNEWalk::computePathElement() {
179
computePlanPathElement();
180
}
181
182
183
void
184
GNEWalk::drawLanePartialGL(const GUIVisualizationSettings& s, const GNESegment* segment, const double offsetFront) const {
185
drawPlanLanePartial(checkDrawPersonPlan(), s, segment, offsetFront, s.widthSettings.walkWidth, s.colorSettings.walkColor, s.colorSettings.selectedPersonPlanColor);
186
}
187
188
189
void
190
GNEWalk::drawJunctionPartialGL(const GUIVisualizationSettings& s, const GNESegment* segment, const double offsetFront) const {
191
drawPlanJunctionPartial(checkDrawPersonPlan(), s, segment, offsetFront, s.widthSettings.walkWidth, s.colorSettings.walkColor, s.colorSettings.selectedPersonPlanColor);
192
}
193
194
195
GNELane*
196
GNEWalk::getFirstPathLane() const {
197
return getFirstPlanPathLane();
198
}
199
200
201
GNELane*
202
GNEWalk::getLastPathLane() const {
203
return getLastPlanPathLane();
204
}
205
206
207
std::string
208
GNEWalk::getAttribute(SumoXMLAttr key) const {
209
switch (key) {
210
case SUMO_ATTR_SPEED:
211
if (mySpeed == myTagProperty->getDefaultDoubleValue(key)) {
212
return "";
213
} else {
214
return toString(mySpeed);
215
}
216
case SUMO_ATTR_DURATION:
217
if (myDuration == myTagProperty->getDefaultTimeValue(key)) {
218
return "";
219
} else {
220
return time2string(myDuration);
221
}
222
default:
223
return getPlanAttribute(key);
224
}
225
}
226
227
228
double
229
GNEWalk::getAttributeDouble(SumoXMLAttr key) const {
230
switch (key) {
231
case SUMO_ATTR_SPEED:
232
return mySpeed;
233
default:
234
return getPlanAttributeDouble(key);
235
}
236
}
237
238
239
Position
240
GNEWalk::getAttributePosition(SumoXMLAttr key) const {
241
return getPlanAttributePosition(key);
242
}
243
244
245
void
246
GNEWalk::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
247
switch (key) {
248
case SUMO_ATTR_SPEED:
249
case SUMO_ATTR_DURATION:
250
GNEChange_Attribute::changeAttribute(this, key, value, undoList);
251
break;
252
default:
253
setPlanAttribute(key, value, undoList);
254
break;
255
}
256
}
257
258
259
bool
260
GNEWalk::isValid(SumoXMLAttr key, const std::string& value) {
261
switch (key) {
262
case SUMO_ATTR_SPEED:
263
return canParse<double>(value) && (parse<double>(value) >= 0);
264
case SUMO_ATTR_DURATION:
265
return canParse<SUMOTime>(value) && (parse<SUMOTime>(value) >= 0);
266
default:
267
return isPlanValid(key, value);
268
}
269
}
270
271
272
bool
273
GNEWalk::isAttributeEnabled(SumoXMLAttr key) const {
274
return isPlanAttributeEnabled(key);
275
}
276
277
278
std::string
279
GNEWalk::getPopUpID() const {
280
return getTagStr();
281
}
282
283
284
std::string
285
GNEWalk::getHierarchyName() const {
286
return getPlanHierarchyName();
287
}
288
289
// ===========================================================================
290
// private
291
// ===========================================================================
292
293
void
294
GNEWalk::setAttribute(SumoXMLAttr key, const std::string& value) {
295
switch (key) {
296
case SUMO_ATTR_SPEED:
297
if (value.empty()) {
298
mySpeed = myTagProperty->getDefaultDoubleValue(key);
299
} else {
300
mySpeed = GNEAttributeCarrier::parse<double>(value);
301
}
302
break;
303
case SUMO_ATTR_DURATION:
304
if (value.empty()) {
305
myDuration = myTagProperty->getDefaultTimeValue(key);
306
} else {
307
myDuration = GNEAttributeCarrier::parse<SUMOTime>(value);
308
}
309
break;
310
default:
311
setPlanAttribute(key, value);
312
break;
313
}
314
}
315
316
/****************************************************************************/
317
318