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#include <config.h>
21
23#include <netedit/GNENet.h>
24#include <netedit/GNEUndoList.h>
25
27
28// ===========================================================================
29// Method definitions
30// ===========================================================================
31
33 ResizingFormat resizingFormat, SumoXMLAttr posAttr,
34 Position& position) :
35 GNEMoveElementView(element, attributesFormat, posAttr, position),
36 myEditWidth((resizingFormat == ResizingFormat::WIDTH_HEIGHT) || (resizingFormat == ResizingFormat::WIDTH_LENGTH)),
37 myEditHeight(resizingFormat == ResizingFormat::WIDTH_HEIGHT),
38 myEditLength(resizingFormat == ResizingFormat::WIDTH_LENGTH) {
39}
40
41
43
44
48 // get snap radius
50 const auto snapRadiusSquared = (snap_radius * snap_radius);
51 // get mouse position
52 const Position mousePosition = myMovedElement->getNet()->getViewNet()->getPositionInformation();
53 // check what we're editing
54 if (myEditLength && (myShapeHeight.size() > 0) && (myShapeHeight.back().distanceSquaredTo2D(mousePosition) <= snapRadiusSquared)) {
55 // edit length
57 } else if (myEditWidth && (myShapeWidth.size() > 0) && (myShapeWidth.front().distanceSquaredTo2D(mousePosition) <= snapRadiusSquared)) {
58 // edit width
60 } else if (myEditWidth && (myShapeWidth.size() > 0) && (myShapeWidth.back().distanceSquaredTo2D(mousePosition) <= snapRadiusSquared)) {
61 // edit width
63 } else if (myEditHeight && (myShapeHeight.size() > 0) && (myShapeHeight.front().distanceSquaredTo2D(mousePosition) <= snapRadiusSquared)) {
64 // edit height
66 } else if (myEditHeight && (myShapeHeight.size() > 0) && (myShapeHeight.back().distanceSquaredTo2D(mousePosition) <= snapRadiusSquared)) {
67 // edit height
69 } else {
70 return nullptr;
71 }
72 } else {
73 // we're moving a position
75 }
76}
77
78
79void
81 // check what are being updated
83 myShapeHeight[1] = moveResult.shapeToUpdate[1];
85 myShapeWidth = moveResult.shapeToUpdate;
87 myShapeHeight = moveResult.shapeToUpdate;
88 } else {
89 // we're moving a position
91 }
92}
93
94
95void
97 // check what are being updated
99 undoList->begin(myMovedElement, TLF("length of %", myMovedElement->getTagStr()));
100 myMovedElement->setAttribute(SUMO_ATTR_LENGTH, toString(myShapeHeight[0].distanceTo2D(moveResult.shapeToUpdate[1])), undoList);
101 undoList->end();
102 } else if (moveResult.operationType == GNEMoveOperation::OperationType::WIDTH) {
103 undoList->begin(myMovedElement, TLF("width of %", myMovedElement->getTagStr()));
105 undoList->end();
107 undoList->begin(myMovedElement, TLF("height of %", myMovedElement->getTagStr()));
109 undoList->end();
110 } else {
111 // we're moving a position
112 GNEMoveElementView::commitMoveShape(moveResult, undoList);
113 }
114}
115
116/****************************************************************************/
#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
void commitMoveShape(const GNEMoveResult &moveResult, GNEUndoList *undoList) override
commit move shape
GNEMoveOperation * getMoveOperation() override
get move operation
void setMoveShape(const GNEMoveResult &moveResult) override
set move shape
PositionVector myShapeWidth
shape width
const bool myEditWidth
check if width can be edited
const bool myEditHeight
check if height can be edited
GNEMoveOperation * getMoveOperation() override
get move operation
void commitMoveShape(const GNEMoveResult &moveResult, GNEUndoList *undoList) override
commit move shape
const bool myEditLength
check if length can be edited
PositionVector myShapeHeight
shape height
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