Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GNERerouterDialog.cpp
Go to the documentation of this file.
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/****************************************************************************/
18// Dialog for edit rerouters
19/****************************************************************************/
20
23#include <netedit/GNENet.h>
24#include <netedit/GNEUndoList.h>
26
27#include "GNERerouterDialog.h"
29
30// ===========================================================================
31// member method definitions
32// ===========================================================================
33
36 // create rerouter intervals element list
38 // open dialog
39 openDialog();
40}
41
42
44
45
46void
48 // nothing to do
49}
50
51
52long
53GNERerouterDialog::onCmdAccept(FXObject*, FXSelector, void*) {
54 // Check if there is overlapping between Intervals
56 // open warning Box
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
68long
69GNERerouterDialog::onCmdReset(FXObject*, FXSelector, void*) {
70 // reset changes
72 // update tables
74 return 1;
75}
76
77// ---------------------------------------------------------------------------
78// GNERerouterDialog::RerouterIntervalsList - methods
79// ---------------------------------------------------------------------------
80
82 GNETemplateElementList(rerouterDialog, rerouterDialog->getContentFrame(), SUMO_TAG_INTERVAL,
83 GNEElementList::Options::SORTELEMENTS | GNEElementList::Options::DIALOG_ELEMENT | GNEElementList::Options::FIXED_HEIGHT) {
84}
85
86
87long
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
102long
104 // simply open dialog for the edited additional element
105 GNERerouterIntervalDialog(getEditedElements().at(rowIndex), myElementDialogParent);
106 return 1;
107}
108
109
110bool
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/****************************************************************************/
DialogType
long long int SUMOTime
Definition GUI.h:36
#define TL(string)
Definition MsgHandler.h:304
#define TLF(string,...)
Definition MsgHandler.h:306
SUMOTime string2time(const std::string &r)
convert string to SUMOTime
Definition SUMOTime.cpp:46
@ SUMO_TAG_INTERVAL
an aggreagated-output interval
@ SUMO_TAG_REROUTER
A rerouter.
@ SUMO_ATTR_BEGIN
weights: time range begin
@ SUMO_ATTR_END
weights: time range end
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:46
virtual double getAttributeDouble(SumoXMLAttr key) const =0
const std::string getID() const override
get ID (all Attribute Carriers have one)
GNENet * getNet() const
get pointer to net
void openDialog(FXWindow *focusableElement=nullptr)
open dialog
Options
FOX-declaration.
GNEApplicationWindow * getGNEApplicationWindow() const
get tag properties database
Definition GNENet.cpp:138
RerouterIntervalsList(GNERerouterDialog *rerouterDialog)
constructor
long openElementDialog(const size_t rowIndex)
open element dialog
bool isOverlapping() const
@briec check if there is overlapping between intervals
~GNERerouterDialog()
destructor
long onCmdAccept(FXObject *, FXSelector, void *)
event after press accept button
void runInternalTest(const InternalTestStep::DialogArgument *dialogArgument)
run internal test
long onCmdReset(FXObject *, FXSelector, void *)
event after press reset button
GNERerouterDialog(GNEAdditional *rerouter)
Constructor.
RerouterIntervalsList * myRerouterIntervals
Element list for rerouter intervals.
GNEAdditional * myElement
pointer to edited element
void resetChanges()
reset changes did in this dialog.
long acceptElementDialog()
close dialog commiting changes
long updateList()
update element list
dialog arguments, used for certain modal dialogs that can not be edited using tab