/****************************************************************************/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 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// ===========================================================================37/**38* @class GNENet39* @brief A NBNetBuilder extended by visualisation and editing capabilities40*/41class GNENet : public GUIGlObject {4243public:44/// @brief constructor45GNENet(NBNetBuilder* netBuilder, const GNETagPropertiesDatabase* tagPropertiesDatabase);4647/// @brief Destructor48~GNENet();4950/// @brief get tag properties database51const GNETagPropertiesDatabase* getTagPropertiesDatabase() const;5253/// @brief get all attribute carriers used in this net54GNENetHelper::AttributeCarriers* getAttributeCarriers() const;5556/// @brief get all attribute carriers templates used in this net57GNENetHelper::ACTemplate* getACTemplates() const;5859/// @brief get saving files handler60GNENetHelper::SavingFilesHandler* getSavingFilesHandler() const;6162/// @brief get saving status63GNENetHelper::SavingStatus* getSavingStatus() const;6465/// @brief get network path manager66GNEPathManager* getNetworkPathManager();6768/// @brief get demand path manager69GNEPathManager* getDemandPathManager();7071/// @brief get data path manager72GNEPathManager* getDataPathManager();7374/// @name inherited from GUIGlObject75/// @{76/**@brief Returns an own popup-menu77*78* @param[in] app The application needed to build the popup-menu79* @param[in] parent The parent window needed to build the popup-menu80* @return The built popup-menu81* @see GUIGlObject::getPopUpMenu82*/83GUIGLObjectPopupMenu* getPopUpMenu(GUIMainWindow& app, GUISUMOAbstractView& parent);8485/**@brief Returns an own parameter window86*87* @param[in] app The application needed to build the parameter window88* @param[in] parent The parent window needed to build the parameter window89* @return The built parameter window90* @see GUIGlObject::getParameterWindow91*/92GUIParameterTableWindow* getParameterWindow(GUIMainWindow& app, GUISUMOAbstractView& parent);9394/**@brief Returns the boundary to which the view shall be centered in order to show the object95*96* @return The boundary the object is within97* @see GUIGlObject::getCenteringBoundary98*/99Boundary getCenteringBoundary() const;100101/// @brief expand boundary102void expandBoundary(const Boundary& newBoundary);103104/// @brief Returns the Z boundary (stored in the x() coordinate) values of 0 do not affect the boundary105const Boundary& getZBoundary() const;106107/// @brief add Z in net boundary108void addZValueInBoundary(const double z);109110/**@brief Draws the object111* @param[in] s The settings for the current view (may influence drawing)112* @see GUIGlObject::drawGL113*/114void drawGL(const GUIVisualizationSettings& s) const;115116/// @}117118/// @brief returns the bounder of the network119const Boundary& getBoundary() const;120121/**@brief Returns the RTree used for visualisation speed-up122* @return The visualisation speed-up123* @note only use in GNEViewNet constructor. For edit grid ALWAYS use addGLObjectIntoGrid/removeGLObjectIntoGrid124*/125SUMORTree& getGrid();126127/// @brief et edges and number of lanes128const std::map<std::string, int>& getEdgesAndNumberOfLanes() const;129130/**@brief creates a new junction131* @param[in] position The position of the new junction132* @param[in] undoList The undolist in which to mark changes133* @return the new junction134*/135GNEJunction* createJunction(const Position& pos, GNEUndoList* undoList);136137/**@brief creates a new edge (unless an edge with the same geometry already138* exists)139* @param[in] src The starting junction140* @param[in] dest The ending junction141* @param[in] edgeTemplate The template edge from which to copy attributes (including lane attrs)142* @param[in] undoList The undoList in which to mark changes143* @param[in] suggestedName144* @param[in] wasSplit Whether the edge was created from a split145* @param[in] allowDuplicateGeom Whether to create the edge even though another edge with the same geometry exists146* @param[in] recomputeConnections Whether connections on the affected junctions must be recomputed147* @return The newly created edge or 0 if no edge was created148*/149GNEEdge* createEdge(GNEJunction* src, GNEJunction* dest, GNEEdge* edgeTemplate, GNEUndoList* undoList,150const std::string& suggestedName = "", bool wasSplit = false, bool allowDuplicateGeom = false,151bool recomputeConnections = true);152153/**@brief delete network element154* @param[in] networkElement The network element to be removed155* @param[in] undoList The undolist in which to mark changes156*/157void deleteNetworkElement(GNENetworkElement* networkElement, GNEUndoList* undoList);158159/**@brief removes junction and all incident edges160* @param[in] junction The junction to be removed161* @param[in] undoList The undolist in which to mark changes162*/163void deleteJunction(GNEJunction* junction, GNEUndoList* undoList);164165/**@brief removes edge166* @param[in] edge The edge to be removed167* @param[in] undoList The undolist in which to mark changes168*/169void deleteEdge(GNEEdge* edge, GNEUndoList* undoList, bool recomputeConnections);170171/**@brief replaces edge172* @param[in] which The edge to be replaced173* @param[in] by The replacement edge174* @param[in] undoList The undolist in which to mark changes175*/176void replaceIncomingEdge(GNEEdge* which, GNEEdge* by, GNEUndoList* undoList);177178/**@brief removes lane179* @param[in] lane The lane to be removed180* @param[in] undoList The undolist in which to mark changes181*/182void deleteLane(GNELane* lane, GNEUndoList* undoList, bool recomputeConnections);183184/**@brief remove connection185* @param[in] connection The connection to be removed186* @param[in] undoList The undolist in which to mark changes187*/188void deleteConnection(GNEConnection* connection, GNEUndoList* undoList);189190/**@brief remove crossing191* @param[in] crossing The crossing to be removed192* @param[in] undoList The undolist in which to mark changes193*/194void deleteCrossing(GNECrossing* crossing, GNEUndoList* undoList);195196/**@brief remove additional197* @param[in] additional The additional to be removed198* @param[in] undoList The undolist in which to mark changes199*/200void deleteAdditional(GNEAdditional* additional, GNEUndoList* undoList);201202/**@brief remove TAZSourceSink203* @param[in] TAZSourceSink The TAZSourceSink to be removed204* @param[in] undoList The undolist in which to mark changes205*/206void deleteTAZSourceSink(GNETAZSourceSink* TAZSourceSink, GNEUndoList* undoList);207208/**@brief remove demand element209* @param[in] demandElement The Shape to be removed210* @param[in] undoList The undolist in which to mark changes211*/212void deleteDemandElement(GNEDemandElement* demandElement, GNEUndoList* undoList);213214/**@brief remove data set215* @param[in] dataSet The data set to be removed216* @param[in] undoList The undolist in which to mark changes217*/218void deleteDataSet(GNEDataSet* dataSet, GNEUndoList* undoList);219220/**@brief remove data interval221* @param[in] dataInterval The data interval to be removed222* @param[in] undoList The undolist in which to mark changes223*/224void deleteDataInterval(GNEDataInterval* dataInterval, GNEUndoList* undoList);225226/**@brief remove generic data227* @param[in] genericData The generic data to be removed228* @param[in] undoList The undolist in which to mark changes229*/230void deleteGenericData(GNEGenericData* genericData, GNEUndoList* undoList);231232/**@brief remove generic data233* @param[in] genericData The generic data to be removed234* @param[in] undoList The undolist in which to mark changes235*/236void deleteMeanData(GNEMeanData* meanData, GNEUndoList* undoList);237238/**@brief duplicates lane239* @param[in] lane The lane to be duplicated240* @param[in] undoList The undolist in which to mark changes241*/242void duplicateLane(GNELane* lane, GNEUndoList* undoList, bool recomputeConnections);243244/**@brief transform lane to restricted lane245* @param[in] vclass vehicle class to restrict246* @param[in] lane The lane to be transformed247* @param[in] undoList The undolist in which to mark changes248*/249bool restrictLane(SUMOVehicleClass vclass, GNELane* lane, GNEUndoList* undoList);250251/**@brief add restricted lane to edge252* @param[in] vclass vehicle class to restrict253* @param[in] edge The edge in which insert restricted lane254* @param[in] index to be changed255* @param[in] undoList The undolist in which to mark changes256*/257bool addRestrictedLane(SUMOVehicleClass vclass, GNEEdge* edge, int index, GNEUndoList* undoList);258259/**@brief add restricted lane to edge260* @param[in] edge The edge in which insert restricted lane261* @param[in] index to be changed262* @param[in] undoList The undolist in which to mark changes263*/264bool addGreenVergeLane(GNEEdge* edge, int index, GNEUndoList* undoList);265266/**@brief remove restricted lane267* @param[in] vclass vehicle class to restrict268* @param[in] edge the edge in which remove sidewalk269* @param[in] undoList The undolist in which to mark changes270*/271bool removeRestrictedLane(SUMOVehicleClass vclass, GNEEdge* edge, GNEUndoList* undoList);272273/**@brief split edge at position by inserting a new junction274* @param[in] edge The edge to be split275* @param[in] pos The position on which to insert the new junction276* @return The new junction and the new edge277*/278std::pair<GNEJunction*, GNEEdge*> splitEdge(GNEEdge* edge, const Position& pos, GNEUndoList* undoList, GNEJunction* newJunction = 0);279280/**@brief split all edges at position by inserting one new junction281* @param[in] edge The edge to be split282* @param[in] oppositeEdge The oppositeEdge to be split283* @param[in] pos The position on which to insert the new junction284*/285void splitEdgesBidi(GNEEdge* edge, GNEEdge* oppositeEdge, const Position& pos, GNEUndoList* undoList);286287/**@brief reverse edge288* @param[in] edge The edge to be reversed289*/290void reverseEdge(GNEEdge* edge, GNEUndoList* undoList);291292/**@brief add reversed edge293* @param[in] edge The edge of which to add the reverse294* @param[in] disconnected add edge reversed or disconnected parallel295* @return Return the new edge or 0296*/297GNEEdge* addReversedEdge(GNEEdge* edge, const bool disconnected, GNEUndoList* undoList);298299/**@brief merge the given junctions300* edges between the given junctions will be deleted301* @param[in] moved The junction that will be eliminated302* @param[in] target The junction that will be enlarged303* @param[in] undoList The undo list with which to register changes304*/305void mergeJunctions(GNEJunction* moved, const GNEJunction* target, GNEUndoList* undoList);306307/// @brief select all roundabout edges and junctions for the current roundabout308void selectRoundabout(GNEJunction* junction, GNEUndoList* undoList);309310/// @brief transform the given junction into a roundabout311void createRoundabout(GNEJunction* junction, GNEUndoList* undoList);312313/// @brief save the network314void saveNetwork();315316/// @brief save plain xml representation of the network (and nothing else)317void savePlain(const std::string& prefix);318319/// @brief save log of joined junctions (and nothing else)320void saveJoined(const std::string& filename);321322/// @brief Set the net to be notified of network changes323void setViewNet(GNEViewNet* viewNet);324325/// @brief add GL Object into net326void addGLObjectIntoGrid(GNEAttributeCarrier* AC);327328/// @brief add GL Object into net329void removeGLObjectFromGrid(GNEAttributeCarrier* AC);330331/// @brief modifies endpoins of the given edge332void changeEdgeEndpoints(GNEEdge* edge, const std::string& newSourceID, const std::string& newDestID);333334/// @brief get view net335GNEViewNet* getViewNet() const;336337/// @brief returns the tllcont of the underlying netbuilder338NBTrafficLightLogicCont& getTLLogicCont();339340/// @brief returns the NBEdgeCont of the underlying netbuilder341NBEdgeCont& getEdgeCont();342343/// @brief initialize GNEConnections344void initGNEConnections();345346/// @brief recompute the network and update lane geometries347void computeAndUpdate(OptionsCont& neteditOptions, bool volatileOptions);348349/**@brief trigger full netbuild computation350* param[in] window The window to inform about delay351* param[in] force Whether to force recomputation even if not needed352* param[in] volatileOptions enable or disable volatile options353*/354void computeNetwork(GNEApplicationWindow* window, bool force = false, bool volatileOptions = false);355356/**@brief compute demand elements357* param[in] window The window to inform about delay358*/359void computeDemandElements(GNEApplicationWindow* window);360361/**@brief compute data elements362* param[in] window The window to inform about delay363*/364void computeDataElements(GNEApplicationWindow* window);365366/**@brief join selected junctions367* @note difference to mergeJunctions:368* - can join more than 2369* - connected edges will keep their geometry (big junction shape is created)370* - no hierarchy: if any junction has a traffic light than the resulting junction will371*/372bool joinSelectedJunctions(GNEUndoList* undoList);373374/// @brief clear invalid crossings375bool cleanInvalidCrossings(GNEUndoList* undoList);376377/// @brief removes junctions that have no edges378void removeSolitaryJunctions(GNEUndoList* undoList);379380/// @brief clean unused routes381void cleanUnusedRoutes(GNEUndoList* undoList);382383/// @brief join routes384void joinRoutes(GNEUndoList* undoList);385386/// @brief adjust person plans387void adjustPersonPlans(GNEUndoList* undoList);388389/// @brief clean invalid demand elements390void cleanInvalidDemandElements(GNEUndoList* undoList);391392/// @brief replace the selected junction by geometry node(s) and merge the edges393void replaceJunctionByGeometry(GNEJunction* junction, GNEUndoList* undoList);394395/// @brief replace the selected junction by a list of junctions for each unique edge endpoint396void splitJunction(GNEJunction* junction, bool reconnect, GNEUndoList* undoList);397398/// @brief clear junction's connections399void clearJunctionConnections(GNEJunction* junction, GNEUndoList* undoList);400401/// @brief reset junction's connections402void resetJunctionConnections(GNEJunction* junction, GNEUndoList* undoList);403404/// @brief clear additionals405void clearAdditionalElements(GNEUndoList* undoList);406407/// @brief clear demand elements408void clearDemandElements(GNEUndoList* undoList);409410/// @brief clear data elements411void clearDataElements(GNEUndoList* undoList);412413/// @brief clear meanDatas414void clearMeanDataElements(GNEUndoList* undoList);415416/**@brief trigger recomputation of junction shape and logic417* param[in] window The window to inform about delay418*/419void computeJunction(GNEJunction* junction);420421/// @brief inform the net about the need for recomputation422void requireRecompute();423424/// @brief check if net require recomputing425bool isNetRecomputed() const;426427/// @brief get pointer to the main App428FXApp* getApp();429430/// @brief get net builder431NBNetBuilder* getNetBuilder() const;432433/// @brief add edge id to the list of explicit turnarounds434void addExplicitTurnaround(std::string id);435436/// @brief remove edge id from the list of explicit turnarounds437void removeExplicitTurnaround(std::string id);438439/// @brief save additional elements440bool saveAdditionals();441442/// @brief save JuPedSim elements443bool saveJuPedSimElements(const std::unordered_set<const GNEAttributeCarrier*>& ACs, const std::string& file);444445/// @brief save demand element elements of the network446bool saveDemandElements();447448/// @brief save data set elements of the network449bool saveDataElements();450451/// @brief get minimum interval452double getDataSetIntervalMinimumBegin() const;453454/// @brief get maximum interval455double getDataSetIntervalMaximumEnd() const;456457/// @brief save meanData elements of the network458bool saveMeanDatas();459460/**@brief save TLS Programs elements of the network461* @param[in] filename name of the file in which save TLS Programs462*/463void saveTLSPrograms(const std::string& filename);464465/// @brief get number of TLS Programs466int getNumberOfTLSPrograms() const;467468/**@brief save edgeTypes elements of the network469* @param[in] filename name of the file in which save edgeTypes470*/471void saveEdgeTypes(const std::string& filename);472473/// @name Functions related to Enable or disable update geometry of elements after insertion474/// @{475/// @brief enable update geometry of elements after inserting or removing an element in net476void enableUpdateGeometry();477478/// @brief disable update geometry of elements after inserting or removing an element in net479void disableUpdateGeometry();480481/// @brief check if update geometry after inserting or removing has to be updated482bool isUpdateGeometryEnabled() const;483484/// @}485486/// @name Functions related to Enable or disable update data of elements after insertion487/// @{488/// @brief enable update data elements after inserting or removing an element in net489void enableUpdateData();490491/// @brief disable update data elements after inserting or removing an element in net492void disableUpdateData();493494/// @brief check if update data after inserting or removing has to be updated495bool isUpdateDataEnabled() const;496497/// @}498499/// @name get junction id counter500unsigned int& getJunctionIDCounter();501502/// @name get edge id counter503unsigned int& getEdgeIDCounter();504505/// @brief variable used for write headers in additional, demand and data elements506static const std::map<SumoXMLAttr, std::string> EMPTY_HEADER;507508protected:509/// @brief the rtree which contains all GUIGlObjects (so named for historical reasons)510SUMORTree myGrid;511512/// @brief The internal netbuilder513NBNetBuilder* myNetBuilder;514515/// @brief The net to be notified of about changes516GNEViewNet* myViewNet = nullptr;517518/// @brief pointer to tagProperties database519const GNETagPropertiesDatabase* myTagPropertiesDatabase = nullptr;520521/// @brief attributeCarriers module522GNENetHelper::AttributeCarriers* myAttributeCarriers = nullptr;523524/// @brief attributeCarriers templates525GNENetHelper::ACTemplate* myACTemplates = nullptr;526527/// @brief saving files handler module528GNENetHelper::SavingFilesHandler* mySavingFilesHandler = nullptr;529530/// @brief saving status module531GNENetHelper::SavingStatus* mySavingStatus = nullptr;532533/// @brief Network path manager534GNEPathManager* myNetworkPathManager = nullptr;535536/// @brief Demand path manager537GNEPathManager* myDemandPathManager = nullptr;538539/// @brief Data path manager540GNEPathManager* myDataPathManager = nullptr;541542/// @name counters for junction/edge IDs543// @{544unsigned int myJunctionIDCounter = 0;545unsigned int myEdgeIDCounter = 0;546// @}547548/// @brief list of edge ids for which turn-arounds must be added explicitly549std::set<std::string> myExplicitTurnarounds;550551/// @brief whether the net needs recomputation552bool myNeedRecompute = true;553554/// @brief Flag to enable or disable update geometry of elements after inserting or removing element in net555bool myUpdateGeometryEnabled = true;556557/// @brief Flag to enable or disable update data elements after inserting or removing element in net558bool myUpdateDataEnabled = true;559560private:561/// @brief Init Junctions and edges562void initJunctionsAndEdges();563564/// @brief return true if there are already a Junction in the given position, false in other case565bool checkJunctionPosition(const Position& pos);566567/// @brief save additionals after confirming invalid objects568void saveAdditionalsConfirmed();569570/// @brief save demand elements after confirming invalid objects571void saveDemandElementsConfirmed();572573/// @brief save data elements after confirming invalid objects574void saveDataElementsConfirmed();575576/// @brief save meanDatas577void saveMeanDatasConfirmed();578579/// @brief write additional element by type and sorted by ID580void writeAdditionalByType(OutputDevice& device, const std::unordered_set<const GNEAttributeCarrier*>& ACs,581const std::vector<SumoXMLTag> tags) const;582583/// @brief write demand element by type and sorted by ID584void writeDemandByType(OutputDevice& device, const std::unordered_set<const GNEAttributeCarrier*>& ACs, SumoXMLTag tag) const;585586/// @brief write route distributions sorted by ID587void writeRouteDistributions(OutputDevice& device, const std::unordered_set<const GNEAttributeCarrier*>& ACs) const;588589/// @brief write route sorted by ID590void writeRoutes(OutputDevice& device, const std::unordered_set<const GNEAttributeCarrier*>& ACs, const bool additionalFile) const;591592/// @brief write vTypeDistributions sorted by ID593void writeVTypeDistributions(OutputDevice& device, const std::unordered_set<const GNEAttributeCarrier*>& ACs) const;594595/// @brief write vTypes sorted by ID596void writeVTypes(OutputDevice& device, const std::unordered_set<const GNEAttributeCarrier*>& ACs, const bool additionalFile) const;597598/// @brief write meanData element by type and sorted by ID599void writeMeanDatas(OutputDevice& device, const std::unordered_set<const GNEAttributeCarrier*>& ACs, SumoXMLTag tag) const;600601/// @brief write vType comment602bool writeVTypeComment(OutputDevice& device, const std::unordered_set<const GNEAttributeCarrier*>& ACs, const bool additionalFile) const;603604/// @brief write route comment605bool writeRouteComment(OutputDevice& device, const std::unordered_set<const GNEAttributeCarrier*>& ACs, const bool additionalFile) const;606607/// @brief write routeProbe comment608bool writeRouteProbeComment(OutputDevice& device, const std::unordered_set<const GNEAttributeCarrier*>& ACs) const;609610/// @brief write calibrator comment611bool writeCalibratorComment(OutputDevice& device, const std::unordered_set<const GNEAttributeCarrier*>& ACs) const;612613/// @brief write stoppingPlace comment614bool writeStoppingPlaceComment(OutputDevice& device, const std::unordered_set<const GNEAttributeCarrier*>& ACs) const;615616/// @brief write detector comment617bool writeDetectorComment(OutputDevice& device, const std::unordered_set<const GNEAttributeCarrier*>& ACs) const;618619/// @brief write other additional comment620bool writeOtherAdditionalsComment(OutputDevice& device, const std::unordered_set<const GNEAttributeCarrier*>& ACs) const;621622/// @brief write shape comment623bool writeShapesComment(OutputDevice& device, const std::unordered_set<const GNEAttributeCarrier*>& ACs) const;624625/// @brief write JuPedSim comment626bool writeJuPedSimComment(OutputDevice& device, const std::unordered_set<const GNEAttributeCarrier*>& ACs) const;627628/// @brief write TAZ comment629bool writeTAZComment(OutputDevice& device, const std::unordered_set<const GNEAttributeCarrier*>& ACs) const;630631/// @brief write Wire comment632bool writeWireComment(OutputDevice& device, const std::unordered_set<const GNEAttributeCarrier*>& ACs) const;633634/// @brief write meanDataEdge comment635bool writeMeanDataEdgeComment(OutputDevice& device) const;636637/// @brief write Wire comment638bool writeMeanDataLaneComment(OutputDevice& device) const;639640/// @brief replace in list attribute641static void replaceInListAttribute(GNEAttributeCarrier* ac, SumoXMLAttr key, const std::string& which, const std::string& by, GNEUndoList* undoList);642643/// @brief the z boundary (stored in the x-coordinate), values of 0 are ignored644Boundary myZBoundary;645646/// @brief map with the Edges and their number of lanes647std::map<std::string, int> myEdgesAndNumberOfLanes;648649/// @brief marker for whether the z-boundary is initialized650static const double Z_INITIALIZED;651652/// @brief Invalidated default constructor.653GNENet() = delete;654655/// @brief Invalidated copy constructor.656GNENet(const GNENet&) = delete;657658/// @brief Invalidated assignment operator.659GNENet& operator=(const GNENet&) = delete;660};661662663