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