Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netedit/elements/moving/GNEMoveElementView.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 GNEMoveElementView.cpp
15
/// @author Pablo Alvarez Lopez
16
/// @date Sep 2025
17
///
18
// Class used for elements that can be moved over view
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 "GNEMoveElementView.h"
27
28
// ===========================================================================
29
// Method definitions
30
// ===========================================================================
31
32
GNEMoveElementView::GNEMoveElementView(GNEAttributeCarrier* element, AttributesFormat attributesFormat,
33
SumoXMLAttr posAttr, Position& position) :
34
GNEMoveElement(element),
35
myPosAttr(posAttr),
36
myPosOverView(position),
37
myAttributesFormat(attributesFormat) {
38
}
39
40
GNEMoveElementView::~GNEMoveElementView() {}
41
42
43
GNEMoveOperation*
44
GNEMoveElementView::getMoveOperation() {
45
// move entire space
46
return new GNEMoveOperation(this, myPosOverView);
47
}
48
49
50
std::string
51
GNEMoveElementView::getMovingAttribute(SumoXMLAttr key) const {
52
if (key == myPosAttr) {
53
return toString(myPosOverView);
54
} else {
55
return myMovedElement->getCommonAttribute(key);
56
}
57
}
58
59
60
double
61
GNEMoveElementView::getMovingAttributeDouble(SumoXMLAttr key) const {
62
return myMovedElement->getCommonAttributeDouble(key);
63
}
64
65
66
Position
67
GNEMoveElementView::getMovingAttributePosition(SumoXMLAttr key) const {
68
if (key == myPosAttr) {
69
return myPosOverView;
70
} else {
71
return myMovedElement->getCommonAttributePosition(key);
72
}
73
}
74
75
76
PositionVector
77
GNEMoveElementView::getMovingAttributePositionVector(SumoXMLAttr key) const {
78
return myMovedElement->getCommonAttributePositionVector(key);
79
}
80
81
82
void
83
GNEMoveElementView::setMovingAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
84
if (key == myPosAttr) {
85
GNEChange_Attribute::changeAttribute(myMovedElement, key, value, undoList);
86
} else {
87
myMovedElement->setCommonAttribute(key, value, undoList);
88
}
89
}
90
91
92
bool
93
GNEMoveElementView::isMovingAttributeValid(SumoXMLAttr key, const std::string& value) const {
94
if (key == myPosAttr) {
95
return GNEAttributeCarrier::canParse<Position>(value);
96
} else {
97
return myMovedElement->isCommonAttributeValid(key, value);
98
}
99
}
100
101
102
void
103
GNEMoveElementView::setMovingAttribute(SumoXMLAttr key, const std::string& value) {
104
if (key == myPosAttr) {
105
myPosOverView = GNEAttributeCarrier::parse<Position>(value);
106
} else {
107
myMovedElement->setCommonAttribute(key, value);
108
}
109
}
110
111
112
void
113
GNEMoveElementView::removeGeometryPoint(const Position /*clickedPosition*/, GNEUndoList* /*undoList*/) {
114
// nothing to do here
115
}
116
117
118
void
119
GNEMoveElementView::writeMoveAttributes(OutputDevice& device) const {
120
// position format
121
if (myAttributesFormat == AttributesFormat::POSITION) {
122
device.writeAttr(SUMO_ATTR_POSITION, myPosOverView);
123
} else {
124
// x-y format
125
if (myAttributesFormat == AttributesFormat::CARTESIAN) {
126
device.writeAttr(SUMO_ATTR_X, myPosOverView.x());
127
device.writeAttr(SUMO_ATTR_Y, myPosOverView.y());
128
}
129
// geo format
130
if (myAttributesFormat == AttributesFormat::GEO) {
131
device.setPrecision(gPrecisionGeo);
132
device.writeAttr(SUMO_ATTR_LON, myMovedElement->getAttributeDouble(SUMO_ATTR_LON));
133
device.writeAttr(SUMO_ATTR_LAT, myMovedElement->getAttributeDouble(SUMO_ATTR_LAT));
134
device.setPrecision();
135
}
136
// z
137
if (myPosOverView.z() != 0) {
138
device.writeAttr(SUMO_ATTR_Z, myPosOverView.z());
139
}
140
}
141
}
142
143
144
void
145
GNEMoveElementView::setMoveShape(const GNEMoveResult& moveResult) {
146
myPosOverView = moveResult.shapeToUpdate.front();
147
// update geometry
148
myMovedElement->updateGeometry();
149
}
150
151
152
void
153
GNEMoveElementView::commitMoveShape(const GNEMoveResult& moveResult, GNEUndoList* undoList) {
154
undoList->begin(myMovedElement, TLF("position of %", myMovedElement->getTagStr()));
155
GNEChange_Attribute::changeAttribute(myMovedElement, SUMO_ATTR_POSITION, toString(moveResult.shapeToUpdate.front()), undoList);
156
undoList->end();
157
}
158
159
/****************************************************************************/
160
161