Path: blob/main/src/netedit/elements/moving/GNEMoveElementCrossing.cpp
185790 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 GNEMoveElementCrossing.cpp14/// @author Pablo Alvarez Lopez15/// @date Oct 202516///17// Class used for moving crossing shapes18/****************************************************************************/19#include <config.h>2021#include <netedit/changes/GNEChange_Attribute.h>22#include <netedit/elements/network/GNECrossing.h>23#include <netedit/GNENet.h>24#include <netedit/GNEUndoList.h>2526#include "GNEMoveElementCrossing.h"2728// ===========================================================================29// Method definitions30// ===========================================================================3132GNEMoveElementCrossing::GNEMoveElementCrossing(GNECrossing* crossing) :33GNEMoveElement(crossing),34myCrossing(crossing) {35}363738GNEMoveElementCrossing::~GNEMoveElementCrossing() {}394041std::string42GNEMoveElementCrossing::getMovingAttribute(SumoXMLAttr key) const {43return myMovedElement->getCommonAttribute(key);44}454647double48GNEMoveElementCrossing::getMovingAttributeDouble(SumoXMLAttr key) const {49return myMovedElement->getCommonAttributeDouble(key);50}515253Position54GNEMoveElementCrossing::getMovingAttributePosition(SumoXMLAttr key) const {55return myMovedElement->getCommonAttributePosition(key);56}575859PositionVector60GNEMoveElementCrossing::getMovingAttributePositionVector(SumoXMLAttr key) const {61return myMovedElement->getCommonAttributePositionVector(key);62}636465void66GNEMoveElementCrossing::setMovingAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {67myMovedElement->setCommonAttribute(key, value, undoList);68}697071bool72GNEMoveElementCrossing::isMovingAttributeValid(SumoXMLAttr key, const std::string& value) const {73return myMovedElement->isCommonAttributeValid(key, value);74}757677void78GNEMoveElementCrossing::setMovingAttribute(SumoXMLAttr key, const std::string& value) {79myMovedElement->setCommonAttribute(key, value);80}818283GNEMoveOperation*84GNEMoveElementCrossing::getMoveOperation() {85// edit depending if shape is being edited86if (myCrossing->isShapeEdited()) {87// calculate move shape operation88return getEditShapeOperation(myCrossing, myCrossing->getCrossingShape(), false);89} else {90return nullptr;91}92}939495void96GNEMoveElementCrossing::removeGeometryPoint(const Position clickedPosition, GNEUndoList* undoList) {97// edit depending if shape is being edited98if (myCrossing->isShapeEdited()) {99// get original shape100PositionVector shape = myCrossing->getCrossingShape();101// check shape size102if (shape.size() > 2) {103// obtain index104int index = shape.indexOfClosest(clickedPosition);105// get snap radius106const double snap_radius = myCrossing->getNet()->getViewNet()->getVisualisationSettings().neteditSizeSettings.crossingGeometryPointRadius;107// check if we have to create a new index108if ((index != -1) && shape[index].distanceSquaredTo2D(clickedPosition) < (snap_radius * snap_radius)) {109// remove geometry point110shape.erase(shape.begin() + index);111// commit new shape112undoList->begin(myCrossing, TLF("remove geometry point of %", myCrossing->getTagStr()));113GNEChange_Attribute::changeAttribute(myCrossing, SUMO_ATTR_CUSTOMSHAPE, toString(shape), undoList, true);114undoList->end();115}116}117}118}119120121void122GNEMoveElementCrossing::setMoveShape(const GNEMoveResult& moveResult) {123// set custom shape124myCrossing->getNBCrossing()->customShape = moveResult.shapeToUpdate;125// update geometry126myCrossing->updateGeometry();127}128129130void131GNEMoveElementCrossing::commitMoveShape(const GNEMoveResult& moveResult, GNEUndoList* undoList) {132// commit new shape133undoList->begin(myCrossing, TLF("moving % of %", toString(SUMO_ATTR_CUSTOMSHAPE), myCrossing->getTagStr()));134GNEChange_Attribute::changeAttribute(myCrossing, SUMO_ATTR_CUSTOMSHAPE, toString(moveResult.shapeToUpdate), undoList, true);135undoList->end();136}137138/****************************************************************************/139140141