Path: blob/main/src/netedit/changes/GNEChange_Crossing.cpp
169678 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 GNEChange_Crossing.cpp14/// @author Pablo Alvarez Lopez15/// @date Oct 201616///17// A network change in which a single junction is created or deleted18/****************************************************************************/1920#include <netedit/GNENet.h>21#include <netedit/elements/network/GNECrossing.h>22#include <netbuild/NBNetBuilder.h>2324#include "GNEChange_Crossing.h"2526// ===========================================================================27// FOX-declarations28// ===========================================================================2930FXIMPLEMENT_ABSTRACT(GNEChange_Crossing, GNEChange, nullptr, 0)3132// ===========================================================================33// member method definitions34// ===========================================================================353637GNEChange_Crossing::GNEChange_Crossing(GNEJunction* junctionParent, const std::vector<NBEdge*>& edges,38double width, bool priority, int customTLIndex, int customTLIndex2, const PositionVector& customShape, bool selected, bool forward):39GNEChange(Supermode::NETWORK, junctionParent, forward, selected),40myJunctionParent(junctionParent),41myEdges(edges),42myWidth(width),43myPriority(priority),44myCustomTLIndex(customTLIndex),45myCustomTLIndex2(customTLIndex2),46myCustomShape(customShape) {47}484950GNEChange_Crossing::GNEChange_Crossing(GNEJunction* junctionParent, const NBNode::Crossing& crossing, bool forward):51GNEChange(Supermode::NETWORK, forward, false),52myJunctionParent(junctionParent),53myEdges(crossing.edges),54myWidth(crossing.width),55myPriority(crossing.priority),56myCustomTLIndex(crossing.customTLIndex),57myCustomTLIndex2(crossing.customTLIndex2),58myCustomShape(crossing.customShape) {59}606162GNEChange_Crossing::~GNEChange_Crossing() {63}646566void GNEChange_Crossing::undo() {67if (myForward) {68// unselect if mySelectedElement is enabled69if (mySelectedElement) {70GNECrossing* crossing = myJunctionParent->retrieveGNECrossing(myJunctionParent->getNBNode()->getCrossing(myEdges), false);71if (crossing) {72crossing->unselectAttributeCarrier();73} else {74#ifdef _DEBUG75WRITE_WARNINGF("Unable to deselect crossing at junction '%' after undo", myJunctionParent->getID());76#endif77}78}79// remove crossing of NBNode80myJunctionParent->getNBNode()->removeCrossing(myEdges);81// rebuild GNECrossings82myJunctionParent->rebuildGNECrossings();83// clean walking areas84myJunctionParent->clearWalkingAreas();85// Check if Flag "haveNetworkCrossings" has to be disabled86if (myJunctionParent->getNet()->getAttributeCarriers()->getCrossings().empty() && (myJunctionParent->getNet()->getNetBuilder()->haveNetworkCrossings())) {87// change flag of NetBuilder (For build GNECrossing)88myJunctionParent->getNet()->getNetBuilder()->setHaveNetworkCrossings(false);89}90} else {91// add crossing of NBNode92NBNode::Crossing* c = myJunctionParent->getNBNode()->addCrossing(myEdges, myWidth, myPriority, myCustomTLIndex, myCustomTLIndex2, myCustomShape);93// Check if Flag "haveNetworkCrossings" has to be enabled94if (!myJunctionParent->getNet()->getNetBuilder()->haveNetworkCrossings() == false) {95myJunctionParent->getNet()->getNetBuilder()->setHaveNetworkCrossings(true);96}97// rebuild GNECrossings98myJunctionParent->rebuildGNECrossings();99// clean walking areas100myJunctionParent->clearWalkingAreas();101// select if mySelectedElement is enabled102if (mySelectedElement) {103if (mySelectedElement) {104GNECrossing* crossing = myJunctionParent->retrieveGNECrossing(c, false);105if (crossing) {106crossing->selectAttributeCarrier();107} else {108#ifdef _DEBUG109WRITE_WARNINGF("Unable to select crossing at junction '%' after undo", myJunctionParent->getID());110#endif111}112}113}114}115// enable save networkElements116myJunctionParent->getNet()->getSavingStatus()->requireSaveNetwork();117}118119120void GNEChange_Crossing::redo() {121if (myForward) {122// add crossing of NBNode and update geometry123NBNode::Crossing* c = myJunctionParent->getNBNode()->addCrossing(myEdges, myWidth, myPriority, myCustomTLIndex, myCustomTLIndex2, myCustomShape);124// Check if Flag "haveNetworkCrossings" has to be enabled125if (myJunctionParent->getNet()->getNetBuilder()->haveNetworkCrossings() == false) {126myJunctionParent->getNet()->getNetBuilder()->setHaveNetworkCrossings(true);127}128// rebuild GNECrossings129myJunctionParent->rebuildGNECrossings();130// clean walking areas131myJunctionParent->clearWalkingAreas();132// select if mySelectedElement is enabled133if (mySelectedElement) {134if (mySelectedElement) {135GNECrossing* crossing = myJunctionParent->retrieveGNECrossing(c, false);136if (crossing) {137crossing->selectAttributeCarrier();138} else {139#ifdef _DEBUG140WRITE_WARNINGF("Unable to select crossing at junction '%' after undo", myJunctionParent->getID());141#endif142}143}144}145} else {146// unselect if mySelectedElement is enabled147if (mySelectedElement) {148GNECrossing* crossing = myJunctionParent->retrieveGNECrossing(myJunctionParent->getNBNode()->getCrossing(myEdges), false);149if (crossing) {150crossing->unselectAttributeCarrier();151} else {152#ifdef _DEBUG153WRITE_WARNINGF("Unable to deselect crossing at junction '%' after undo", myJunctionParent->getID());154#endif155}156}157// remove crossing of NBNode and update geometry158myJunctionParent->getNBNode()->removeCrossing(myEdges);159// rebuild GNECrossings160myJunctionParent->rebuildGNECrossings();161// clean walking areas162myJunctionParent->clearWalkingAreas();163// Check if Flag "haveNetworkCrossings" has to be disabled164if (myJunctionParent->getNet()->getAttributeCarriers()->getCrossings().empty() && (myJunctionParent->getNet()->getNetBuilder()->haveNetworkCrossings())) {165// change flag of NetBuilder (For build GNECrossing)166myJunctionParent->getNet()->getNetBuilder()->setHaveNetworkCrossings(false);167}168}169// enable save networkElements170myJunctionParent->getNet()->getSavingStatus()->requireSaveNetwork();171}172173174std::string175GNEChange_Crossing::undoName() const {176if (myForward) {177return TL("Undo create crossing");178} else {179return TL("Undo delete crossing");180}181}182183184std::string185GNEChange_Crossing::redoName() const {186if (myForward) {187return TL("Redo create crossing");188} else {189return TL("Redo delete crossing");190}191}192193194