Path: blob/main/src/netedit/dialogs/elements/GNEVariableSpeedSignDialog.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 GNEVariableSpeedSignDialog.cpp14/// @author Pablo Alvarez Lopez15/// @date April 201616///17// Dialog for edit variableSpeedSigns18/****************************************************************************/1920#include <netedit/dialogs/basic/GNEWarningBasicDialog.h>21#include <netedit/elements/additional/GNEVariableSpeedSignStep.h>22#include <netedit/GNENet.h>23#include <netedit/GNEUndoList.h>24#include <netedit/GNEViewParent.h>25#include <utils/options/OptionsCont.h>2627#include "GNEVariableSpeedSignDialog.h"2829// ===========================================================================30// member method definitions31// ===========================================================================3233GNEVariableSpeedSignDialog::GNEVariableSpeedSignDialog(GNEAdditional* variableSpeedSign) :34GNETemplateElementDialog<GNEAdditional>(variableSpeedSign, DialogType::VSS) {35// create variableSpeedSign steps element list36myVariableSpeedSignSteps = new VariableSpeedSignStepsList(this);37// open dialog38openDialog();39}404142GNEVariableSpeedSignDialog::~GNEVariableSpeedSignDialog() {}434445void46GNEVariableSpeedSignDialog::runInternalTest(const InternalTestStep::DialogArgument* /*dialogArgument*/) {47// nothing to do48}495051long52GNEVariableSpeedSignDialog::onCmdAccept(FXObject*, FXSelector, void*) {53// Check if there is overlapping between Steps54if (!myVariableSpeedSignSteps->isSorted()) {55// open warning Box56GNEWarningBasicDialog(myElement->getNet()->getViewNet()->getViewParent()->getGNEAppWindows(),57TLF("VariableSpeedSign steps of % '%' cannot be saved", toString(SUMO_TAG_VSS), myElement->getID()),58TL("Steps has to be sorted."));59return 1;60} else {61// close dialog accepting changes62return acceptElementDialog();63}64}656667long68GNEVariableSpeedSignDialog::onCmdReset(FXObject*, FXSelector, void*) {69// reset changes70resetChanges();71// update tables72myVariableSpeedSignSteps->updateList();73return 1;74}7576// ---------------------------------------------------------------------------77// GNEVariableSpeedSignDialog::VariableSpeedSignStepsList - methods78// ---------------------------------------------------------------------------7980GNEVariableSpeedSignDialog::VariableSpeedSignStepsList::VariableSpeedSignStepsList(GNEVariableSpeedSignDialog* variableSpeedSignDialog) :81GNETemplateElementList(variableSpeedSignDialog, variableSpeedSignDialog->getContentFrame(), SUMO_TAG_STEP,82GNEElementList::Options::SORTELEMENTS | GNEElementList::Options::FIXED_HEIGHT) {83}848586long87GNEVariableSpeedSignDialog::VariableSpeedSignStepsList::addNewElement() {88// create step depending of number of steps89if (getEditedElements().empty()) {90return insertElement(new GNEVariableSpeedSignStep(myElementDialogParent->getElement(), 0,91OptionsCont::getOptions().getFloat("default.speed")));92} else {93SUMOTime biggestTime = 0;94// get end with biggest end95for (const auto& step : getEditedElements()) {96const auto time = string2time(step->getAttribute(SUMO_ATTR_TIME));97if (biggestTime < time) {98biggestTime = time;99}100}101return insertElement(new GNEVariableSpeedSignStep(myElementDialogParent->getElement(), biggestTime + string2time("10"),102OptionsCont::getOptions().getFloat("default.speed")));103}104}105106107long108GNEVariableSpeedSignDialog::VariableSpeedSignStepsList::openElementDialog(const size_t /*rowIndex*/) {109// nothing to edit in steps110return 1;111}112113114bool115GNEVariableSpeedSignDialog::VariableSpeedSignStepsList::isSorted() const {116// declare a vector to store steps117std::vector<double> sortedSteps;118// save time steps119for (const auto& step : getEditedElements()) {120sortedSteps.push_back(step->getAttributeDouble(SUMO_ATTR_TIME));121}122// check if all are sorted123if (sortedSteps.size() > 1) {124// check if the next step is bigger than the current step125for (int i = 0; i < (int)sortedSteps.size() - 1; i++) {126if (sortedSteps.at(i) > sortedSteps.at(i + 1)) {127return false;128}129}130}131return true;132}133134/****************************************************************************/135136137