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