Eclipse SUMO - Simulation of Urban MObility
GNEPathManager.h
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3// Copyright (C) 2001-2022 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>
28
29
30// ===========================================================================
31// class definitions
32// ===========================================================================
33
34class GNENet;
36class GNEEdge;
37class GNELane;
38class GNEJunction;
39class GNEAdditional;
40
42
43public:
45 class PathElement;
46
48 class Segment {
49
50 public:
52 Segment(GNEPathManager* pathManager, PathElement* element, const GNELane* lane,
53 const bool firstSegment, const bool lastSegment);
54
56 Segment(GNEPathManager* pathManager, PathElement* element, const GNEJunction* junction,
57 const GNELane* previousLane, const GNELane* nextLane);
58
60 ~Segment();
61
63 bool isFirstSegment() const;
64
66 bool isLastSegment() const;
67
70
72 const GNELane* getLane() const;
73
75 const GNELane* getPreviousLane() const;
76
78 const GNELane* getNextLane() const;
79
81 const GNEJunction* getJunction() const;
82
84 Segment* getNextSegment() const;
85
87 void setNextSegment(Segment* nexSegment);
88
91
93 void setPreviousSegment(Segment* nexSegment);
94
96 bool isLabelSegment() const;
97
99 void markSegmentLabel();
100
101 protected:
104
107
109 const bool myFirstSegment;
110
112 const bool myLastSegment;
113
116
119
122
125
128
131
134
135 private:
137 Segment();
138
140 Segment(const Segment&) = delete;
141
143 Segment& operator=(const Segment&) = delete;
144 };
145
147 class PathElement : public GUIGlObject {
148
149 public:
150 enum Options {
151 NETWORK_ELEMENT = 1 << 0, // Network element
152 ADDITIONAL_ELEMENT = 1 << 1, // Additional element
153 DEMAND_ELEMENT = 1 << 2, // Demand element
154 DATA_ELEMENT = 1 << 3, // Data element
155 ROUTE = 1 << 4, // Route (needed for overlapping labels)
156 };
157
159 PathElement(GUIGlObjectType type, const std::string& microsimID, FXIcon* icon, const int options);
160
162 virtual ~PathElement();
163
165 bool isNetworkElement() const;
166
168 bool isAdditionalElement() const;
169
171 bool isDemandElement() const;
172
174 bool isDataElement() const;
175
177 bool isRoute() const;
178
180 virtual void computePathElement() = 0;
181
188 virtual void drawPartialGL(const GUIVisualizationSettings& s, const GNELane* lane, const GNEPathManager::Segment* segment, const double offsetFront) const = 0;
189
197 virtual void drawPartialGL(const GUIVisualizationSettings& s, const GNELane* fromLane, const GNELane* toLane, const GNEPathManager::Segment* segment, const double offsetFront) const = 0;
198
200 virtual GNELane* getFirstPathLane() const = 0;
201
203 virtual GNELane* getLastPathLane() const = 0;
204
206 virtual double getPathElementDepartValue() const = 0;
207
210
212 virtual double getPathElementArrivalValue() const = 0;
213
216
217 private:
219 const int myOption;
220
222 PathElement() = delete;
223
225 PathElement(const PathElement&) = delete;
226
229 };
230
233
234 public:
236 PathCalculator(const GNENet* net);
237
240
243
245 std::vector<GNEEdge*> calculateDijkstraPath(const SUMOVehicleClass vClass, const std::vector<GNEEdge*>& partialEdges) const;
246
248 std::vector<GNEEdge*> calculateDijkstraPath(const SUMOVehicleClass vClass, const GNEJunction* fromJunction, const GNEJunction* toJunction) const;
249
251 void calculateReachability(const SUMOVehicleClass vClass, GNEEdge* originEdge);
252
254 bool consecutiveEdgesConnected(const SUMOVehicleClass vClass, const GNEEdge* from, const GNEEdge* to) const;
255
257 bool busStopConnected(const GNEAdditional* busStop, const GNEEdge* edge) const;
258
260 bool isPathCalculatorUpdated() const;
261
264
265 private:
267 const GNENet* myNet;
268
271
274
276 std::vector<GNEEdge*> optimizeJunctionPath(const std::vector<GNEEdge*>& edges) const;
277 };
278
280 class PathDraw {
281
282 public:
284 PathDraw();
285
287 ~PathDraw();
288
290 void clearPathDraw();
291
293 bool drawPathGeometry(const bool dottedElement, const GNELane* lane, SumoXMLTag tag);
294
296 bool drawPathGeometry(const bool dottedElement, const GNELane* fromLane, const GNELane* toLane, SumoXMLTag tag);
297
298 private:
300 std::map<const GNELane*, std::set<SumoXMLTag> > myLaneDrawedElements;
301
303 std::map<const std::pair<const GNELane*, const GNELane*>, std::set<SumoXMLTag> > myLane2laneDrawedElements;
304 };
305
307 GNEPathManager(const GNENet* net);
308
311
314
316 const PathElement* getPathElement(const GUIGlObject* GLObject) const;
317
320
322 bool isPathValid(const PathElement* pathElement) const;
323
325 const GNELane* getFirstLane(const PathElement* pathElement) const;
326
328 void calculatePathEdges(PathElement* pathElement, SUMOVehicleClass vClass, const std::vector<GNEEdge*> edges);
329
331 void calculatePathLanes(PathElement* pathElement, SUMOVehicleClass vClass, const std::vector<GNELane*> lanes);
332
334 void calculatePathJunctions(PathElement* pathElement, SUMOVehicleClass vClass, const std::vector<GNEJunction*> junctions);
335
337 void calculateConsecutivePathEdges(PathElement* pathElement, SUMOVehicleClass vClass, const std::vector<GNEEdge*> edges);
338
340 void calculateConsecutivePathLanes(PathElement* pathElement, const std::vector<GNELane*> lanes);
341
343 void removePath(PathElement* pathElement);
344
346 void drawLanePathElements(const GUIVisualizationSettings& s, const GNELane* lane);
347
349 void drawJunctionPathElements(const GUIVisualizationSettings& s, const GNEJunction* junction);
350
352 void forceDrawPath(const GUIVisualizationSettings& s, const PathElement* pathElement) const;
353
355 void invalidateLanePath(const GNELane* lane);
356
358 void invalidateJunctionPath(const GNEJunction* junction);
359
361 void clearDemandPaths();
362
363protected:
365 void addSegmentInLaneSegments(Segment* segment, const GNELane* lane);
366
368 void addSegmentInJunctionSegments(Segment* segment, const GNEJunction* junction);
369
372
374 void clearSegments();
375
377 bool connectedLanes(const GNELane* fromLane, const GNELane* toLane) const;
378
381
384
386 std::map<const PathElement*, std::vector<Segment*> > myPaths;
387
389 std::map<const GNELane*, std::set<Segment*> > myLaneSegments;
390
392 std::map<const GNEJunction*, std::set<Segment*> > myJunctionSegments;
393
394private:
397
400};
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.
Definition: GNEAdditional.h:48
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
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 path calculator (called when SuperModes Demand or Data is selected)
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
PathCalculator(const GNENet *net)
constructor
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...
std::vector< GNEEdge * > calculateDijkstraPath(const SUMOVehicleClass vClass, const std::vector< GNEEdge * > &partialEdges) const
calculate Dijkstra path between a list of partial edges
const GNENet * myNet
pointer to net
class used to mark path draw
bool drawPathGeometry(const bool dottedElement, 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.
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
virtual void drawPartialGL(const GUIVisualizationSettings &s, const GNELane *lane, const GNEPathManager::Segment *segment, const double offsetFront) const =0
Draws partial object (lane)
virtual double getPathElementArrivalValue() const =0
get path element arrival lane pos
bool isNetworkElement() const
check if pathElement is a network element
virtual void computePathElement()=0
compute pathElement
virtual ~PathElement()
destructor
virtual double getPathElementDepartValue() const =0
get path element depart lane pos
virtual Position getPathElementDepartPos() const =0
get path element depart position
bool isAdditionalElement() const
check if pathElement is an additional element
virtual Position getPathElementArrivalPos() const =0
get path element arrival position
bool isRoute() const
check if pathElement is a route
PathElement()=delete
invalidate default constructor
virtual void drawPartialGL(const GUIVisualizationSettings &s, const GNELane *fromLane, const GNELane *toLane, const GNEPathManager::Segment *segment, const double offsetFront) const =0
Draws partial object (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
const GNELane * myNextLane
next 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
void setNextSegment(Segment *nexSegment)
set next segment
void setPreviousSegment(Segment *nexSegment)
set previous segment
const GNELane * myLane
lane associated with this segment
const bool myLastSegment
lastSegment
GNEPathManager * myPathManager
path manager
const GNEJunction * getJunction() const
get junction associated with this 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
const GNELane * myPreviousLane
previous lane
const bool myFirstSegment
first segment
PathCalculator * getPathCalculator()
obtain instance of PathCalculator
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
PathCalculator * myPathCalculator
PathCalculator instance.
void invalidateLanePath(const GNELane *lane)
invalidate lane path
void clearDemandPaths()
clear demand paths
void calculateConsecutivePathEdges(PathElement *pathElement, SUMOVehicleClass vClass, const std::vector< GNEEdge * > edges)
calculate consecutive path edges
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
void calculatePathJunctions(PathElement *pathElement, SUMOVehicleClass vClass, const std::vector< GNEJunction * > junctions)
calculate path junctions (using dijkstra, require path calculator updated)
std::map< const PathElement *, std::vector< Segment * > > myPaths
map with path element and their associated segments
void drawLanePathElements(const GUIVisualizationSettings &s, const GNELane *lane)
draw lane path elements
void removePath(PathElement *pathElement)
remove path
GNEPathManager(const GNEPathManager &)=delete
Invalidated copy constructor.
std::map< const GNELane *, std::set< Segment * > > myLaneSegments
map with lane segments
void clearSegmentFromJunctionAndLaneSegments(Segment *segment)
clear segments from junction and lane Segments (called by Segment destructor)
PathDraw * myPathDraw
PathDraw instance.
void calculatePathEdges(PathElement *pathElement, SUMOVehicleClass vClass, const std::vector< GNEEdge * > edges)
calculate path edges (using dijkstra, require path calculator updated)
void drawJunctionPathElements(const GUIVisualizationSettings &s, const GNEJunction *junction)
draw junction path elements
void forceDrawPath(const GUIVisualizationSettings &s, const PathElement *pathElement) const
force draw path (used carefully, ONLY when we're inspecting a path element, due slowdowns)
~GNEPathManager()
destructor
const GNELane * getFirstLane(const PathElement *pathElement) const
get first lane associated with path element
void calculatePathLanes(PathElement *pathElement, SUMOVehicleClass vClass, const std::vector< GNELane * > lanes)
calculate path lanes (using dijkstra, require path calculator updated)
GNEPathManager(const GNENet *net)
constructor
bool isPathValid(const PathElement *pathElement) const
check if path element is valid
void calculateConsecutivePathLanes(PathElement *pathElement, const std::vector< GNELane * > lanes)
calculate consecutive path lanes
Stores the information about how to visualize structures.
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:37