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>
27 
28 
29 // ===========================================================================
30 // class definitions
31 // ===========================================================================
32 
34 class GNELane;
35 class GNENet;
36 
38 
39 public:
41  class PathElement;
42 
44  class Segment {
45 
46  public:
48  Segment(GNEPathManager* pathManager, PathElement* element, const GNELane* lane,
49  const bool firstSegment, const bool lastSegment);
50 
52  Segment(GNEPathManager* pathManager, PathElement* element, const GNEJunction* junction,
53  const GNELane* previousLane, const GNELane* nextLane);
54 
56  ~Segment();
57 
59  bool isFirstSegment() const;
60 
62  bool isLastSegment() const;
63 
65  PathElement* getPathElement() const;
66 
68  const GNELane* getLane() const;
69 
71  const GNELane* getPreviousLane() const;
72 
74  const GNELane* getNextLane() const;
75 
77  const GNEJunction* getJunction() const;
78 
80  Segment* getNextSegment() const;
81 
83  void setNextSegment(Segment* nexSegment);
84 
86  Segment* getPreviousSegment() const;
87 
89  void setPreviousSegment(Segment* nexSegment);
90 
92  bool isLabelSegment() const;
93 
95  void markSegmentLabel();
96 
97  protected:
100 
103 
105  const bool myFirstSegment;
106 
108  const bool myLastSegment;
109 
111  const GNELane* myLane;
112 
115 
118 
121 
124 
127 
130 
131  private:
133  Segment();
134 
136  Segment(const Segment&) = delete;
137 
139  Segment& operator=(const Segment&) = delete;
140  };
141 
143  class PathElement {
144 
145  public:
146  enum Options {
147  NETWORK_ELEMENT = 1 << 0, // Network element
148  ADDITIONAL_ELEMENT = 1 << 1, // Additional element
149  DEMAND_ELEMENT = 1 << 2, // Demand element
150  DATA_ELEMENT = 1 << 3, // Data element
151  ROUTE = 1 << 4, // Route (needed for overlapping labels)
152  };
153 
155  PathElement(const int options);
156 
158  ~PathElement();
159 
161  bool isNetworkElement() const;
162 
164  bool isAdditionalElement() const;
165 
167  bool isDemandElement() const;
168 
170  bool isDataElement() const;
171 
173  bool isRoute() const;
174 
176  virtual void computePathElement() = 0;
177 
184  virtual void drawPartialGL(const GUIVisualizationSettings& s, const GNELane* lane, const GNEPathManager::Segment* segment, const double offsetFront) const = 0;
185 
193  virtual void drawPartialGL(const GUIVisualizationSettings& s, const GNELane* fromLane, const GNELane* toLane, const GNEPathManager::Segment* segment, const double offsetFront) const = 0;
194 
196  virtual GNELane* getFirstPathLane() const = 0;
197 
199  virtual GNELane* getLastPathLane() const = 0;
200 
202  virtual double getPathElementDepartValue() const = 0;
203 
205  virtual Position getPathElementDepartPos() const = 0;
206 
208  virtual double getPathElementArrivalValue() const = 0;
209 
211  virtual Position getPathElementArrivalPos() const = 0;
212 
213  private:
215  PathElement();
216 
218  const int myOption;
219  };
220 
223 
224  public:
226  PathCalculator(const GNENet* net);
227 
229  ~PathCalculator();
230 
232  void updatePathCalculator();
233 
235  std::vector<GNEEdge*> calculateDijkstraPath(const SUMOVehicleClass vClass, const std::vector<GNEEdge*>& partialEdges) const;
236 
238  std::vector<GNEEdge*> calculateDijkstraPath(const SUMOVehicleClass vClass, const GNEJunction* fromJunction, const GNEJunction* toJunction) const;
239 
241  void calculateReachability(const SUMOVehicleClass vClass, GNEEdge* originEdge);
242 
244  bool consecutiveEdgesConnected(const SUMOVehicleClass vClass, const GNEEdge* from, const GNEEdge* to) const;
245 
247  bool busStopConnected(const GNEAdditional* busStop, const GNEEdge* edge) const;
248 
250  bool isPathCalculatorUpdated() const;
251 
254 
255  private:
257  const GNENet* myNet;
258 
261 
264  };
265 
267  class PathDraw {
268 
269  public:
271  PathDraw();
272 
274  ~PathDraw();
275 
277  void clearPathDraw();
278 
280  bool drawPathGeometry(const bool dottedElement, const GNELane* lane, SumoXMLTag tag);
281 
283  bool drawPathGeometry(const bool dottedElement, const GNELane* fromLane, const GNELane* toLane, 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 
297  ~GNEPathManager();
298 
301 
304 
306  bool isPathValid(const PathElement* pathElement) const;
307 
309  const GNELane* getFirstLane(const PathElement* pathElement) const;
310 
312  void calculatePathEdges(PathElement* pathElement, SUMOVehicleClass vClass, const std::vector<GNEEdge*> edges);
313 
315  void calculatePathLanes(PathElement* pathElement, SUMOVehicleClass vClass, const std::vector<GNELane*> lanes);
316 
318  void calculateConsecutivePathEdges(PathElement* pathElement, SUMOVehicleClass vClass, const std::vector<GNEEdge*> edges);
319 
321  void calculateConsecutivePathLanes(PathElement* pathElement, const std::vector<GNELane*> lanes);
322 
324  void removePath(PathElement* pathElement);
325 
327  void drawLanePathElements(const GUIVisualizationSettings& s, const GNELane* lane);
328 
330  void drawJunctionPathElements(const GUIVisualizationSettings& s, const GNEJunction* junction);
331 
333  void forceDrawPath(const GUIVisualizationSettings& s, const PathElement* pathElement) const;
334 
336  void invalidateLanePath(const GNELane* lane);
337 
339  void invalidateJunctionPath(const GNEJunction* junction);
340 
342  void clearDemandPaths();
343 
344 protected:
346  void addSegmentInLaneSegments(Segment* segment, const GNELane* lane);
347 
349  void addSegmentInJunctionSegments(Segment* segment, const GNEJunction* junction);
350 
353 
355  void clearSegments();
356 
358  bool connectedLanes(const GNELane* fromLane, const GNELane* toLane) const;
359 
362 
365 
367  std::map<const PathElement*, std::vector<Segment*> > myPaths;
368 
370  std::map<const GNELane*, std::set<Segment*> > myLaneSegments;
371 
373  std::map<const GNEJunction*, std::set<Segment*> > myJunctionSegments;
374 
375 private:
377  GNEPathManager(const GNEPathManager&) = delete;
378 
381 };
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 belongs to GNENet but has influency 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 consecutives 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
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
bool isDataElement() const
check if pathElement is a data element
const int myOption
pathElement option
PathElement()
default constructor
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 double getPathElementDepartValue() const =0
get path element depart lane pos
virtual Position getPathElementDepartPos() const =0
get path element depart position
virtual GNELane * getLastPathLane() const =0
get last path lane
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
virtual GNELane * getFirstPathLane() const =0
get first path lane
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)
const GNELane * getPreviousLane() const
get previous lane
const GNELane * myNextLane
next lane
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 & operator=(const Segment &)=delete
Invalidated assignment operator.
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
PathDraw * getPathDraw()
obtain instance of PathDraw
void clearSegments()
clear segments
PathCalculator * myPathCalculator
PathCalculator instance.
void invalidateLanePath(const GNELane *lane)
invalidate lane path
GNEPathManager & operator=(const GNEPathManager &)=delete
Invalidated assignment operator.
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
std::map< const PathElement *, std::vector< Segment * > > myPaths
map with path element and their asociated 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