Path: blob/main/src/netedit/elements/moving/GNEMoveElementJunction.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 GNEMoveElementJunction.cpp14/// @author Pablo Alvarez Lopez15/// @date Oct 202516///17// Class used for moving junctions18/****************************************************************************/19#include <config.h>2021#include <netedit/changes/GNEChange_Attribute.h>22#include <netedit/frames/common/GNEMoveFrame.h>23#include <netedit/GNENet.h>24#include <netedit/GNEUndoList.h>25#include <netedit/GNEViewParent.h>2627#include "GNEMoveElementJunction.h"2829// ===========================================================================30// Method definitions31// ===========================================================================3233GNEMoveElementJunction::GNEMoveElementJunction(GNEJunction* junction) :34GNEMoveElement(junction),35myJunction(junction) {36}373839GNEMoveElementJunction::~GNEMoveElementJunction() {}404142GNEMoveOperation*43GNEMoveElementJunction::getMoveOperation() {44// edit depending if shape is being edited45if (myJunction->isShapeEdited()) {46// calculate move shape operation47return getEditShapeOperation(myJunction, myJunction->getNBNode()->getShape(), false);48} else {49// return move junction position50return new GNEMoveOperation(this, myJunction->getNBNode()->getPosition());51}52}535455GNEJunction*56GNEMoveElementJunction::getJunction() const {57return myJunction;58}596061std::string62GNEMoveElementJunction::getMovingAttribute(SumoXMLAttr key) const {63return myMovedElement->getCommonAttribute(key);64}656667double68GNEMoveElementJunction::getMovingAttributeDouble(SumoXMLAttr key) const {69return myMovedElement->getCommonAttributeDouble(key);70}717273Position74GNEMoveElementJunction::getMovingAttributePosition(SumoXMLAttr key) const {75return myMovedElement->getCommonAttributePosition(key);76}777879PositionVector80GNEMoveElementJunction::getMovingAttributePositionVector(SumoXMLAttr key) const {81return myMovedElement->getCommonAttributePositionVector(key);82}838485void86GNEMoveElementJunction::setMovingAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {87myMovedElement->setCommonAttribute(key, value, undoList);88}899091bool92GNEMoveElementJunction::isMovingAttributeValid(SumoXMLAttr key, const std::string& value) const {93return myMovedElement->isCommonAttributeValid(key, value);94}959697void98GNEMoveElementJunction::setMovingAttribute(SumoXMLAttr key, const std::string& value) {99myMovedElement->setCommonAttribute(key, value);100}101102103void104GNEMoveElementJunction::removeGeometryPoint(const Position clickedPosition, GNEUndoList* undoList) {105// edit depending if shape is being edited106if (myJunction->isShapeEdited()) {107// get original shape108PositionVector shape = myJunction->getNBNode()->getShape();109// check shape size110if (shape.size() > 2) {111// obtain index112int index = shape.indexOfClosest(clickedPosition);113// get snap radius114const double snap_radius = myJunction->getNet()->getViewNet()->getVisualisationSettings().neteditSizeSettings.junctionGeometryPointRadius;115// check if we have to create a new index116if ((index != -1) && shape[index].distanceSquaredTo2D(clickedPosition) < (snap_radius * snap_radius)) {117// remove geometry point118shape.erase(shape.begin() + index);119// commit new shape120undoList->begin(myJunction, TLF("remove geometry point of %", myJunction->getTagStr()));121GNEChange_Attribute::changeAttribute(myJunction, SUMO_ATTR_SHAPE, toString(shape), undoList, true);122undoList->end();123}124}125}126}127128129void130GNEMoveElementJunction::setMoveShape(const GNEMoveResult& moveResult) {131// clear contour132myJunction->myNetworkElementContour.clearContour();133// set new position in NBNode without updating grid134if (myJunction->isShapeEdited()) {135// set new shape136myJunction->getNBNode()->setCustomShape(moveResult.shapeToUpdate);137} else if (moveResult.shapeToUpdate.size() > 0) {138// obtain NBNode position139const Position orig = myJunction->getNBNode()->getPosition();140// move geometry141myJunction->moveJunctionGeometry(moveResult.shapeToUpdate.front(), false);142// check if move only center143const bool onlyMoveCenter = myJunction->getNet()->getViewParent()->getMoveFrame()->getNetworkMoveOptions()->getMoveOnlyJunctionCenter();144// set new position of adjacent edges depending if we're moving a selection145for (const auto& NBEdge : myJunction->getNBNode()->getEdges()) {146myJunction->getNet()->getAttributeCarriers()->retrieveEdge(NBEdge->getID())->updateJunctionPosition(myJunction, onlyMoveCenter ? myJunction->getNBNode()->getPosition() : orig);147}148}149myJunction->updateGeometry();150}151152153void154GNEMoveElementJunction::commitMoveShape(const GNEMoveResult& moveResult, GNEUndoList* undoList) {155// make sure that newShape isn't empty156if (moveResult.shapeToUpdate.size() > 0) {157// check if we're editing a shape158if (myJunction->isShapeEdited()) {159// commit new shape160undoList->begin(myJunction, TLF("moving shape of %", myJunction->getTagStr()));161myJunction->setAttribute(SUMO_ATTR_SHAPE, toString(moveResult.shapeToUpdate), undoList);162undoList->end();163} else if (myJunction->getNBNode()->hasCustomShape()) {164// commit new shape165undoList->begin(myJunction, TLF("moving custom shape of %", myJunction->getTagStr()));166myJunction->setAttribute(SUMO_ATTR_POSITION, toString(moveResult.shapeToUpdate.front()), undoList);167// calculate offset and apply to custom shape168const auto customShapeOffset = moveResult.shapeToUpdate.front() - myJunction->getNBNode()->getCenter();169const auto customShapeMoved = myJunction->getNBNode()->getShape().added(customShapeOffset);170myJunction->setAttribute(SUMO_ATTR_SHAPE, toString(customShapeMoved), undoList);171undoList->end();172} else {173myJunction->setAttribute(SUMO_ATTR_POSITION, toString(moveResult.shapeToUpdate.front()), undoList);174}175}176}177178/****************************************************************************/179180181