Path: blob/main/src/netedit/elements/network/GNEJunction.h
185790 views
/****************************************************************************/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 GNEJunction.h14/// @author Jakob Erdmann15/// @date Feb 201116///17// A class for visualizing and editing junctions in netedit (adapted from18// GUIJunctionWrapper)19/****************************************************************************/20#pragma once21#include <config.h>2223#include <netbuild/NBNode.h>24#include <netedit/elements/GNECandidateElement.h>25#include <netedit/elements/moving/GNEMoveResult.h>26#include <utils/gui/globjects/GUIPolygon.h>2728#include "GNENetworkElement.h"2930// ===========================================================================31// class declarations32// ===========================================================================3334class GNEConnection;35class GNECrossing;36class GNEEdge;37class GNEInternalLane;38class GNEMoveElementJunction;39class GNEMoveOperation;40class GNENet;41class GNEWalkingArea;42class NBTrafficLightDefinition;4344// ===========================================================================45// class definitions46// ===========================================================================4748class GNEJunction : public GNENetworkElement, public GNECandidateElement {4950/// @brief Declare friend class51friend class GNEChange_TLS;52friend class GNEChange_Crossing;53friend class GNEMoveElementJunction;5455public:56/**@brief Constructor57* @param[in] net The net to inform about gui updates58* @param[in] nbn The represented node59* @param[in] loaded Whether the junction was loaded from a file60*/61GNEJunction(GNENet* net, NBNode* nbn, bool loaded = false);6263/// @brief Destructor64~GNEJunction();6566/// @brief methods to retrieve the elements linked to this junction67/// @{6869/// @brief get GNEMoveElement associated with this junction70GNEMoveElement* getMoveElement() const override;7172/// @brief get parameters associated with this junction73Parameterised* getParameters() override;7475/// @brief get parameters associated with this junction (constant)76const Parameterised* getParameters() const override;7778/// @}7980/// @name Functions related with geometry of element81/// @{82/// @brief get junction shape83const PositionVector& getJunctionShape() const;8485/// @brief update pre-computed geometry information (including crossings)86void updateGeometry() override;8788/// @brief update pre-computed geometry information without modifying netbuild structures89// @note: using an extra function because updateGeometry overrides an abstract virtual function90void updateGeometryAfterNetbuild(bool rebuildNBNodeCrossings = false);9192/// @brief Returns position of hierarchical element in view93Position getPositionInView() const;9495/// @}9697/// @name Function related with contour drawing98/// @{99100/// @brief check if draw from contour (green)101bool checkDrawFromContour() const override;102103/// @brief check if draw from contour (magenta)104bool checkDrawToContour() const override;105106/// @brief check if draw related contour (cyan)107bool checkDrawRelatedContour() const override;108109/// @brief check if draw over contour (orange)110bool checkDrawOverContour() const override;111112/// @brief check if draw delete contour (pink/white)113bool checkDrawDeleteContour() const override;114115/// @brief check if draw delete contour small (pink/white)116bool checkDrawDeleteContourSmall() const override;117118/// @brief check if draw select contour (blue)119bool checkDrawSelectContour() const override;120121/// @brief check if draw move contour (red)122bool checkDrawMoveContour() const override;123124/// @}125126/// @name inherited from GUIGlObject127/// @{128/**@brief Returns an own popup-menu129*130* @param[in] app The application needed to build the popup-menu131* @param[in] parent The parent window needed to build the popup-menu132* @return The built popup-menu133* @see GUIGlObject::getPopUpMenu134*/135GUIGLObjectPopupMenu* getPopUpMenu(GUIMainWindow& app, GUISUMOAbstractView& parent) override;136137/// @brief return exaggeration associated with this GLObject138double getExaggeration(const GUIVisualizationSettings& s) const override;139140/// @brief Returns the boundary to which the view shall be centered in order to show the object141Boundary getCenteringBoundary() const override;142143/// @brief update centering boundary (implies change in RTREE)144void updateCenteringBoundary(const bool updateGrid);145146/**@brief Draws the object147* @param[in] s The settings for the current view (may influence drawing)148* @see GUIGlObject::drawGL149*/150void drawGL(const GUIVisualizationSettings& s) const override;151152/// @brief delete element153void deleteGLObject() override;154155/// @brief update GLObject (geometry, ID, etc.)156void updateGLObject() override;157/// @}158159/// @brief Return net build node160NBNode* getNBNode() const;161162/// @brief return GNEJunction neighbours163std::vector<GNEJunction*> getJunctionNeighbours() const;164165/// @brief add incoming GNEEdge166void addIncomingGNEEdge(GNEEdge* edge);167168/// @brief add outgoing GNEEdge169void addOutgoingGNEEdge(GNEEdge* edge);170171/// @brief remove incoming GNEEdge172void removeIncomingGNEEdge(GNEEdge* edge);173174/// @brief remove outgoing GNEEdge175void removeOutgoingGNEEdge(GNEEdge* edge);176177/// @brief Returns incoming GNEEdges178const std::vector<GNEEdge*>& getGNEIncomingEdges() const;179180/// @brief Returns incoming GNEEdges181const std::vector<GNEEdge*>& getGNEOutgoingEdges() const;182183/// @brief Returns GNECrossings184const std::vector<GNECrossing*>& getGNECrossings() const;185186/// @brief Returns GNEWalkingAreas187const std::vector<GNEWalkingArea*>& getGNEWalkingAreas() const;188189/// @brief Returns all GNEConnections vinculated with this junction190std::vector<GNEConnection*> getGNEConnections() const;191192/// @brief marks as first junction in createEdge-mode193void markAsCreateEdgeSource();194195/// @brief removes mark as first junction in createEdge-mode196void unMarkAsCreateEdgeSource();197198/// @brief notify the junction of being selected in tls-mode. (used to control drawing)199void selectTLS(bool selected);200201/// @name inherited from GNEAttributeCarrier202/// @{203/* @brief method for getting the Attribute of an XML key204* @param[in] key The attribute key205* @return string with the value associated to key206*/207std::string getAttribute(SumoXMLAttr key) const override;208209/* @brief method for getting the Attribute of an XML key in double format210* @param[in] key The attribute key211* @return double with the value associated to key212*/213double getAttributeDouble(SumoXMLAttr key) const override;214215/* @brief method for getting the Attribute of an XML key in position format216* @param[in] key The attribute key217* @return position with the value associated to key218*/219Position getAttributePosition(SumoXMLAttr key) const override;220221/* @brief method for getting the Attribute of an XML key in Position format222* @param[in] key The attribute key223* @return position with the value associated to key224*/225PositionVector getAttributePositionVector(SumoXMLAttr key) const override;226227/* @brief method for setting the attribute and letting the object perform additional changes228* @param[in] key The attribute key229* @param[in] value The new value230* @param[in] undoList The undoList on which to register changes231*/232void setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) override;233234/* @brief method for checking if the key and their correspond attribute are valids235* @param[in] key The attribute key236* @param[in] value The value associated to key key237* @return true if the value is valid, false in other case238*/239bool isValid(SumoXMLAttr key, const std::string& value) override;240241/* @brief method for check if the value for certain attribute is set242* @param[in] key The attribute key243*/244bool isAttributeEnabled(SumoXMLAttr key) const override;245246/* @brief method for check if the value for certain attribute is computed (for example, due a network recomputing)247* @param[in] key The attribute key248*/249bool isAttributeComputed(SumoXMLAttr key) const override;250251/// @}252253/// @brief set responsibility for deleting internal structures254void setResponsible(bool newVal);255256/* @brief notify junction that one of its edges has changed its shape, and257* therefore the junction shape is no longer valid */258void invalidateShape();259260/* @brief update validity of this junctions logic261* if the logic is invalidated, existing connections are removed via undo-list262* so that the previous state can be restored263* also calls invalidateTLS264* @param[in] valid The new validity of the junction265* @note: this should always be called with an active command group266*/267void setLogicValid(bool valid, GNEUndoList* undoList, const std::string& status = FEATURE_GUESSED);268269/// @brief remove all connections from the given edge270void removeConnectionsFrom(GNEEdge* edge, GNEUndoList* undoList, bool updateTLS, int lane = -1);271272/// @brief remove all connections to the given edge273void removeConnectionsTo(GNEEdge* edge, GNEUndoList* undoList, bool updateTLS, int lane = -1);274275/// @brief prevent re-guessing connections at this junction276void markAsModified(GNEUndoList* undoList);277278/* @brief invalidates loaded or edited TLS279* @param[in] deletedConnection If a valid connection is given a replacement def with this connection removed280* but all other information intact will be computed instead of guessing a new tlDef281* @note: this should always be called with an active command group282*/283void invalidateTLS(GNEUndoList* undoList,284const NBConnection& deletedConnection = NBConnection::InvalidConnection,285const NBConnection& addedConnection = NBConnection::InvalidConnection);286287/// @brief replace one edge by another in all tls connections288void replaceIncomingConnections(GNEEdge* which, GNEEdge* by, GNEUndoList* undoList);289290/// @brief removes the given edge from all pedestrian crossings291void removeEdgeFromCrossings(GNEEdge* edge, GNEUndoList* undoList);292293/// @brief whether this junction has a valid logic294bool isLogicValid();295296/// @brief get GNECrossing if exist, and if not create it if create is enabled297GNECrossing* retrieveGNECrossing(NBNode::Crossing* NBNodeCrossing, bool createIfNoExist = true);298299/// @brief get GNEWalkingArea if exist, and if not create it if create is enabled300GNEWalkingArea* retrieveGNEWalkingArea(const std::string& NBNodeWalkingAreaID, bool createIfNoExist = true);301302/// @brief mark connections as deprecated303void markConnectionsDeprecated(bool includingNeighbours);304305/// @brief set junction Type (using undo/redo)306void setJunctionType(const std::string& value, GNEUndoList* undoList);307308/// @brief clear walking areas309void clearWalkingAreas();310311/// @brief rebuilds WalkingAreas objects for this junction312void rebuildGNEWalkingAreas();313314/// @brief add internal lane315void addInternalLane(const GNEInternalLane* internalLane);316317/// @brief remove internal lane318void removeInternalLane(const GNEInternalLane* internalLane);319320protected:321/// @brief move element junction322GNEMoveElementJunction* myMoveElementJunction = nullptr;323324/// @brief A reference to the represented junction325NBNode* myNBNode;326327/// @brief edge boundary328Boundary myJunctionBoundary;329330/// @brief drawing toggle (used to avoid double draws)331int* myDrawingToggle;332333/// @brief variable used for draw circle contours334GNEContour myCircleContour;335336/// @brief vector with the (child) incomings GNEEdges vinculated with this junction337std::vector<GNEEdge*> myGNEIncomingEdges;338339/// @brief vector with the (child) outgoings GNEEdges vinculated with this junction340std::vector<GNEEdge*> myGNEOutgoingEdges;341342/// @brief the built crossing objects343std::vector<GNECrossing*> myGNECrossings;344345/// @brief the built walkingArea objects346std::vector<GNEWalkingArea*> myGNEWalkingAreas;347348/// @brief internal lanes related placed in this junction349std::vector<const GNEInternalLane*> myInternalLanes;350351/// @brief whether this junction is the first junction for a newly creatededge352/// @see GNEApplicationWindow::createEdgeSource)353bool myAmCreateEdgeSource = false;354355/// @brief modification status of the junction logic (all connections across this junction)356std::string myLogicStatus;357358/// @brief whether we are responsible for deleting myNBNode359bool myAmResponsible = false;360361/// @brief whether this junctions logic is valid362bool myHasValidLogic;363364/// @brief whether this junction is selected in tls-mode365bool myAmTLSSelected = false;366367/// @brief whether this junction probably should have some connections but doesn't368bool myColorForMissingConnections = false;369370/// @brief An object that stores the shape and its tesselation371mutable TesselatedPolygon myTesselation;372373/// @brief exaggeration used in tesselation374mutable double myExaggeration = 1;375376private:377/// @brief check if draw junction as bubble378bool drawAsBubble(const GUIVisualizationSettings& s, const double junctionShapeArea) const;379380/// @brief draw junction as bubble381void drawJunctionAsBubble(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d,382const double exaggeration) const;383384/// @brief draw junction as bubble385void drawJunctionAsShape(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d,386const double exaggeration) const;387388/// @brief draw junction center (only in move mode)389void drawJunctionCenter(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d) const;390391/// @brief draw TLS icon392void drawTLSIcon(const GUIVisualizationSettings& s) const;393394/// @brief draw elevation395void drawElevation(const GUIVisualizationSettings& s) const;396397/// @brief draw junction name398void drawJunctionName(const GUIVisualizationSettings& s) const;399400/// @brief draw junction childs401void drawJunctionChildren(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d) const;402403/// @brief calculate contour404void calculateJunctioncontour(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d,405const double exaggeration, const bool drawBubble) const;406407/// @brief method for setting the attribute and nothing else (used in GNEChange_Attribute)408void setAttribute(SumoXMLAttr key, const std::string& value) override;409410/**@brief reposition the node at pos without updating GRID and informs the edges411* @param[in] pos The new position412* @note: those operations are not added to the undoList.413*/414void moveJunctionGeometry(const Position& pos, const bool updateEdgeBoundaries);415416/// @brief sets junction color depending on circumstances417RGBColor setColor(const GUIVisualizationSettings& s, bool bubble) const;418419/// @brief determines color value420double getColorValue(const GUIVisualizationSettings& s, int activeScheme) const override;421422/// @brief compute whether this junction probably should have some connections but doesn't423void checkMissingConnections();424425/// @brief adds a traffic light426void addTrafficLight(NBTrafficLightDefinition* tlDef, bool forceInsert);427428/// @brief removes a traffic light429void removeTrafficLight(NBTrafficLightDefinition* tlDef);430431/// @brief rebuilds crossing objects for this junction432void rebuildGNECrossings(bool rebuildNBNodeCrossings = true);433434/// @brief remove the given connections from all traffic light definitions of this junction435void removeTLSConnections(std::vector<NBConnection>& connections, GNEUndoList* undoList);436437/// @brief temporarily mirror coordinates in lefthand network to compute correct crossing geometries438void mirrorXLeftHand();439440/// @brief build TLS operations contextual menu441void buildTLSOperations(GUISUMOAbstractView& parent, GUIGLObjectPopupMenu* ret, const int numSelectedJunctions);442443/// @brief Invalidated copy constructor.444GNEJunction(const GNEJunction&) = delete;445446/// @brief Invalidated assignment operator.447GNEJunction& operator=(const GNEJunction&) = delete;448};449450451