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
35 GNEMoveElement(junction),
36 myJunction(junction) {
37}
38
39
41
42
45 // edit depending if shape is being edited
47 // calculate move shape operation
49 } else {
50 // return move junction position
51 return new GNEMoveOperation(this, myJunction->getNBNode()->getPosition());
52 }
53}
54
55
56std::string
60
61
62double
66
67
72
73
78
79
80void
81GNEMoveElementJunction::setMovingAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
82 myMovedElement->setCommonAttribute(key, value, undoList);
83}
84
85
86bool
87GNEMoveElementJunction::isMovingAttributeValid(SumoXMLAttr key, const std::string& value) const {
88 return myMovedElement->isCommonAttributeValid(key, value);
89}
90
91
92void
96
97
98void
100 // edit depending if shape is being edited
101 if (myJunction->isShapeEdited()) {
102 // get original shape
104 // check shape size
105 if (shape.size() > 2) {
106 // obtain index
107 int index = shape.indexOfClosest(clickedPosition);
108 // get snap radius
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
128 // set new position in NBNode without updating grid
129 if (myJunction->isShapeEdited()) {
130 // set new shape
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
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 }
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()));
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
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
double getCommonAttributeDouble(SumoXMLAttr key) const
PositionVector getCommonAttributePositionVector(SumoXMLAttr key) const
void setCommonAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
const std::string & getTagStr() const
get tag assigned to this object in string format
Position getCommonAttributePosition(SumoXMLAttr key) const
GNENet * getNet() const
get pointer to net
bool isCommonAttributeValid(SumoXMLAttr key, const std::string &value) const
std::string getCommonAttribute(SumoXMLAttr key) const
static void changeAttribute(GNEAttributeCarrier *AC, SumoXMLAttr key, const std::string &value, GNEUndoList *undoList, const bool force=false)
change attribute
void clearContour() const
void clear contour
void moveJunctionGeometry(const Position &pos, const bool updateEdgeBoundaries)
reposition the node at pos without updating GRID and informs the edges
void updateGeometry() override
update pre-computed geometry information (including crossings)
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList) override
NBNode * getNBNode() const
Return net build node.
GNEAttributeCarrier * myMovedElement
pointer to element
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
bool getMoveOnlyJunctionCenter() const
check if option "move only junction center" is enabled
NetworkMoveOptions * getNetworkMoveOptions() const
get network mode options
PositionVector shapeToUpdate
shape to update (edited in moveElement)
GNEEdge * retrieveEdge(const std::string &id, bool hardFail=true) const
get edge by id
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
get all attribute carriers used in this net
Definition GNENet.cpp:144
GNEViewNet * getViewNet() const
get view net
Definition GNENet.cpp:2193
GNEContour myNetworkElementContour
network element contour
bool isShapeEdited() const
check if shape is being edited
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...
GNEViewParent * getViewParent() const
get the net object
GNEMoveFrame * getMoveFrame() const
get frame for move elements
const GUIVisualizationSettings & getVisualisationSettings() const
get visualization settings (read only)
GUIVisualizationNeteditSizeSettings neteditSizeSettings
netedit size settings
The representation of a single edge during network building.
Definition NBEdge.h:92
const std::string & getID() const
Definition NBEdge.h:1551
Position getCenter() const
Returns a position that is guaranteed to lie within the node shape.
Definition NBNode.cpp:4212
void setCustomShape(const PositionVector &shape)
set the junction shape
Definition NBNode.cpp:2789
bool hasCustomShape() const
return whether the shape was set by the user
Definition NBNode.h:601
const Position & getPosition() const
Definition NBNode.h:260
const EdgeVector & getEdges() const
Returns all edges which participate in this node (Edges that start or end at this node)
Definition NBNode.h:278
const PositionVector & getShape() const
retrieve the junction shape
Definition NBNode.cpp:2783
A point in 2D or 3D with translation and scaling methods.
Definition Position.h:37
A list of positions.
PositionVector added(const Position &offset) const
int indexOfClosest(const Position &p, bool twoD=false) const
static const double junctionGeometryPointRadius
moving junction geometry point radius