Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GNEMoveElementConnection.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 connection shapes
19/****************************************************************************/
20#include <config.h>
21
24#include <netedit/GNENet.h>
25#include <netedit/GNEUndoList.h>
26
28
29// ===========================================================================
30// Method definitions
31// ===========================================================================
32
37
38
40
41
44 // edit depending if shape is being edited
45 if (myConnection->isShapeEdited()) {
46 // get connection
47 const auto& connection = myConnection->getNBEdgeConnection();
48 // calculate move shape operation
49 return getEditShapeOperation(myConnection, connection.customShape.size() > 0 ? connection.customShape : myConnection->myConnectionGeometry.getShape(), false);
50 } else {
51 return nullptr;
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 (myConnection->isShapeEdited()) {
102 // get connection
103 const auto& connection = myConnection->getNBEdgeConnection();
104 // get original shape
105 PositionVector shape = connection.customShape.size() > 0 ? connection.customShape : connection.shape;
106 // check shape size
107 if (shape.size() > 2) {
108 // obtain index
109 int index = shape.indexOfClosest(clickedPosition);
110 // get snap radius
111 const double snap_radius = myConnection->getNet()->getViewNet()->getVisualisationSettings().neteditSizeSettings.connectionGeometryPointRadius;
112 // check if we have to create a new index
113 if ((index != -1) && shape[index].distanceSquaredTo2D(clickedPosition) < (snap_radius * snap_radius)) {
114 // remove geometry point
115 shape.erase(shape.begin() + index);
116 // commit new shape
117 undoList->begin(myConnection, TLF("remove geometry point of %", myConnection->getTagStr()));
119 undoList->end();
120 }
121 }
122 }
123}
124
125
126void
128 // set custom shape
129 myConnection->getNBEdgeConnection().customShape = moveResult.shapeToUpdate;
130 // mark junction as deprecated
131 myConnection->myShapeDeprecated = true;
132 // update geometry
133 myConnection->updateGeometry();
134}
135
136
137void
139 // commit new shape
140 undoList->begin(myConnection, TLF("moving custom shape of %", myConnection->getTagStr()));
142 undoList->end();
143}
144
145/****************************************************************************/
#define TLF(string,...)
Definition MsgHandler.h:306
const std::string invalid_return< std::string >::value
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ SUMO_ATTR_CUSTOMSHAPE
whether a given shape is user-defined
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
std::string getMovingAttribute(SumoXMLAttr key) const override
get moving attribute
PositionVector getMovingAttributePositionVector(SumoXMLAttr key) const override
get moving attribute positionVector
void setMoveShape(const GNEMoveResult &moveResult) override
set move shape
void commitMoveShape(const GNEMoveResult &moveResult, GNEUndoList *undoList) override
commit move shape
bool isMovingAttributeValid(SumoXMLAttr key, const std::string &value) const override
check if the given moving attribute is valid
void removeGeometryPoint(const Position clickedPosition, GNEUndoList *undoList) override
remove geometry point in the clicked position
GNEMoveOperation * getMoveOperation() override
get move operation
Position getMovingAttributePosition(SumoXMLAttr key) const override
get moving attribute position
double getMovingAttributeDouble(SumoXMLAttr key) const override
get moving attribute double
GNEConnection * myConnection
pointer to connection
void setMovingAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList) override
set moving attribute (using undo-list)
GNEMoveElementConnection()=delete
invalidate default constructor
GNEAttributeCarrier * myMovedElement
pointer to element
GNEMoveElement(GNEAttributeCarrier *movedElement)
constructor
GNEMoveOperation * getEditShapeOperation(const GUIGlObject *obj, const PositionVector originalShape, const bool maintainShapeClosed)
calculate move shape operation
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...
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