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-2024 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#include <config.h>
21
22#include <netedit/GNENet.h>
23#include <netedit/GNEViewNet.h>
26
27#include "GNEChange_Lane.h"
28
29
30// ===========================================================================
31// FOX-declarations
32// ===========================================================================
33FXIMPLEMENT_ABSTRACT(GNEChange_Lane, GNEChange, nullptr, 0)
34
35
36// ===========================================================================
37// member method definitions
38// ===========================================================================
39
40GNEChange_Lane::GNEChange_Lane(GNEEdge* edge, const NBEdge::Lane& laneAttrs):
41 GNEChange(Supermode::NETWORK, true, false),
42 myEdge(edge),
43 myLane(nullptr),
44 myLaneAttrs(laneAttrs),
45 myRecomputeConnections(true) {
46 myEdge->incRef("GNEChange_Lane");
47}
48
49
50GNEChange_Lane::GNEChange_Lane(GNEEdge* edge, GNELane* lane, const NBEdge::Lane& laneAttrs, bool forward, bool recomputeConnections):
51 GNEChange(Supermode::NETWORK, lane, forward, lane->isAttributeCarrierSelected()),
52 myEdge(edge),
53 myLane(lane),
54 myLaneAttrs(laneAttrs),
55 myRecomputeConnections(recomputeConnections) {
56 // include both references (To edge and lane)
57 myEdge->incRef("GNEChange_Lane");
58 myLane->incRef("GNEChange_Lane");
59}
60
61
63 // only continue we have undo-redo mode enabled
65 myEdge->decRef("GNEChange_Lane");
66 if (myEdge->unreferenced()) {
67 // show extra information for tests
68 WRITE_DEBUG("Deleting unreferenced " + myEdge->getTagStr() + " '" + myEdge->getID() + "' in GNEChange_Lane");
69 delete myEdge;
70 }
71 if (myLane) {
72 myLane->decRef("GNEChange_Lane");
73 if (myLane->unreferenced()) {
74 // show extra information for tests
75 WRITE_DEBUG("Deleting unreferenced " + myLane->getTagStr() + " '" + myLane->getID() + "' in GNEChange_Lane");
76 // delete lane
77 delete myLane;
78 }
79 }
80 }
81}
82
83
84void
86 if (myForward) {
87 // show extra information for tests
88 if (myLane != nullptr) {
89 WRITE_DEBUG("Removing " + myLane->getTagStr() + " '" + myLane->getID() + "' from " + toString(SUMO_TAG_EDGE));
90 // unselect if mySelectedElement is enabled
93 }
94 // restore container
96 } else {
97 WRITE_DEBUG("Removing nullptr " + toString(SUMO_TAG_LANE) + " from " + toString(SUMO_TAG_EDGE));
98 }
99 // remove lane from edge (note: myLane can be nullptr)
100 myEdge->removeLane(myLane, false);
101 } else {
102 // show extra information for tests
103 if (myLane != nullptr) {
104 WRITE_DEBUG("Adding " + myLane->getTagStr() + " '" + myLane->getID() + "' into " + toString(SUMO_TAG_EDGE));
105 // select if mySelectedElement is enabled
106 if (mySelectedElement) {
108 }
109 // restore container
111 } else {
112 WRITE_DEBUG("Adding nullptr " + toString(SUMO_TAG_LANE) + " into " + toString(SUMO_TAG_EDGE));
113 }
114 // add lane and their attributes to edge (lane removal is reverted, no need to recompute connections)
116 }
117 // enable save networkElements
119}
120
121
122void
124 if (myForward) {
125 // show extra information for tests
126 if (myLane != nullptr) {
127 WRITE_DEBUG("Adding " + myLane->getTagStr() + " '" + myLane->getID() + "' into " + toString(SUMO_TAG_EDGE));
128 // select if mySelectedElement is enabled
129 if (mySelectedElement) {
131 }
132 // add lane into parents and children
134 } else {
135 WRITE_DEBUG("Adding nullptr " + toString(SUMO_TAG_LANE) + " into " + toString(SUMO_TAG_EDGE));
136 }
137 // add lane and their attributes to edge
139 } else {
140 // show extra information for tests
141 if (myLane != nullptr) {
142 WRITE_DEBUG("Removing " + myLane->getTagStr() + " '" + myLane->getID() + "' from " + toString(SUMO_TAG_EDGE));
143 // unselect if mySelectedElement is enabled
144 if (mySelectedElement) {
146 }
147 // remove lane from parents and children
149 } else {
150 WRITE_DEBUG("Removing nullptr " + toString(SUMO_TAG_LANE) + " from " + toString(SUMO_TAG_EDGE));
151 }
152 // remove lane from edge
154 }
155 // enable save networkElements
157}
158
159
160std::string
162 if (myForward) {
163 return (TL("Undo create lane '") + myLane->getID() + "'");
164 } else {
165 return (TL("Undo delete lane '") + myLane->getID() + "'");
166 }
167}
168
169
170std::string
172 if (myForward) {
173 return (TL("Redo create lane '") + myLane->getID() + "'");
174 } else {
175 return (TL("Redo delete lane '") + myLane->getID() + "'");
176 }
177}
Supermode
@brie enum for supermodes
@ NETWORK
Network mode (Edges, junctions, etc..)
#define WRITE_DEBUG(msg)
Definition MsgHandler.h:306
#define TL(string)
Definition MsgHandler.h:315
@ SUMO_TAG_LANE
begin/end of the description of a single lane
@ SUMO_TAG_EDGE
begin/end of the description of an edge
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:46
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
const std::string & getTagStr() const
get tag assigned to this object in string format
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:212
const bool mySelectedElement
flag for check if element is selected
Definition GNEChange.h:215
void addElementInParentsAndChildren(T *element)
add given element into parents and children (only use in redo() function)
Definition GNEChange.h:124
void removeElementFromParentsAndChildren(T *element)
remove given element from parents and children (only use in redo() function)
Definition GNEChange.h:167
void restoreHierarchicalContainers()
restore container (only use in undo() function)
Definition GNEChange.cpp:94
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:2180
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:2127
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:133
GNEViewNet * getViewNet() const
get view net
Definition GNENet.cpp:2163
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