Path: blob/main/src/netedit/elements/moving/GNEMoveElementConnection.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 GNEMoveElementConnection.cpp14/// @author Pablo Alvarez Lopez15/// @date Oct 202516///17// Class used for moving connection shapes18/****************************************************************************/19#include <config.h>2021#include <netedit/changes/GNEChange_Attribute.h>22#include <netedit/elements/network/GNEConnection.h>23#include <netedit/GNENet.h>24#include <netedit/GNEUndoList.h>2526#include "GNEMoveElementConnection.h"2728// ===========================================================================29// Method definitions30// ===========================================================================3132GNEMoveElementConnection::GNEMoveElementConnection(GNEConnection* connection) :33GNEMoveElement(connection),34myConnection(connection) {35}363738GNEMoveElementConnection::~GNEMoveElementConnection() {}394041GNEMoveOperation*42GNEMoveElementConnection::getMoveOperation() {43// edit depending if shape is being edited44if (myConnection->isShapeEdited()) {45// get connection46const auto& connection = myConnection->getNBEdgeConnection();47// calculate move shape operation48return getEditShapeOperation(myConnection, connection.customShape.size() > 0 ? connection.customShape : myConnection->myConnectionGeometry.getShape(), false);49} else {50return nullptr;51}52}535455std::string56GNEMoveElementConnection::getMovingAttribute(SumoXMLAttr key) const {57return myMovedElement->getCommonAttribute(key);58}596061double62GNEMoveElementConnection::getMovingAttributeDouble(SumoXMLAttr key) const {63return myMovedElement->getCommonAttributeDouble(key);64}656667Position68GNEMoveElementConnection::getMovingAttributePosition(SumoXMLAttr key) const {69return myMovedElement->getCommonAttributePosition(key);70}717273PositionVector74GNEMoveElementConnection::getMovingAttributePositionVector(SumoXMLAttr key) const {75return myMovedElement->getCommonAttributePositionVector(key);76}777879void80GNEMoveElementConnection::setMovingAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {81myMovedElement->setCommonAttribute(key, value, undoList);82}838485bool86GNEMoveElementConnection::isMovingAttributeValid(SumoXMLAttr key, const std::string& value) const {87return myMovedElement->isCommonAttributeValid(key, value);88}899091void92GNEMoveElementConnection::setMovingAttribute(SumoXMLAttr key, const std::string& value) {93myMovedElement->setCommonAttribute(key, value);94}959697void98GNEMoveElementConnection::removeGeometryPoint(const Position clickedPosition, GNEUndoList* undoList) {99// edit depending if shape is being edited100if (myConnection->isShapeEdited()) {101// get connection102const auto& connection = myConnection->getNBEdgeConnection();103// get original shape104PositionVector shape = connection.customShape.size() > 0 ? connection.customShape : connection.shape;105// check shape size106if (shape.size() > 2) {107// obtain index108int index = shape.indexOfClosest(clickedPosition);109// get snap radius110const double snap_radius = myConnection->getNet()->getViewNet()->getVisualisationSettings().neteditSizeSettings.connectionGeometryPointRadius;111// check if we have to create a new index112if ((index != -1) && shape[index].distanceSquaredTo2D(clickedPosition) < (snap_radius * snap_radius)) {113// remove geometry point114shape.erase(shape.begin() + index);115// commit new shape116undoList->begin(myConnection, TLF("remove geometry point of %", myConnection->getTagStr()));117GNEChange_Attribute::changeAttribute(myConnection, SUMO_ATTR_CUSTOMSHAPE, toString(shape), undoList);118undoList->end();119}120}121}122}123124125void126GNEMoveElementConnection::setMoveShape(const GNEMoveResult& moveResult) {127// set custom shape128myConnection->getNBEdgeConnection().customShape = moveResult.shapeToUpdate;129// mark junction as deprecated130myConnection->myShapeDeprecated = true;131// update geometry132myConnection->updateGeometry();133}134135136void137GNEMoveElementConnection::commitMoveShape(const GNEMoveResult& moveResult, GNEUndoList* undoList) {138// commit new shape139undoList->begin(myConnection, TLF("moving custom shape of %", myConnection->getTagStr()));140GNEChange_Attribute::changeAttribute(myConnection, SUMO_ATTR_CUSTOMSHAPE, toString(moveResult.shapeToUpdate), undoList);141undoList->end();142}143144/****************************************************************************/145146147