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