Eclipse SUMO - Simulation of Urban MObility
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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),
43 myRecomputeConnections(true) {
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
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
86 }
87 } else {
88 // show extra information for tests
91 }
92 // add lane and their attributes to edge (lane removal is reverted, no need to recompute connections)
94 }
95 // enable save networkElements
97}
98
99
100void
102 if (myForward) {
103 // show extra information for tests
104 if (myLane && mySelectedElement) {
106 }
107 // add lane and their attributes to edge
109 } else {
110 // special case if lane exist
111 if (myLane && mySelectedElement) {
113 }
114 // remove lane from edge
116 }
117 // enable save networkElements
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:305
const std::string getID() const
get ID (all Attribute Carriers have one)
void selectAttributeCarrier()
select attribute carrier using GUIGlobalSelection
void unselectAttributeCarrier()
unselect attribute carrier using GUIGlobalSelection
GNENet * getNet() const
get pointer to net
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
A road/street connecting two junctions (netedit-version)
Definition GNEEdge.h:53
void removeLane(GNELane *lane, bool recomputeConnections)
@briefdecrease the number of lanes by one. argument is only used to increase robustness (assertions)
Definition GNEEdge.cpp:2216
void addLane(GNELane *lane, const NBEdge::Lane &laneAttrs, bool recomputeConnections)
increase number of lanes by one use the given attributes and restore the GNELane
Definition GNEEdge.cpp:2156
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
Definition GNELane.h:46
void requireSaveNetwork()
inform that network has to be saved
GNENetHelper::SavingStatus * getSavingStatus() const
get saving status
Definition GNENet.cpp:164
GNEViewNet * getViewNet() const
get view net
Definition GNENet.cpp:2194
void decRef(const std::string &debugMsg="")
Decrease reference.
void incRef(const std::string &debugMsg="")
Increase reference.
bool unreferenced()
check if object ins't referenced
GNEViewParent * getViewParent() const
get the net object
GNEApplicationWindow * getGNEAppWindows() const
get GNE Application Windows
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