Path: blob/main/src/netedit/dialogs/elements/GNECalibratorDialog.cpp
169684 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 GNECalibratorDialog.cpp14/// @author Pablo Alvarez Lopez15/// @date March 201716///17// Dialog for edit calibrators18/****************************************************************************/1920#include <netedit/dialogs/basic/GNEWarningBasicDialog.h>21#include <netedit/dialogs/elements/GNEVehicleTypeDialog.h>22#include <netedit/elements/additional/GNECalibratorFlow.h>23#include <netedit/elements/demand/GNERoute.h>24#include <netedit/elements/demand/GNEVType.h>25#include <netedit/GNENet.h>26#include <netedit/GNEUndoList.h>27#include <netedit/GNEViewParent.h>28#include <utils/gui/div/GUIDesigns.h>2930#include "GNECalibratorDialog.h"31#include "GNEAttributeCarrierDialog.h"3233// ===========================================================================34// member method definitions35// ===========================================================================3637GNECalibratorDialog::GNECalibratorDialog(GNEAdditional* calibrator) :38GNETemplateElementDialog<GNEAdditional>(calibrator, DialogType::CALIBRATOR) {39// Create two columns, one for Routes and VehicleTypes, and other for Flows40FXHorizontalFrame* columns = new FXHorizontalFrame(myContentFrame, GUIDesignUniformHorizontalFrame);41FXVerticalFrame* columnLeft = new FXVerticalFrame(columns, GUIDesignAuxiliarFrame);42FXVerticalFrame* columnRight = new FXVerticalFrame(columns, GUIDesignAuxiliarFrame);43// create route element list44myRoutes = new RoutesList(this, columnLeft);45// create closing lane reroute element list46myVTypes = new VTypesList(this, columnLeft);47// parking area reroute48myCalibratorFlows = new CalibratorFlowsList(this, columnRight, myRoutes, myVTypes);49// open dialog50openDialog();51}525354GNECalibratorDialog::~GNECalibratorDialog() {}555657void58GNECalibratorDialog::runInternalTest(const InternalTestStep::DialogArgument* /*dialogArgument*/) {59// nothing to do60}616263long64GNECalibratorDialog::onCmdAccept(FXObject*, FXSelector, void*) {65// declare strings66const auto warningTitle = TLF("Error updating % '%'", myElement->getTagStr(), myElement->getID());67const auto infoA = TLF("% '%' cannot be updated because", myElement->getTagStr(), myElement->getID());68std::string infoB;69// set infoB70if (!myRoutes->isListValid()) {71infoB = TLF("there are invalid %s.", toString(SUMO_TAG_ROUTE));72} else if (!myVTypes->isListValid()) {73infoB = TLF("there are invalid %s.", toString(SUMO_TAG_VTYPE));74} else if (!myCalibratorFlows->isListValid()) {75infoB = TLF("there are invalid %s.", toString(GNE_TAG_CALIBRATOR_FLOW));76}77// continue depending of info78if (infoB.size() > 0) {79// open question dialog box with two lines80GNEWarningBasicDialog(myElement->getNet()->getViewNet()->getViewParent()->getGNEAppWindows(), warningTitle, infoA, infoB);81return 1;82} else {83// close dialog accepting changes84return acceptElementDialog();85}86}878889long90GNECalibratorDialog::onCmdReset(FXObject*, FXSelector, void*) {91// reset changes92resetChanges();93// update tables94myRoutes->updateList();95myVTypes->updateList();96myCalibratorFlows->updateList();97return 1;98}99100// ---------------------------------------------------------------------------101// GNECalibratorDialog::RoutesList - methods102// ---------------------------------------------------------------------------103104GNECalibratorDialog::RoutesList::RoutesList(GNECalibratorDialog* rerouterDialog, FXVerticalFrame* contentFrame) :105GNETemplateElementList(rerouterDialog, contentFrame, SUMO_TAG_ROUTE,106GNEElementList::Options::DIALOG_ELEMENT | GNEElementList::Options::FIXED_HEIGHT) {107}108109110long111GNECalibratorDialog::RoutesList::addNewElement() {112// create route using calibrator as parent113GNERoute* route = new GNERoute(myElementDialogParent->getElement());114// insert route115insertElement(route);116// open route dialog117const auto routeDialog = GNEAttributeCarrierDialog(route);118// continue depending of result of routeDialog119if (routeDialog.getResult() != GNEDialog::Result::ACCEPT) {120// remove route121return removeElement(route);122} else {123return 1;124}125}126127128long129GNECalibratorDialog::RoutesList::openElementDialog(const size_t rowIndex) {130// open attribute carrier dialog131GNEAttributeCarrierDialog(myEditedElements.at(rowIndex));132return 1;133}134135// ---------------------------------------------------------------------------136// GNECalibratorDialog::VTypesList - methods137// ---------------------------------------------------------------------------138139GNECalibratorDialog::VTypesList::VTypesList(GNECalibratorDialog* rerouterDialog, FXVerticalFrame* contentFrame) :140GNETemplateElementList(rerouterDialog, contentFrame, SUMO_TAG_VTYPE,141GNEElementList::Options::DIALOG_ELEMENT | GNEElementList::Options::FIXED_HEIGHT) {142}143144145long146GNECalibratorDialog::VTypesList::addNewElement() {147// create vType148GNEVType* vType = new GNEVType(myElementDialogParent->getElement());149// insert vType150insertElement(vType);151// open route dialog152const auto vTypeDialog = GNEVehicleTypeDialog(vType);153// continue depending of result of routeDialog154if (vTypeDialog.getResult() != GNEDialog::Result::ACCEPT) {155// remove vType156return removeElement(vType);157} else {158return 1;159}160}161162163long164GNECalibratorDialog::VTypesList::openElementDialog(const size_t rowIndex) {165// open vType dialog166GNEVehicleTypeDialog(myEditedElements.at(rowIndex));167return 1;168}169170// ---------------------------------------------------------------------------171// GNECalibratorDialog::CalibratorFlowsList - methods172// ---------------------------------------------------------------------------173174GNECalibratorDialog::CalibratorFlowsList::CalibratorFlowsList(GNECalibratorDialog* rerouterDialog, FXVerticalFrame* contentFrame,175RoutesList* routesList, VTypesList* vTypesList) :176GNETemplateElementList(rerouterDialog, contentFrame, GNE_TAG_CALIBRATOR_FLOW,177GNEElementList::Options::SORTELEMENTS | GNEElementList::Options::DIALOG_ELEMENT),178myRoutesList(routesList),179myVTypesList(vTypesList) {180// disable if there are no routes in net181if (rerouterDialog->getElement()->getNet()->getAttributeCarriers()->getDemandElements().at(SUMO_TAG_ROUTE).size() == 0) {182disableList(TL("No routes in net"));183}184}185186187long188GNECalibratorDialog::CalibratorFlowsList::addNewElement() {189// get vType190GNEDemandElement* vType = nullptr;191if (myVTypesList->getEditedElements().size() > 0) {192vType = myVTypesList->getEditedElements().back();193} else {194vType = myElementDialogParent->getElement()->getNet()->getAttributeCarriers()->getDemandElements().at(SUMO_TAG_VTYPE).begin()->second;195}196// get route197GNEDemandElement* route = nullptr;198if (myVTypesList->getEditedElements().size() > 0) {199route = myVTypesList->getEditedElements().back();200} else {201route = myElementDialogParent->getElement()->getNet()->getAttributeCarriers()->getDemandElements().at(SUMO_TAG_ROUTE).begin()->second;202}203// check if route and vType are valid204if (route && vType) {205// create vType206GNECalibratorFlow* calibratorFlow = new GNECalibratorFlow(myElementDialogParent->getElement(), vType, route);207// add using undo-redo208insertElement(calibratorFlow);209// open route dialog210const auto calibratorFlowDialog = GNEAttributeCarrierDialog(calibratorFlow);211// continue depending of result of routeDialog212if (calibratorFlowDialog.getResult() != GNEDialog::Result::CANCEL) {213// add calibratorFlow214return removeElement(calibratorFlow);215}216}217return 1;218}219220221long222GNECalibratorDialog::CalibratorFlowsList::openElementDialog(const size_t rowIndex) {223// open attribute carrier dialog224GNEAttributeCarrierDialog(myEditedElements.at(rowIndex));225return 1;226}227228/****************************************************************************/229230231