Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/utils/gui/div/GUIViewObjectsHandler.h
169685 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 GUIViewObjectsHandler.h
15
/// @author Pablo Alvarez Lopez
16
/// @date Jun 22
17
///
18
// class used for handle objects over view
19
/****************************************************************************/
20
#pragma once
21
#include <config.h>
22
23
#include <vector>
24
#include <unordered_map>
25
#include <utils/geom/Triangle.h>
26
#include <utils/gui/globjects/GUIGlObject.h>
27
#include <utils/gui/settings/GUIVisualizationSettings.h>
28
29
// ===========================================================================
30
// class declaration
31
// ===========================================================================
32
33
class GNEJunction;
34
class GNEEdge;
35
class GNELane;
36
class GNERoute;
37
class GNEPathElement;
38
class GNESegment;
39
40
// ===========================================================================
41
// class definitions
42
// ===========================================================================
43
44
class GUIViewObjectsHandler {
45
46
public:
47
/// @brief object container
48
struct ObjectContainer {
49
50
/// @brief parameter constructor
51
ObjectContainer(const GUIGlObject* object_) :
52
object(object_) {}
53
54
/// @brief object
55
const GUIGlObject* object = nullptr;
56
57
/// @brief vector with geometry points
58
std::vector<int> geometryPoints;
59
60
/// @brief position over shape
61
Position posOverShape = Position::INVALID;
62
63
/// @brief offset of position over shape
64
double offset = 0;
65
};
66
67
/// @brief object container layer
68
struct ObjectContainerLayer : public std::vector<ObjectContainer> {
69
70
/// @brief parameter constructor
71
ObjectContainerLayer() {}
72
73
// @brief append object container and resize if neccesary
74
void append(const ObjectContainer& objectContainer);
75
};
76
77
/// @brief typedef for pack elements sorted by layer
78
typedef std::map<double, ObjectContainerLayer > GLObjectsSortedContainer;
79
80
/// @brief constructor
81
GUIViewObjectsHandler();
82
83
/// @brief reset view objects handler
84
void reset();
85
86
/// @name position and boundary functions. used for defining the posion that will be check (usually the mouse position)
87
/// @{
88
/// @brief get selection position
89
const Position& getSelectionPosition() const;
90
91
/// @brief get selection triangle
92
const Triangle& getSelectionTriangle() const;
93
94
/// @brief set selection position
95
void setSelectionPosition(const Position& pos);
96
97
/// @brief set selection triangle
98
void setSelectionTriangle(const Triangle& triangle);
99
100
/// @brief return true if we're selecting using a triangle
101
bool selectingUsingRectangle() const;
102
103
/// @}
104
105
/// @name check functions. If the result is positive, the given GLObject will be added to elementUnderCursor
106
/// @{
107
/// @brief check boundary parent element
108
bool checkBoundaryParentObject(const GUIGlObject* GLObject, const double layer, const GUIGlObject* parent);
109
110
/// @brief check if mouse is within elements geometry (for circles)
111
bool checkCircleObject(const GUIVisualizationSettings::Detail d, const GUIGlObject* GLObject,
112
const Position& center, const double radius, const double layer);
113
114
/// @brief check if mouse is within geometry point
115
bool checkGeometryPoint(const GUIVisualizationSettings::Detail d, const GUIGlObject* GLObject,
116
const PositionVector& shape, const int index, const double layer, const double radius);
117
118
/// @brief check if mouse is within geometry point
119
bool checkPositionOverShape(const GUIVisualizationSettings::Detail d, const GUIGlObject* GLObject,
120
const PositionVector& shape, const double layer, const double distance);
121
122
/// @brief check (closed) shape element
123
bool checkShapeObject(const GUIGlObject* GLObject, const PositionVector& shape, const Boundary& shapeBoundary,
124
const double layer, const GNESegment* segment);
125
/// @}
126
127
/// @name functions used for mark (select) elements
128
/// @{
129
/// @brief add element into list of elements under cursor
130
bool selectObject(const GUIGlObject* GLObject, const double layer, const bool checkDuplicated,
131
const bool fullBoundary, const GNESegment* segment);
132
133
/// @brief add geometryPoint into list of elements under cursor
134
bool selectGeometryPoint(const GUIGlObject* GLObject, const int newIndex, const double layer);
135
136
/// @brief select position over shape (for example, the position over a lane shape)
137
bool selectPositionOverShape(const GUIGlObject* GLObject, const Position& pos, const double layer, const double offset);
138
139
/// @brief check if element was already selected
140
bool isObjectSelected(const GUIGlObject* GLObject) const;
141
142
/// @brief check rectangle selection
143
bool checkRectangleSelection(const GUIVisualizationSettings& s, const GUIGlObject* GLObject,
144
const double layer, const GUIGlObject* parent);
145
146
/// @brief get all elements under cursor sorted by layer
147
const GLObjectsSortedContainer& getSelectedObjects() const;
148
149
/// @brief get segment associated with the given GLObject (if exist)
150
const GNESegment* getSelectedSegment(const GUIGlObject* GLObject) const;
151
152
/// @brief get geometry points for the given glObject
153
const std::vector<int>& getSelectedGeometryPoints(const GUIGlObject* GLObject) const;
154
155
/// @brief get position over shape
156
const Position& getSelectedPositionOverShape(const GUIGlObject* GLObject) const;
157
158
/// @brief get number of selected objects
159
int getNumberOfSelectedObjects() const;
160
161
/// @brief reverse selected objects
162
void reverseSelectedObjects();
163
164
/// @}
165
166
/// @name functions related with redrawing path elements
167
/// @{
168
/// @brief get redrawing objects
169
const std::set<const GNEPathElement*>& getRedrawPathElements() const;
170
171
/// @brief check if the given path element has to be redraw again
172
bool isPathElementMarkForRedraw(const GNEPathElement* pathElement) const;
173
174
/// @brief add path element to redrawing set
175
void addToRedrawPathElements(const GNEPathElement* pathElement);
176
177
/// @}
178
179
/// @name functions related with merging junctions
180
/// @{
181
/// @brief get merging junctions
182
const std::vector<const GNEJunction*>& getMergingJunctions() const;
183
184
/// @brief add to merging junctions (used for marking junctions to merge)
185
bool addMergingJunctions(const GNEJunction* junction);
186
187
/// @}
188
189
/// @brief move the given object to the front (currently used only in netedit)
190
void updateFrontObject(const GUIGlObject* GLObject);
191
192
/// @brief isolate edge geometry points (used for moving)
193
void isolateEdgeGeometryPoints();
194
195
/// @brief recompute boundaries
196
GUIGlObjectType recomputeBoundaries = GLO_NETWORK;
197
198
/// @brief marked edge (used in create edge mode, for splitting)
199
const GNEEdge* markedEdge = nullptr;
200
201
/// @brief marked lane (used in create edge mode, for splitting)
202
const GNELane* markedLane = nullptr;
203
204
/// @brief marked TAZ (used in create TAZRel mode)
205
const GUIGlObject* markedTAZ = nullptr;
206
207
/// @brief marked route (used in create vehicle mode)
208
const GNERoute* markedRoute = nullptr;
209
210
/// @brief marked first geometry point (used for moving/delete geometry points)
211
const GUIGlObject* markedFirstGeometryPoint = nullptr;
212
213
/// @brief marked first geometry point (used for moving/delete geometry points)
214
const GUIGlObject* markedSecondGeometryPoint = nullptr;
215
216
protected:
217
/// @brief selected element sorted by layer
218
GLObjectsSortedContainer mySortedSelectedObjects;
219
220
/// @brief map with selected elements and if was selected with full boundary (used only to avoid double selections)
221
std::unordered_map<const GUIGlObject*, std::pair<bool, const GNESegment*> > mySelectedObjects;
222
223
/// @brief number of selected objects
224
int myNumberOfSelectedObjects = 0;
225
226
/// @brief set with path elements marked for redrawing
227
std::set<const GNEPathElement*> myRedrawPathElements;
228
229
/// @brief selection triangle
230
Triangle mySelectionTriangle;
231
232
/// @brief position
233
Position mySelectionPosition;
234
235
/// @brief empty geometry points
236
std::vector<int> myEmptyGeometryPoints;
237
238
/// @brief merging junctions
239
std::vector<const GNEJunction*> myMergingJunctions;
240
241
private:
242
/// @brief set copy constructor private
243
GUIViewObjectsHandler(const GUIViewObjectsHandler&) = default;
244
245
/// @brief set assignment operator private
246
GUIViewObjectsHandler& operator=(const GUIViewObjectsHandler&) = default;
247
};
248
249