Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GNEChange_Lane.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2001-2025 German Aerospace Center (DLR) and others.
4// This program and the accompanying materials are made available under the
5// terms of the Eclipse Public License 2.0 which is available at
6// https://www.eclipse.org/legal/epl-2.0/
7// This Source Code may also be made available under the following Secondary
8// Licenses when the conditions for such availability set forth in the Eclipse
9// Public License 2.0 are satisfied: GNU General Public License, version 2
10// or later which is available at
11// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13/****************************************************************************/
18// A network change in which a single lane is created or deleted
19/****************************************************************************/
20
21#include <netedit/GNENet.h>
22#include <netedit/GNEViewNet.h>
25
26#include "GNEChange_Lane.h"
27
28// ===========================================================================
29// FOX-declarations
30// ===========================================================================
31
32FXIMPLEMENT_ABSTRACT(GNEChange_Lane, GNEChange, nullptr, 0)
33
34// ===========================================================================
35// member method definitions
36// ===========================================================================
37
38GNEChange_Lane::GNEChange_Lane(GNEEdge* edge, const NBEdge::Lane& laneAttrs):
39 GNEChange(Supermode::NETWORK, true, false),
40 myEdge(edge),
41 myLane(nullptr),
42 myLaneAttrs(laneAttrs),
44 myEdge->incRef("GNEChange_Lane");
45}
46
47
48GNEChange_Lane::GNEChange_Lane(GNEEdge* edge, GNELane* lane, const NBEdge::Lane& laneAttrs, bool forward, bool recomputeConnections):
49 GNEChange(Supermode::NETWORK, lane, forward, lane->isAttributeCarrierSelected()),
50 myEdge(edge),
51 myLane(lane),
52 myLaneAttrs(laneAttrs),
53 myRecomputeConnections(recomputeConnections) {
54 // include both references (To edge and lane)
55 myEdge->incRef("GNEChange_Lane");
56 myLane->incRef("GNEChange_Lane");
57}
58
59
61 // only continue we have undo-redo mode enabled
62 if (myEdge->getNet()->getViewNet()->getViewParent()->getGNEAppWindows()->isUndoRedoAllowed()) {
63 myEdge->decRef("GNEChange_Lane");
64 if (myEdge->unreferenced()) {
65 delete myEdge;
66 }
67 if (myLane) {
68 myLane->decRef("GNEChange_Lane");
69 if (myLane->unreferenced()) {
70 // delete lane
71 delete myLane;
72 }
73 }
74 }
75}
76
77
78void
80 if (myForward) {
81 // remove lane from edge (note: myLane can be nullptr)
82 myEdge->removeLane(myLane, false);
83 // special case if lane exist
85 myLane->unselectAttributeCarrier();
86 }
87 } else {
88 // show extra information for tests
90 myLane->selectAttributeCarrier();
91 }
92 // add lane and their attributes to edge (lane removal is reverted, no need to recompute connections)
93 myEdge->addLane(myLane, myLaneAttrs, false);
94 }
95 // enable save networkElements
96 myEdge->getNet()->getSavingStatus()->requireSaveNetwork();
97}
98
99
100void
102 if (myForward) {
103 // show extra information for tests
104 if (myLane && mySelectedElement) {
105 myLane->selectAttributeCarrier();
106 }
107 // add lane and their attributes to edge
109 } else {
110 // special case if lane exist
111 if (myLane && mySelectedElement) {
112 myLane->unselectAttributeCarrier();
113 }
114 // remove lane from edge
116 }
117 // enable save networkElements
118 myEdge->getNet()->getSavingStatus()->requireSaveNetwork();
119}
120
121
122std::string
124 if (myForward) {
125 return (TL("Undo create lane '") + myLane->getID() + "'");
126 } else {
127 return (TL("Undo delete lane '") + myLane->getID() + "'");
128 }
129}
130
131
132std::string
134 if (myForward) {
135 return (TL("Redo create lane '") + myLane->getID() + "'");
136 } else {
137 return (TL("Redo delete lane '") + myLane->getID() + "'");
138 }
139}
Supermode
@brie enum for supermodes
@ NETWORK
Network mode (Edges, junctions, etc..).
#define TL(string)
Definition MsgHandler.h:304
const NBEdge::Lane myLaneAttrs
we need to preserve the attributes explicitly because they are not contained withing GNELane itself
void redo()
redo action
std::string redoName() const
get Redo name
GNEChange_Lane(GNEEdge *edge, const NBEdge::Lane &laneAttrs)
Constructor for creating a lane.
~GNEChange_Lane()
Destructor.
GNELane * myLane
we need to preserve the lane because it maybe the target of GNEChange_Attribute commands
bool myRecomputeConnections
whether to recompute connection when adding a new lane
GNEEdge * myEdge
we need the edge because it is the target of our change commands
void undo()
undo action
std::string undoName() const
return undoName
the function-object for an editing operation (abstract base)
Definition GNEChange.h:56
bool myForward
we group antagonistic commands (create junction/delete junction) and keep them apart by this flag
Definition GNEChange.h:180
const bool mySelectedElement
flag for check if element is selected
Definition GNEChange.h:183
GNEChange(Supermode supermode, bool forward, const bool selectedElement)
Constructor.
Definition GNEChange.cpp:34
C++ TraCI client API implementation.
The representation of a single edge during network building.
Definition NBEdge.h:92
An (internal) definition of a single lane of an edge.
Definition NBEdge.h:143