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-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/****************************************************************************/
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
56std::string
58 return myMovedElement->getCommonAttribute(key);
59}
60
61
62double
64 return myMovedElement->getCommonAttributeDouble(key);
65}
66
67
70 return myMovedElement->getCommonAttributePosition(key);
71}
72
73
76 return myMovedElement->getCommonAttributePositionVector(key);
77}
78
79
80void
82 myMovedElement->setCommonAttribute(key, value, undoList);
83}
84
85
86bool
88 return myMovedElement->isCommonAttributeValid(key, value);
89}
90
91
92void
94 myMovedElement->setCommonAttribute(key, value);
95}
96
97
98void
100 // edit depending if shape is being edited
101 if (myJunction->isShapeEdited()) {
102 // get original shape
103 PositionVector shape = myJunction->getNBNode()->getShape();
104 // check shape size
105 if (shape.size() > 2) {
106 // obtain index
107 int index = shape.indexOfClosest(clickedPosition);
108 // get snap radius
109 const double snap_radius = myJunction->getNet()->getViewNet()->getVisualisationSettings().neteditSizeSettings.junctionGeometryPointRadius;
110 // check if we have to create a new index
111 if ((index != -1) && shape[index].distanceSquaredTo2D(clickedPosition) < (snap_radius * snap_radius)) {
112 // remove geometry point
113 shape.erase(shape.begin() + index);
114 // commit new shape
115 undoList->begin(myJunction, TLF("remove geometry point of %", myJunction->getTagStr()));
117 undoList->end();
118 }
119 }
120 }
121}
122
123
124void
126 // clear contour
127 myJunction->myNetworkElementContour.clearContour();
128 // set new position in NBNode without updating grid
129 if (myJunction->isShapeEdited()) {
130 // set new shape
131 myJunction->getNBNode()->setCustomShape(moveResult.shapeToUpdate);
132 } else if (moveResult.shapeToUpdate.size() > 0) {
133 // obtain NBNode position
134 const Position orig = myJunction->getNBNode()->getPosition();
135 // move geometry
136 myJunction->moveJunctionGeometry(moveResult.shapeToUpdate.front(), false);
137 // check if move only center
138 const bool onlyMoveCenter = myJunction->getNet()->getViewNet()->getViewParent()->getMoveFrame()->getNetworkMoveOptions()->getMoveOnlyJunctionCenter();
139 // set new position of adjacent edges depending if we're moving a selection
140 for (const auto& NBEdge : myJunction->getNBNode()->getEdges()) {
141 myJunction->getNet()->getAttributeCarriers()->retrieveEdge(NBEdge->getID())->updateJunctionPosition(myJunction, onlyMoveCenter ? myJunction->getNBNode()->getPosition() : orig);
142 }
143 }
144 myJunction->updateGeometry();
145}
146
147
148void
150 // make sure that newShape isn't empty
151 if (moveResult.shapeToUpdate.size() > 0) {
152 // check if we're editing a shape
153 if (myJunction->isShapeEdited()) {
154 // commit new shape
155 undoList->begin(myJunction, TLF("moving shape of %", myJunction->getTagStr()));
156 myJunction->setAttribute(SUMO_ATTR_SHAPE, toString(moveResult.shapeToUpdate), undoList);
157 undoList->end();
158 } else if (myJunction->getNBNode()->hasCustomShape()) {
159 // commit new shape
160 undoList->begin(myJunction, TLF("moving custom shape of %", myJunction->getTagStr()));
161 myJunction->setAttribute(SUMO_ATTR_POSITION, toString(moveResult.shapeToUpdate.front()), undoList);
162 // calculate offset and apply to custom shape
163 const auto customShapeOffset = moveResult.shapeToUpdate.front() - myJunction->getNBNode()->getCenter();
164 const auto customShapeMoved = myJunction->getNBNode()->getShape().added(customShapeOffset);
165 myJunction->setAttribute(SUMO_ATTR_SHAPE, toString(customShapeMoved), undoList);
166 undoList->end();
167 } else {
168 myJunction->setAttribute(SUMO_ATTR_POSITION, toString(moveResult.shapeToUpdate.front()), undoList);
169 }
170 }
171}
172
173/****************************************************************************/
#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:46
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 * 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