Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netedit/elements/GNEMoveElement.h
169678 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 GNEMoveElement.h
15
/// @author Pablo Alvarez Lopez
16
/// @date Mar 2020
17
///
18
// Class used for elements that own a movable shape
19
/****************************************************************************/
20
#pragma once
21
#include <config.h>
22
23
#include <utils/gui/div/GUIGeometry.h>
24
25
// ===========================================================================
26
// class declaration
27
// ===========================================================================
28
29
class GNELane;
30
class GNEMoveElement;
31
class GNEUndoList;
32
class GNEViewNet;
33
class GUIGlObject;
34
35
// ===========================================================================
36
// class definitions
37
// ===========================================================================
38
39
/// @brief move operation
40
class GNEMoveOperation {
41
42
public:
43
enum class OperationType {
44
POSITION,
45
ENTIRE_SHAPE,
46
GEOMETRY_POINTS,
47
WIDTH,
48
HEIGHT,
49
LENGTH,
50
SINGLE_LANE,
51
SINGLE_LANE_MOVE_FIRST,
52
SINGLE_LANE_MOVE_LAST,
53
SINGLE_LANE_MOVE_BOTH,
54
MULTIPLE_LANES_MOVE_FIRST,
55
MULTIPLE_LANES_MOVE_LAST,
56
MULTIPLE_LANES_MOVE_BOTH_FIRST,
57
MULTIPLE_LANES_MOVE_BOTH_LAST
58
};
59
60
/// @brief constructor for values with a single position (junctions, E3, ParkingSpaces...)
61
GNEMoveOperation(GNEMoveElement* moveElement,
62
const Position originalPosition);
63
64
/// @brief constructor for entire geometries (Polygon with blocked shapes)
65
GNEMoveOperation(GNEMoveElement* moveElement,
66
const PositionVector originalShape);
67
68
/// @brief constructor for entire geometries (Polygon with blocked shapes)
69
GNEMoveOperation(GNEMoveElement* moveElement,
70
const PositionVector originalShape,
71
const bool firstGeometryPoint,
72
const OperationType operationType);
73
74
/// @brief constructor for elements with editable shapes (edges, polygons...)
75
GNEMoveOperation(GNEMoveElement* moveElement,
76
const PositionVector originalShape,
77
const std::vector<int> originalgeometryPoints,
78
const PositionVector shapeToMove,
79
const std::vector<int> geometryPointsToMove);
80
81
/// @brief constructor for elements placed over lanes with one position (detectors, vehicles...)
82
GNEMoveOperation(GNEMoveElement* moveElement,
83
const GNELane* lane,
84
const double firstPosition,
85
const bool allowChangeLane);
86
87
/// @brief constructor for elements placed over same lanes with two positions (StoppingPlaces)
88
GNEMoveOperation(GNEMoveElement* moveElement,
89
const GNELane* lane,
90
const double firstPosition,
91
const double lastPosition,
92
const bool allowChangeLane,
93
const OperationType operationType);
94
95
/// @brief constructor for elements placed over two lanes with two positions (E2 Multilane, vehicles..)
96
GNEMoveOperation(GNEMoveElement* moveElement,
97
const GNELane* firstLane,
98
const double firstStartPos,
99
const GNELane* lastLane,
100
const double lastStartPos,
101
const bool allowChangeLane,
102
const OperationType operationType);
103
104
/// @brief destructor
105
~GNEMoveOperation();
106
107
/// @brief move element
108
GNEMoveElement* moveElement;
109
110
/// @brief original shape
111
const PositionVector originalShape;
112
113
/// @brief original shape points to move (of original shape)
114
const std::vector<int> originalGeometryPoints;
115
116
/// @brief original first lane
117
const GNELane* firstLane = nullptr;
118
119
/// @brief original first Position
120
const double firstPosition = INVALID_DOUBLE;
121
122
/// @brief original last lane
123
const GNELane* lastLane = nullptr;
124
125
/// @brief original last Position
126
const double lastPosition = INVALID_DOUBLE;
127
128
/**@brief shape to move
129
* @note: it can be different of originalShape, for example due a new geometry point
130
*/
131
const PositionVector shapeToMove;
132
133
/// @brief shape points to move (of shapeToMove)
134
const std::vector<int> geometryPointsToMove;
135
136
/// @brief allow change lane
137
const bool allowChangeLane;
138
139
/// @brief first position (used for edit with/height
140
const bool firstGeometryPoint;
141
142
/// @brief operation type
143
const OperationType operationType;
144
145
private:
146
/// @brief Invalidated copy constructor.
147
GNEMoveOperation(const GNEMoveOperation&) = delete;
148
149
/// @brief Invalidated assignment operator.
150
GNEMoveOperation& operator=(const GNEMoveOperation&) = delete;
151
};
152
153
/// @brief move offset
154
class GNEMoveOffset {
155
156
public:
157
/// @brief constructor
158
GNEMoveOffset();
159
160
/// @brief constructor for X-Y move
161
GNEMoveOffset(const double x, const double y);
162
163
/// @brief constructor for Z move
164
GNEMoveOffset(const double z);
165
166
/// @brief destructor
167
~GNEMoveOffset();
168
169
/// @brief X
170
const double x;
171
172
/// @brief Y
173
const double y;
174
175
/// @brief Z
176
const double z;
177
};
178
179
/// @brief move result
180
class GNEMoveResult {
181
182
public:
183
/// @brief constructor
184
GNEMoveResult(const GNEMoveOperation* moveOperation);
185
186
/// @brief destructor
187
~GNEMoveResult();
188
189
/// @brief clear lanes
190
void clearLanes();
191
192
/// @brief shape to update (edited in moveElement)
193
PositionVector shapeToUpdate;
194
195
/// @brief shape points to move (of shapeToMove)
196
std::vector<int> geometryPointsToMove;
197
198
/// @brief move operation
199
const GNEMoveOperation::OperationType operationType;
200
201
/// @brief lane offset
202
double firstLaneOffset;
203
204
/// @brief new first Lane
205
const GNELane* newFirstLane;
206
207
/// @brief new first position
208
double newFirstPos;
209
210
/// @brief lane offset
211
double lastLaneOffset;
212
213
/// @brief new last Lane
214
const GNELane* newLastLane;
215
216
/// @brief new last position
217
double newLastPos;
218
219
private:
220
/// @brief Invalidated copy constructor.
221
GNEMoveResult(const GNEMoveResult&) = delete;
222
};
223
224
225
/// @brief move element
226
class GNEMoveElement {
227
228
public:
229
/// @brief constructor
230
GNEMoveElement();
231
232
//// @brief empty destructor
233
virtual ~GNEMoveElement() {}
234
235
/**@brief get move operation
236
* @note returned GNEMoveOperation can be nullptr
237
*/
238
virtual GNEMoveOperation* getMoveOperation() = 0;
239
240
/// @brief remove geometry point in the clicked position
241
virtual void removeGeometryPoint(const Position clickedPosition, GNEUndoList* undoList) = 0;
242
243
/// @brief move element the for given offset (note: offset can be X-Y-0, 0-0-Z or X-Y-Z)
244
static void moveElement(const GNEViewNet* viewNet, GNEMoveOperation* moveOperation, const GNEMoveOffset& offset);
245
246
/// @brief commit move element for the given offset
247
static void commitMove(const GNEViewNet* viewNet, GNEMoveOperation* moveOperation, const GNEMoveOffset& offset, GNEUndoList* undoList);
248
249
protected:
250
/// @brief move element lateral offset (used by elements placed over lanes
251
double myMoveElementLateralOffset;
252
253
/// @brief calculate move shape operation
254
GNEMoveOperation* calculateMoveShapeOperation(const GUIGlObject* obj, const PositionVector originalShape, const bool maintainShapeClosed);
255
256
private:
257
/// @brief set move shape
258
virtual void setMoveShape(const GNEMoveResult& moveResult) = 0;
259
260
/// @brief commit move shape
261
virtual void commitMoveShape(const GNEMoveResult& moveResult, GNEUndoList* undoList) = 0;
262
263
/// @brief calculate lane offset
264
static double calculateLaneOffset(const GNEViewNet* viewNet, const GNELane* lane, const double firstPosition, const double lastPosition,
265
const GNEMoveOffset& offset, const double extremFrom, const double extremTo);
266
267
/// @brief calculate single movement over one lane
268
static void calculateMoveResult(GNEMoveResult& moveResult, const GNEViewNet* viewNet, const GNELane* lane, const double pos,
269
const GNEMoveOffset& offset, const double extremFrom, const double extremTo);
270
271
/// @brief calculate double movement over one lane
272
static void calculateMoveResult(GNEMoveResult& moveResult, const GNEViewNet* viewNet, const GNELane* lane, const double firstPos,
273
const double lastPos, const GNEMoveOffset& offset);
274
275
/// @brief calculate double movement over two lanes
276
static void calculateMoveResult(GNEMoveResult& moveResult, const GNEViewNet* viewNet, const GNELane* firstLane, const double firstPos,
277
const GNELane* lastLane, const double lastPos, const GNEMoveOffset& offset);
278
279
/// @brief calculate new lane change
280
static void calculateNewLaneChange(const GNEViewNet* viewNet, const GNELane* originalLane, const GNELane*& newLane, double& laneOffset);
281
282
/// @brief calculate width/height shape
283
static PositionVector calculateExtrapolatedVector(const GNEMoveOperation* moveOperation, const GNEMoveResult& moveResult);
284
285
/// @brief Invalidated copy constructor.
286
GNEMoveElement(const GNEMoveElement&) = delete;
287
288
/// @brief Invalidated assignment operator.
289
GNEMoveElement& operator=(const GNEMoveElement&) = delete;
290
};
291
292