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