/****************************************************************************/1// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2// Copyright (C) 2001-2026 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 GNENet.h14/// @author Jakob Erdmann15/// @date Feb 201116///17// The lop level container for GNE-network-components such as GNEEdge and18// GNEJunction. Contains an internal instances of NBNetBuilder GNE components19// wrap netbuild-components of this underlying NBNetBuilder and supply20// visualisation and editing capabilities (adapted from GUINet)21//22// WorkrouteFlow (rough draft)23// wrap NB-components24// do netedit stuff25// call NBNetBuilder::buildLoaded to save results26//27/****************************************************************************/28#pragma once29#include <config.h>3031#include "GNENetHelper.h"32#include "GNEPathManager.h"3334// ===========================================================================35// class definitions36// ===========================================================================3738class GNENet : public GUIGlObject {3940public:41/// @brief constructor42GNENet(GNEApplicationWindow* applicationWindow, NBNetBuilder* netBuilder);4344/// @brief Destructor45~GNENet();4647/// @brief get tag properties database48GNEApplicationWindow* getGNEApplicationWindow() const;4950/// @brief get view net (used for simplify code)51GNEViewNet* getViewNet() const;5253/// @brief get view parent (used for simplify code)54GNEViewParent* getViewParent() const;5556/// @brief get undo list(used for simplify code)57GNEUndoList* getUndoList() const;5859/// @brief get tag properties database (used for simplify code)60const GNETagPropertiesDatabase* getTagPropertiesDatabase() const;6162/// @brief get net builder63NBNetBuilder* getNetBuilder() const;6465/// @brief get all attribute carriers used in this net66GNENetHelper::AttributeCarriers* getAttributeCarriers() const;6768/// @brief get all attribute carriers templates used in this net69GNENetHelper::ACTemplate* getACTemplates() const;7071/// @brief get saving status72GNENetHelper::SavingStatus* getSavingStatus() const;7374/// @brief get network path manager75GNEPathManager* getNetworkPathManager();7677/// @brief get demand path manager78GNEPathManager* getDemandPathManager();7980/// @brief get data path manager81GNEPathManager* getDataPathManager();8283/// @name inherited from GUIGlObject84/// @{85/**@brief Returns an own popup-menu86*87* @param[in] app The application needed to build the popup-menu88* @param[in] parent The parent window needed to build the popup-menu89* @return The built popup-menu90* @see GUIGlObject::getPopUpMenu91*/92GUIGLObjectPopupMenu* getPopUpMenu(GUIMainWindow& app, GUISUMOAbstractView& parent) override;9394/**@brief Returns an own parameter window95*96* @param[in] app The application needed to build the parameter window97* @param[in] parent The parent window needed to build the parameter window98* @return The built parameter window99* @see GUIGlObject::getParameterWindow100*/101GUIParameterTableWindow* getParameterWindow(GUIMainWindow& app, GUISUMOAbstractView& parent) override;102103/**@brief Returns the boundary to which the view shall be centered in order to show the object104*105* @return The boundary the object is within106* @see GUIGlObject::getCenteringBoundary107*/108Boundary getCenteringBoundary() const override;109110/// @brief expand boundary111void expandBoundary(const Boundary& newBoundary);112113/// @brief Returns the Z boundary (stored in the x() coordinate) values of 0 do not affect the boundary114const Boundary& getZBoundary() const;115116/// @brief add Z in net boundary117void addZValueInBoundary(const double z);118119/**@brief Draws the object120* @param[in] s The settings for the current view (may influence drawing)121* @see GUIGlObject::drawGL122*/123void drawGL(const GUIVisualizationSettings& s) const override;124125/// @}126127/// @brief returns the bounder of the network128const Boundary& getBoundary() const;129130/**@brief Returns the RTree used for visualisation speed-up131* @return The visualisation speed-up132* @note only use in GNEViewNet constructor. For edit grid ALWAYS use addGLObjectIntoGrid/removeGLObjectIntoGrid133*/134SUMORTree& getGrid();135136/// @brief et edges and number of lanes137const std::map<std::string, int>& getEdgesAndNumberOfLanes() const;138139/**@brief creates a new junction140* @param[in] position The position of the new junction141* @param[in] undoList The undolist in which to mark changes142* @return the new junction143*/144GNEJunction* createJunction(const Position& pos, GNEUndoList* undoList);145146/**@brief creates a new edge (unless an edge with the same geometry already147* exists)148* @param[in] src The starting junction149* @param[in] dest The ending junction150* @param[in] edgeTemplate The template edge from which to copy attributes (including lane attrs)151* @param[in] undoList The undoList in which to mark changes152* @param[in] suggestedName153* @param[in] wasSplit Whether the edge was created from a split154* @param[in] allowDuplicateGeom Whether to create the edge even though another edge with the same geometry exists155* @param[in] recomputeConnections Whether connections on the affected junctions must be recomputed156* @return The newly created edge or 0 if no edge was created157*/158GNEEdge* createEdge(GNEJunction* src, GNEJunction* dest, GNEEdge* edgeTemplate, GNEUndoList* undoList,159const std::string& suggestedName = "", bool wasSplit = false, bool allowDuplicateGeom = false,160bool recomputeConnections = true);161162/**@brief delete network element163* @param[in] networkElement The network element to be removed164* @param[in] undoList The undolist in which to mark changes165*/166void deleteNetworkElement(GNENetworkElement* networkElement, GNEUndoList* undoList);167168/**@brief removes junction and all incident edges169* @param[in] junction The junction to be removed170* @param[in] undoList The undolist in which to mark changes171*/172void deleteJunction(GNEJunction* junction, GNEUndoList* undoList);173174/**@brief removes edge175* @param[in] edge The edge to be removed176* @param[in] undoList The undolist in which to mark changes177*/178void deleteEdge(GNEEdge* edge, GNEUndoList* undoList, bool recomputeConnections);179180/**@brief replaces edge181* @param[in] which The edge to be replaced182* @param[in] by The replacement edge183* @param[in] undoList The undolist in which to mark changes184*/185void replaceIncomingEdge(GNEEdge* which, GNEEdge* by, GNEUndoList* undoList);186187/**@brief removes lane188* @param[in] lane The lane to be removed189* @param[in] undoList The undolist in which to mark changes190*/191void deleteLane(GNELane* lane, GNEUndoList* undoList, bool recomputeConnections);192193/**@brief remove connection194* @param[in] connection The connection to be removed195* @param[in] undoList The undolist in which to mark changes196*/197void deleteConnection(GNEConnection* connection, GNEUndoList* undoList);198199/**@brief remove crossing200* @param[in] crossing The crossing to be removed201* @param[in] undoList The undolist in which to mark changes202*/203void deleteCrossing(GNECrossing* crossing, GNEUndoList* undoList);204205/**@brief remove additional206* @param[in] additional The additional to be removed207* @param[in] undoList The undolist in which to mark changes208*/209void deleteAdditional(GNEAdditional* additional, GNEUndoList* undoList);210211/**@brief remove TAZSourceSink212* @param[in] TAZSourceSink The TAZSourceSink to be removed213* @param[in] undoList The undolist in which to mark changes214*/215void deleteTAZSourceSink(GNETAZSourceSink* TAZSourceSink, GNEUndoList* undoList);216217/**@brief remove demand element218* @param[in] demandElement The Shape to be removed219* @param[in] undoList The undolist in which to mark changes220*/221void deleteDemandElement(GNEDemandElement* demandElement, GNEUndoList* undoList);222223/**@brief remove data set224* @param[in] dataSet The data set to be removed225* @param[in] undoList The undolist in which to mark changes226*/227void deleteDataSet(GNEDataSet* dataSet, GNEUndoList* undoList);228229/**@brief remove data interval230* @param[in] dataInterval The data interval to be removed231* @param[in] undoList The undolist in which to mark changes232*/233void deleteDataInterval(GNEDataInterval* dataInterval, GNEUndoList* undoList);234235/**@brief remove generic data236* @param[in] genericData The generic data to be removed237* @param[in] undoList The undolist in which to mark changes238*/239void deleteGenericData(GNEGenericData* genericData, GNEUndoList* undoList);240241/**@brief remove generic data242* @param[in] genericData The generic data to be removed243* @param[in] undoList The undolist in which to mark changes244*/245void deleteMeanData(GNEMeanData* meanData, GNEUndoList* undoList);246247/**@brief duplicates lane248* @param[in] lane The lane to be duplicated249* @param[in] undoList The undolist in which to mark changes250*/251void duplicateLane(GNELane* lane, GNEUndoList* undoList, bool recomputeConnections);252253/**@brief transform lane to restricted lane254* @param[in] vclass vehicle class to restrict255* @param[in] lane The lane to be transformed256* @param[in] undoList The undolist in which to mark changes257*/258bool restrictLane(SUMOVehicleClass vclass, GNELane* lane, GNEUndoList* undoList);259260/**@brief add restricted lane to edge261* @param[in] vclass vehicle class to restrict262* @param[in] edge The edge in which insert restricted lane263* @param[in] index to be changed264* @param[in] undoList The undolist in which to mark changes265*/266bool addRestrictedLane(SUMOVehicleClass vclass, GNEEdge* edge, int index, GNEUndoList* undoList);267268/**@brief add restricted lane to edge269* @param[in] edge The edge in which insert restricted lane270* @param[in] index to be changed271* @param[in] undoList The undolist in which to mark changes272*/273bool addGreenVergeLane(GNEEdge* edge, int index, GNEUndoList* undoList);274275/**@brief remove restricted lane276* @param[in] vclass vehicle class to restrict277* @param[in] edge the edge in which remove sidewalk278* @param[in] undoList The undolist in which to mark changes279*/280bool removeRestrictedLane(SUMOVehicleClass vclass, GNEEdge* edge, GNEUndoList* undoList);281282/**@brief split edge at position by inserting a new junction283* @param[in] edge The edge to be split284* @param[in] pos The position on which to insert the new junction285* @return The new junction and the new edge286*/287std::pair<GNEJunction*, GNEEdge*> splitEdge(GNEEdge* edge, const Position& pos, GNEUndoList* undoList, GNEJunction* newJunction = 0);288289/**@brief split all edges at position by inserting one new junction290* @param[in] edge The edge to be split291* @param[in] oppositeEdge The oppositeEdge to be split292* @param[in] pos The position on which to insert the new junction293*/294void splitEdgesBidi(GNEEdge* edge, GNEEdge* oppositeEdge, const Position& pos, GNEUndoList* undoList);295296/**@brief reverse edge297* @param[in] edge The edge to be reversed298*/299void reverseEdge(GNEEdge* edge, GNEUndoList* undoList);300301/**@brief add reversed edge302* @param[in] edge The edge of which to add the reverse303* @param[in] disconnected add edge reversed or disconnected parallel304* @return Return the new edge or 0305*/306GNEEdge* addReversedEdge(GNEEdge* edge, const bool disconnected, GNEUndoList* undoList);307308/**@brief merge the given junctions309* edges between the given junctions will be deleted310* @param[in] moved The junction that will be eliminated311* @param[in] target The junction that will be enlarged312* @param[in] undoList The undo list with which to register changes313*/314void mergeJunctions(GNEJunction* moved, const GNEJunction* target, GNEUndoList* undoList);315316/// @brief select all roundabout edges and junctions for the current roundabout317void selectRoundabout(GNEJunction* junction, GNEUndoList* undoList);318319/// @brief transform the given junction into a roundabout320void createRoundabout(GNEJunction* junction, GNEUndoList* undoList);321322/// @brief save the network323void saveNetwork();324325/// @brief save plain xml representation of the network (and nothing else)326void savePlain(const std::string& prefix, const OptionsCont& netconvertOptions);327328/// @brief save log of joined junctions (and nothing else)329void saveJoined(const std::string& filename);330331/// @brief add GL Object into net332void addGLObjectIntoGrid(GNEAttributeCarrier* AC);333334/// @brief add GL Object into net335void removeGLObjectFromGrid(GNEAttributeCarrier* AC);336337/// @brief modifies endpoins of the given edge338void changeEdgeEndpoints(GNEEdge* edge, const std::string& newSourceID, const std::string& newDestID);339340341/// @brief returns the tllcont of the underlying netbuilder342NBTrafficLightLogicCont& getTLLogicCont();343344/// @brief returns the NBEdgeCont of the underlying netbuilder345NBEdgeCont& getEdgeCont();346347/// @brief initialize GNEConnections348void initGNEConnections();349350/// @brief recompute the network and update lane geometries351void computeAndUpdate(OptionsCont& neteditOptions, bool volatileOptions);352353/**@brief trigger full netbuild computation354* param[in] window The window to inform about delay355* param[in] force Whether to force recomputation even if not needed356* param[in] volatileOptions enable or disable volatile options357*/358void computeNetwork(GNEApplicationWindow* window, bool force = false, bool volatileOptions = false);359360/**@brief compute demand elements361* param[in] window The window to inform about delay362*/363void computeDemandElements(GNEApplicationWindow* window);364365/**@brief compute data elements366* param[in] window The window to inform about delay367*/368void computeDataElements(GNEApplicationWindow* window);369370/**@brief join selected junctions371* @note difference to mergeJunctions:372* - can join more than 2373* - connected edges will keep their geometry (big junction shape is created)374* - no hierarchy: if any junction has a traffic light than the resulting junction will375*/376bool joinSelectedJunctions(GNEUndoList* undoList);377378/// @brief clear invalid crossings379bool cleanInvalidCrossings(GNEUndoList* undoList);380381/// @brief removes junctions that have no edges382void removeSolitaryJunctions(GNEUndoList* undoList);383384/// @brief clean unused routes385void cleanUnusedRoutes(GNEUndoList* undoList);386387/// @brief join routes388void joinRoutes(GNEUndoList* undoList);389390/// @brief adjust person plans391void adjustPersonPlans(GNEUndoList* undoList);392393/// @brief clean invalid demand elements394void cleanInvalidDemandElements(GNEUndoList* undoList);395396/// @brief replace the selected junction by geometry node(s) and merge the edges397void replaceJunctionByGeometry(GNEJunction* junction, GNEUndoList* undoList);398399/// @brief replace the selected junction by a list of junctions for each unique edge endpoint400void splitJunction(GNEJunction* junction, bool reconnect, GNEUndoList* undoList);401402/// @brief clear junction's connections403void clearJunctionConnections(GNEJunction* junction, GNEUndoList* undoList);404405/// @brief reset junction's connections406void resetJunctionConnections(GNEJunction* junction, GNEUndoList* undoList);407408/// @brief clear additionals409void clearAdditionalElements(GNEUndoList* undoList);410411/// @brief clear demand elements412void clearDemandElements(GNEUndoList* undoList);413414/// @brief clear data elements415void clearDataElements(GNEUndoList* undoList);416417/// @brief clear meanDatas418void clearMeanDataElements(GNEUndoList* undoList);419420/**@brief trigger recomputation of junction shape and logic421* param[in] window The window to inform about delay422*/423void computeJunction(GNEJunction* junction);424425/// @brief inform the net about the need for recomputation426void requireRecompute();427428/// @brief check if net require recomputing429bool isNetRecomputed() const;430431/// @brief add edge id to the list of explicit turnarounds432void addExplicitTurnaround(std::string id);433434/// @brief remove edge id from the list of explicit turnarounds435void removeExplicitTurnaround(std::string id);436437/// @brief save additional elements438bool saveAdditionals();439440/// @brief save JuPedSim elements441bool saveJuPedSimElements(const std::string& filename);442443/// @brief save demand element elements of the network444bool saveDemandElements();445446/// @brief save data set elements of the network447bool saveDataElements();448449/// @brief get minimum interval450double getDataSetIntervalMinimumBegin() const;451452/// @brief get maximum interval453double getDataSetIntervalMaximumEnd() const;454455/// @brief save meanData elements of the network456bool saveMeanDatas();457458/**@brief save TLS Programs elements of the network459* @param[in] filename name of the file in which save TLS Programs460*/461void saveTLSPrograms(const std::string& filename);462463/// @brief get number of TLS Programs464int getNumberOfTLSPrograms() const;465466/**@brief save edgeTypes elements of the network467* @param[in] filename name of the file in which save edgeTypes468*/469void saveEdgeTypes(const std::string& filename);470471/// @name Functions related to Enable or disable update geometry of elements after insertion472/// @{473/// @brief enable update geometry of elements after inserting or removing an element in net474void enableUpdateGeometry();475476/// @brief disable update geometry of elements after inserting or removing an element in net477void disableUpdateGeometry();478479/// @brief check if update geometry after inserting or removing has to be updated480bool isUpdateGeometryEnabled() const;481482/// @}483484/// @name Functions related to Enable or disable update data of elements after insertion485/// @{486/// @brief enable update data elements after inserting or removing an element in net487void enableUpdateData();488489/// @brief disable update data elements after inserting or removing an element in net490void disableUpdateData();491492/// @brief check if update data after inserting or removing has to be updated493bool isUpdateDataEnabled() const;494495/// @}496497/// @name get junction id counter498unsigned int& getJunctionIDCounter();499500/// @name get edge id counter501unsigned int& getEdgeIDCounter();502503/// @brief variable used for write headers in additional, demand and data elements504static const std::map<SumoXMLAttr, std::string> EMPTY_HEADER;505506protected:507/// @brief the rtree which contains all GUIGlObjects (so named for historical reasons)508SUMORTree myGrid;509510/// @brief pointer to application window511GNEApplicationWindow* myApplicationWindow = nullptr;512513/// @brief The internal netbuilder514NBNetBuilder* myNetBuilder = nullptr;515516/// @brief attributeCarriers module517GNENetHelper::AttributeCarriers* myAttributeCarriers = nullptr;518519/// @brief attributeCarriers templates520GNENetHelper::ACTemplate* myACTemplates = nullptr;521522/// @brief saving status module523GNENetHelper::SavingStatus* mySavingStatus = nullptr;524525/// @brief Network path manager526GNEPathManager* myNetworkPathManager = nullptr;527528/// @brief Demand path manager529GNEPathManager* myDemandPathManager = nullptr;530531/// @brief Data path manager532GNEPathManager* myDataPathManager = nullptr;533534/// @name counters for junction/edge IDs535// @{536unsigned int myJunctionIDCounter = 0;537unsigned int myEdgeIDCounter = 0;538// @}539540/// @brief list of edge ids for which turn-arounds must be added explicitly541std::set<std::string> myExplicitTurnarounds;542543/// @brief whether the net needs recomputation544bool myNeedRecompute = true;545546/// @brief Flag to enable or disable update geometry of elements after inserting or removing element in net547bool myUpdateGeometryEnabled = true;548549/// @brief Flag to enable or disable update data elements after inserting or removing element in net550bool myUpdateDataEnabled = true;551552private:553/// @brief Init Junctions and edges554void initJunctionsAndEdges();555556/// @brief return true if there are already a Junction in the given position, false in other case557bool checkJunctionPosition(const Position& pos);558559/// @brief write additionals demand elements and meanData in output device560void writeAdditionalFileElements(OutputDevice& device, const FileBucket* fileBucket);561562/// @brief write additional element by type and sorted by ID563void writeAdditionalByType(OutputDevice& device, const FileBucket* fileBucket, const std::vector<SumoXMLTag> tags) const;564565/// @brief write demand element by type and sorted by ID566void writeDemandByType(OutputDevice& device, const FileBucket* fileBucket, SumoXMLTag tag) const;567568/// @brief write route distributions sorted by ID569void writeRouteDistributions(OutputDevice& device, const FileBucket* fileBucket) const;570571/// @brief write route sorted by ID572void writeRoutes(OutputDevice& device, const FileBucket* fileBucket) const;573574/// @brief write vTypeDistributions sorted by ID575void writeVTypeDistributions(OutputDevice& device, const FileBucket* fileBucket) const;576577/// @brief write vTypes sorted by ID578void writeVTypes(OutputDevice& device, const FileBucket* fileBucket) const;579580/// @brief write meanData element by type and sorted by ID581void writeMeanDatas(OutputDevice& device, const FileBucket* fileBucket, SumoXMLTag tag) const;582583/// @brief write vType comment584bool writeVTypeComment(OutputDevice& device, const FileBucket* fileBucket) const;585586/// @brief write route comment587bool writeRouteComment(OutputDevice& device, const FileBucket* fileBucket) const;588589/// @brief write rerouter comment590bool writeRerouterComment(OutputDevice& device, const FileBucket* fileBucket) const;591592/// @brief write variable speed sign comment593bool writeVariableSpeedSignComment(OutputDevice& device, const FileBucket* fileBucket) const;594595/// @brief write routeProbe comment596bool writeRouteProbeComment(OutputDevice& device, const FileBucket* fileBucket) const;597598/// @brief write vaporizer comment599bool writeVaporizerComment(OutputDevice& device, const FileBucket* fileBucket) const;600601/// @brief write calibrator comment602bool writeCalibratorComment(OutputDevice& device, const FileBucket* fileBucket) const;603604/// @brief write stoppingPlace comment605bool writeStoppingPlaceComment(OutputDevice& device, const FileBucket* fileBucket) const;606607/// @brief write detector comment608bool writeDetectorComment(OutputDevice& device, const FileBucket* fileBucket) const;609610/// @brief write shape comment611bool writeShapesComment(OutputDevice& device, const FileBucket* fileBucket) const;612613/// @brief write JuPedSim comment614bool writeJuPedSimComment(OutputDevice& device, const FileBucket* fileBucket) const;615616/// @brief write TAZ comment617bool writeTAZComment(OutputDevice& device, const FileBucket* fileBucket) const;618619/// @brief write Wire comment620bool writeWireComment(OutputDevice& device, const FileBucket* fileBucket) const;621622/// @brief write meanDataEdge comment623bool writeMeanDataEdgeComment(OutputDevice& device, const FileBucket* fileBucket) const;624625/// @brief write Wire comment626bool writeMeanDataLaneComment(OutputDevice& device, const FileBucket* fileBucket) const;627628/// @brief replace in list attribute629static void replaceInListAttribute(GNEAttributeCarrier* ac, SumoXMLAttr key, const std::string& which, const std::string& by, GNEUndoList* undoList);630631/// @brief the z boundary (stored in the x-coordinate), values of 0 are ignored632Boundary myZBoundary;633634/// @brief map with the Edges and their number of lanes635std::map<std::string, int> myEdgesAndNumberOfLanes;636637/// @brief marker for whether the z-boundary is initialized638static const double Z_INITIALIZED;639640/// @brief Invalidated default constructor.641GNENet() = delete;642643/// @brief Invalidated copy constructor.644GNENet(const GNENet&) = delete;645646/// @brief Invalidated assignment operator.647GNENet& operator=(const GNENet&) = delete;648};649650651