Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GNEPathManager.h
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2001-2024 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/****************************************************************************/
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>
30
31
32// ===========================================================================
33// class definitions
34// ===========================================================================
35
36class GNENet;
38class GNEEdge;
39class GNELane;
40class GNEJunction;
41class GNEAdditional;
42
44
45public:
47 class PathElement;
48
50 class Segment {
51
52 public:
54 Segment(GNEPathManager* pathManager, PathElement* element, const GNELane* lane, std::vector<Segment*>& segments);
55
57 Segment(GNEPathManager* pathManager, PathElement* element, const GNEJunction* junction, std::vector<Segment*>& segments);
58
60 ~Segment();
61
63 GNEContour* getContour() const;
64
66 bool isFirstSegment() const;
67
69 bool isLastSegment() const;
70
73
75 const GNELane* getLane() const;
76
78 const GNELane* getPreviousLane() const;
79
81 const GNELane* getNextLane() const;
82
84 const GNEJunction* getJunction() const;
85
87 Segment* getNextSegment() const;
88
91
93 bool isLabelSegment() const;
94
96 void markSegmentLabel();
97
98 protected:
101
104
107
110
113
116
119
122
123 private:
125 Segment();
126
128 Segment(const Segment&) = delete;
129
131 Segment& operator=(const Segment&) = delete;
132 };
133
135 class PathElement : public GUIGlObject {
136
137 public:
138 enum Options {
139 NETWORK_ELEMENT = 1 << 0, // Network element
140 ADDITIONAL_ELEMENT = 1 << 1, // Additional element
141 DEMAND_ELEMENT = 1 << 2, // Demand element
142 DATA_ELEMENT = 1 << 3, // Data element
143 ROUTE = 1 << 4, // Route (needed for overlapping labels)
144 };
145
147 PathElement(GUIGlObjectType type, const std::string& microsimID, FXIcon* icon, const int options);
148
150 virtual ~PathElement();
151
153 bool isNetworkElement() const;
154
156 bool isAdditionalElement() const;
157
159 bool isDemandElement() const;
160
162 bool isDataElement() const;
163
165 bool isRoute() const;
166
168 virtual void computePathElement() = 0;
169
171 virtual bool isPathElementSelected() const = 0;
172
178 virtual void drawLanePartialGL(const GUIVisualizationSettings& s, const GNEPathManager::Segment* segment, const double offsetFront) const = 0;
179
185 virtual void drawJunctionPartialGL(const GUIVisualizationSettings& s, const GNEPathManager::Segment* segment, const double offsetFront) const = 0;
186
188 virtual GNELane* getFirstPathLane() const = 0;
189
191 virtual GNELane* getLastPathLane() const = 0;
192
193 private:
195 const int myOption;
196
198 PathElement() = delete;
199
201 PathElement(const PathElement&) = delete;
202
205 };
206
209
210 public:
212 PathCalculator(const GNENet* net);
213
216
221
223 std::vector<GNEEdge*> calculateDijkstraPath(const SUMOVehicleClass vClass, const std::vector<GNEEdge*>& edges) const;
224
226 std::vector<GNEEdge*> calculateDijkstraPath(const SUMOVehicleClass vClass, GNEEdge* fromEdge, GNEEdge* toEdge) const;
227
229 std::vector<GNEEdge*> calculateDijkstraPath(const SUMOVehicleClass vClass, GNEEdge* fromEdge, GNEJunction* toJunction) const;
230
232 std::vector<GNEEdge*> calculateDijkstraPath(const SUMOVehicleClass vClass, GNEJunction* fromJunction, GNEEdge* toEdge) const;
233
235 std::vector<GNEEdge*> calculateDijkstraPath(const SUMOVehicleClass vClass, GNEJunction* fromJunction, GNEJunction* toJunction) const;
236
238 void calculateReachability(const SUMOVehicleClass vClass, GNEEdge* originEdge);
239
241 bool consecutiveEdgesConnected(const SUMOVehicleClass vClass, const GNEEdge* from, const GNEEdge* to) const;
242
244 bool busStopConnected(const GNEAdditional* busStop, const GNEEdge* edge) const;
245
247 bool isPathCalculatorUpdated() const;
248
251
252 private:
254 const GNENet* myNet;
255
258
261
263 std::vector<GNEEdge*> optimizeJunctionPath(const std::vector<GNEEdge*>& edges) const;
264 };
265
267 class PathDraw {
268
269 public:
271 PathDraw();
272
274 ~PathDraw();
275
277 void clearPathDraw();
278
280 bool checkDrawPathGeometry(const GUIVisualizationSettings& s, const GNELane* lane, SumoXMLTag tag);
281
283 bool checkDrawPathGeometry(const GUIVisualizationSettings& s, const Segment* segment, SumoXMLTag tag);
284
285 private:
287 std::map<const GNELane*, std::set<SumoXMLTag> > myLaneDrawedElements;
288
290 std::map<const std::pair<const GNELane*, const GNELane*>, std::set<SumoXMLTag> > myLane2laneDrawedElements;
291 };
292
294 GNEPathManager(const GNENet* net);
295
298
301
303 const PathElement* getPathElement(const GUIGlObject* GLObject) const;
304
306 const std::vector<Segment*>& getPathElementSegments(PathElement* pathElement) const;
307
310
312 bool isPathValid(const PathElement* pathElement) const;
313
315 const GNELane* getFirstLane(const PathElement* pathElement) const;
316
318 void calculatePath(PathElement* pathElement, SUMOVehicleClass vClass, GNELane* fromLane, GNELane* toLane);
319
321 void calculatePath(PathElement* pathElement, SUMOVehicleClass vClass, GNELane* fromLane, GNEJunction* toJunction);
322
324 void calculatePath(PathElement* pathElement, SUMOVehicleClass vClass, GNEJunction* fromJunction, GNELane* toLane);
325
327 void calculatePath(PathElement* pathElement, SUMOVehicleClass vClass, GNEJunction* fromJunction, GNEJunction* toJunction);
328
330 void calculatePath(PathElement* pathElement, SUMOVehicleClass vClass, const std::vector<GNEEdge*>& edges);
331
333 void calculateConsecutivePathEdges(PathElement* pathElement, SUMOVehicleClass vClass, const std::vector<GNEEdge*>& edges,
334 const int firstLaneIndex = -1, const int lastLaneIndex = -1);
335
337 void calculateConsecutivePathLanes(PathElement* pathElement, const std::vector<GNELane*>& lanes);
338
340 void removePath(PathElement* pathElement);
341
343 void drawLanePathElements(const GUIVisualizationSettings& s, const GNELane* lane) const;
344
346 void drawJunctionPathElements(const GUIVisualizationSettings& s, const GNEJunction* junction) const;
347
349 void addPathElementToRedrawBuffer(const GNEPathManager::PathElement* pathElement) const;
350
352 void invalidateLanePath(const GNELane* lane);
353
355 void invalidateJunctionPath(const GNEJunction* junction);
356
358 void clearSegments();
359
360protected:
362 void addSegmentInLaneSegments(Segment* segment, const GNELane* lane);
363
365 void addSegmentInJunctionSegments(Segment* segment, const GNEJunction* junction);
366
369
371 bool connectedLanes(const GNELane* fromLane, const GNELane* toLane) const;
372
374 void buildPath(PathElement* pathElement, SUMOVehicleClass vClass, const std::vector<GNEEdge*> path,
375 GNELane* fromLane, GNEJunction* fromJunction, GNELane* toLane, GNEJunction* toJunction);
376
379
382
384 std::map<const PathElement*, std::vector<Segment*> > myPaths;
385
387 std::map<const GNELane*, std::set<Segment*> > myLaneSegments;
388
390 std::map<const GNEJunction*, std::set<Segment*> > myJunctionSegments;
391
393 bool myCleaningSegments = false;
394
395private:
397 void markLabelSegment(const std::vector<Segment*>& segments) const;
398
400 const std::vector<Segment*> myEmptySegments;
401
404
407};
GUIGlObjectType
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types.
SumoXMLTag
Numbers representing SUMO-XML - element names.
An Element which don't belong to GNENet but has influence in the simulation.
A road/street connecting two junctions (netedit-version)
Definition GNEEdge.h:53
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
Definition GNELane.h:46
A NBNetBuilder extended by visualisation and editing capabilities.
Definition GNENet.h:42
class used to calculate paths in nets
std::vector< GNEEdge * > calculateDijkstraPath(const SUMOVehicleClass vClass, const std::vector< GNEEdge * > &edges) const
calculate Dijkstra path between a list of edges (for example, from-via-to edges)
bool consecutiveEdgesConnected(const SUMOVehicleClass vClass, const GNEEdge *from, const GNEEdge *to) const
check if exist a path between the two given consecutive edges for the given VClass
void updatePathCalculator()
update DijkstraRouter (needed a good calculation of dijkstra path after modifying network)
bool isPathCalculatorUpdated() const
check if pathCalculator is updated
SUMOAbstractRouter< NBRouterEdge, NBVehicle > * myDijkstraRouter
SUMO Abstract myDijkstraRouter.
void invalidatePathCalculator()
invalidate pathCalculator
void calculateReachability(const SUMOVehicleClass vClass, GNEEdge *originEdge)
calculate reachability for given edge
std::vector< GNEEdge * > optimizeJunctionPath(const std::vector< GNEEdge * > &edges) const
optimize junction path
bool myPathCalculatorUpdated
flag for checking if path calculator is updated
bool busStopConnected(const GNEAdditional *busStop, const GNEEdge *edge) const
check if exist a path between the given busStop and edge (Either a valid lane or an acces) for pedest...
const GNENet * myNet
pointer to net
class used to mark path draw
bool checkDrawPathGeometry(const GUIVisualizationSettings &s, const GNELane *lane, SumoXMLTag tag)
check if path element geometry must be drawn in the given lane
std::map< const std::pair< const GNELane *, const GNELane * >, std::set< SumoXMLTag > > myLane2laneDrawedElements
map for saving tags drawn in junctions
void clearPathDraw()
clear path draw
std::map< const GNELane *, std::set< SumoXMLTag > > myLaneDrawedElements
map for saving tags drawn in lanes
class used for path elements
PathElement(const PathElement &)=delete
Invalidated copy constructor.
virtual void drawLanePartialGL(const GUIVisualizationSettings &s, const GNEPathManager::Segment *segment, const double offsetFront) const =0
Draws partial object over lane.
bool isDataElement() const
check if pathElement is a data element
const int myOption
pathElement option
virtual GNELane * getLastPathLane() const =0
get last path lane
bool isDemandElement() const
check if pathElement is a demand element
bool isNetworkElement() const
check if pathElement is a network element
virtual void computePathElement()=0
compute pathElement
virtual ~PathElement()
destructor
virtual bool isPathElementSelected() const =0
check if path element is selected
bool isAdditionalElement() const
check if pathElement is an additional element
bool isRoute() const
check if pathElement is a route
PathElement()=delete
invalidate default constructor
virtual void drawJunctionPartialGL(const GUIVisualizationSettings &s, const GNEPathManager::Segment *segment, const double offsetFront) const =0
Draws partial object over junction.
PathElement & operator=(const PathElement &)=delete
Invalidated assignment operator.
virtual GNELane * getFirstPathLane() const =0
get first path lane
const GNELane * getPreviousLane() const
get previous lane
Segment & operator=(const Segment &)=delete
Invalidated assignment operator.
Segment * myNextSegment
pointer to next segment (use for draw red line)
PathElement * getPathElement() const
get path element
Segment * getPreviousSegment() const
get previous segment
GNEContour * getContour() const
getcontour associated with segment
const GNELane * myLane
lane associated with this segment
GNEPathManager * myPathManager
path manager
const GNEJunction * getJunction() const
get junction associated with this segment
GNEContour * myContour
contour associated with segment
const GNELane * getNextLane() const
get next lane
PathElement * myPathElement
path element
Segment * myPreviousSegment
pointer to previous segment (use for draw red line)
bool isLabelSegment() const
check if segment is label segment
Segment(const Segment &)=delete
Invalidated copy constructor.
void markSegmentLabel()
mark segment as middle segment
Segment()
default constructor
bool myLabelSegment
flag for check if this segment is a label segment
Segment * getNextSegment() const
get next segment
const GNELane * getLane() const
get lane associated with this segment
const GNEJunction * myJunction
junction associated with this segment
bool isLastSegment() const
check if segment is the last path's segment
bool isFirstSegment() const
check if segment is the first path's segment
PathCalculator * getPathCalculator()
obtain instance of PathCalculator
const std::vector< Segment * > & getPathElementSegments(PathElement *pathElement) const
get path segments
const std::vector< Segment * > myEmptySegments
empty segments (used in getPathElementSegments)
void addSegmentInJunctionSegments(Segment *segment, const GNEJunction *junction)
add segments int junctionSegments (called by Segment constructor)
std::map< const GNEJunction *, std::set< Segment * > > myJunctionSegments
map with junction segments
void invalidateJunctionPath(const GNEJunction *junction)
invalidate junction path
const PathElement * getPathElement(const GUIGlObject *GLObject) const
get path element
PathDraw * getPathDraw()
obtain instance of PathDraw
GNEPathManager & operator=(const GNEPathManager &)=delete
Invalidated assignment operator.
void clearSegments()
clear segments
void addPathElementToRedrawBuffer(const GNEPathManager::PathElement *pathElement) const
add path elements to redraw buffer
void markLabelSegment(const std::vector< Segment * > &segments) const
mark label segment
PathCalculator * myPathCalculator
PathCalculator instance.
void invalidateLanePath(const GNELane *lane)
invalidate lane path
void addSegmentInLaneSegments(Segment *segment, const GNELane *lane)
add segments int laneSegments (called by Segment constructor)
bool connectedLanes(const GNELane *fromLane, const GNELane *toLane) const
check if given lanes are connected
std::map< const PathElement *, std::vector< Segment * > > myPaths
map with path element and their associated segments
void removePath(PathElement *pathElement)
remove path
void drawLanePathElements(const GUIVisualizationSettings &s, const GNELane *lane) const
draw lane path elements
GNEPathManager(const GNEPathManager &)=delete
Invalidated copy constructor.
std::map< const GNELane *, std::set< Segment * > > myLaneSegments
map with lane segments
void drawJunctionPathElements(const GUIVisualizationSettings &s, const GNEJunction *junction) const
draw junction path elements
void clearSegmentFromJunctionAndLaneSegments(Segment *segment)
clear segments from junction and lane Segments (called by Segment destructor)
bool myCleaningSegments
flag for clear segments quickly
void calculateConsecutivePathEdges(PathElement *pathElement, SUMOVehicleClass vClass, const std::vector< GNEEdge * > &edges, const int firstLaneIndex=-1, const int lastLaneIndex=-1)
calculate consecutive path edges
PathDraw * myPathDraw
PathDraw instance.
void buildPath(PathElement *pathElement, SUMOVehicleClass vClass, const std::vector< GNEEdge * > path, GNELane *fromLane, GNEJunction *fromJunction, GNELane *toLane, GNEJunction *toJunction)
build path
~GNEPathManager()
destructor
const GNELane * getFirstLane(const PathElement *pathElement) const
get first lane associated with path element
void calculateConsecutivePathLanes(PathElement *pathElement, const std::vector< GNELane * > &lanes)
calculate consecutive path lanes
bool isPathValid(const PathElement *pathElement) const
check if path element is valid
void calculatePath(PathElement *pathElement, SUMOVehicleClass vClass, GNELane *fromLane, GNELane *toLane)
calculate path between from-to edges (using dijkstra, require path calculator updated)
Stores the information about how to visualize structures.