Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netedit/elements/moving/GNEMoveElementJunction.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 GNEMoveElementJunction.cpp
15
/// @author Pablo Alvarez Lopez
16
/// @date Oct 2025
17
///
18
// Class used for moving junctions
19
/****************************************************************************/
20
#include <config.h>
21
22
#include <netedit/changes/GNEChange_Attribute.h>
23
#include <netedit/frames/common/GNEMoveFrame.h>
24
#include <netedit/GNENet.h>
25
#include <netedit/GNEUndoList.h>
26
#include <netedit/GNEViewParent.h>
27
28
#include "GNEMoveElementJunction.h"
29
30
// ===========================================================================
31
// Method definitions
32
// ===========================================================================
33
34
GNEMoveElementJunction::GNEMoveElementJunction(GNEJunction* junction) :
35
GNEMoveElement(junction),
36
myJunction(junction) {
37
}
38
39
40
GNEMoveElementJunction::~GNEMoveElementJunction() {}
41
42
43
GNEMoveOperation*
44
GNEMoveElementJunction::getMoveOperation() {
45
// edit depending if shape is being edited
46
if (myJunction->isShapeEdited()) {
47
// calculate move shape operation
48
return getEditShapeOperation(myJunction, myJunction->getNBNode()->getShape(), false);
49
} else {
50
// return move junction position
51
return new GNEMoveOperation(this, myJunction->getNBNode()->getPosition());
52
}
53
}
54
55
56
GNEJunction*
57
GNEMoveElementJunction::getJunction() const {
58
return myJunction;
59
}
60
61
62
std::string
63
GNEMoveElementJunction::getMovingAttribute(SumoXMLAttr key) const {
64
return myMovedElement->getCommonAttribute(key);
65
}
66
67
68
double
69
GNEMoveElementJunction::getMovingAttributeDouble(SumoXMLAttr key) const {
70
return myMovedElement->getCommonAttributeDouble(key);
71
}
72
73
74
Position
75
GNEMoveElementJunction::getMovingAttributePosition(SumoXMLAttr key) const {
76
return myMovedElement->getCommonAttributePosition(key);
77
}
78
79
80
PositionVector
81
GNEMoveElementJunction::getMovingAttributePositionVector(SumoXMLAttr key) const {
82
return myMovedElement->getCommonAttributePositionVector(key);
83
}
84
85
86
void
87
GNEMoveElementJunction::setMovingAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
88
myMovedElement->setCommonAttribute(key, value, undoList);
89
}
90
91
92
bool
93
GNEMoveElementJunction::isMovingAttributeValid(SumoXMLAttr key, const std::string& value) const {
94
return myMovedElement->isCommonAttributeValid(key, value);
95
}
96
97
98
void
99
GNEMoveElementJunction::setMovingAttribute(SumoXMLAttr key, const std::string& value) {
100
myMovedElement->setCommonAttribute(key, value);
101
}
102
103
104
void
105
GNEMoveElementJunction::removeGeometryPoint(const Position clickedPosition, GNEUndoList* undoList) {
106
// edit depending if shape is being edited
107
if (myJunction->isShapeEdited()) {
108
// get original shape
109
PositionVector shape = myJunction->getNBNode()->getShape();
110
// check shape size
111
if (shape.size() > 2) {
112
// obtain index
113
int index = shape.indexOfClosest(clickedPosition);
114
// get snap radius
115
const double snap_radius = myJunction->getNet()->getViewNet()->getVisualisationSettings().neteditSizeSettings.junctionGeometryPointRadius;
116
// check if we have to create a new index
117
if ((index != -1) && shape[index].distanceSquaredTo2D(clickedPosition) < (snap_radius * snap_radius)) {
118
// remove geometry point
119
shape.erase(shape.begin() + index);
120
// commit new shape
121
undoList->begin(myJunction, TLF("remove geometry point of %", myJunction->getTagStr()));
122
GNEChange_Attribute::changeAttribute(myJunction, SUMO_ATTR_SHAPE, toString(shape), undoList, true);
123
undoList->end();
124
}
125
}
126
}
127
}
128
129
130
void
131
GNEMoveElementJunction::setMoveShape(const GNEMoveResult& moveResult) {
132
// clear contour
133
myJunction->myNetworkElementContour.clearContour();
134
// set new position in NBNode without updating grid
135
if (myJunction->isShapeEdited()) {
136
// set new shape
137
myJunction->getNBNode()->setCustomShape(moveResult.shapeToUpdate);
138
} else if (moveResult.shapeToUpdate.size() > 0) {
139
// obtain NBNode position
140
const Position orig = myJunction->getNBNode()->getPosition();
141
// move geometry
142
myJunction->moveJunctionGeometry(moveResult.shapeToUpdate.front(), false);
143
// check if move only center
144
const bool onlyMoveCenter = myJunction->getNet()->getViewParent()->getMoveFrame()->getNetworkMoveOptions()->getMoveOnlyJunctionCenter();
145
// set new position of adjacent edges depending if we're moving a selection
146
for (const auto& NBEdge : myJunction->getNBNode()->getEdges()) {
147
myJunction->getNet()->getAttributeCarriers()->retrieveEdge(NBEdge->getID())->updateJunctionPosition(myJunction, onlyMoveCenter ? myJunction->getNBNode()->getPosition() : orig);
148
}
149
}
150
myJunction->updateGeometry();
151
}
152
153
154
void
155
GNEMoveElementJunction::commitMoveShape(const GNEMoveResult& moveResult, GNEUndoList* undoList) {
156
// make sure that newShape isn't empty
157
if (moveResult.shapeToUpdate.size() > 0) {
158
// check if we're editing a shape
159
if (myJunction->isShapeEdited()) {
160
// commit new shape
161
undoList->begin(myJunction, TLF("moving shape of %", myJunction->getTagStr()));
162
myJunction->setAttribute(SUMO_ATTR_SHAPE, toString(moveResult.shapeToUpdate), undoList);
163
undoList->end();
164
} else if (myJunction->getNBNode()->hasCustomShape()) {
165
// commit new shape
166
undoList->begin(myJunction, TLF("moving custom shape of %", myJunction->getTagStr()));
167
myJunction->setAttribute(SUMO_ATTR_POSITION, toString(moveResult.shapeToUpdate.front()), undoList);
168
// calculate offset and apply to custom shape
169
const auto customShapeOffset = moveResult.shapeToUpdate.front() - myJunction->getNBNode()->getCenter();
170
const auto customShapeMoved = myJunction->getNBNode()->getShape().added(customShapeOffset);
171
myJunction->setAttribute(SUMO_ATTR_SHAPE, toString(customShapeMoved), undoList);
172
undoList->end();
173
} else {
174
myJunction->setAttribute(SUMO_ATTR_POSITION, toString(moveResult.shapeToUpdate.front()), undoList);
175
}
176
}
177
}
178
179
/****************************************************************************/
180
181