Path: blob/main/src/netedit/elements/moving/GNEMoveElementLane.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 GNEMoveElementLane.cpp14/// @author Pablo Alvarez Lopez15/// @date Oct 202516///17// Class used for moving lane shapes18/****************************************************************************/19#include <config.h>2021#include <netedit/changes/GNEChange_Attribute.h>22#include <netedit/GNENet.h>23#include <netedit/GNEUndoList.h>2425#include "GNEMoveElementLane.h"2627// ===========================================================================28// Method definitions29// ===========================================================================3031GNEMoveElementLane::GNEMoveElementLane(GNELane* lane) :32GNEMoveElement(lane),33myLane(lane) {34}353637GNEMoveElementLane::~GNEMoveElementLane() {}383940GNEMoveOperation*41GNEMoveElementLane::getMoveOperation() {42// edit depending if shape is being edited43if (myLane->isShapeEdited()) {44// calculate move shape operation45return getEditShapeOperation(myLane, myLane->getLaneShape(), false);46} else {47return nullptr;48}49}505152std::string53GNEMoveElementLane::getMovingAttribute(SumoXMLAttr key) const {54return myMovedElement->getCommonAttribute(key);55}565758double59GNEMoveElementLane::getMovingAttributeDouble(SumoXMLAttr key) const {60return myMovedElement->getCommonAttributeDouble(key);61}626364Position65GNEMoveElementLane::getMovingAttributePosition(SumoXMLAttr key) const {66return myMovedElement->getCommonAttributePosition(key);67}686970PositionVector71GNEMoveElementLane::getMovingAttributePositionVector(SumoXMLAttr key) const {72return myMovedElement->getCommonAttributePositionVector(key);73}747576void77GNEMoveElementLane::setMovingAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {78myMovedElement->setCommonAttribute(key, value, undoList);79}808182bool83GNEMoveElementLane::isMovingAttributeValid(SumoXMLAttr key, const std::string& value) const {84return myMovedElement->isCommonAttributeValid(key, value);85}868788void89GNEMoveElementLane::setMovingAttribute(SumoXMLAttr key, const std::string& value) {90myMovedElement->setCommonAttribute(key, value);91}929394void95GNEMoveElementLane::removeGeometryPoint(const Position clickedPosition, GNEUndoList* undoList) {96// edit depending if shape is being edited97if (myLane->isShapeEdited()) {98// get original shape99PositionVector shape = myLane->getLaneShape();100// check shape size101if (shape.size() > 2) {102// obtain index103int index = shape.indexOfClosest(clickedPosition);104// get snap radius105const double snap_radius = myLane->getNet()->getViewNet()->getVisualisationSettings().neteditSizeSettings.laneGeometryPointRadius;106// check if we have to create a new index107if ((index != -1) && shape[index].distanceSquaredTo2D(clickedPosition) < (snap_radius * snap_radius)) {108// remove geometry point109shape.erase(shape.begin() + index);110// commit new shape111undoList->begin(myLane, TLF("remove geometry point of %", myLane->getTagStr()));112GNEChange_Attribute::changeAttribute(myLane, SUMO_ATTR_CUSTOMSHAPE, toString(shape), undoList);113undoList->end();114}115}116}117}118119120void121GNEMoveElementLane::setMoveShape(const GNEMoveResult& moveResult) {122// set custom shape123myLane->getParentEdges().front()->getNBEdge()->getLaneStruct(myLane->getIndex()).customShape = moveResult.shapeToUpdate;124// update geometry125myLane->updateGeometry();126}127128129void130GNEMoveElementLane::commitMoveShape(const GNEMoveResult& moveResult, GNEUndoList* undoList) {131// commit new shape132undoList->begin(myLane, TLF("moving custom shape of %", myLane->getTagStr()));133GNEChange_Attribute::changeAttribute(myLane, SUMO_ATTR_CUSTOMSHAPE, toString(moveResult.shapeToUpdate), undoList);134undoList->end();135}136137/****************************************************************************/138139140