Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netedit/elements/demand/GNEPersonTrip.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 GNEPersonTrip.cpp
15
/// @author Pablo Alvarez Lopez
16
/// @date Jun 2019
17
///
18
// A class for visualizing person trips in Netedit
19
/****************************************************************************/
20
21
#include <netedit/changes/GNEChange_Attribute.h>
22
#include <netedit/GNENet.h>
23
24
#include "GNEPersonTrip.h"
25
26
27
// ===========================================================================
28
// method definitions
29
// ===========================================================================
30
#ifdef _MSC_VER
31
#pragma warning(push)
32
#pragma warning(disable: 4355) // mask warning about "this" in initializers
33
#endif
34
GNEPersonTrip::GNEPersonTrip(SumoXMLTag tag, GNENet* net) :
35
GNEDemandElement(net, tag),
36
GNEDemandElementPlan(this, -1, -1) {
37
}
38
39
40
GNEPersonTrip::GNEPersonTrip(SumoXMLTag tag, GNEDemandElement* personParent, const GNEPlanParents& planParameters,
41
const double arrivalPosition, const std::vector<std::string>& types, const std::vector<std::string>& modes,
42
const std::vector<std::string>& lines, const double walkFactor, const std::string& group) :
43
GNEDemandElement(personParent, tag),
44
GNEDemandElementPlan(this, -1, arrivalPosition),
45
myVTypes(types),
46
myModes(modes),
47
myLines(lines),
48
myWalkFactor(walkFactor),
49
myGroup(group) {
50
// set parents
51
setParents<GNEJunction*>(planParameters.getJunctions());
52
setParents<GNEEdge*>(planParameters.getEdges());
53
setParents<GNEAdditional*>(planParameters.getAdditionalElements());
54
setParents<GNEDemandElement*>(planParameters.getDemandElements(personParent));
55
// update centering boundary without updating grid
56
updatePlanCenteringBoundary(false);
57
}
58
#ifdef _MSC_VER
59
#pragma warning(pop)
60
#endif
61
62
GNEPersonTrip::~GNEPersonTrip() {}
63
64
65
GNEMoveElement*
66
GNEPersonTrip::getMoveElement() const {
67
return myMoveElementPlan;
68
}
69
70
71
Parameterised*
72
GNEPersonTrip::getParameters() {
73
return nullptr;
74
}
75
76
77
const Parameterised*
78
GNEPersonTrip::getParameters() const {
79
return nullptr;
80
}
81
82
83
GUIGLObjectPopupMenu*
84
GNEPersonTrip::getPopUpMenu(GUIMainWindow& app, GUISUMOAbstractView& parent) {
85
return getPlanPopUpMenu(app, parent);
86
}
87
88
89
void
90
GNEPersonTrip::writeDemandElement(OutputDevice& device) const {
91
// first write origin stop (if this element starts in a stoppingPlace)
92
writeOriginStop(device);
93
// write rest of attributes
94
device.openTag(SUMO_TAG_PERSONTRIP);
95
writeLocationAttributes(device);
96
if (myModes.size() > 0) {
97
device.writeAttr(SUMO_ATTR_MODES, myModes);
98
}
99
if (myLines.size() > 0) {
100
device.writeAttr(SUMO_ATTR_LINES, myLines);
101
}
102
if (myVTypes.size() > 0) {
103
device.writeAttr(SUMO_ATTR_VTYPES, myVTypes);
104
}
105
if (myWalkFactor > 0) {
106
device.writeAttr(SUMO_ATTR_WALKFACTOR, myWalkFactor);
107
}
108
if (myGroup.size() > 0) {
109
device.writeAttr(SUMO_ATTR_GROUP, myGroup);
110
}
111
device.closeTag();
112
}
113
114
115
GNEDemandElement::Problem
116
GNEPersonTrip::isDemandElementValid() const {
117
return isPlanPersonValid();
118
}
119
120
121
std::string
122
GNEPersonTrip::getDemandElementProblem() const {
123
return getPersonPlanProblem();
124
}
125
126
127
void
128
GNEPersonTrip::fixDemandElementProblem() {
129
// currently the only solution is removing PersonTrip
130
}
131
132
133
SUMOVehicleClass
134
GNEPersonTrip::getVClass() const {
135
return SVC_PEDESTRIAN;
136
}
137
138
139
const RGBColor&
140
GNEPersonTrip::getColor() const {
141
return myNet->getViewNet()->getVisualisationSettings().colorSettings.personTripColor;
142
}
143
144
145
void
146
GNEPersonTrip::updateGeometry() {
147
updatePlanGeometry();
148
}
149
150
151
Position
152
GNEPersonTrip::getPositionInView() const {
153
return getPlanPositionInView();
154
}
155
156
157
std::string
158
GNEPersonTrip::getParentName() const {
159
return getParentDemandElements().front()->getID();
160
}
161
162
163
Boundary
164
GNEPersonTrip::getCenteringBoundary() const {
165
return getPlanCenteringBoundary();
166
}
167
168
169
void
170
GNEPersonTrip::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
171
// geometry of this element cannot be splitted
172
}
173
174
175
void
176
GNEPersonTrip::drawGL(const GUIVisualizationSettings& s) const {
177
drawPlanGL(checkDrawPersonPlan(), s, s.colorSettings.personTripColor, s.colorSettings.selectedPersonPlanColor);
178
}
179
180
181
void
182
GNEPersonTrip::computePathElement() {
183
computePlanPathElement();
184
}
185
186
187
void
188
GNEPersonTrip::drawLanePartialGL(const GUIVisualizationSettings& s, const GNESegment* segment, const double offsetFront) const {
189
drawPlanLanePartial(checkDrawPersonPlan(), s, segment, offsetFront, s.widthSettings.personTripWidth, s.colorSettings.personTripColor, s.colorSettings.selectedPersonPlanColor);
190
}
191
192
193
void
194
GNEPersonTrip::drawJunctionPartialGL(const GUIVisualizationSettings& s, const GNESegment* segment, const double offsetFront) const {
195
drawPlanJunctionPartial(checkDrawPersonPlan(), s, segment, offsetFront, s.widthSettings.personTripWidth, s.colorSettings.personTripColor, s.colorSettings.selectedPersonPlanColor);
196
}
197
198
199
GNELane*
200
GNEPersonTrip::getFirstPathLane() const {
201
return getFirstPlanPathLane();
202
}
203
204
205
GNELane*
206
GNEPersonTrip::getLastPathLane() const {
207
return getLastPlanPathLane();
208
}
209
210
211
std::string
212
GNEPersonTrip::getAttribute(SumoXMLAttr key) const {
213
switch (key) {
214
// specific person plan attributes
215
case SUMO_ATTR_MODES:
216
return joinToString(myModes, " ");
217
case SUMO_ATTR_VTYPES:
218
return joinToString(myVTypes, " ");
219
case SUMO_ATTR_LINES:
220
return joinToString(myLines, " ");
221
case SUMO_ATTR_WALKFACTOR:
222
return toString(myWalkFactor);
223
case SUMO_ATTR_GROUP:
224
return toString(myGroup);
225
default:
226
return getPlanAttribute(key);
227
}
228
}
229
230
231
double
232
GNEPersonTrip::getAttributeDouble(SumoXMLAttr key) const {
233
switch (key) {
234
case SUMO_ATTR_WALKFACTOR:
235
return myWalkFactor;
236
default:
237
return getPlanAttributeDouble(key);
238
}
239
}
240
241
242
Position
243
GNEPersonTrip::getAttributePosition(SumoXMLAttr key) const {
244
return getPlanAttributePosition(key);
245
}
246
247
248
void
249
GNEPersonTrip::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
250
switch (key) {
251
case SUMO_ATTR_MODES:
252
case SUMO_ATTR_VTYPES:
253
case SUMO_ATTR_LINES:
254
case SUMO_ATTR_WALKFACTOR:
255
case SUMO_ATTR_GROUP:
256
GNEChange_Attribute::changeAttribute(this, key, value, undoList);
257
break;
258
default:
259
setPlanAttribute(key, value, undoList);
260
break;
261
}
262
}
263
264
265
bool
266
GNEPersonTrip::isValid(SumoXMLAttr key, const std::string& value) {
267
switch (key) {
268
// specific person plan attributes
269
case SUMO_ATTR_MODES: {
270
SVCPermissions dummyModeSet;
271
std::string dummyError;
272
return SUMOVehicleParameter::parsePersonModes(value, myTagProperty->getTagStr(), "", dummyModeSet, dummyError);
273
}
274
case SUMO_ATTR_VTYPES:
275
case SUMO_ATTR_LINES:
276
return true;
277
case SUMO_ATTR_WALKFACTOR:
278
return canParse<double>(value) && (parse<double>(value) >= 0);
279
case SUMO_ATTR_GROUP:
280
return true;
281
default:
282
return isPlanValid(key, value);
283
}
284
}
285
286
287
bool
288
GNEPersonTrip::isAttributeEnabled(SumoXMLAttr key) const {
289
return isPlanAttributeEnabled(key);
290
}
291
292
293
std::string
294
GNEPersonTrip::getPopUpID() const {
295
return getTagStr();
296
}
297
298
299
std::string
300
GNEPersonTrip::getHierarchyName() const {
301
return getPlanHierarchyName();
302
}
303
304
// ===========================================================================
305
// private
306
// ===========================================================================
307
308
void
309
GNEPersonTrip::setAttribute(SumoXMLAttr key, const std::string& value) {
310
switch (key) {
311
// specific person plan attributes
312
case SUMO_ATTR_MODES:
313
myModes = GNEAttributeCarrier::parse<std::vector<std::string> >(value);
314
break;
315
case SUMO_ATTR_VTYPES:
316
myVTypes = GNEAttributeCarrier::parse<std::vector<std::string> >(value);
317
break;
318
case SUMO_ATTR_LINES:
319
myLines = GNEAttributeCarrier::parse<std::vector<std::string> >(value);
320
break;
321
case SUMO_ATTR_WALKFACTOR:
322
myWalkFactor = parse<double>(value);
323
break;
324
case SUMO_ATTR_GROUP:
325
myGroup = value;
326
break;
327
default:
328
setPlanAttribute(key, value);
329
break;
330
}
331
}
332
333
/****************************************************************************/
334
335