Path: blob/main/src/netedit/dialogs/elements/GNERerouterDialog.cpp
169685 views
/****************************************************************************/1// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2// Copyright (C) 2001-2025 German Aerospace Center (DLR) and others.3// This program and the accompanying materials are made available under the4// terms of the Eclipse Public License 2.0 which is available at5// https://www.eclipse.org/legal/epl-2.0/6// This Source Code may also be made available under the following Secondary7// Licenses when the conditions for such availability set forth in the Eclipse8// Public License 2.0 are satisfied: GNU General Public License, version 29// or later which is available at10// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html11// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later12/****************************************************************************/13/// @file GNERerouterDialog.cpp14/// @author Pablo Alvarez Lopez15/// @date April 201616///17// Dialog for edit rerouters18/****************************************************************************/1920#include <netedit/dialogs/basic/GNEWarningBasicDialog.h>21#include <netedit/elements/additional/GNERerouterInterval.h>22#include <netedit/GNENet.h>23#include <netedit/GNEUndoList.h>24#include <netedit/GNEViewParent.h>2526#include "GNERerouterDialog.h"27#include "GNERerouterIntervalDialog.h"2829// ===========================================================================30// member method definitions31// ===========================================================================3233GNERerouterDialog::GNERerouterDialog(GNEAdditional* rerouter) :34GNETemplateElementDialog<GNEAdditional>(rerouter, DialogType::REROUTER) {35// create rerouter intervals element list36myRerouterIntervals = new RerouterIntervalsList(this);37// open dialog38openDialog();39}404142GNERerouterDialog::~GNERerouterDialog() {}434445void46GNERerouterDialog::runInternalTest(const InternalTestStep::DialogArgument* /*dialogArgument*/) {47// nothing to do48}495051long52GNERerouterDialog::onCmdAccept(FXObject*, FXSelector, void*) {53// Check if there is overlapping between Intervals54if (!myRerouterIntervals->isOverlapping()) {55// open warning Box56GNEWarningBasicDialog(myElement->getNet()->getViewNet()->getViewParent()->getGNEAppWindows(),57TLF("Rerouter intervals of % '%' cannot be saved", toString(SUMO_TAG_REROUTER), myElement->getID()),58TL(". There are intervals overlapped."));59return 1;60} else {61// close dialog accepting changes62return acceptElementDialog();63}64}656667long68GNERerouterDialog::onCmdReset(FXObject*, FXSelector, void*) {69// reset changes70resetChanges();71// update tables72myRerouterIntervals->updateList();73return 1;74}7576// ---------------------------------------------------------------------------77// GNERerouterDialog::RerouterIntervalsList - methods78// ---------------------------------------------------------------------------7980GNERerouterDialog::RerouterIntervalsList::RerouterIntervalsList(GNERerouterDialog* rerouterDialog) :81GNETemplateElementList(rerouterDialog, rerouterDialog->getContentFrame(), SUMO_TAG_INTERVAL,82GNEElementList::Options::SORTELEMENTS | GNEElementList::Options::DIALOG_ELEMENT | GNEElementList::Options::FIXED_HEIGHT) {83}848586long87GNERerouterDialog::RerouterIntervalsList::addNewElement() {88SUMOTime end = 0;89// get end with biggest end90for (const auto& interval : getEditedElements()) {91const auto intervalEnd = string2time(interval->getAttribute(SUMO_ATTR_END));92if (end < intervalEnd) {93end = intervalEnd;94}95}96// create interval97return insertElement(new GNERerouterInterval(myElementDialogParent->getElement(), end, end + string2time("3600")));98}99100101long102GNERerouterDialog::RerouterIntervalsList::openElementDialog(const size_t rowIndex) {103// simply open dialog for the edited additional element104GNERerouterIntervalDialog(getEditedElements().at(rowIndex));105return 1;106}107108109bool110GNERerouterDialog::RerouterIntervalsList::isOverlapping() const {111// declare a vector to keep sorted children112std::vector<std::pair<std::pair<double, double>, GNEAdditional*> > sortedIntervals;113// iterate over child interval114for (const auto& interval : getEditedElements()) {115// add interval to sorted intervals116sortedIntervals.push_back(std::make_pair(std::make_pair(0., 0.), interval));117// set begin and end118sortedIntervals.back().first.first = interval->getAttributeDouble(SUMO_ATTR_BEGIN);119sortedIntervals.back().first.second = interval->getAttributeDouble(SUMO_ATTR_END);120}121// sort intervals by begin and end122std::sort(sortedIntervals.begin(), sortedIntervals.end());123// if we have only one interval or less, there is no overlapping124if (sortedIntervals.size() <= 1) {125return true;126} else {127// check if the next end is bigger than the current begin128for (int i = 0; i < (int)sortedIntervals.size() - 1; i++) {129if (sortedIntervals.at(i).first.second > sortedIntervals.at(i + 1).first.first) {130return false;131}132}133}134return true;135}136137/****************************************************************************/138139140