Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GNEMoveElementViewResizable.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 elements that can be moved over view and resized
19/****************************************************************************/
20
22#include <netedit/GNENet.h>
23#include <netedit/GNEUndoList.h>
24
26
27// ===========================================================================
28// Method definitions
29// ===========================================================================
30
32 ResizingFormat resizingFormat, SumoXMLAttr posAttr,
33 Position& position, double& width, double& height) :
34 GNEMoveElementView(element, attributesFormat, posAttr, position),
35 myWidth(width),
36 myHeight(height),
37 myEditWidth((resizingFormat == ResizingFormat::WIDTH_HEIGHT) || (resizingFormat == ResizingFormat::WIDTH_LENGTH)),
38 myEditHeight(resizingFormat == ResizingFormat::WIDTH_HEIGHT),
39 myEditLength(resizingFormat == ResizingFormat::WIDTH_LENGTH) {
40}
41
42
44
45
49 // get snap radius
51 const auto snapRadiusSquared = (snap_radius * snap_radius);
52 // get mouse position
53 const Position mousePosition = myMovedElement->getNet()->getViewNet()->getPositionInformation();
54 // check what we're editing
55 if (myEditLength && (myShapeHeight.size() > 0) && (myShapeHeight.back().distanceSquaredTo2D(mousePosition) <= snapRadiusSquared)) {
56 // edit length
58 } else if (myEditWidth && (myShapeWidth.size() > 0) && (myShapeWidth.front().distanceSquaredTo2D(mousePosition) <= snapRadiusSquared)) {
59 // edit width
61 } else if (myEditWidth && (myShapeWidth.size() > 0) && (myShapeWidth.back().distanceSquaredTo2D(mousePosition) <= snapRadiusSquared)) {
62 // edit width
64 } else if (myEditHeight && (myShapeHeight.size() > 0) && (myShapeHeight.front().distanceSquaredTo2D(mousePosition) <= snapRadiusSquared)) {
65 // edit height
67 } else if (myEditHeight && (myShapeHeight.size() > 0) && (myShapeHeight.back().distanceSquaredTo2D(mousePosition) <= snapRadiusSquared)) {
68 // edit height
70 } else {
71 return nullptr;
72 }
73 } else {
74 // we're moving a position
76 }
77}
78
79
80void
82 // check what are being updated
84 myShapeHeight[1] = moveResult.shapeToUpdate[1];
86 myShapeWidth = moveResult.shapeToUpdate;
88 myShapeHeight = moveResult.shapeToUpdate;
89 } else {
90 // we're moving a position
92 }
93}
94
95
96void
98 // check what are being updated
100 undoList->begin(myMovedElement, TLF("length of %", myMovedElement->getTagStr()));
101 myMovedElement->setAttribute(SUMO_ATTR_LENGTH, toString(myShapeHeight[0].distanceTo2D(moveResult.shapeToUpdate[1])), undoList);
102 undoList->end();
103 } else if (moveResult.operationType == GNEMoveOperation::OperationType::WIDTH) {
104 undoList->begin(myMovedElement, TLF("width of %", myMovedElement->getTagStr()));
106 undoList->end();
108 undoList->begin(myMovedElement, TLF("height of %", myMovedElement->getTagStr()));
110 undoList->end();
111 } else {
112 // we're moving a position
113 GNEMoveElementView::commitMoveShape(moveResult, undoList);
114 }
115}
116
117/****************************************************************************/
#define TLF(string,...)
Definition MsgHandler.h:306
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ SUMO_ATTR_HEIGHT
@ SUMO_ATTR_LENGTH
@ SUMO_ATTR_WIDTH
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:46
bool drawMovingGeometryPoints() const
check if draw moving geometry points
const std::string & getTagStr() const
get tag assigned to this object in string format
GNENet * getNet() const
get pointer to net
virtual void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)=0
GNEAttributeCarrier * myMovedElement
pointer to element
AttributesFormat
attributes format
friend class GNEMoveElementViewResizable
resizable needs access
void setMoveShape(const GNEMoveResult &moveResult) override
set move shape
GNEMoveOperation * getMoveOperation()
get move operation
void commitMoveShape(const GNEMoveResult &moveResult, GNEUndoList *undoList) override
commit move shape
void setMoveShape(const GNEMoveResult &moveResult) override
set move shape
PositionVector myShapeWidth
shape width
const double myEditLength
check if length can be edited
const double myEditWidth
check if width can be edited
void commitMoveShape(const GNEMoveResult &moveResult, GNEUndoList *undoList) override
commit move shape
GNEMoveOperation * getMoveOperation()
get move operation
PositionVector myShapeHeight
shape height
const double myEditHeight
check if height can be edited
const GNEMoveOperation::OperationType operationType
move operation
PositionVector shapeToUpdate
shape to update (edited in moveElement)
GNEViewNet * getViewNet() const
get view net
Definition GNENet.cpp:2193
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 GUIVisualizationSettings & getVisualisationSettings() const
get visualization settings (read only)
virtual Position getPositionInformation() const
Returns the cursor's x/y position within the network.
GUIVisualizationNeteditSizeSettings neteditSizeSettings
netedit size settings
A point in 2D or 3D with translation and scaling methods.
Definition Position.h:37
double length2D() const
Returns the length.
static const double additionalGeometryPointRadius
moving additional geometry point radius