Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netedit/elements/demand/GNERouteRef.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 GNERouteRef.cpp
15
/// @author Pablo Alvarez Lopez
16
/// @date April 2025
17
///
18
// A class for route references
19
/****************************************************************************/
20
21
#include <netedit/GNENet.h>
22
#include <netedit/GNETagProperties.h>
23
#include <netedit/changes/GNEChange_Attribute.h>
24
25
#include "GNERouteRef.h"
26
#include "GNEVehicle.h"
27
28
// ===========================================================================
29
// GNERouteRef - methods
30
// ===========================================================================
31
32
GNERouteRef::GNERouteRef(GNENet* net) :
33
GNEDemandElement(net, GNE_TAG_ROUTEREF) {
34
}
35
36
37
GNERouteRef::GNERouteRef(GNEDemandElement* distributionParent, GNEDemandElement* routeParent) :
38
GNEDemandElement(distributionParent, GNE_TAG_ROUTEREF) {
39
// set parents
40
setParents<GNEDemandElement*>({distributionParent, routeParent});
41
}
42
43
44
GNERouteRef::GNERouteRef(GNEDemandElement* distributionParent, GNEDemandElement* routeParent,
45
const double probability) :
46
GNEDemandElement(distributionParent, GNE_TAG_ROUTEREF),
47
myProbability(probability) {
48
// set parents
49
setParents<GNEDemandElement*>({distributionParent, routeParent});
50
}
51
52
53
GNERouteRef::~GNERouteRef() {}
54
55
56
GNEMoveElement*
57
GNERouteRef::getMoveElement() const {
58
return nullptr;
59
}
60
61
62
Parameterised*
63
GNERouteRef::getParameters() {
64
return nullptr;
65
}
66
67
68
const Parameterised*
69
GNERouteRef::getParameters() const {
70
return nullptr;
71
}
72
73
74
GUIGLObjectPopupMenu*
75
GNERouteRef::getPopUpMenu(GUIMainWindow& app, GUISUMOAbstractView& parent) {
76
// create popup
77
GUIGLObjectPopupMenu* ret = new GUIGLObjectPopupMenu(app, parent, this);
78
// build common options
79
buildPopUpMenuCommonOptions(ret, app, myNet->getViewNet(), myTagProperty->getTag(), mySelected);
80
return ret;
81
}
82
83
84
void
85
GNERouteRef::writeDemandElement(OutputDevice& device) const {
86
device.openTag(SUMO_TAG_ROUTE);
87
device.writeAttr(SUMO_ATTR_REFID, getAttribute(SUMO_ATTR_REFID));
88
if (myProbability != INVALID_DOUBLE) {
89
device.writeAttr(SUMO_ATTR_PROB, myProbability);
90
}
91
// close tag
92
device.closeTag();
93
}
94
95
96
GNEDemandElement::Problem
97
GNERouteRef::isDemandElementValid() const {
98
return Problem::OK;
99
}
100
101
102
std::string
103
GNERouteRef::getDemandElementProblem() const {
104
return "";
105
}
106
107
108
void
109
GNERouteRef::fixDemandElementProblem() {
110
// currently the only solution is removing Route
111
}
112
113
114
SUMOVehicleClass
115
GNERouteRef::getVClass() const {
116
return getParentDemandElements().back()->getVClass();
117
}
118
119
120
const RGBColor&
121
GNERouteRef::getColor() const {
122
return RGBColor::INVISIBLE;
123
}
124
125
126
void
127
GNERouteRef::updateGeometry() {
128
// nothing to update
129
}
130
131
132
Position
133
GNERouteRef::getPositionInView() const {
134
return getParentDemandElements().front()->getPositionInView();
135
}
136
137
138
std::string
139
GNERouteRef::getParentName() const {
140
return getParentDemandElements().front()->getID();
141
}
142
143
144
double
145
GNERouteRef::getExaggeration(const GUIVisualizationSettings& /*s*/) const {
146
return 1;
147
}
148
149
150
Boundary
151
GNERouteRef::getCenteringBoundary() const {
152
if (getParentDemandElements().size() > 1) {
153
return getParentDemandElements().at(1)->getCenteringBoundary();
154
} else {
155
return Boundary(-0.1, -0.1, 0.1, 0.1);
156
}
157
}
158
159
160
void
161
GNERouteRef::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/,
162
const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
163
// nothing to do
164
}
165
166
167
void
168
GNERouteRef::drawGL(const GUIVisualizationSettings& /*s*/) const {
169
// nothing to draw
170
}
171
172
173
void
174
GNERouteRef::computePathElement() {
175
// nothing to do
176
}
177
178
179
void
180
GNERouteRef::drawLanePartialGL(const GUIVisualizationSettings& /*s*/, const GNESegment* /*segment*/, const double /*offsetFront*/) const {
181
// nothing to draw
182
}
183
184
185
void
186
GNERouteRef::drawJunctionPartialGL(const GUIVisualizationSettings& /*s*/, const GNESegment* /*segment*/, const double /*offsetFront*/) const {
187
// nothing to draw
188
}
189
190
191
GNELane*
192
GNERouteRef::getFirstPathLane() const {
193
return getParentDemandElements().back()->getFirstPathLane();
194
}
195
196
197
GNELane*
198
GNERouteRef::getLastPathLane() const {
199
return getParentDemandElements().back()->getLastPathLane();
200
}
201
202
203
std::string
204
GNERouteRef::getAttribute(SumoXMLAttr key) const {
205
switch (key) {
206
case SUMO_ATTR_ID:
207
return getMicrosimID();
208
case SUMO_ATTR_REFID:
209
return getParentDemandElements().back()->getID();
210
case SUMO_ATTR_PROB:
211
if (myProbability == INVALID_DOUBLE) {
212
return getParentDemandElements().at(1)->getAttribute(key);
213
} else {
214
return toString(myProbability);
215
}
216
case GNE_ATTR_DEFAULT_PROBABILITY:
217
return (myProbability == INVALID_DOUBLE) ? TRUE_STR : FALSE_STR;
218
default:
219
return getCommonAttribute(key);
220
}
221
}
222
223
224
double
225
GNERouteRef::getAttributeDouble(SumoXMLAttr key) const {
226
switch (key) {
227
case SUMO_ATTR_PROB:
228
if (myProbability == INVALID_DOUBLE) {
229
return getParentDemandElements().at(1)->getAttributeDouble(key);
230
} else {
231
return myProbability;
232
}
233
default:
234
return getCommonAttributeDouble(key);
235
}
236
}
237
238
239
Position
240
GNERouteRef::getAttributePosition(SumoXMLAttr key) const {
241
return getCommonAttributePosition(key);
242
}
243
244
245
bool
246
GNERouteRef::isAttributeEnabled(SumoXMLAttr key) const {
247
switch (key) {
248
case SUMO_ATTR_REFID:
249
return false;
250
default:
251
return true;
252
}
253
}
254
255
256
void
257
GNERouteRef::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
258
if (value == getAttribute(key)) {
259
return; //avoid needless changes, later logic relies on the fact that attributes have changed
260
}
261
switch (key) {
262
case SUMO_ATTR_PROB:
263
GNEChange_Attribute::changeAttribute(this, key, value, undoList);
264
break;
265
default:
266
setCommonAttribute(key, value, undoList);
267
break;
268
}
269
}
270
271
272
bool
273
GNERouteRef::isValid(SumoXMLAttr key, const std::string& value) {
274
switch (key) {
275
case SUMO_ATTR_PROB:
276
if (value.empty()) {
277
return true;
278
} else {
279
return canParse<double>(value) && (parse<double>(value) >= 0);
280
}
281
default:
282
return isCommonAttributeValid(key, value);
283
}
284
}
285
286
bool
287
GNERouteRef::isAttributeComputed(SumoXMLAttr key) const {
288
switch (key) {
289
case SUMO_ATTR_PROB:
290
return myProbability == INVALID_DOUBLE;
291
default:
292
return false;
293
}
294
}
295
296
std::string
297
GNERouteRef::getPopUpID() const {
298
return getTagStr();
299
}
300
301
302
std::string
303
GNERouteRef::getHierarchyName() const {
304
return TLF("%: %, %", myTagProperty->getTagStr(), getParentDemandElements().back()->getID(), getAttribute(SUMO_ATTR_PROB));
305
}
306
307
// ===========================================================================
308
// private
309
// ===========================================================================
310
311
void
312
GNERouteRef::setAttribute(SumoXMLAttr key, const std::string& value) {
313
switch (key) {
314
case SUMO_ATTR_PROB:
315
if (value.empty()) {
316
myProbability = INVALID_DOUBLE;
317
} else {
318
myProbability = parse<double>(value);
319
}
320
break;
321
default:
322
setCommonAttribute(key, value);
323
break;
324
}
325
}
326
327
/****************************************************************************/
328
329