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
23#include <netedit/GNENet.h>
24#include <netedit/GNEUndoList.h>
25
27
28// ===========================================================================
29// Method definitions
30// ===========================================================================
31
33 GNEMoveElement(connection),
34 myConnection(connection) {
35}
36
37
39
40
43 // edit depending if shape is being edited
45 // get connection
46 const auto& connection = myConnection->getNBEdgeConnection();
47 // calculate move shape operation
48 return getEditShapeOperation(myConnection, connection.customShape.size() > 0 ? connection.customShape : myConnection->myConnectionGeometry.getShape(), false);
49 } else {
50 return nullptr;
51 }
52}
53
54
55std::string
59
60
61double
65
66
71
72
77
78
79void
80GNEMoveElementConnection::setMovingAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
81 myMovedElement->setCommonAttribute(key, value, undoList);
82}
83
84
85bool
87 return myMovedElement->isCommonAttributeValid(key, value);
88}
89
90
91void
95
96
97void
99 // edit depending if shape is being edited
101 // get connection
102 const auto& connection = myConnection->getNBEdgeConnection();
103 // get original shape
104 PositionVector shape = connection.customShape.size() > 0 ? connection.customShape : connection.shape;
105 // check shape size
106 if (shape.size() > 2) {
107 // obtain index
108 int index = shape.indexOfClosest(clickedPosition);
109 // get snap radius
111 // check if we have to create a new index
112 if ((index != -1) && shape[index].distanceSquaredTo2D(clickedPosition) < (snap_radius * snap_radius)) {
113 // remove geometry point
114 shape.erase(shape.begin() + index);
115 // commit new shape
116 undoList->begin(myConnection, TLF("remove geometry point of %", myConnection->getTagStr()));
118 undoList->end();
119 }
120 }
121 }
122}
123
124
125void
127 // set custom shape
129 // mark junction as deprecated
131 // update geometry
133}
134
135
136void
138 // commit new shape
139 undoList->begin(myConnection, TLF("moving custom shape of %", myConnection->getTagStr()));
141 undoList->end();
142}
143
144/****************************************************************************/
#define TLF(string,...)
Definition MsgHandler.h:306
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
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
GUIGeometry myConnectionGeometry
connection geometry
void updateGeometry() override
update pre-computed geometry information
NBEdge::Connection & getNBEdgeConnection() const
get Edge::Connection
bool myShapeDeprecated
flag to indicate that connection's shape has to be updated
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()
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
GNEMoveOperation * getEditShapeOperation(const GUIGlObject *obj, const PositionVector originalShape, const bool maintainShapeClosed)
calculate move shape operation
PositionVector shapeToUpdate
shape to update (edited in moveElement)
GNEViewNet * getViewNet() const
get view net
Definition GNENet.cpp:2193
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...
const PositionVector & getShape() const
The shape of the additional element.
const GUIVisualizationSettings & getVisualisationSettings() const
get visualization settings (read only)
GUIVisualizationNeteditSizeSettings neteditSizeSettings
netedit size settings
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
static const double connectionGeometryPointRadius
moving connection geometry point radius
PositionVector customShape
custom shape for connection
Definition NBEdge.h:249