Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netedit/elements/moving/GNEMoveElementVehicle.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 GNEMoveElementVehicle.cpp
15
/// @author Pablo Alvarez Lopez
16
/// @date Oct 2025
17
///
18
// Class used for elements that can be moved over a edge with two positions
19
/****************************************************************************/
20
#include <config.h>
21
22
#include <foreign/fontstash/fontstash.h>
23
#include <netedit/changes/GNEChange_Attribute.h>
24
#include <netedit/changes/GNEChange_Connection.h>
25
#include <netedit/elements/demand/GNEVehicle.h>
26
#include <netedit/elements/GNEAttributeCarrier.h>
27
#include <netedit/elements/moving/GNEMoveElement.h>
28
#include <netedit/elements/network/GNEConnection.h>
29
#include <netedit/frames/common/GNEMoveFrame.h>
30
#include <netedit/GNENet.h>
31
#include <netedit/GNETagProperties.h>
32
#include <netedit/GNEUndoList.h>
33
#include <netedit/GNEViewNet.h>
34
#include <netedit/GNEViewParent.h>
35
#include <utils/gui/div/GLHelper.h>
36
#include <utils/gui/div/GUIGlobalViewObjectsHandler.h>
37
#include <utils/gui/globjects/GLIncludes.h>
38
#include <utils/gui/globjects/GUIGlObject.h>
39
#include <utils/options/OptionsCont.h>
40
#include <utils/vehicle/SUMORouteHandler.h>
41
#include <utils/xml/NamespaceIDs.h>
42
43
#include "GNEMoveElementVehicle.h"
44
45
// ===========================================================================
46
// static definitions
47
// ===========================================================================
48
49
const double GNEMoveElementVehicle::arrivalPositionDiameter = SUMO_const_halfLaneWidth * 0.5;
50
51
// ===========================================================================
52
// member method definitions
53
// ===========================================================================
54
55
GNEMoveElementVehicle::GNEMoveElementVehicle(GNEVehicle* vehicle, GNEEdge* fromEdge, GNEEdge* toEdge) :
56
GNEMoveElement(vehicle),
57
myVehicle(vehicle) {
58
// set parents
59
vehicle->getHierarchicalElement()->setParents<GNEEdge*>({fromEdge, toEdge});
60
}
61
62
63
GNEMoveElementVehicle::~GNEMoveElementVehicle() {}
64
65
66
GNEMoveOperation*
67
GNEMoveElementVehicle::getMoveOperation() {
68
// get first and last lanes
69
const GNELane* firstLane = myVehicle->getFirstPathLane();
70
const GNELane* lastLane = myVehicle->getLastPathLane();
71
// check both lanes
72
if (firstLane && lastLane) {
73
// get depart and arrival positions (doubles)
74
const double startPosDouble = myVehicle->getAttributeDouble(SUMO_ATTR_DEPARTPOS);
75
const double endPosDouble = (myVehicle->getAttributeDouble(SUMO_ATTR_ARRIVALPOS) < 0) ? lastLane->getLaneShape().length2D() : myVehicle->getAttributeDouble(SUMO_ATTR_ARRIVALPOS);
76
// check if allow change lane
77
const bool allowChangeLane = myVehicle->getNet()->getViewParent()->getMoveFrame()->getCommonMoveOptions()->getAllowChangeLane();
78
// obtain diameter
79
const double diameter = myVehicle->getAttributeDouble(SUMO_ATTR_WIDTH) > myVehicle->getAttributeDouble(SUMO_ATTR_LENGTH) ? myVehicle->getAttributeDouble(SUMO_ATTR_WIDTH) : myVehicle->getAttributeDouble(SUMO_ATTR_LENGTH);
80
// return move operation depending if we're editing departPos or arrivalPos
81
if (myVehicle->getNet()->getViewNet()->getPositionInformation().distanceSquaredTo2D(myVehicle->getAttributePosition(GNE_ATTR_PLAN_GEOMETRY_STARTPOS)) < (diameter * diameter)) {
82
return new GNEMoveOperation(this, firstLane, startPosDouble, lastLane, INVALID_DOUBLE, true, allowChangeLane);
83
} else if (myVehicle->getNet()->getViewNet()->getPositionInformation().distanceSquaredTo2D(myVehicle->getAttributePosition(GNE_ATTR_PLAN_GEOMETRY_ENDPOS)) < (arrivalPositionDiameter * arrivalPositionDiameter)) {
84
return new GNEMoveOperation(this, firstLane, INVALID_DOUBLE, lastLane, endPosDouble, false, allowChangeLane);
85
}
86
}
87
// nothing to move
88
return nullptr;
89
}
90
91
92
std::string
93
GNEMoveElementVehicle::getMovingAttribute(SumoXMLAttr key) const {
94
return myMovedElement->getCommonAttribute(key);
95
}
96
97
98
double
99
GNEMoveElementVehicle::getMovingAttributeDouble(SumoXMLAttr key) const {
100
return myMovedElement->getCommonAttributeDouble(key);
101
}
102
103
104
Position
105
GNEMoveElementVehicle::getMovingAttributePosition(SumoXMLAttr key) const {
106
return myMovedElement->getCommonAttributePosition(key);
107
}
108
109
110
PositionVector
111
GNEMoveElementVehicle::getMovingAttributePositionVector(SumoXMLAttr key) const {
112
return myMovedElement->getCommonAttributePositionVector(key);
113
}
114
115
116
void
117
GNEMoveElementVehicle::setMovingAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
118
myMovedElement->setCommonAttribute(key, value, undoList);
119
}
120
121
122
bool
123
GNEMoveElementVehicle::isMovingAttributeValid(SumoXMLAttr key, const std::string& value) const {
124
return myMovedElement->isCommonAttributeValid(key, value);
125
}
126
127
128
void
129
GNEMoveElementVehicle::setMovingAttribute(SumoXMLAttr key, const std::string& value) {
130
myMovedElement->setCommonAttribute(key, value);
131
}
132
133
134
void
135
GNEMoveElementVehicle::removeGeometryPoint(const Position /*clickedPosition*/, GNEUndoList* /*undoList*/) {
136
// nothing to do here
137
}
138
139
140
void
141
GNEMoveElementVehicle::setMoveShape(const GNEMoveResult& moveResult) {
142
if (moveResult.newFirstPos != INVALID_DOUBLE) {
143
// change depart
144
myVehicle->departPosProcedure = DepartPosDefinition::GIVEN;
145
myVehicle->parametersSet |= VEHPARS_DEPARTPOS_SET;
146
myVehicle->departPos = moveResult.newFirstPos;
147
// check if depart lane has to be changed
148
if (moveResult.newFirstLane) {
149
// set new depart lane
150
std::string error = "";
151
myVehicle->parseDepartLane(moveResult.newFirstLane->getID(), myVehicle->getTagStr(), myVehicle->getID(), myVehicle->departLane, myVehicle->departLaneProcedure, error);
152
// mark parameter as set
153
myVehicle->parametersSet |= VEHPARS_DEPARTLANE_SET;
154
}
155
} else if (moveResult.newLastPos != INVALID_DOUBLE) {
156
// change arrival
157
myVehicle->arrivalPosProcedure = ArrivalPosDefinition::GIVEN;
158
myVehicle->parametersSet |= VEHPARS_ARRIVALPOS_SET;
159
myVehicle->arrivalPos = moveResult.newFirstPos;
160
// check if arrival lane has to be changed
161
if (moveResult.newLastLane) {
162
// set new arrival lane
163
std::string error = "";
164
myVehicle->parseArrivalLane(moveResult.newLastLane->getID(), myVehicle->getTagStr(), myVehicle->getID(), myVehicle->departLane, myVehicle->arrivalLaneProcedure, error);
165
// mark parameter as set
166
myVehicle->parametersSet |= VEHPARS_ARRIVALLANE_SET;
167
}
168
}
169
// set lateral offset
170
myMovingLateralOffset = moveResult.firstLaneOffset;
171
// update geometry
172
myVehicle->updateGeometry();
173
}
174
175
176
void
177
GNEMoveElementVehicle::commitMoveShape(const GNEMoveResult& moveResult, GNEUndoList* undoList) {
178
// reset lateral offset
179
myMovingLateralOffset = 0;
180
// check value
181
if (moveResult.newFirstPos != INVALID_DOUBLE) {
182
// begin change attribute
183
undoList->begin(myVehicle, TLF("departPos of %", myVehicle->getTagStr()));
184
// now set departPos
185
myVehicle->setAttribute(SUMO_ATTR_DEPARTPOS, toString(moveResult.newFirstPos), undoList);
186
// check if depart lane has to be changed
187
if (moveResult.newFirstLane) {
188
// set new depart lane
189
myVehicle->setAttribute(SUMO_ATTR_DEPARTLANE, toString(moveResult.newFirstLane->getIndex()), undoList);
190
}
191
} else if (moveResult.newLastPos != INVALID_DOUBLE) {
192
// begin change attribute
193
undoList->begin(myVehicle, TLF("arrivalPos of %", myVehicle->getTagStr()));
194
// now set arrivalPos
195
myVehicle->setAttribute(SUMO_ATTR_ARRIVALPOS, toString(moveResult.newLastPos), undoList);
196
// check if arrival lane has to be changed
197
if (moveResult.newLastLane) {
198
// set new arrival lane
199
myVehicle->setAttribute(SUMO_ATTR_ARRIVALLANE, toString(moveResult.newLastLane->getIndex()), undoList);
200
}
201
}
202
// end change attribute
203
undoList->end();
204
}
205
206
/****************************************************************************/
207
208