Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netedit/elements/moving/GNEMoveElementLane.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 GNEMoveElementLane.cpp
15
/// @author Pablo Alvarez Lopez
16
/// @date Oct 2025
17
///
18
// Class used for moving lane shapes
19
/****************************************************************************/
20
#include <config.h>
21
22
#include <netedit/changes/GNEChange_Attribute.h>
23
#include <netedit/GNENet.h>
24
#include <netedit/GNEUndoList.h>
25
26
#include "GNEMoveElementLane.h"
27
28
// ===========================================================================
29
// Method definitions
30
// ===========================================================================
31
32
GNEMoveElementLane::GNEMoveElementLane(GNELane* lane) :
33
GNEMoveElement(lane),
34
myLane(lane) {
35
}
36
37
38
GNEMoveElementLane::~GNEMoveElementLane() {}
39
40
41
GNEMoveOperation*
42
GNEMoveElementLane::getMoveOperation() {
43
// edit depending if shape is being edited
44
if (myLane->isShapeEdited()) {
45
// calculate move shape operation
46
return getEditShapeOperation(myLane, myLane->getLaneShape(), false);
47
} else {
48
return nullptr;
49
}
50
}
51
52
53
std::string
54
GNEMoveElementLane::getMovingAttribute(SumoXMLAttr key) const {
55
return myMovedElement->getCommonAttribute(key);
56
}
57
58
59
double
60
GNEMoveElementLane::getMovingAttributeDouble(SumoXMLAttr key) const {
61
return myMovedElement->getCommonAttributeDouble(key);
62
}
63
64
65
Position
66
GNEMoveElementLane::getMovingAttributePosition(SumoXMLAttr key) const {
67
return myMovedElement->getCommonAttributePosition(key);
68
}
69
70
71
PositionVector
72
GNEMoveElementLane::getMovingAttributePositionVector(SumoXMLAttr key) const {
73
return myMovedElement->getCommonAttributePositionVector(key);
74
}
75
76
77
void
78
GNEMoveElementLane::setMovingAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
79
myMovedElement->setCommonAttribute(key, value, undoList);
80
}
81
82
83
bool
84
GNEMoveElementLane::isMovingAttributeValid(SumoXMLAttr key, const std::string& value) const {
85
return myMovedElement->isCommonAttributeValid(key, value);
86
}
87
88
89
void
90
GNEMoveElementLane::setMovingAttribute(SumoXMLAttr key, const std::string& value) {
91
myMovedElement->setCommonAttribute(key, value);
92
}
93
94
95
void
96
GNEMoveElementLane::removeGeometryPoint(const Position clickedPosition, GNEUndoList* undoList) {
97
// edit depending if shape is being edited
98
if (myLane->isShapeEdited()) {
99
// get original shape
100
PositionVector shape = myLane->getLaneShape();
101
// check shape size
102
if (shape.size() > 2) {
103
// obtain index
104
int index = shape.indexOfClosest(clickedPosition);
105
// get snap radius
106
const double snap_radius = myLane->getNet()->getViewNet()->getVisualisationSettings().neteditSizeSettings.laneGeometryPointRadius;
107
// check if we have to create a new index
108
if ((index != -1) && shape[index].distanceSquaredTo2D(clickedPosition) < (snap_radius * snap_radius)) {
109
// remove geometry point
110
shape.erase(shape.begin() + index);
111
// commit new shape
112
undoList->begin(myLane, TLF("remove geometry point of %", myLane->getTagStr()));
113
GNEChange_Attribute::changeAttribute(myLane, SUMO_ATTR_CUSTOMSHAPE, toString(shape), undoList);
114
undoList->end();
115
}
116
}
117
}
118
}
119
120
121
void
122
GNEMoveElementLane::setMoveShape(const GNEMoveResult& moveResult) {
123
// set custom shape
124
myLane->getParentEdges().front()->getNBEdge()->getLaneStruct(myLane->getIndex()).customShape = moveResult.shapeToUpdate;
125
// update geometry
126
myLane->updateGeometry();
127
}
128
129
130
void
131
GNEMoveElementLane::commitMoveShape(const GNEMoveResult& moveResult, GNEUndoList* undoList) {
132
// commit new shape
133
undoList->begin(myLane, TLF("moving custom shape of %", myLane->getTagStr()));
134
GNEChange_Attribute::changeAttribute(myLane, SUMO_ATTR_CUSTOMSHAPE, toString(moveResult.shapeToUpdate), undoList);
135
undoList->end();
136
}
137
138
/****************************************************************************/
139
140