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