Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GNEMoveElementPlan.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2001-2025 German Aerospace Center (DLR) and others.
4// This program and the accompanying materials are made available under the
5// terms of the Eclipse Public License 2.0 which is available at
6// https://www.eclipse.org/legal/epl-2.0/
7// This Source Code may also be made available under the following Secondary
8// Licenses when the conditions for such availability set forth in the Eclipse
9// Public License 2.0 are satisfied: GNU General Public License, version 2
10// or later which is available at
11// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13/****************************************************************************/
18// Class used for elements that can be moved over a edge with two positions
19/****************************************************************************/
20#include <config.h>
21
25#include <netedit/GNENet.h>
26#include <netedit/GNEUndoList.h>
27
28#include "GNEMoveElementPlan.h"
29
30// ===========================================================================
31// member method definitions
32// ===========================================================================
33
35 GNEMoveElement(planElement),
36 myPlanElement(planElement),
37 myArrivalPosition(departPos) {
38}
39
40
42
43
46 // get tag property
47 const auto tagProperty = myPlanElement->getTagProperty();
48 // only move personTrips defined over edges
49 if (tagProperty->planToEdge() || tagProperty->planConsecutiveEdges() || tagProperty->planEdge()) {
50 // get geometry end pos
51 const Position geometryEndPos = myPlanElement->getAttributePosition(GNE_ATTR_PLAN_GEOMETRY_ENDPOS);
52 // calculate circle width squared
54 // check if we clicked over a geometry end pos
55 if (myPlanElement->getNet()->getViewNet()->getPositionInformation().distanceSquaredTo2D(geometryEndPos) <= ((circleWidthSquared + 2))) {
56 // continue depending of parent edges
57 if (myPlanElement->getParentEdges().size() > 0) {
58 return new GNEMoveOperation(this, myPlanElement->getParentEdges().back()->getLaneByAllowedVClass(myPlanElement->getVClass()), myArrivalPosition, false);
59 } else {
60 return new GNEMoveOperation(this, myPlanElement->getParentDemandElements().at(1)->getParentEdges().back()->getLaneByAllowedVClass(myPlanElement->getVClass()), myArrivalPosition, false);
61 }
62 }
63 }
64 return nullptr;
65}
66
67
68std::string
70 return myMovedElement->getCommonAttribute(key);
71}
72
73
74double
76 return myMovedElement->getCommonAttributeDouble(key);
77}
78
79
82 return myMovedElement->getCommonAttributePosition(key);
83}
84
85
88 return myMovedElement->getCommonAttributePositionVector(key);
89}
90
91
92void
94 myMovedElement->setCommonAttribute(key, value, undoList);
95}
96
97
98bool
100 return myMovedElement->isCommonAttributeValid(key, value);
101}
102
103
104void
106 myMovedElement->setCommonAttribute(key, value);
107}
108
109
110void
111GNEMoveElementPlan::removeGeometryPoint(const Position /*clickedPosition*/, GNEUndoList* /*undoList*/) {
112 // nothing to do here
113}
114
115
116void
118 // change both position
119 myArrivalPosition = moveResult.newLastPos;
120 // update geometry
121 myPlanElement->updateGeometry();
122}
123
124
125void
127 undoList->begin(myPlanElement, TLF("arrivalPos of %", myPlanElement->getTagStr()));
128 // now adjust start position
129 myPlanElement->setAttribute(SUMO_ATTR_ARRIVALPOS, toString(moveResult.newFirstPos), undoList);
130 undoList->end();
131}
132
133/****************************************************************************/
#define TLF(string,...)
Definition MsgHandler.h:306
const std::string invalid_return< std::string >::value
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ SUMO_ATTR_ARRIVALPOS
@ GNE_ATTR_PLAN_GEOMETRY_ENDPOS
person/container geometry end position
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:46
GNEAttributeCarrier * myMovedElement
pointer to element
GNEMoveElement(GNEAttributeCarrier *movedElement)
constructor
bool isMovingAttributeValid(SumoXMLAttr key, const std::string &value) const override
check if the given moving attribute is valid
Position getMovingAttributePosition(SumoXMLAttr key) const override
get moving attribute position
PositionVector getMovingAttributePositionVector(SumoXMLAttr key) const override
get moving attribute positionVector
void commitMoveShape(const GNEMoveResult &moveResult, GNEUndoList *undoList) override
commit move shape
double getMovingAttributeDouble(SumoXMLAttr key) const override
get moving attribute double
GNEMoveOperation * getMoveOperation() override
get edge movable move operation for elements with
void removeGeometryPoint(const Position clickedPosition, GNEUndoList *undoList) override
remove geometry point in the clicked position
void setMovingAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList) override
set moving attribute (using undo-list)
GNEDemandElement * myPlanElement
planElement
~GNEMoveElementPlan()
Destructor.
void setMoveShape(const GNEMoveResult &moveResult) override
set move shape
double & myArrivalPosition
departPos
std::string getMovingAttribute(SumoXMLAttr key) const override
get moving attribute
GNEMoveElementPlan(GNEDemandElement *planElement, double &departPos)
Constructor.
static const double arrivalPositionDiameter
vehicle arrival position radius
double newFirstPos
new first position
double newLastPos
new last position
void end()
End undo command sub-group. If the sub-group is still empty, it will be deleted; otherwise,...
void begin(GUIIcon icon, const std::string &description)
Begin undo command sub-group with current supermode. This begins a new group of commands that are tre...
A point in 2D or 3D with translation and scaling methods.
Definition Position.h:37
A list of positions.