Path: blob/main/src/netedit/dialogs/elements/GNERerouterIntervalDialog.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 GNERerouterIntervalDialog.cpp14/// @author Pablo Alvarez Lopez15/// @date eb 201716///17// Dialog for edit rerouter intervals18/****************************************************************************/1920#include <netedit/dialogs/basic/GNEWarningBasicDialog.h>21#include <netedit/elements/additional/GNEClosingLaneReroute.h>22#include <netedit/elements/additional/GNEClosingReroute.h>23#include <netedit/elements/additional/GNEDestProbReroute.h>24#include <netedit/elements/additional/GNEParkingAreaReroute.h>25#include <netedit/elements/additional/GNERouteProbReroute.h>26#include <netedit/GNENet.h>27#include <netedit/GNEUndoList.h>28#include <netedit/GNEViewParent.h>29#include <utils/gui/div/GUIDesigns.h>3031#include "GNEAttributeCarrierDialog.h"32#include "GNERerouterIntervalDialog.h"3334// ===========================================================================35// member method definitions36// ===========================================================================3738GNERerouterIntervalDialog::GNERerouterIntervalDialog(GNEAdditional* rerouterInterval) :39GNETemplateElementDialog<GNEAdditional>(rerouterInterval, DialogType::REROUTERINTERVAL) {40// Create auxiliar frames for tables41FXHorizontalFrame* columns = new FXHorizontalFrame(myContentFrame, GUIDesignAuxiliarHorizontalFrame);42FXVerticalFrame* columnLeft = new FXVerticalFrame(columns, GUIDesignAuxiliarVerticalFrame);43FXVerticalFrame* columnCenter = new FXVerticalFrame(columns, GUIDesignAuxiliarVerticalFrame);44FXVerticalFrame* columnRight = new FXVerticalFrame(columns, GUIDesignAuxiliarVerticalFrame);45// create closing reroute element list46myClosingReroutes = new ClosingReroutesList(this, columnLeft);47// create closing lane reroute element list48myClosingLaneReroutes = new ClosingLaneReroutesList(this, columnLeft);49// dest prob reroute50myDestProbReroutes = new DestProbReroutesList(this, columnCenter);51// route prob reroute52myRouteProbReroutes = new RouteProbReroutesList(this, columnCenter);53// parking area reroute54myParkingAreaReroutes = new ParkingAreaReroutesList(this, columnRight);55// open dialog56openDialog();57}585960GNERerouterIntervalDialog::~GNERerouterIntervalDialog() {}616263void64GNERerouterIntervalDialog::runInternalTest(const InternalTestStep::DialogArgument* /*dialogArgument*/) {65// nothing to do (yet)66}676869long70GNERerouterIntervalDialog::onCmdAccept(FXObject*, FXSelector, void*) {71// get rerouter parent72const auto rerouterParent = myElement->getParentAdditionals().at(0);73// declare strings74const std::string warningTitle = TLF("Error updating % of % '%'", myElement->getTagStr(), rerouterParent->getTagStr(), rerouterParent->getID());75const std::string infoA = TLF("% of % '%' cannot be updated because", myElement->getTagStr(), rerouterParent->getTagStr(), rerouterParent->getID());76std::string infoB;77// set infoB78if (myClosingReroutes->getEditedElements().empty() && myClosingLaneReroutes->getEditedElements().empty() &&79myRouteProbReroutes->getEditedElements().empty() && myDestProbReroutes->getEditedElements().empty() &&80myParkingAreaReroutes->getEditedElements().empty()) {81infoB = TLF("at least one % must be defined.", myElement->getTagStr());82} else if (!myClosingReroutes->isListValid()) {83infoB = TLF("there are invalid %s.", toString(SUMO_TAG_CLOSING_REROUTE));84} else if (!myClosingLaneReroutes->isListValid()) {85infoB = TLF("there are invalid %s.", toString(SUMO_TAG_CLOSING_LANE_REROUTE));86} else if (!myRouteProbReroutes->isListValid()) {87infoB = TLF("there are invalid %s.", toString(SUMO_TAG_ROUTE_PROB_REROUTE));88} else if (!myDestProbReroutes->isListValid()) {89infoB = TLF("there are invalid %s.", toString(SUMO_TAG_DEST_PROB_REROUTE));90} else if (!myParkingAreaReroutes->isListValid()) {91infoB = TLF("there are invalid %s.", toString(SUMO_TAG_PARKING_AREA_REROUTE));92}93// continue depending of info94if (infoB.size() > 0) {95// open question dialog box with two lines96GNEWarningBasicDialog(myElement->getNet()->getViewNet()->getViewParent()->getGNEAppWindows(), warningTitle, infoA, infoB);97return 1;98} else {99// close dialog accepting changes100return acceptElementDialog();101}102}103104105long106GNERerouterIntervalDialog::onCmdReset(FXObject*, FXSelector, void*) {107// reset changes108resetChanges();109// update tables110myClosingReroutes->updateList();111myClosingLaneReroutes->updateList();112myDestProbReroutes->updateList();113myRouteProbReroutes->updateList();114myParkingAreaReroutes->updateList();115return 1;116}117118// ---------------------------------------------------------------------------119// GNERerouterIntervalDialog::ClosingReroutesList - methods120// ---------------------------------------------------------------------------121122GNERerouterIntervalDialog::ClosingReroutesList::ClosingReroutesList(GNERerouterIntervalDialog* rerouterIntervalDialog,123FXVerticalFrame* contentFrame) :124GNETemplateElementList(rerouterIntervalDialog, contentFrame, SUMO_TAG_CLOSING_REROUTE,125GNEElementList::Options::DIALOG_ELEMENT | GNEElementList::Options::DIALOG_VCLASS | GNEElementList::Options::FIXED_HEIGHT) {126// disable if there are no edges in net127if (rerouterIntervalDialog->getElement()->getNet()->getAttributeCarriers()->getEdges().size() == 0) {128disableList(TL("No edges in net"));129}130}131132133long134GNERerouterIntervalDialog::ClosingReroutesList::addNewElement() {135// get edge136const auto edge = myElementDialogParent->getElement()->getNet()->getAttributeCarriers()->getEdges().begin()->second;137// create closing reroute138return insertElement(new GNEClosingReroute(myElementDialogParent->getElement(), edge, SVCAll));139}140141142long143GNERerouterIntervalDialog::ClosingReroutesList::openElementDialog(const size_t rowIndex) {144// open attribute carrier dialog145GNEAttributeCarrierDialog(myEditedElements.at(rowIndex)->getParentEdges().front());146return 1;147}148149// ---------------------------------------------------------------------------150// GNERerouterIntervalDialog::ClosingLaneReroutesList - methods151// ---------------------------------------------------------------------------152153GNERerouterIntervalDialog::ClosingLaneReroutesList::ClosingLaneReroutesList(GNERerouterIntervalDialog* rerouterIntervalDialog,154FXVerticalFrame* contentFrame) :155GNETemplateElementList(rerouterIntervalDialog, contentFrame, SUMO_TAG_CLOSING_LANE_REROUTE,156GNEElementList::Options::DIALOG_ELEMENT | GNEElementList::Options::DIALOG_VCLASS | GNEElementList::Options::FIXED_HEIGHT) {157// disable if there are no edges in net158if (rerouterIntervalDialog->getElement()->getNet()->getAttributeCarriers()->getLanes().size() == 0) {159disableList(TL("No lanes in net"));160}161}162163164long165GNERerouterIntervalDialog::ClosingLaneReroutesList::addNewElement() {166// get lane167const auto lane = myElementDialogParent->getElement()->getNet()->getAttributeCarriers()->getEdges().begin()->second->getChildLanes().front();168// create closing lane reroute169return insertElement(new GNEClosingLaneReroute(myElementDialogParent->getElement(), lane, SVCAll));170}171172173long174GNERerouterIntervalDialog::ClosingLaneReroutesList::openElementDialog(const size_t rowIndex) {175// open attribute carrier dialog176GNEAttributeCarrierDialog(myEditedElements.at(rowIndex)->getParentLanes().front());177return 1;178}179180// ---------------------------------------------------------------------------181// GNERerouterIntervalDialog::DestProbReroutesList - methods182// ---------------------------------------------------------------------------183184GNERerouterIntervalDialog::DestProbReroutesList::DestProbReroutesList(GNERerouterIntervalDialog* rerouterIntervalDialog,185FXVerticalFrame* contentFrame) :186GNETemplateElementList(rerouterIntervalDialog, contentFrame, SUMO_TAG_DEST_PROB_REROUTE,187GNEElementList::Options::DIALOG_ELEMENT | GNEElementList::Options::FIXED_HEIGHT) {188// disable if there are no edges in net189if (rerouterIntervalDialog->getElement()->getNet()->getAttributeCarriers()->getEdges().size() == 0) {190disableList(TL("No edges in net"));191}192}193194195long196GNERerouterIntervalDialog::DestProbReroutesList::addNewElement() {197// get edge198const auto edge = myElementDialogParent->getElement()->getNet()->getAttributeCarriers()->getEdges().begin()->second;199// create dest prob reroute200return insertElement(new GNEDestProbReroute(myElementDialogParent->getElement(), edge, 1));201}202203204long205GNERerouterIntervalDialog::DestProbReroutesList::openElementDialog(const size_t rowIndex) {206// open attribute carrier dialog207GNEAttributeCarrierDialog(myEditedElements.at(rowIndex)->getParentEdges().front());208return 1;209}210211// ---------------------------------------------------------------------------212// GNERerouterIntervalDialog::RouteProbReroutesList - methods213// ---------------------------------------------------------------------------214215GNERerouterIntervalDialog::RouteProbReroutesList::RouteProbReroutesList(GNERerouterIntervalDialog* rerouterIntervalDialog,216FXVerticalFrame* contentFrame) :217GNETemplateElementList(rerouterIntervalDialog, contentFrame, SUMO_TAG_ROUTE_PROB_REROUTE,218GNEElementList::Options::DIALOG_ELEMENT | GNEElementList::Options::FIXED_HEIGHT) {219// disable if the rerouter has multiple edges (random routes can only work from one edge)220if (rerouterIntervalDialog->getElement()->getParentAdditionals().at(0)->getChildEdges().size() > 1) {221disableList(TL("Rerouter has more than one edge"));222}223// disable if there are no routes in net224if (rerouterIntervalDialog->getElement()->getNet()->getAttributeCarriers()->getDemandElements().at(SUMO_TAG_ROUTE).size() == 0) {225disableList(TL("No routes in net"));226}227}228229230long231GNERerouterIntervalDialog::RouteProbReroutesList::addNewElement() {232// get route233const auto route = myElementDialogParent->getElement()->getNet()->getAttributeCarriers()->getDemandElements().at(SUMO_TAG_ROUTE).begin()->second;234// create route prob reroute235return insertElement(new GNERouteProbReroute(myElementDialogParent->getElement(), route, 1));236}237238239long240GNERerouterIntervalDialog::RouteProbReroutesList::openElementDialog(const size_t rowIndex) {241// open attribute carrier dialog242GNEAttributeCarrierDialog(myEditedElements.at(rowIndex)->getParentDemandElements().front());243return 1;244}245246// ---------------------------------------------------------------------------247// GNERerouterIntervalDialog::ParkingAreaReroutesList - methods248// ---------------------------------------------------------------------------249250GNERerouterIntervalDialog::ParkingAreaReroutesList::ParkingAreaReroutesList(GNERerouterIntervalDialog* rerouterIntervalDialog,251FXVerticalFrame* contentFrame) :252GNETemplateElementList(rerouterIntervalDialog, contentFrame, SUMO_TAG_PARKING_AREA_REROUTE,253GNEElementList::Options::DIALOG_ELEMENT) {254// disable if there are no parking areas in net255if (rerouterIntervalDialog->getElement()->getNet()->getAttributeCarriers()->getAdditionals().at(SUMO_TAG_PARKING_AREA).size() == 0) {256disableList(TL("No parkingAreas in net"));257}258}259260261long262GNERerouterIntervalDialog::ParkingAreaReroutesList::addNewElement() {263// get parking area264const auto parkingArea = myElementDialogParent->getElement()->getNet()->getAttributeCarriers()->getAdditionals().at(SUMO_TAG_PARKING_AREA).begin()->second;265// create parking area reroute266return insertElement(new GNEParkingAreaReroute(myElementDialogParent->getElement(), parkingArea, 1, 1));267}268269270long271GNERerouterIntervalDialog::ParkingAreaReroutesList::openElementDialog(const size_t rowIndex) {272// open attribute carrier dialog273GNEAttributeCarrierDialog(myEditedElements.at(rowIndex)->getParentAdditionals().back());274return 1;275}276277/****************************************************************************/278279280