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