Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netedit/elements/additional/GNERerouter.cpp
193674 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 GNERerouter.cpp
15
/// @author Pablo Alvarez Lopez
16
/// @date Nov 2015
17
///
18
//
19
/****************************************************************************/
20
21
#include <netedit/changes/GNEChange_Attribute.h>
22
#include <netedit/dialogs/elements/GNERerouterDialog.h>
23
#include <netedit/elements/moving/GNEMoveElementView.h>
24
#include <netedit/GNENet.h>
25
#include <netedit/GNEUndoList.h>
26
27
#include "GNERerouter.h"
28
#include "GNERerouterSymbol.h"
29
30
// ===========================================================================
31
// member method definitions
32
// ===========================================================================
33
34
GNERerouter::GNERerouter(GNENet* net) :
35
GNEAdditional(net, SUMO_TAG_REROUTER),
36
GNEAdditionalSquared(this) {
37
}
38
39
40
GNERerouter::GNERerouter(const std::string& id, GNENet* net, FileBucket* fileBucket, const Position& pos, const std::string& name,
41
double probability, bool off, bool optional, SUMOTime timeThreshold, const std::vector<std::string>& vTypes,
42
const Parameterised::Map& parameters) :
43
GNEAdditional(id, net, SUMO_TAG_REROUTER, fileBucket, name),
44
GNEAdditionalSquared(this, pos),
45
Parameterised(parameters),
46
myProbability(probability),
47
myOff(off),
48
myOptional(optional),
49
myTimeThreshold(timeThreshold),
50
myVTypes(vTypes) {
51
// update centering boundary without updating grid
52
updateCenteringBoundary(false);
53
}
54
55
56
GNERerouter::~GNERerouter() {
57
}
58
59
60
GNEMoveElement*
61
GNERerouter::getMoveElement() const {
62
return myMoveElementView;
63
}
64
65
66
Parameterised*
67
GNERerouter::getParameters() {
68
return this;
69
}
70
71
72
const Parameterised*
73
GNERerouter::getParameters() const {
74
return this;
75
}
76
77
78
void
79
GNERerouter::writeAdditional(OutputDevice& device) const {
80
// avoid write rerouters without edges
81
if (getAttribute(SUMO_ATTR_EDGES).size() > 0) {
82
device.openTag(SUMO_TAG_REROUTER);
83
// write common additional attributes
84
writeAdditionalAttributes(device);
85
// write move atributes
86
myMoveElementView->writeMoveAttributes(device);
87
// write specific attributes
88
device.writeAttr(SUMO_ATTR_EDGES, getAttribute(SUMO_ATTR_EDGES));
89
if (myProbability != 1.0) {
90
device.writeAttr(SUMO_ATTR_PROB, myProbability);
91
}
92
if (time2string(myTimeThreshold) != "0.00") {
93
device.writeAttr(SUMO_ATTR_HALTING_TIME_THRESHOLD, time2string(myTimeThreshold));
94
}
95
if (!myVTypes.empty()) {
96
device.writeAttr(SUMO_ATTR_VTYPES, myVTypes);
97
}
98
if (myOff) {
99
device.writeAttr(SUMO_ATTR_OFF, myOff);
100
}
101
if (myOptional) {
102
device.writeAttr(SUMO_ATTR_OPTIONAL, myOptional);
103
}
104
// write all rerouter interval
105
for (const auto& rerouterInterval : getChildAdditionals()) {
106
if (!rerouterInterval->getTagProperty()->isSymbol()) {
107
rerouterInterval->writeAdditional(device);
108
}
109
}
110
// write parameters (Always after children to avoid problems with additionals.xsd)
111
writeParams(device);
112
device.closeTag();
113
} else {
114
WRITE_WARNING("Rerouter '" + getID() + TL("' needs at least one edge"));
115
}
116
}
117
118
119
bool
120
GNERerouter::isAdditionalValid() const {
121
return true;
122
}
123
124
125
std::string GNERerouter::getAdditionalProblem() const {
126
return "";
127
}
128
129
130
void
131
GNERerouter::fixAdditionalProblem() {
132
// nothing to fix
133
}
134
135
136
bool
137
GNERerouter::checkDrawMoveContour() const {
138
// get edit modes
139
const auto& editModes = myNet->getViewNet()->getEditModes();
140
// check if we're in move mode
141
if (!myNet->getViewNet()->isCurrentlyMovingElements() && editModes.isCurrentSupermodeNetwork() &&
142
!myNet->getViewNet()->getEditNetworkElementShapes().getEditedNetworkElement() &&
143
(editModes.networkEditMode == NetworkEditMode::NETWORK_MOVE) && myNet->getViewNet()->checkOverLockedElement(this, mySelected)) {
144
// only move the first element
145
return myNet->getViewNet()->getViewObjectsSelector().getGUIGlObjectFront() == this;
146
} else {
147
return false;
148
}
149
}
150
151
152
void
153
GNERerouter::updateGeometry() {
154
updatedSquaredGeometry();
155
}
156
157
158
Position
159
GNERerouter::getPositionInView() const {
160
return myPosOverView;
161
}
162
163
164
void
165
GNERerouter::updateCenteringBoundary(const bool updateGrid) {
166
updatedSquaredCenteringBoundary(updateGrid);
167
}
168
169
170
void
171
GNERerouter::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
172
// geometry of this element cannot be splitted
173
}
174
175
176
void
177
GNERerouter::openAdditionalDialog(FXWindow* restoringFocusWindow) {
178
// Open rerouter dialog
179
UNUSED_PARAMETER(restoringFocusWindow);
180
GNERerouterDialog(this);
181
}
182
183
184
std::string
185
GNERerouter::getParentName() const {
186
return myNet->getMicrosimID();
187
}
188
189
190
void
191
GNERerouter::drawGL(const GUIVisualizationSettings& s) const {
192
const auto& inspectedElements = myNet->getViewNet()->getInspectedElements();
193
// first check if additional has to be drawn
194
if (myNet->getViewNet()->getDataViewOptions().showAdditionals()) {
195
// draw parent and child lines
196
drawParentChildLines(s, s.additionalSettings.connectionColor, true);
197
// draw Rerouter
198
drawSquaredAdditional(s, s.additionalSettings.rerouterSize, GUITexture::REROUTER, GUITexture::REROUTER_SELECTED);
199
// iterate over additionals and check if drawn
200
for (const auto& interval : getChildAdditionals()) {
201
// if rerouter or their intevals are selected, then draw
202
if (myNet->getViewNet()->getNetworkViewOptions().showSubAdditionals() ||
203
isAttributeCarrierSelected() || inspectedElements.isACInspected(this) ||
204
interval->isAttributeCarrierSelected() || inspectedElements.isACInspected(interval) ||
205
interval->isMarkedForDrawingFront()) {
206
interval->drawGL(s);
207
} else {
208
// if rerouterElements are inspected or selected, then draw
209
for (const auto& rerouterElement : interval->getChildAdditionals()) {
210
if (rerouterElement->isAttributeCarrierSelected() || inspectedElements.isACInspected(rerouterElement) ||
211
rerouterElement->isMarkedForDrawingFront()) {
212
interval->drawGL(s);
213
}
214
}
215
}
216
}
217
}
218
}
219
220
221
std::string
222
GNERerouter::getAttribute(SumoXMLAttr key) const {
223
switch (key) {
224
case SUMO_ATTR_ID:
225
return getMicrosimID();
226
case SUMO_ATTR_EDGES: {
227
std::vector<std::string> edges;
228
for (const auto& rerouterSymbol : getChildAdditionals()) {
229
if (rerouterSymbol->getTagProperty()->isSymbol()) {
230
edges.push_back(rerouterSymbol->getAttribute(SUMO_ATTR_EDGE));
231
}
232
}
233
return toString(edges);
234
}
235
case SUMO_ATTR_NAME:
236
return myAdditionalName;
237
case SUMO_ATTR_PROB:
238
return toString(myProbability);
239
case SUMO_ATTR_HALTING_TIME_THRESHOLD:
240
return time2string(myTimeThreshold);
241
case SUMO_ATTR_VTYPES:
242
return toString(myVTypes);
243
case SUMO_ATTR_OFF:
244
return toString(myOff);
245
case SUMO_ATTR_OPTIONAL:
246
return toString(myOptional);
247
default:
248
return myMoveElementView->getMovingAttribute(key);
249
}
250
}
251
252
253
double
254
GNERerouter::getAttributeDouble(SumoXMLAttr key) const {
255
switch (key) {
256
case SUMO_ATTR_PROB:
257
return myProbability;
258
default:
259
return myMoveElementView->getMovingAttributeDouble(key);
260
}
261
}
262
263
264
Position
265
GNERerouter::getAttributePosition(SumoXMLAttr key) const {
266
return myMoveElementView->getMovingAttributePosition(key);
267
}
268
269
270
PositionVector
271
GNERerouter::getAttributePositionVector(SumoXMLAttr key) const {
272
return myMoveElementView->getMovingAttributePositionVector(key);
273
}
274
275
276
void
277
GNERerouter::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
278
if (value == getAttribute(key)) {
279
return; //avoid needless changes, later logic relies on the fact that attributes have changed
280
}
281
switch (key) {
282
// special case for lanes due rerouter Symbols
283
case SUMO_ATTR_EDGES:
284
// rebuild rerouter Symbols
285
rebuildRerouterSymbols(value, undoList);
286
break;
287
case SUMO_ATTR_ID:
288
case SUMO_ATTR_NAME:
289
case SUMO_ATTR_PROB:
290
case SUMO_ATTR_HALTING_TIME_THRESHOLD:
291
case SUMO_ATTR_VTYPES:
292
case SUMO_ATTR_OFF:
293
case SUMO_ATTR_OPTIONAL:
294
GNEChange_Attribute::changeAttribute(this, key, value, undoList);
295
break;
296
default:
297
myMoveElementView->setMovingAttribute(key, value, undoList);
298
break;
299
}
300
}
301
302
303
bool
304
GNERerouter::isValid(SumoXMLAttr key, const std::string& value) {
305
switch (key) {
306
case SUMO_ATTR_ID:
307
return isValidAdditionalID(value);
308
case SUMO_ATTR_EDGES:
309
return canParse<std::vector<GNEEdge*> >(myNet, value, false);
310
case SUMO_ATTR_NAME:
311
return SUMOXMLDefinitions::isValidAttribute(value);
312
case SUMO_ATTR_PROB:
313
return canParse<double>(value) && (parse<double>(value) >= 0) && (parse<double>(value) <= 1);
314
case SUMO_ATTR_HALTING_TIME_THRESHOLD:
315
return canParse<SUMOTime>(value);
316
case SUMO_ATTR_VTYPES:
317
if (value.empty()) {
318
return true;
319
} else {
320
return SUMOXMLDefinitions::isValidListOfTypeID(value);
321
}
322
case SUMO_ATTR_OFF:
323
return canParse<bool>(value);
324
case SUMO_ATTR_OPTIONAL:
325
return canParse<bool>(value);
326
default:
327
return myMoveElementView->isMovingAttributeValid(key, value);
328
}
329
}
330
331
332
std::string
333
GNERerouter::getPopUpID() const {
334
return getTagStr() + ": " + getID();
335
}
336
337
338
std::string
339
GNERerouter::getHierarchyName() const {
340
return getTagStr();
341
}
342
343
// ===========================================================================
344
// private
345
// ===========================================================================
346
347
void
348
GNERerouter::setAttribute(SumoXMLAttr key, const std::string& value) {
349
switch (key) {
350
case SUMO_ATTR_EDGES:
351
throw InvalidArgument(getTagStr() + " cannot be edited");
352
case SUMO_ATTR_ID:
353
// update microsimID
354
setAdditionalID(value);
355
break;
356
case SUMO_ATTR_NAME:
357
myAdditionalName = value;
358
break;
359
case SUMO_ATTR_PROB:
360
myProbability = parse<double>(value);
361
break;
362
case SUMO_ATTR_HALTING_TIME_THRESHOLD:
363
myTimeThreshold = parse<SUMOTime>(value);
364
break;
365
case SUMO_ATTR_VTYPES:
366
myVTypes = parse<std::vector<std::string> >(value);
367
break;
368
case SUMO_ATTR_OFF:
369
myOff = parse<bool>(value);
370
break;
371
case SUMO_ATTR_OPTIONAL:
372
myOptional = parse<bool>(value);
373
break;
374
default:
375
myMoveElementView->setMovingAttribute(key, value);
376
break;
377
}
378
// update boundary (except for template)
379
if (getID().size() > 0) {
380
updateCenteringBoundary(true);
381
}
382
}
383
384
385
void
386
GNERerouter::rebuildRerouterSymbols(const std::string& value, GNEUndoList* undoList) {
387
undoList->begin(this, ("change " + getTagStr() + " attribute").c_str());
388
// drop all additional children
389
while (getChildAdditionals().size() > 0) {
390
undoList->add(new GNEChange_Additional(getChildAdditionals().front(), false), true);
391
}
392
// get edge vector
393
const std::vector<GNEEdge*> edges = parse<std::vector<GNEEdge*> >(myNet, value);
394
// create new VSS Symbols
395
for (const auto& edge : edges) {
396
// create VSS Symbol
397
GNEAdditional* VSSSymbol = new GNERerouterSymbol(this, edge);
398
// add it using GNEChange_Additional
399
myNet->getUndoList()->add(new GNEChange_Additional(VSSSymbol, true), true);
400
}
401
undoList->end();
402
}
403
404
405
/****************************************************************************/
406
407