Path: blob/main/src/netedit/dialogs/elements/GNECalibratorDialog.cpp
193674 views
/****************************************************************************/1// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2// Copyright (C) 2001-2026 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// parking area reroute40myCalibratorFlows = new CalibratorFlowsList(this, myContentFrame);41// open dialog42openDialog();43}444546GNECalibratorDialog::~GNECalibratorDialog() {}474849void50GNECalibratorDialog::runInternalTest(const InternalTestStep::DialogArgument* /*dialogArgument*/) {51// nothing to do52}535455long56GNECalibratorDialog::onCmdAccept(FXObject*, FXSelector, void*) {57// declare strings58const auto warningTitle = TLF("Error updating % '%'", myElement->getTagStr(), myElement->getID());59const auto infoA = TLF("% '%' cannot be updated because", myElement->getTagStr(), myElement->getID());60const auto infoB = TLF("there are invalid %s.", toString(GNE_TAG_CALIBRATOR_FLOW));61// continue depending of info62if (!myCalibratorFlows->isListValid()) {63// open question dialog box with two lines64GNEWarningBasicDialog(myElement->getNet()->getGNEApplicationWindow(), this, warningTitle, infoA, infoB);65return 1;66} else {67// close dialog accepting changes68return acceptElementDialog();69}70}717273long74GNECalibratorDialog::onCmdReset(FXObject*, FXSelector, void*) {75// reset changes76resetChanges();77myCalibratorFlows->updateList();78return 1;79}8081// ---------------------------------------------------------------------------82// GNECalibratorDialog::CalibratorFlowsList - methods83// ---------------------------------------------------------------------------8485GNECalibratorDialog::CalibratorFlowsList::CalibratorFlowsList(GNECalibratorDialog* calibratorDialog, FXVerticalFrame* contentFrame) :86GNETemplateElementList(calibratorDialog, contentFrame, GNE_TAG_CALIBRATOR_FLOW,87GNEElementList::Options::SORTELEMENTS | GNEElementList::Options::DIALOG_ELEMENT | GNEElementList::Options::FIXED_HEIGHT) {88// disable if there are no routes in net89if (calibratorDialog->getElement()->getNet()->getAttributeCarriers()->getDemandElements().at(SUMO_TAG_ROUTE).size() == 0) {90disableList(TL("No routes in net"));91}92}939495long96GNECalibratorDialog::CalibratorFlowsList::addNewElement() {97// get vType98GNEDemandElement* vType = myElementDialogParent->getElement()->getNet()->getAttributeCarriers()->retrieveDemandElement(SUMO_TAG_VTYPE, DEFAULT_VTYPE_ID);99// get route100GNEDemandElement* route = myElementDialogParent->getElement()->getNet()->getAttributeCarriers()->getDemandElements().at(SUMO_TAG_ROUTE).begin()->second;101// calculate begin based in last calibrator flow102SUMOTime begin = 0;103for (const auto& child : myElementDialogParent->getElement()->getChildAdditionals()) {104if (child->getTagProperty()->getTag() == GNE_TAG_CALIBRATOR_FLOW) {105begin = GNEAttributeCarrier::parse<SUMOTime>(child->getAttribute(SUMO_ATTR_END));106}107}108const SUMOTime duration = GNEAttributeCarrier::parse<SUMOTime>("3600");109// create vType110GNECalibratorFlow* calibratorFlow = new GNECalibratorFlow(myElementDialogParent->getElement(), begin, begin + duration, vType, route);111// add using undo-redo112insertElement(calibratorFlow);113// open route dialog114const GNEAttributeCarrierDialog calibratorFlowDialog(calibratorFlow, myElementDialogParent);115// continue depending of result of routeDialog116if (calibratorFlowDialog.getResult() != GNEDialog::Result::ACCEPT) {117// add calibratorFlow118return removeElement(calibratorFlow);119} else if (calibratorFlow->getFileBucket()->getFilename().empty()) {120// in this case, the bucket has to be updated manually121if (vType->getAttribute(GNE_ATTR_DEFAULT_VTYPE_MODIFIED) == GNEAttributeCarrier::TRUE_STR) {122vType->changeFileBucket(calibratorFlow->getFileBucket());123}124route->changeFileBucket(calibratorFlow->getFileBucket());125} else {126if (vType->getAttribute(GNE_ATTR_DEFAULT_VTYPE_MODIFIED) == GNEAttributeCarrier::TRUE_STR) {127vType->setAttribute(GNE_ATTR_SAVEFILE, calibratorFlow->getFileBucket()->getFilename(), calibratorFlow->getNet()->getUndoList());128}129route->setAttribute(GNE_ATTR_SAVEFILE, calibratorFlow->getFileBucket()->getFilename(), calibratorFlow->getNet()->getUndoList());130}131updateList();132return 1;133}134135136long137GNECalibratorDialog::CalibratorFlowsList::openElementDialog(const size_t rowIndex) {138// open attribute carrier dialog139GNEAttributeCarrierDialog(myEditedElements.at(rowIndex), myElementDialogParent);140return 1;141}142143/****************************************************************************/144145146