Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GNEMoveElementJunction.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2001-2026 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/****************************************************************************/
18// Class used for moving junctions
19/****************************************************************************/
20#include <config.h>
21
24#include <netedit/GNENet.h>
25#include <netedit/GNEUndoList.h>
27
29
30// ===========================================================================
31// Method definitions
32// ===========================================================================
33
38
39
41
42
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
60
61
62std::string
64 return myMovedElement->getCommonAttribute(key);
65}
66
67
68double
70 return myMovedElement->getCommonAttributeDouble(key);
71}
72
73
76 return myMovedElement->getCommonAttributePosition(key);
77}
78
79
82 return myMovedElement->getCommonAttributePositionVector(key);
83}
84
85
86void
88 myMovedElement->setCommonAttribute(key, value, undoList);
89}
90
91
92bool
94 return myMovedElement->isCommonAttributeValid(key, value);
95}
96
97
98void
100 myMovedElement->setCommonAttribute(key, value);
101}
102
103
104void
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()));
123 undoList->end();
124 }
125 }
126 }
127}
128
129
130void
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
154void
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/****************************************************************************/
#define TLF(string,...)
Definition MsgHandler.h:306
const std::string invalid_return< std::string >::value
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ SUMO_ATTR_SHAPE
edge: the shape in xml-definition
@ SUMO_ATTR_POSITION
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:49
static void changeAttribute(GNEAttributeCarrier *AC, SumoXMLAttr key, const std::string &value, GNEUndoList *undoList, const bool force=false)
change attribute
GNEAttributeCarrier * myMovedElement
pointer to element
GNEMoveElement(GNEAttributeCarrier *movedElement)
constructor
GNEMoveOperation * getEditShapeOperation(const GUIGlObject *obj, const PositionVector originalShape, const bool maintainShapeClosed)
calculate move shape operation
GNEJunction * getJunction() const
get pointer to junction
GNEJunction * myJunction
pointer to junction
void commitMoveShape(const GNEMoveResult &moveResult, GNEUndoList *undoList) override
commit move shape
GNEMoveElementJunction()=delete
invalidate default constructor
std::string getMovingAttribute(SumoXMLAttr key) const override
get moving attribute
void removeGeometryPoint(const Position clickedPosition, GNEUndoList *undoList) override
remove geometry point in the clicked position
PositionVector getMovingAttributePositionVector(SumoXMLAttr key) const override
get moving attribute positionVector
void setMoveShape(const GNEMoveResult &moveResult) override
set move shape
double getMovingAttributeDouble(SumoXMLAttr key) const override
get moving attribute double
bool isMovingAttributeValid(SumoXMLAttr key, const std::string &value) const override
check if the given moving attribute is valid
GNEMoveOperation * getMoveOperation() override
get move operation
void setMovingAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList) override
set moving attribute (using undo-list)
Position getMovingAttributePosition(SumoXMLAttr key) const override
get moving attribute position
PositionVector shapeToUpdate
shape to update (edited in moveElement)
void end()
End undo command sub-group. If the sub-group is still empty, it will be deleted; otherwise,...
void begin(GUIIcon icon, const std::string &description)
Begin undo command sub-group with current supermode. This begins a new group of commands that are tre...
The representation of a single edge during network building.
Definition NBEdge.h:92
const std::string & getID() const
Definition NBEdge.h:1551
A point in 2D or 3D with translation and scaling methods.
Definition Position.h:37
A list of positions.
int indexOfClosest(const Position &p, bool twoD=false) const