Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netedit/elements/moving/GNEMoveElementViewResizable.cpp
185790 views
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
/****************************************************************************/
14
/// @file GNEMoveElementViewResizable.cpp
15
/// @author Pablo Alvarez Lopez
16
/// @date Sep 2025
17
///
18
// Class used for elements that can be moved over view and resized
19
/****************************************************************************/
20
#include <config.h>
21
22
#include <netedit/changes/GNEChange_Attribute.h>
23
#include <netedit/GNENet.h>
24
#include <netedit/GNEUndoList.h>
25
26
#include "GNEMoveElementViewResizable.h"
27
28
// ===========================================================================
29
// Method definitions
30
// ===========================================================================
31
32
GNEMoveElementViewResizable::GNEMoveElementViewResizable(GNEAttributeCarrier* element, AttributesFormat attributesFormat,
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
42
GNEMoveElementViewResizable::~GNEMoveElementViewResizable() {}
43
44
45
GNEMoveOperation*
46
GNEMoveElementViewResizable::getMoveOperation() {
47
if (myMovedElement->drawMovingGeometryPoints()) {
48
// get snap radius
49
const auto snap_radius = myMovedElement->getNet()->getViewNet()->getVisualisationSettings().neteditSizeSettings.additionalGeometryPointRadius;
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
56
return new GNEMoveOperation(this, myShapeHeight, false, GNEMoveOperation::OperationType::LENGTH);
57
} else if (myEditWidth && (myShapeWidth.size() > 0) && (myShapeWidth.front().distanceSquaredTo2D(mousePosition) <= snapRadiusSquared)) {
58
// edit width
59
return new GNEMoveOperation(this, myShapeWidth, true, GNEMoveOperation::OperationType::WIDTH);
60
} else if (myEditWidth && (myShapeWidth.size() > 0) && (myShapeWidth.back().distanceSquaredTo2D(mousePosition) <= snapRadiusSquared)) {
61
// edit width
62
return new GNEMoveOperation(this, myShapeWidth, false, GNEMoveOperation::OperationType::WIDTH);
63
} else if (myEditHeight && (myShapeHeight.size() > 0) && (myShapeHeight.front().distanceSquaredTo2D(mousePosition) <= snapRadiusSquared)) {
64
// edit height
65
return new GNEMoveOperation(this, myShapeHeight, true, GNEMoveOperation::OperationType::HEIGHT);
66
} else if (myEditHeight && (myShapeHeight.size() > 0) && (myShapeHeight.back().distanceSquaredTo2D(mousePosition) <= snapRadiusSquared)) {
67
// edit height
68
return new GNEMoveOperation(this, myShapeHeight, false, GNEMoveOperation::OperationType::HEIGHT);
69
} else {
70
return nullptr;
71
}
72
} else {
73
// we're moving a position
74
return GNEMoveElementView::getMoveOperation();
75
}
76
}
77
78
79
void
80
GNEMoveElementViewResizable::setMoveShape(const GNEMoveResult& moveResult) {
81
// check what are being updated
82
if (moveResult.operationType == GNEMoveOperation::OperationType::LENGTH) {
83
myShapeHeight[1] = moveResult.shapeToUpdate[1];
84
} else if (moveResult.operationType == GNEMoveOperation::OperationType::WIDTH) {
85
myShapeWidth = moveResult.shapeToUpdate;
86
} else if (moveResult.operationType == GNEMoveOperation::OperationType::HEIGHT) {
87
myShapeHeight = moveResult.shapeToUpdate;
88
} else {
89
// we're moving a position
90
GNEMoveElementView::setMoveShape(moveResult);
91
}
92
}
93
94
95
void
96
GNEMoveElementViewResizable::commitMoveShape(const GNEMoveResult& moveResult, GNEUndoList* undoList) {
97
// check what are being updated
98
if (moveResult.operationType == GNEMoveOperation::OperationType::LENGTH) {
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()));
104
myMovedElement->setAttribute(SUMO_ATTR_WIDTH, toString(moveResult.shapeToUpdate.length2D()), undoList);
105
undoList->end();
106
} else if (moveResult.operationType == GNEMoveOperation::OperationType::HEIGHT) {
107
undoList->begin(myMovedElement, TLF("height of %", myMovedElement->getTagStr()));
108
myMovedElement->setAttribute(SUMO_ATTR_HEIGHT, toString(moveResult.shapeToUpdate.length2D()), undoList);
109
undoList->end();
110
} else {
111
// we're moving a position
112
GNEMoveElementView::commitMoveShape(moveResult, undoList);
113
}
114
}
115
116
/****************************************************************************/
117
118