/****************************************************************************/1// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2// Copyright (C) 2001-2025 German Aerospace Center (DLR) and others.3// This program and the accompanying materials are made available under the4// terms of the Eclipse Public License 2.0 which is available at5// https://www.eclipse.org/legal/epl-2.0/6// This Source Code may also be made available under the following Secondary7// Licenses when the conditions for such availability set forth in the Eclipse8// Public License 2.0 are satisfied: GNU General Public License, version 29// or later which is available at10// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html11// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later12/****************************************************************************/13/// @file GNEPathManager.h14/// @author Pablo Alvarez Lopez15/// @date Feb 201116///17// Manager for paths in netedit (routes, trips, flows...)18/****************************************************************************/19#pragma once20#include <config.h>2122#include <netbuild/NBEdge.h>23#include <netbuild/NBVehicle.h>24#include <netedit/elements/GNEContour.h>25#include <utils/common/SUMOVehicleClass.h>26#include <utils/router/SUMOAbstractRouter.h>27#include <utils/gui/settings/GUIVisualizationSettings.h>282930// ===========================================================================31// class declaration32// ===========================================================================3334class GNENet;35class GNEEdge;36class GNELane;37class GNEJunction;38class GNEAdditional;39class GNEPathElement;40class GNESegment;41class GUIGlObject;4243// ===========================================================================44// class definitions45// ===========================================================================4647class GNEPathManager {4849/// @brief friend class declaration50friend class GNESegment;5152public:5354/// @brief class used to calculate paths in nets55class PathCalculator {5657public:58/// @brief constructor59PathCalculator(const GNENet* net);6061/// @brief destructor62~PathCalculator();6364/**@brief update DijkstraRouter (needed a good calculation of dijkstra path after modifying network)65* @note only needed if this path calculator requiere to use the calculateDijkstraPath(...) functions66*/67void updatePathCalculator();6869/// @brief calculate Dijkstra path between a list of edges (for example, from-via-to edges)70std::vector<GNEEdge*> calculateDijkstraPath(const SUMOVehicleClass vClass, const std::vector<GNEEdge*>& edges) const;7172/// @brief calculate Dijkstra path between one edge73std::vector<GNEEdge*> calculateDijkstraPath(const SUMOVehicleClass vClass, GNEEdge* fromEdge, GNEEdge* toEdge) const;7475/// @brief calculate Dijkstra path between from edge and to junction76std::vector<GNEEdge*> calculateDijkstraPath(const SUMOVehicleClass vClass, GNEEdge* fromEdge, GNEJunction* toJunction) const;7778/// @brief calculate Dijkstra path between from junction and to edge79std::vector<GNEEdge*> calculateDijkstraPath(const SUMOVehicleClass vClass, GNEJunction* fromJunction, GNEEdge* toEdge) const;8081/// @brief calculate Dijkstra path between two Junctions82std::vector<GNEEdge*> calculateDijkstraPath(const SUMOVehicleClass vClass, GNEJunction* fromJunction, GNEJunction* toJunction) const;8384/// @brief calculate reachability for given edge85void calculateReachability(const SUMOVehicleClass vClass, GNEEdge* originEdge);8687/// @brief check if exist a path between the two given consecutive edges for the given VClass88bool consecutiveEdgesConnected(const SUMOVehicleClass vClass, const GNEEdge* from, const GNEEdge* to) const;8990/// @brief check if exist a path between the given busStop and edge (Either a valid lane or an acces) for pedestrians91bool busStopConnected(const GNEAdditional* busStop, const GNEEdge* edge) const;9293/// @brief check if pathCalculator is updated94bool isPathCalculatorUpdated() const;9596/// @brief invalidate pathCalculator97void invalidatePathCalculator();9899private:100/// @brief pointer to net101const GNENet* myNet;102103/// @brief flag for checking if path calculator is updated104bool myPathCalculatorUpdated;105106/// @brief SUMO Abstract myDijkstraRouter107SUMOAbstractRouter<NBRouterEdge, NBVehicle>* myDijkstraRouter;108109/// @brief optimize junction path110std::vector<GNEEdge*> optimizeJunctionPath(const std::vector<GNEEdge*>& edges) const;111};112113/// @brief class used to mark path draw114class PathDraw {115116public:117/// @brief constructor118PathDraw();119120/// @brief destructor121~PathDraw();122123/// @brief clear path draw124void clearPathDraw();125126/// @brief check if path element geometry must be drawn in the given lane127bool checkDrawPathGeometry(const GUIVisualizationSettings& s, const GNELane* lane, const SumoXMLTag tag, const bool isPlan);128129/// @brief check if path element geometry must be drawn in the given junction130bool checkDrawPathGeometry(const GUIVisualizationSettings& s, const GNESegment* segment, const SumoXMLTag tag, const bool isPlan);131132private:133/// @brief map for saving tags drawn in lanes134std::map<const GNELane*, std::set<SumoXMLTag> > myLaneDrawedElements;135136/// @brief map for saving tags drawn in junctions137std::map<const std::pair<const GNELane*, const GNELane*>, std::set<SumoXMLTag> > myLane2laneDrawedElements;138};139140/// @brief constructor141GNEPathManager(const GNENet* net);142143/// @brief destructor144~GNEPathManager();145146/// @brief obtain instance of PathCalculator147PathCalculator* getPathCalculator();148149/// @brief get path element150const GNEPathElement* getPathElement(const GUIGlObject* GLObject) const;151152/// @brief get path segments153const std::vector<GNESegment*>& getPathElementSegments(GNEPathElement* pathElement) const;154155/// @brief obtain instance of PathDraw156PathDraw* getPathDraw();157158/// @brief check if path element is valid159bool isPathValid(const GNEPathElement* pathElement) const;160161/// @brief get first lane associated with path element162const GNELane* getFirstLane(const GNEPathElement* pathElement) const;163164/// @brief calculate path between from-to edges (using dijkstra, require path calculator updated)165void calculatePath(GNEPathElement* pathElement, SUMOVehicleClass vClass, GNELane* fromLane, GNELane* toLane);166167/// @brief calculate path between from edge and to junction(using dijkstra, require path calculator updated)168void calculatePath(GNEPathElement* pathElement, SUMOVehicleClass vClass, GNELane* fromLane, GNEJunction* toJunction);169170/// @brief calculate path between from junction and to edge (using dijkstra, require path calculator updated)171void calculatePath(GNEPathElement* pathElement, SUMOVehicleClass vClass, GNEJunction* fromJunction, GNELane* toLane);172173/// @brief calculate path between from junction and to junction (using dijkstra, require path calculator updated)174void calculatePath(GNEPathElement* pathElement, SUMOVehicleClass vClass, GNEJunction* fromJunction, GNEJunction* toJunction);175176/// @brief calculate path lanes between list of edges (using dijkstra, require path calculator updated)177void calculatePath(GNEPathElement* pathElement, SUMOVehicleClass vClass, const std::vector<GNEEdge*>& edges);178179/// @brief calculate consecutive path edges180void calculateConsecutivePathEdges(GNEPathElement* pathElement, SUMOVehicleClass vClass, const std::vector<GNEEdge*>& edges,181const int firstLaneIndex = -1, const int lastLaneIndex = -1);182183/// @brief calculate consecutive path lanes184void calculateConsecutivePathLanes(GNEPathElement* pathElement, const std::vector<GNELane*>& lanes);185186/// @brief remove path187void removePath(GNEPathElement* pathElement);188189/// @brief draw lane path elements190void drawLanePathElements(const GUIVisualizationSettings& s, const GNELane* lane) const;191192/// @brief draw junction path elements193void drawJunctionPathElements(const GUIVisualizationSettings& s, const GNEJunction* junction) const;194195/// @brief redraw path elements saved in gViewObjectsHandler buffer196void redrawPathElements(const GUIVisualizationSettings& s) const;197198/// @brief invalidate lane path199void invalidateLanePath(const GNELane* lane);200201/// @brief invalidate junction path202void invalidateJunctionPath(const GNEJunction* junction);203204/// @brief clear segments205void clearSegments();206207protected:208/// @brief add segments int laneSegments (called by GNESegment constructor)209void addSegmentInLaneSegments(GNESegment* segment, const GNELane* lane);210211/// @brief add segments int junctionSegments (called by GNESegment constructor)212void addSegmentInJunctionSegments(GNESegment* segment, const GNEJunction* junction);213214/// @brief clear segments from junction and lane Segments (called by GNESegment destructor)215void clearSegmentFromJunctionAndLaneSegments(GNESegment* segment);216217/// @brief check if given lanes are connected218bool connectedLanes(const GNELane* fromLane, const GNELane* toLane) const;219220/// @brief build path221void buildPath(GNEPathElement* pathElement, SUMOVehicleClass vClass, const std::vector<GNEEdge*> path,222GNELane* fromLane, GNEJunction* fromJunction, GNELane* toLane, GNEJunction* toJunction);223224/// @brief PathCalculator instance225PathCalculator* myPathCalculator;226227/// @brief PathDraw instance228PathDraw* myPathDraw;229230/// @brief map with path element and their associated segments231std::map<const GNEPathElement*, std::vector<GNESegment*> > myPaths;232233/// @brief map with lane segments234std::map<const GNELane*, std::set<GNESegment*> > myLaneSegments;235236/// @brief map with junction segments237std::map<const GNEJunction*, std::set<GNESegment*> > myJunctionSegments;238239/// @brief flag for clear segments quickly240bool myCleaningSegments = false;241242private:243/// @brief mark label segment244void markLabelSegment(const std::vector<GNESegment*>& segments) const;245246/// @brief empty segments (used in getPathElementSegments)247const std::vector<GNESegment*> myEmptySegments;248249/// @brief Invalidated copy constructor.250GNEPathManager(const GNEPathManager&) = delete;251252/// @brief Invalidated assignment operator.253GNEPathManager& operator=(const GNEPathManager&) = delete;254};255256257