Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netedit/GNEPathManager.h
169666 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 GNEPathManager.h
15
/// @author Pablo Alvarez Lopez
16
/// @date Feb 2011
17
///
18
// Manager for paths in netedit (routes, trips, flows...)
19
/****************************************************************************/
20
#pragma once
21
#include <config.h>
22
23
#include <netbuild/NBEdge.h>
24
#include <netbuild/NBVehicle.h>
25
#include <netedit/elements/GNEContour.h>
26
#include <utils/common/SUMOVehicleClass.h>
27
#include <utils/router/SUMOAbstractRouter.h>
28
#include <utils/gui/settings/GUIVisualizationSettings.h>
29
30
31
// ===========================================================================
32
// class declaration
33
// ===========================================================================
34
35
class GNENet;
36
class GNEEdge;
37
class GNELane;
38
class GNEJunction;
39
class GNEAdditional;
40
class GNEPathElement;
41
class GNESegment;
42
class GUIGlObject;
43
44
// ===========================================================================
45
// class definitions
46
// ===========================================================================
47
48
class GNEPathManager {
49
50
/// @brief friend class declaration
51
friend class GNESegment;
52
53
public:
54
55
/// @brief class used to calculate paths in nets
56
class PathCalculator {
57
58
public:
59
/// @brief constructor
60
PathCalculator(const GNENet* net);
61
62
/// @brief destructor
63
~PathCalculator();
64
65
/**@brief update DijkstraRouter (needed a good calculation of dijkstra path after modifying network)
66
* @note only needed if this path calculator requiere to use the calculateDijkstraPath(...) functions
67
*/
68
void updatePathCalculator();
69
70
/// @brief calculate Dijkstra path between a list of edges (for example, from-via-to edges)
71
std::vector<GNEEdge*> calculateDijkstraPath(const SUMOVehicleClass vClass, const std::vector<GNEEdge*>& edges) const;
72
73
/// @brief calculate Dijkstra path between one edge
74
std::vector<GNEEdge*> calculateDijkstraPath(const SUMOVehicleClass vClass, GNEEdge* fromEdge, GNEEdge* toEdge) const;
75
76
/// @brief calculate Dijkstra path between from edge and to junction
77
std::vector<GNEEdge*> calculateDijkstraPath(const SUMOVehicleClass vClass, GNEEdge* fromEdge, GNEJunction* toJunction) const;
78
79
/// @brief calculate Dijkstra path between from junction and to edge
80
std::vector<GNEEdge*> calculateDijkstraPath(const SUMOVehicleClass vClass, GNEJunction* fromJunction, GNEEdge* toEdge) const;
81
82
/// @brief calculate Dijkstra path between two Junctions
83
std::vector<GNEEdge*> calculateDijkstraPath(const SUMOVehicleClass vClass, GNEJunction* fromJunction, GNEJunction* toJunction) const;
84
85
/// @brief calculate reachability for given edge
86
void calculateReachability(const SUMOVehicleClass vClass, GNEEdge* originEdge);
87
88
/// @brief check if exist a path between the two given consecutive edges for the given VClass
89
bool consecutiveEdgesConnected(const SUMOVehicleClass vClass, const GNEEdge* from, const GNEEdge* to) const;
90
91
/// @brief check if exist a path between the given busStop and edge (Either a valid lane or an acces) for pedestrians
92
bool busStopConnected(const GNEAdditional* busStop, const GNEEdge* edge) const;
93
94
/// @brief check if pathCalculator is updated
95
bool isPathCalculatorUpdated() const;
96
97
/// @brief invalidate pathCalculator
98
void invalidatePathCalculator();
99
100
private:
101
/// @brief pointer to net
102
const GNENet* myNet;
103
104
/// @brief flag for checking if path calculator is updated
105
bool myPathCalculatorUpdated;
106
107
/// @brief SUMO Abstract myDijkstraRouter
108
SUMOAbstractRouter<NBRouterEdge, NBVehicle>* myDijkstraRouter;
109
110
/// @brief optimize junction path
111
std::vector<GNEEdge*> optimizeJunctionPath(const std::vector<GNEEdge*>& edges) const;
112
};
113
114
/// @brief class used to mark path draw
115
class PathDraw {
116
117
public:
118
/// @brief constructor
119
PathDraw();
120
121
/// @brief destructor
122
~PathDraw();
123
124
/// @brief clear path draw
125
void clearPathDraw();
126
127
/// @brief check if path element geometry must be drawn in the given lane
128
bool checkDrawPathGeometry(const GUIVisualizationSettings& s, const GNELane* lane, const SumoXMLTag tag, const bool isPlan);
129
130
/// @brief check if path element geometry must be drawn in the given junction
131
bool checkDrawPathGeometry(const GUIVisualizationSettings& s, const GNESegment* segment, const SumoXMLTag tag, const bool isPlan);
132
133
private:
134
/// @brief map for saving tags drawn in lanes
135
std::map<const GNELane*, std::set<SumoXMLTag> > myLaneDrawedElements;
136
137
/// @brief map for saving tags drawn in junctions
138
std::map<const std::pair<const GNELane*, const GNELane*>, std::set<SumoXMLTag> > myLane2laneDrawedElements;
139
};
140
141
/// @brief constructor
142
GNEPathManager(const GNENet* net);
143
144
/// @brief destructor
145
~GNEPathManager();
146
147
/// @brief obtain instance of PathCalculator
148
PathCalculator* getPathCalculator();
149
150
/// @brief get path element
151
const GNEPathElement* getPathElement(const GUIGlObject* GLObject) const;
152
153
/// @brief get path segments
154
const std::vector<GNESegment*>& getPathElementSegments(GNEPathElement* pathElement) const;
155
156
/// @brief obtain instance of PathDraw
157
PathDraw* getPathDraw();
158
159
/// @brief check if path element is valid
160
bool isPathValid(const GNEPathElement* pathElement) const;
161
162
/// @brief get first lane associated with path element
163
const GNELane* getFirstLane(const GNEPathElement* pathElement) const;
164
165
/// @brief calculate path between from-to edges (using dijkstra, require path calculator updated)
166
void calculatePath(GNEPathElement* pathElement, SUMOVehicleClass vClass, GNELane* fromLane, GNELane* toLane);
167
168
/// @brief calculate path between from edge and to junction(using dijkstra, require path calculator updated)
169
void calculatePath(GNEPathElement* pathElement, SUMOVehicleClass vClass, GNELane* fromLane, GNEJunction* toJunction);
170
171
/// @brief calculate path between from junction and to edge (using dijkstra, require path calculator updated)
172
void calculatePath(GNEPathElement* pathElement, SUMOVehicleClass vClass, GNEJunction* fromJunction, GNELane* toLane);
173
174
/// @brief calculate path between from junction and to junction (using dijkstra, require path calculator updated)
175
void calculatePath(GNEPathElement* pathElement, SUMOVehicleClass vClass, GNEJunction* fromJunction, GNEJunction* toJunction);
176
177
/// @brief calculate path lanes between list of edges (using dijkstra, require path calculator updated)
178
void calculatePath(GNEPathElement* pathElement, SUMOVehicleClass vClass, const std::vector<GNEEdge*>& edges);
179
180
/// @brief calculate consecutive path edges
181
void calculateConsecutivePathEdges(GNEPathElement* pathElement, SUMOVehicleClass vClass, const std::vector<GNEEdge*>& edges,
182
const int firstLaneIndex = -1, const int lastLaneIndex = -1);
183
184
/// @brief calculate consecutive path lanes
185
void calculateConsecutivePathLanes(GNEPathElement* pathElement, const std::vector<GNELane*>& lanes);
186
187
/// @brief remove path
188
void removePath(GNEPathElement* pathElement);
189
190
/// @brief draw lane path elements
191
void drawLanePathElements(const GUIVisualizationSettings& s, const GNELane* lane) const;
192
193
/// @brief draw junction path elements
194
void drawJunctionPathElements(const GUIVisualizationSettings& s, const GNEJunction* junction) const;
195
196
/// @brief redraw path elements saved in gViewObjectsHandler buffer
197
void redrawPathElements(const GUIVisualizationSettings& s) const;
198
199
/// @brief invalidate lane path
200
void invalidateLanePath(const GNELane* lane);
201
202
/// @brief invalidate junction path
203
void invalidateJunctionPath(const GNEJunction* junction);
204
205
/// @brief clear segments
206
void clearSegments();
207
208
protected:
209
/// @brief add segments int laneSegments (called by GNESegment constructor)
210
void addSegmentInLaneSegments(GNESegment* segment, const GNELane* lane);
211
212
/// @brief add segments int junctionSegments (called by GNESegment constructor)
213
void addSegmentInJunctionSegments(GNESegment* segment, const GNEJunction* junction);
214
215
/// @brief clear segments from junction and lane Segments (called by GNESegment destructor)
216
void clearSegmentFromJunctionAndLaneSegments(GNESegment* segment);
217
218
/// @brief check if given lanes are connected
219
bool connectedLanes(const GNELane* fromLane, const GNELane* toLane) const;
220
221
/// @brief build path
222
void buildPath(GNEPathElement* pathElement, SUMOVehicleClass vClass, const std::vector<GNEEdge*> path,
223
GNELane* fromLane, GNEJunction* fromJunction, GNELane* toLane, GNEJunction* toJunction);
224
225
/// @brief PathCalculator instance
226
PathCalculator* myPathCalculator;
227
228
/// @brief PathDraw instance
229
PathDraw* myPathDraw;
230
231
/// @brief map with path element and their associated segments
232
std::map<const GNEPathElement*, std::vector<GNESegment*> > myPaths;
233
234
/// @brief map with lane segments
235
std::map<const GNELane*, std::set<GNESegment*> > myLaneSegments;
236
237
/// @brief map with junction segments
238
std::map<const GNEJunction*, std::set<GNESegment*> > myJunctionSegments;
239
240
/// @brief flag for clear segments quickly
241
bool myCleaningSegments = false;
242
243
private:
244
/// @brief mark label segment
245
void markLabelSegment(const std::vector<GNESegment*>& segments) const;
246
247
/// @brief empty segments (used in getPathElementSegments)
248
const std::vector<GNESegment*> myEmptySegments;
249
250
/// @brief Invalidated copy constructor.
251
GNEPathManager(const GNEPathManager&) = delete;
252
253
/// @brief Invalidated assignment operator.
254
GNEPathManager& operator=(const GNEPathManager&) = delete;
255
};
256
257