Path: blob/main/src/netedit/elements/moving/GNEMoveElementViewResizable.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 GNEMoveElementViewResizable.cpp14/// @author Pablo Alvarez Lopez15/// @date Sep 202516///17// Class used for elements that can be moved over view and resized18/****************************************************************************/19#include <config.h>2021#include <netedit/changes/GNEChange_Attribute.h>22#include <netedit/GNENet.h>23#include <netedit/GNEUndoList.h>2425#include "GNEMoveElementViewResizable.h"2627// ===========================================================================28// Method definitions29// ===========================================================================3031GNEMoveElementViewResizable::GNEMoveElementViewResizable(GNEAttributeCarrier* element, AttributesFormat attributesFormat,32ResizingFormat resizingFormat, SumoXMLAttr posAttr,33Position& position) :34GNEMoveElementView(element, attributesFormat, posAttr, position),35myEditWidth((resizingFormat == ResizingFormat::WIDTH_HEIGHT) || (resizingFormat == ResizingFormat::WIDTH_LENGTH)),36myEditHeight(resizingFormat == ResizingFormat::WIDTH_HEIGHT),37myEditLength(resizingFormat == ResizingFormat::WIDTH_LENGTH) {38}394041GNEMoveElementViewResizable::~GNEMoveElementViewResizable() {}424344GNEMoveOperation*45GNEMoveElementViewResizable::getMoveOperation() {46if (myMovedElement->drawMovingGeometryPoints()) {47// get snap radius48const auto snap_radius = myMovedElement->getNet()->getViewNet()->getVisualisationSettings().neteditSizeSettings.additionalGeometryPointRadius;49const auto snapRadiusSquared = (snap_radius * snap_radius);50// get mouse position51const Position mousePosition = myMovedElement->getNet()->getViewNet()->getPositionInformation();52// check what we're editing53if (myEditLength && (myShapeHeight.size() > 0) && (myShapeHeight.back().distanceSquaredTo2D(mousePosition) <= snapRadiusSquared)) {54// edit length55return new GNEMoveOperation(this, myShapeHeight, false, GNEMoveOperation::OperationType::LENGTH);56} else if (myEditWidth && (myShapeWidth.size() > 0) && (myShapeWidth.front().distanceSquaredTo2D(mousePosition) <= snapRadiusSquared)) {57// edit width58return new GNEMoveOperation(this, myShapeWidth, true, GNEMoveOperation::OperationType::WIDTH);59} else if (myEditWidth && (myShapeWidth.size() > 0) && (myShapeWidth.back().distanceSquaredTo2D(mousePosition) <= snapRadiusSquared)) {60// edit width61return new GNEMoveOperation(this, myShapeWidth, false, GNEMoveOperation::OperationType::WIDTH);62} else if (myEditHeight && (myShapeHeight.size() > 0) && (myShapeHeight.front().distanceSquaredTo2D(mousePosition) <= snapRadiusSquared)) {63// edit height64return new GNEMoveOperation(this, myShapeHeight, true, GNEMoveOperation::OperationType::HEIGHT);65} else if (myEditHeight && (myShapeHeight.size() > 0) && (myShapeHeight.back().distanceSquaredTo2D(mousePosition) <= snapRadiusSquared)) {66// edit height67return new GNEMoveOperation(this, myShapeHeight, false, GNEMoveOperation::OperationType::HEIGHT);68} else {69return nullptr;70}71} else {72// we're moving a position73return GNEMoveElementView::getMoveOperation();74}75}767778void79GNEMoveElementViewResizable::setMoveShape(const GNEMoveResult& moveResult) {80// check what are being updated81if (moveResult.operationType == GNEMoveOperation::OperationType::LENGTH) {82myShapeHeight[1] = moveResult.shapeToUpdate[1];83} else if (moveResult.operationType == GNEMoveOperation::OperationType::WIDTH) {84myShapeWidth = moveResult.shapeToUpdate;85} else if (moveResult.operationType == GNEMoveOperation::OperationType::HEIGHT) {86myShapeHeight = moveResult.shapeToUpdate;87} else {88// we're moving a position89GNEMoveElementView::setMoveShape(moveResult);90}91}929394void95GNEMoveElementViewResizable::commitMoveShape(const GNEMoveResult& moveResult, GNEUndoList* undoList) {96// check what are being updated97if (moveResult.operationType == GNEMoveOperation::OperationType::LENGTH) {98undoList->begin(myMovedElement, TLF("length of %", myMovedElement->getTagStr()));99myMovedElement->setAttribute(SUMO_ATTR_LENGTH, toString(myShapeHeight[0].distanceTo2D(moveResult.shapeToUpdate[1])), undoList);100undoList->end();101} else if (moveResult.operationType == GNEMoveOperation::OperationType::WIDTH) {102undoList->begin(myMovedElement, TLF("width of %", myMovedElement->getTagStr()));103myMovedElement->setAttribute(SUMO_ATTR_WIDTH, toString(moveResult.shapeToUpdate.length2D()), undoList);104undoList->end();105} else if (moveResult.operationType == GNEMoveOperation::OperationType::HEIGHT) {106undoList->begin(myMovedElement, TLF("height of %", myMovedElement->getTagStr()));107myMovedElement->setAttribute(SUMO_ATTR_HEIGHT, toString(moveResult.shapeToUpdate.length2D()), undoList);108undoList->end();109} else {110// we're moving a position111GNEMoveElementView::commitMoveShape(moveResult, undoList);112}113}114115/****************************************************************************/116117118