Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netedit/elements/additional/GNEDestProbReroute.cpp
193884 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2001-2026 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 GNEDestProbReroute.cpp
15
/// @author Pablo Alvarez Lopez
16
/// @date Jan 2017
17
///
18
//
19
/****************************************************************************/
20
#include <config.h>
21
22
#include <netedit/changes/GNEChange_Attribute.h>
23
#include <netedit/GNENet.h>
24
25
#include "GNEDestProbReroute.h"
26
27
// ===========================================================================
28
// member method definitions
29
// ===========================================================================
30
31
GNEDestProbReroute::GNEDestProbReroute(GNENet* net):
32
GNEAdditional(net, SUMO_TAG_DEST_PROB_REROUTE),
33
GNEAdditionalListed(this),
34
myNewEdgeDestination(nullptr),
35
myProbability(0) {
36
}
37
38
39
GNEDestProbReroute::GNEDestProbReroute(GNEAdditional* rerouterIntervalParent, GNEEdge* newEdgeDestination, double probability):
40
GNEAdditional(rerouterIntervalParent, SUMO_TAG_DEST_PROB_REROUTE, ""),
41
GNEAdditionalListed(this),
42
myNewEdgeDestination(newEdgeDestination),
43
myProbability(probability) {
44
// set parents
45
setParent<GNEAdditional*>(rerouterIntervalParent);
46
setParent<GNEEdge*>(newEdgeDestination);
47
// update boundary of rerouter parent
48
rerouterIntervalParent->getParentAdditionals().front()->updateCenteringBoundary(true);
49
}
50
51
52
GNEDestProbReroute::~GNEDestProbReroute() {}
53
54
55
GNEMoveElement*
56
GNEDestProbReroute::getMoveElement() const {
57
return nullptr;
58
}
59
60
61
Parameterised*
62
GNEDestProbReroute::getParameters() {
63
return nullptr;
64
}
65
66
67
const Parameterised*
68
GNEDestProbReroute::getParameters() const {
69
return nullptr;
70
}
71
72
73
void
74
GNEDestProbReroute::writeAdditional(OutputDevice& device) const {
75
device.openTag(SUMO_TAG_DEST_PROB_REROUTE);
76
// write common additional attributes
77
writeAdditionalAttributes(device);
78
// write specific attributes
79
device.writeAttr(SUMO_ATTR_ID, getAttribute(SUMO_ATTR_EDGE));
80
device.writeAttr(SUMO_ATTR_PROB, myProbability);
81
device.closeTag();
82
}
83
84
85
bool
86
GNEDestProbReroute::isAdditionalValid() const {
87
return true;
88
}
89
90
91
std::string
92
GNEDestProbReroute::getAdditionalProblem() const {
93
return "";
94
}
95
96
97
void
98
GNEDestProbReroute::fixAdditionalProblem() {
99
// nothing to fix
100
}
101
102
103
bool
104
GNEDestProbReroute::checkDrawMoveContour() const {
105
return false;
106
}
107
108
109
void
110
GNEDestProbReroute::updateGeometry() {
111
updateGeometryListedAdditional();
112
}
113
114
115
Position
116
GNEDestProbReroute::getPositionInView() const {
117
return getListedPositionInView();
118
}
119
120
121
void
122
GNEDestProbReroute::updateCenteringBoundary(const bool /*updateGrid*/) {
123
// nothing to update
124
}
125
126
127
void
128
GNEDestProbReroute::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
129
// geometry of this element cannot be splitted
130
}
131
132
133
std::string
134
GNEDestProbReroute::getParentName() const {
135
return getParentAdditionals().at(0)->getID();
136
}
137
138
139
void
140
GNEDestProbReroute::drawGL(const GUIVisualizationSettings& s) const {
141
// draw dest prob reroute as listed attribute
142
drawListedAdditional(s, RGBColor::RED, RGBColor::YELLOW, GUITexture::REROUTER_DESTPROBREROUTE,
143
getAttribute(SUMO_ATTR_EDGE) + ": " + getAttribute(SUMO_ATTR_PROB));
144
}
145
146
147
std::string
148
GNEDestProbReroute::getAttribute(SumoXMLAttr key) const {
149
switch (key) {
150
case SUMO_ATTR_ID:
151
return getMicrosimID();
152
case SUMO_ATTR_EDGE:
153
return myNewEdgeDestination->getID();
154
case SUMO_ATTR_PROB:
155
return toString(myProbability);
156
case GNE_ATTR_PARENT:
157
return getParentAdditionals().at(0)->getID();
158
default:
159
return getCommonAttribute(key);
160
}
161
}
162
163
164
double
165
GNEDestProbReroute::getAttributeDouble(SumoXMLAttr key) const {
166
return getCommonAttributeDouble(key);
167
}
168
169
170
Position
171
GNEDestProbReroute::getAttributePosition(SumoXMLAttr key) const {
172
return getCommonAttributePosition(key);
173
}
174
175
176
PositionVector
177
GNEDestProbReroute::getAttributePositionVector(SumoXMLAttr key) const {
178
return getCommonAttributePositionVector(key);
179
}
180
181
182
void
183
GNEDestProbReroute::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
184
if (value == getAttribute(key)) {
185
return; //avoid needless changes, later logic relies on the fact that attributes have changed
186
}
187
switch (key) {
188
case SUMO_ATTR_ID:
189
case SUMO_ATTR_EDGE:
190
case SUMO_ATTR_PROB:
191
GNEChange_Attribute::changeAttribute(this, key, value, undoList);
192
break;
193
default:
194
setCommonAttribute(key, value, undoList);
195
break;
196
}
197
}
198
199
200
bool
201
GNEDestProbReroute::isValid(SumoXMLAttr key, const std::string& value) {
202
switch (key) {
203
case SUMO_ATTR_ID:
204
return isValidAdditionalID(value);
205
case SUMO_ATTR_EDGE:
206
return (myNet->getAttributeCarriers()->retrieveEdge(value, false) != nullptr);
207
case SUMO_ATTR_PROB:
208
return canParse<double>(value) && parse<double>(value) >= 0 && parse<double>(value) <= 1;
209
default:
210
return isCommonAttributeValid(key, value);
211
}
212
}
213
214
215
std::string
216
GNEDestProbReroute::getPopUpID() const {
217
return getTagStr();
218
}
219
220
221
std::string
222
GNEDestProbReroute::getHierarchyName() const {
223
return getTagStr() + ": " + myNewEdgeDestination->getID();
224
}
225
226
// ===========================================================================
227
// private
228
// ===========================================================================
229
230
void
231
GNEDestProbReroute::setAttribute(SumoXMLAttr key, const std::string& value) {
232
switch (key) {
233
case SUMO_ATTR_ID:
234
// update microsimID
235
setAdditionalID(value);
236
break;
237
case SUMO_ATTR_EDGE:
238
myNewEdgeDestination = myNet->getAttributeCarriers()->retrieveEdge(value);
239
break;
240
case SUMO_ATTR_PROB:
241
myProbability = parse<double>(value);
242
break;
243
default:
244
setCommonAttribute(key, value);
245
break;
246
}
247
}
248
249
/****************************************************************************/
250
251