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.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 
36 class GNENet;
38 class GNEEdge;
39 class GNELane;
40 class GNEJunction;
41 class GNEAdditional;
42 
44 
45 public:
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 
72  PathElement* getPathElement() const;
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 
90  Segment* getPreviousSegment() const;
91 
93  bool isLabelSegment() const;
94 
96  void markSegmentLabel();
97 
98  protected:
101 
104 
106  const GNELane* myLane;
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 
204  PathElement& operator=(const PathElement&) = delete;
205  };
206 
209 
210  public:
212  PathCalculator(const GNENet* net);
213 
215  ~PathCalculator();
216 
218  void updatePathCalculator();
219 
221  std::vector<GNEEdge*> calculateDijkstraPath(const SUMOVehicleClass vClass, const std::vector<GNEEdge*>& edges) const;
222 
224  std::vector<GNEEdge*> calculateDijkstraPath(const SUMOVehicleClass vClass, GNEEdge* fromEdge, GNEEdge* toEdge) const;
225 
227  std::vector<GNEEdge*> calculateDijkstraPath(const SUMOVehicleClass vClass, GNEEdge* fromEdge, GNEJunction* toJunction) const;
228 
230  std::vector<GNEEdge*> calculateDijkstraPath(const SUMOVehicleClass vClass, GNEJunction* fromJunction, GNEEdge* toEdge) const;
231 
233  std::vector<GNEEdge*> calculateDijkstraPath(const SUMOVehicleClass vClass, GNEJunction* fromJunction, GNEJunction* toJunction) const;
234 
236  void calculateReachability(const SUMOVehicleClass vClass, GNEEdge* originEdge);
237 
239  bool consecutiveEdgesConnected(const SUMOVehicleClass vClass, const GNEEdge* from, const GNEEdge* to) const;
240 
242  bool busStopConnected(const GNEAdditional* busStop, const GNEEdge* edge) const;
243 
245  bool isPathCalculatorUpdated() const;
246 
249 
250  private:
252  const GNENet* myNet;
253 
256 
259 
261  std::vector<GNEEdge*> optimizeJunctionPath(const std::vector<GNEEdge*>& edges) const;
262  };
263 
265  class PathDraw {
266 
267  public:
269  PathDraw();
270 
272  ~PathDraw();
273 
275  void clearPathDraw();
276 
278  bool checkDrawPathGeometry(const GUIVisualizationSettings& s, const GNELane* lane, SumoXMLTag tag);
279 
281  bool checkDrawPathGeometry(const GUIVisualizationSettings& s, const Segment* segment, SumoXMLTag tag);
282 
283  private:
285  std::map<const GNELane*, std::set<SumoXMLTag> > myLaneDrawedElements;
286 
288  std::map<const std::pair<const GNELane*, const GNELane*>, std::set<SumoXMLTag> > myLane2laneDrawedElements;
289  };
290 
292  GNEPathManager(const GNENet* net);
293 
295  ~GNEPathManager();
296 
299 
301  const PathElement* getPathElement(const GUIGlObject* GLObject) const;
302 
304  const std::vector<Segment*>& getPathElementSegments(PathElement* pathElement) const;
305 
308 
310  bool isPathValid(const PathElement* pathElement) const;
311 
313  const GNELane* getFirstLane(const PathElement* pathElement) const;
314 
316  void calculatePath(PathElement* pathElement, SUMOVehicleClass vClass, GNELane* fromLane, GNELane* toLane);
317 
319  void calculatePath(PathElement* pathElement, SUMOVehicleClass vClass, GNELane* fromLane, GNEJunction* toJunction);
320 
322  void calculatePath(PathElement* pathElement, SUMOVehicleClass vClass, GNEJunction* fromJunction, GNELane* toLane);
323 
325  void calculatePath(PathElement* pathElement, SUMOVehicleClass vClass, GNEJunction* fromJunction, GNEJunction* toJunction);
326 
328  void calculatePath(PathElement* pathElement, SUMOVehicleClass vClass, const std::vector<GNEEdge*> edges);
329 
331  void calculatePath(PathElement* pathElement, SUMOVehicleClass vClass, const std::vector<GNELane*> lanes);
332 
334  void calculateConsecutivePathEdges(PathElement* pathElement, SUMOVehicleClass vClass, const std::vector<GNEEdge*> edges);
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 forceDrawPath(const GUIVisualizationSettings& s, const PathElement* pathElement) const;
350 
352  void invalidateLanePath(const GNELane* lane);
353 
355  void invalidateJunctionPath(const GNEJunction* junction);
356 
358  void clearDemandPaths();
359 
360 protected:
362  void addSegmentInLaneSegments(Segment* segment, const GNELane* lane);
363 
365  void addSegmentInJunctionSegments(Segment* segment, const GNEJunction* junction);
366 
369 
371  void clearSegments();
372 
374  bool connectedLanes(const GNELane* fromLane, const GNELane* toLane) const;
375 
377  void buildPath(PathElement* pathElement, SUMOVehicleClass vClass, const std::vector<GNEEdge*> path,
378  GNELane* fromLane, GNEJunction* fromJunction, GNELane* toLane, GNEJunction* toJunction);
379 
382 
385 
387  std::map<const PathElement*, std::vector<Segment*> > myPaths;
388 
390  std::map<const GNELane*, std::vector<Segment*> > myLaneSegments;
391 
393  std::map<const GNEJunction*, std::vector<Segment*> > myJunctionSegments;
394 
395 private:
397  void markLabelSegment(const std::vector<Segment*>& segments) const;
398 
400  const std::vector<Segment*> myEmptySegments;
401 
403  GNEPathManager(const GNEPathManager&) = delete;
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.
Definition: GNEAdditional.h:49
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 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...
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
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
virtual GNELane * getLastPathLane() const =0
get last path lane
bool isAdditionalElement() const
check if pathElement is an additional element
bool isRoute() const
check if pathElement is a route
virtual GNELane * getFirstPathLane() const =0
get first path lane
PathElement & operator=(const PathElement &)=delete
Invalidated assignment operator.
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.
const GNELane * getPreviousLane() const
get previous lane
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 & 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
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)
void invalidateJunctionPath(const GNEJunction *junction)
invalidate junction path
const PathElement * getPathElement(const GUIGlObject *GLObject) const
get path element
PathDraw * getPathDraw()
obtain instance of PathDraw
void clearSegments()
clear segments
std::map< const GNELane *, std::vector< Segment * > > myLaneSegments
map with lane segments
void markLabelSegment(const std::vector< Segment * > &segments) const
mark label segment
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 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 GNEJunction *, std::vector< Segment * > > myJunctionSegments
map with junction 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)
PathDraw * myPathDraw
PathDraw instance.
void forceDrawPath(const GUIVisualizationSettings &s, const PathElement *pathElement) const
force draw path (used carefully, ONLY when we're inspecting a path element, due slowdowns)
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
GNEPathManager(const GNENet *net)
constructor
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)
void calculateConsecutivePathLanes(PathElement *pathElement, const std::vector< GNELane * > lanes)
calculate consecutive path lanes
Stores the information about how to visualize structures.