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
23#include <netedit/GNENet.h>
24#include <netedit/GNEUndoList.h>
26
28
29// ===========================================================================
30// Method definitions
31// ===========================================================================
32
34 GNEMoveElement(junction),
35 myJunction(junction) {
36}
37
38
40
41
44 // edit depending if shape is being edited
46 // calculate move shape operation
48 } else {
49 // return move junction position
50 return new GNEMoveOperation(this, myJunction->getNBNode()->getPosition());
51 }
52}
53
54
55std::string
59
60
61double
65
66
71
72
77
78
79void
80GNEMoveElementJunction::setMovingAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
81 myMovedElement->setCommonAttribute(key, value, undoList);
82}
83
84
85bool
86GNEMoveElementJunction::isMovingAttributeValid(SumoXMLAttr key, const std::string& value) const {
87 return myMovedElement->isCommonAttributeValid(key, value);
88}
89
90
91void
95
96
97void
99 // edit depending if shape is being edited
100 if (myJunction->isShapeEdited()) {
101 // get original shape
103 // check shape size
104 if (shape.size() > 2) {
105 // obtain index
106 int index = shape.indexOfClosest(clickedPosition);
107 // get snap radius
109 // check if we have to create a new index
110 if ((index != -1) && shape[index].distanceSquaredTo2D(clickedPosition) < (snap_radius * snap_radius)) {
111 // remove geometry point
112 shape.erase(shape.begin() + index);
113 // commit new shape
114 undoList->begin(myJunction, TLF("remove geometry point of %", myJunction->getTagStr()));
116 undoList->end();
117 }
118 }
119 }
120}
121
122
123void
125 // clear contour
127 // set new position in NBNode without updating grid
128 if (myJunction->isShapeEdited()) {
129 // set new shape
131 } else if (moveResult.shapeToUpdate.size() > 0) {
132 // obtain NBNode position
133 const Position orig = myJunction->getNBNode()->getPosition();
134 // move geometry
135 myJunction->moveJunctionGeometry(moveResult.shapeToUpdate.front(), false);
136 // check if move only center
138 // set new position of adjacent edges depending if we're moving a selection
139 for (const auto& NBEdge : myJunction->getNBNode()->getEdges()) {
140 myJunction->getNet()->getAttributeCarriers()->retrieveEdge(NBEdge->getID())->updateJunctionPosition(myJunction, onlyMoveCenter ? myJunction->getNBNode()->getPosition() : orig);
141 }
142 }
144}
145
146
147void
149 // make sure that newShape isn't empty
150 if (moveResult.shapeToUpdate.size() > 0) {
151 // check if we're editing a shape
152 if (myJunction->isShapeEdited()) {
153 // commit new shape
154 undoList->begin(myJunction, TLF("moving shape of %", myJunction->getTagStr()));
156 undoList->end();
157 } else if (myJunction->getNBNode()->hasCustomShape()) {
158 // commit new shape
159 undoList->begin(myJunction, TLF("moving custom shape of %", myJunction->getTagStr()));
160 myJunction->setAttribute(SUMO_ATTR_POSITION, toString(moveResult.shapeToUpdate.front()), undoList);
161 // calculate offset and apply to custom shape
162 const auto customShapeOffset = moveResult.shapeToUpdate.front() - myJunction->getNBNode()->getCenter();
163 const auto customShapeMoved = myJunction->getNBNode()->getShape().added(customShapeOffset);
164 myJunction->setAttribute(SUMO_ATTR_SHAPE, toString(customShapeMoved), undoList);
165 undoList->end();
166 } else {
167 myJunction->setAttribute(SUMO_ATTR_POSITION, toString(moveResult.shapeToUpdate.front()), undoList);
168 }
169 }
170}
171
172/****************************************************************************/
#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
GNEMoveOperation * getMoveOperation()
get move operation
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
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:4221
void setCustomShape(const PositionVector &shape)
set the junction shape
Definition NBNode.cpp:2787
bool hasCustomShape() const
return whether the shape was set by the user
Definition NBNode.h:591
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:2781
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