Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netedit/dialogs/elements/GNERerouterDialog.cpp
169685 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 GNERerouterDialog.cpp
15
/// @author Pablo Alvarez Lopez
16
/// @date April 2016
17
///
18
// Dialog for edit rerouters
19
/****************************************************************************/
20
21
#include <netedit/dialogs/basic/GNEWarningBasicDialog.h>
22
#include <netedit/elements/additional/GNERerouterInterval.h>
23
#include <netedit/GNENet.h>
24
#include <netedit/GNEUndoList.h>
25
#include <netedit/GNEViewParent.h>
26
27
#include "GNERerouterDialog.h"
28
#include "GNERerouterIntervalDialog.h"
29
30
// ===========================================================================
31
// member method definitions
32
// ===========================================================================
33
34
GNERerouterDialog::GNERerouterDialog(GNEAdditional* rerouter) :
35
GNETemplateElementDialog<GNEAdditional>(rerouter, DialogType::REROUTER) {
36
// create rerouter intervals element list
37
myRerouterIntervals = new RerouterIntervalsList(this);
38
// open dialog
39
openDialog();
40
}
41
42
43
GNERerouterDialog::~GNERerouterDialog() {}
44
45
46
void
47
GNERerouterDialog::runInternalTest(const InternalTestStep::DialogArgument* /*dialogArgument*/) {
48
// nothing to do
49
}
50
51
52
long
53
GNERerouterDialog::onCmdAccept(FXObject*, FXSelector, void*) {
54
// Check if there is overlapping between Intervals
55
if (!myRerouterIntervals->isOverlapping()) {
56
// open warning Box
57
GNEWarningBasicDialog(myElement->getNet()->getViewNet()->getViewParent()->getGNEAppWindows(),
58
TLF("Rerouter intervals of % '%' cannot be saved", toString(SUMO_TAG_REROUTER), myElement->getID()),
59
TL(". There are intervals overlapped."));
60
return 1;
61
} else {
62
// close dialog accepting changes
63
return acceptElementDialog();
64
}
65
}
66
67
68
long
69
GNERerouterDialog::onCmdReset(FXObject*, FXSelector, void*) {
70
// reset changes
71
resetChanges();
72
// update tables
73
myRerouterIntervals->updateList();
74
return 1;
75
}
76
77
// ---------------------------------------------------------------------------
78
// GNERerouterDialog::RerouterIntervalsList - methods
79
// ---------------------------------------------------------------------------
80
81
GNERerouterDialog::RerouterIntervalsList::RerouterIntervalsList(GNERerouterDialog* rerouterDialog) :
82
GNETemplateElementList(rerouterDialog, rerouterDialog->getContentFrame(), SUMO_TAG_INTERVAL,
83
GNEElementList::Options::SORTELEMENTS | GNEElementList::Options::DIALOG_ELEMENT | GNEElementList::Options::FIXED_HEIGHT) {
84
}
85
86
87
long
88
GNERerouterDialog::RerouterIntervalsList::addNewElement() {
89
SUMOTime end = 0;
90
// get end with biggest end
91
for (const auto& interval : getEditedElements()) {
92
const auto intervalEnd = string2time(interval->getAttribute(SUMO_ATTR_END));
93
if (end < intervalEnd) {
94
end = intervalEnd;
95
}
96
}
97
// create interval
98
return insertElement(new GNERerouterInterval(myElementDialogParent->getElement(), end, end + string2time("3600")));
99
}
100
101
102
long
103
GNERerouterDialog::RerouterIntervalsList::openElementDialog(const size_t rowIndex) {
104
// simply open dialog for the edited additional element
105
GNERerouterIntervalDialog(getEditedElements().at(rowIndex));
106
return 1;
107
}
108
109
110
bool
111
GNERerouterDialog::RerouterIntervalsList::isOverlapping() const {
112
// declare a vector to keep sorted children
113
std::vector<std::pair<std::pair<double, double>, GNEAdditional*> > sortedIntervals;
114
// iterate over child interval
115
for (const auto& interval : getEditedElements()) {
116
// add interval to sorted intervals
117
sortedIntervals.push_back(std::make_pair(std::make_pair(0., 0.), interval));
118
// set begin and end
119
sortedIntervals.back().first.first = interval->getAttributeDouble(SUMO_ATTR_BEGIN);
120
sortedIntervals.back().first.second = interval->getAttributeDouble(SUMO_ATTR_END);
121
}
122
// sort intervals by begin and end
123
std::sort(sortedIntervals.begin(), sortedIntervals.end());
124
// if we have only one interval or less, there is no overlapping
125
if (sortedIntervals.size() <= 1) {
126
return true;
127
} else {
128
// check if the next end is bigger than the current begin
129
for (int i = 0; i < (int)sortedIntervals.size() - 1; i++) {
130
if (sortedIntervals.at(i).first.second > sortedIntervals.at(i + 1).first.first) {
131
return false;
132
}
133
}
134
}
135
return true;
136
}
137
138
/****************************************************************************/
139
140