Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netedit/elements/moving/GNEMoveElementPlan.cpp
185790 views
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
/****************************************************************************/
14
/// @file GNEMoveElementPlan.cpp
15
/// @author Pablo Alvarez Lopez
16
/// @date Oct 2025
17
///
18
// Class used for elements that can be moved over a edge with two positions
19
/****************************************************************************/
20
#include <config.h>
21
22
#include <netedit/changes/GNEChange_Attribute.h>
23
#include <netedit/elements/demand/GNEDemandElementPlan.h>
24
#include <netedit/elements/moving/GNEMoveElementVehicle.h>
25
#include <netedit/GNENet.h>
26
#include <netedit/GNEUndoList.h>
27
28
#include "GNEMoveElementPlan.h"
29
30
// ===========================================================================
31
// member method definitions
32
// ===========================================================================
33
34
GNEMoveElementPlan::GNEMoveElementPlan(GNEDemandElement* planElement, double& departPos) :
35
GNEMoveElement(planElement),
36
myPlanElement(planElement),
37
myArrivalPosition(departPos) {
38
}
39
40
41
GNEMoveElementPlan::~GNEMoveElementPlan() {}
42
43
44
GNEMoveOperation*
45
GNEMoveElementPlan::getMoveOperation() {
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
53
const double circleWidthSquared = GNEMoveElementVehicle::arrivalPositionDiameter * GNEMoveElementVehicle::arrivalPositionDiameter;
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
68
std::string
69
GNEMoveElementPlan::getMovingAttribute(SumoXMLAttr key) const {
70
return myMovedElement->getCommonAttribute(key);
71
}
72
73
74
double
75
GNEMoveElementPlan::getMovingAttributeDouble(SumoXMLAttr key) const {
76
return myMovedElement->getCommonAttributeDouble(key);
77
}
78
79
80
Position
81
GNEMoveElementPlan::getMovingAttributePosition(SumoXMLAttr key) const {
82
return myMovedElement->getCommonAttributePosition(key);
83
}
84
85
86
PositionVector
87
GNEMoveElementPlan::getMovingAttributePositionVector(SumoXMLAttr key) const {
88
return myMovedElement->getCommonAttributePositionVector(key);
89
}
90
91
92
void
93
GNEMoveElementPlan::setMovingAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
94
myMovedElement->setCommonAttribute(key, value, undoList);
95
}
96
97
98
bool
99
GNEMoveElementPlan::isMovingAttributeValid(SumoXMLAttr key, const std::string& value) const {
100
return myMovedElement->isCommonAttributeValid(key, value);
101
}
102
103
104
void
105
GNEMoveElementPlan::setMovingAttribute(SumoXMLAttr key, const std::string& value) {
106
myMovedElement->setCommonAttribute(key, value);
107
}
108
109
110
void
111
GNEMoveElementPlan::removeGeometryPoint(const Position /*clickedPosition*/, GNEUndoList* /*undoList*/) {
112
// nothing to do here
113
}
114
115
116
void
117
GNEMoveElementPlan::setMoveShape(const GNEMoveResult& moveResult) {
118
// change both position
119
myArrivalPosition = moveResult.newLastPos;
120
// update geometry
121
myPlanElement->updateGeometry();
122
}
123
124
125
void
126
GNEMoveElementPlan::commitMoveShape(const GNEMoveResult& moveResult, GNEUndoList* undoList) {
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
/****************************************************************************/
134
135