Path: blob/main/src/netedit/elements/moving/GNEMoveElementView.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 GNEMoveElementView.cpp14/// @author Pablo Alvarez Lopez15/// @date Sep 202516///17// Class used for elements that can be moved over view18/****************************************************************************/19#include <config.h>2021#include <netedit/changes/GNEChange_Attribute.h>22#include <netedit/GNENet.h>23#include <netedit/GNEUndoList.h>2425#include "GNEMoveElementView.h"2627// ===========================================================================28// Method definitions29// ===========================================================================3031GNEMoveElementView::GNEMoveElementView(GNEAttributeCarrier* element, AttributesFormat attributesFormat,32SumoXMLAttr posAttr, Position& position) :33GNEMoveElement(element),34myPosAttr(posAttr),35myPosOverView(position),36myAttributesFormat(attributesFormat) {37}3839GNEMoveElementView::~GNEMoveElementView() {}404142GNEMoveOperation*43GNEMoveElementView::getMoveOperation() {44// move entire space45return new GNEMoveOperation(this, myPosOverView);46}474849std::string50GNEMoveElementView::getMovingAttribute(SumoXMLAttr key) const {51if (key == myPosAttr) {52return toString(myPosOverView);53} else {54return myMovedElement->getCommonAttribute(key);55}56}575859double60GNEMoveElementView::getMovingAttributeDouble(SumoXMLAttr key) const {61return myMovedElement->getCommonAttributeDouble(key);62}636465Position66GNEMoveElementView::getMovingAttributePosition(SumoXMLAttr key) const {67if (key == myPosAttr) {68return myPosOverView;69} else {70return myMovedElement->getCommonAttributePosition(key);71}72}737475PositionVector76GNEMoveElementView::getMovingAttributePositionVector(SumoXMLAttr key) const {77return myMovedElement->getCommonAttributePositionVector(key);78}798081void82GNEMoveElementView::setMovingAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {83if (key == myPosAttr) {84GNEChange_Attribute::changeAttribute(myMovedElement, key, value, undoList);85} else {86myMovedElement->setCommonAttribute(key, value, undoList);87}88}899091bool92GNEMoveElementView::isMovingAttributeValid(SumoXMLAttr key, const std::string& value) const {93if (key == myPosAttr) {94return GNEAttributeCarrier::canParse<Position>(value);95} else {96return myMovedElement->isCommonAttributeValid(key, value);97}98}99100101void102GNEMoveElementView::setMovingAttribute(SumoXMLAttr key, const std::string& value) {103if (key == myPosAttr) {104myPosOverView = GNEAttributeCarrier::parse<Position>(value);105} else {106myMovedElement->setCommonAttribute(key, value);107}108}109110111void112GNEMoveElementView::removeGeometryPoint(const Position /*clickedPosition*/, GNEUndoList* /*undoList*/) {113// nothing to do here114}115116117void118GNEMoveElementView::writeMoveAttributes(OutputDevice& device) const {119// position format120if (myAttributesFormat == AttributesFormat::POSITION) {121device.writeAttr(SUMO_ATTR_POSITION, myPosOverView);122} else {123// x-y format124if (myAttributesFormat == AttributesFormat::CARTESIAN) {125device.writeAttr(SUMO_ATTR_X, myPosOverView.x());126device.writeAttr(SUMO_ATTR_Y, myPosOverView.y());127}128// geo format129if (myAttributesFormat == AttributesFormat::GEO) {130device.setPrecision(gPrecisionGeo);131device.writeAttr(SUMO_ATTR_LON, myMovedElement->getAttributeDouble(SUMO_ATTR_LON));132device.writeAttr(SUMO_ATTR_LAT, myMovedElement->getAttributeDouble(SUMO_ATTR_LAT));133device.setPrecision();134}135// z136if (myPosOverView.z() != 0) {137device.writeAttr(SUMO_ATTR_Z, myPosOverView.z());138}139}140}141142143void144GNEMoveElementView::setMoveShape(const GNEMoveResult& moveResult) {145myPosOverView = moveResult.shapeToUpdate.front();146// update geometry147myMovedElement->updateGeometry();148}149150151void152GNEMoveElementView::commitMoveShape(const GNEMoveResult& moveResult, GNEUndoList* undoList) {153undoList->begin(myMovedElement, TLF("position of %", myMovedElement->getTagStr()));154GNEChange_Attribute::changeAttribute(myMovedElement, SUMO_ATTR_POSITION, toString(moveResult.shapeToUpdate.front()), undoList);155undoList->end();156}157158/****************************************************************************/159160161