Path: blob/main/src/netedit/elements/moving/GNEMoveElementPlan.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 GNEMoveElementPlan.cpp14/// @author Pablo Alvarez Lopez15/// @date Oct 202516///17// Class used for elements that can be moved over a edge with two positions18/****************************************************************************/19#include <config.h>2021#include <netedit/changes/GNEChange_Attribute.h>22#include <netedit/elements/demand/GNEDemandElementPlan.h>23#include <netedit/elements/moving/GNEMoveElementVehicle.h>24#include <netedit/GNENet.h>25#include <netedit/GNEUndoList.h>2627#include "GNEMoveElementPlan.h"2829// ===========================================================================30// member method definitions31// ===========================================================================3233GNEMoveElementPlan::GNEMoveElementPlan(GNEDemandElement* planElement, double& departPos) :34GNEMoveElement(planElement),35myPlanElement(planElement),36myArrivalPosition(departPos) {37}383940GNEMoveElementPlan::~GNEMoveElementPlan() {}414243GNEMoveOperation*44GNEMoveElementPlan::getMoveOperation() {45// get tag property46const auto tagProperty = myPlanElement->getTagProperty();47// only move personTrips defined over edges48if (tagProperty->planToEdge() || tagProperty->planConsecutiveEdges() || tagProperty->planEdge()) {49// get geometry end pos50const Position geometryEndPos = myPlanElement->getAttributePosition(GNE_ATTR_PLAN_GEOMETRY_ENDPOS);51// calculate circle width squared52const double circleWidthSquared = GNEMoveElementVehicle::arrivalPositionDiameter * GNEMoveElementVehicle::arrivalPositionDiameter;53// check if we clicked over a geometry end pos54if (myPlanElement->getNet()->getViewNet()->getPositionInformation().distanceSquaredTo2D(geometryEndPos) <= ((circleWidthSquared + 2))) {55// continue depending of parent edges56if (myPlanElement->getParentEdges().size() > 0) {57return new GNEMoveOperation(this, myPlanElement->getParentEdges().back()->getLaneByAllowedVClass(myPlanElement->getVClass()), myArrivalPosition, false);58} else {59return new GNEMoveOperation(this, myPlanElement->getParentDemandElements().at(1)->getParentEdges().back()->getLaneByAllowedVClass(myPlanElement->getVClass()), myArrivalPosition, false);60}61}62}63return nullptr;64}656667std::string68GNEMoveElementPlan::getMovingAttribute(SumoXMLAttr key) const {69return myMovedElement->getCommonAttribute(key);70}717273double74GNEMoveElementPlan::getMovingAttributeDouble(SumoXMLAttr key) const {75return myMovedElement->getCommonAttributeDouble(key);76}777879Position80GNEMoveElementPlan::getMovingAttributePosition(SumoXMLAttr key) const {81return myMovedElement->getCommonAttributePosition(key);82}838485PositionVector86GNEMoveElementPlan::getMovingAttributePositionVector(SumoXMLAttr key) const {87return myMovedElement->getCommonAttributePositionVector(key);88}899091void92GNEMoveElementPlan::setMovingAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {93myMovedElement->setCommonAttribute(key, value, undoList);94}959697bool98GNEMoveElementPlan::isMovingAttributeValid(SumoXMLAttr key, const std::string& value) const {99return myMovedElement->isCommonAttributeValid(key, value);100}101102103void104GNEMoveElementPlan::setMovingAttribute(SumoXMLAttr key, const std::string& value) {105myMovedElement->setCommonAttribute(key, value);106}107108109void110GNEMoveElementPlan::removeGeometryPoint(const Position /*clickedPosition*/, GNEUndoList* /*undoList*/) {111// nothing to do here112}113114115void116GNEMoveElementPlan::setMoveShape(const GNEMoveResult& moveResult) {117// change both position118myArrivalPosition = moveResult.newLastPos;119// update geometry120myPlanElement->updateGeometry();121}122123124void125GNEMoveElementPlan::commitMoveShape(const GNEMoveResult& moveResult, GNEUndoList* undoList) {126undoList->begin(myPlanElement, TLF("arrivalPos of %", myPlanElement->getTagStr()));127// now adjust start position128myPlanElement->setAttribute(SUMO_ATTR_ARRIVALPOS, toString(moveResult.newFirstPos), undoList);129undoList->end();130}131132/****************************************************************************/133134135