Eclipse SUMO - Simulation of Urban MObility
GNEChange_Lane.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3// Copyright (C) 2001-2022 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
24#include "GNEChange_Lane.h"
25
26
27// ===========================================================================
28// FOX-declarations
29// ===========================================================================
30FXIMPLEMENT_ABSTRACT(GNEChange_Lane, GNEChange, nullptr, 0)
31
32
33// ===========================================================================
34// member method definitions
35// ===========================================================================
36
37GNEChange_Lane::GNEChange_Lane(GNEEdge* edge, const NBEdge::Lane& laneAttrs):
38 GNEChange(Supermode::NETWORK, true, false),
39 myEdge(edge),
40 myLane(nullptr),
41 myLaneAttrs(laneAttrs),
42 myRecomputeConnections(true) {
43 myEdge->incRef("GNEChange_Lane");
44}
45
46
47GNEChange_Lane::GNEChange_Lane(GNEEdge* edge, GNELane* lane, const NBEdge::Lane& laneAttrs, bool forward, bool recomputeConnections):
48 GNEChange(Supermode::NETWORK, lane, forward, lane->isAttributeCarrierSelected()),
49 myEdge(edge),
50 myLane(lane),
51 myLaneAttrs(laneAttrs),
52 myRecomputeConnections(recomputeConnections) {
53 // include both references (To edge and lane)
54 myEdge->incRef("GNEChange_Lane");
55 myLane->incRef("GNEChange_Lane");
56}
57
58
60 assert(myEdge);
61 myEdge->decRef("GNEChange_Lane");
62 if (myEdge->unreferenced()) {
63 // show extra information for tests
64 WRITE_DEBUG("Deleting unreferenced " + myEdge->getTagStr() + " '" + myEdge->getID() + "' in GNEChange_Lane");
65 delete myEdge;
66 }
67 if (myLane) {
68 myLane->decRef("GNEChange_Lane");
69 if (myLane->unreferenced()) {
70 // show extra information for tests
71 WRITE_DEBUG("Deleting unreferenced " + myLane->getTagStr() + " '" + myLane->getID() + "' in GNEChange_Lane");
72 // delete lane
73 delete myLane;
74 }
75 }
76}
77
78
79void
81 if (myForward) {
82 // show extra information for tests
83 if (myLane != nullptr) {
84 WRITE_DEBUG("Removing " + myLane->getTagStr() + " '" + myLane->getID() + "' from " + toString(SUMO_TAG_EDGE));
85 // unselect if mySelectedElement is enabled
88 }
89 // restore container
91 } else {
92 WRITE_DEBUG("Removing nullptr " + toString(SUMO_TAG_LANE) + " from " + toString(SUMO_TAG_EDGE));
93 }
94 // remove lane from edge (note: myLane can be nullptr)
95 myEdge->removeLane(myLane, false);
96 } else {
97 // show extra information for tests
98 if (myLane != nullptr) {
99 WRITE_DEBUG("Adding " + myLane->getTagStr() + " '" + myLane->getID() + "' into " + toString(SUMO_TAG_EDGE));
100 // select if mySelectedElement is enabled
101 if (mySelectedElement) {
103 }
104 // restore container
106 } else {
107 WRITE_DEBUG("Adding nullptr " + toString(SUMO_TAG_LANE) + " into " + toString(SUMO_TAG_EDGE));
108 }
109 // add lane and their attributes to edge (lane removal is reverted, no need to recompute connections)
111 }
112 // enable save networkElements
113 myEdge->getNet()->requireSaveNet(true);
114}
115
116
117void
119 if (myForward) {
120 // show extra information for tests
121 if (myLane != nullptr) {
122 WRITE_DEBUG("Adding " + myLane->getTagStr() + " '" + myLane->getID() + "' into " + toString(SUMO_TAG_EDGE));
123 // select if mySelectedElement is enabled
124 if (mySelectedElement) {
126 }
127 // add lane into parents and children
129 } else {
130 WRITE_DEBUG("Adding nullptr " + toString(SUMO_TAG_LANE) + " into " + toString(SUMO_TAG_EDGE));
131 }
132 // add lane and their attributes to edge
134 } else {
135 // show extra information for tests
136 if (myLane != nullptr) {
137 WRITE_DEBUG("Removing " + myLane->getTagStr() + " '" + myLane->getID() + "' from " + toString(SUMO_TAG_EDGE));
138 // unselect if mySelectedElement is enabled
139 if (mySelectedElement) {
141 }
142 // remove lane from parents and children
144 } else {
145 WRITE_DEBUG("Removing nullptr " + toString(SUMO_TAG_LANE) + " from " + toString(SUMO_TAG_EDGE));
146 }
147 // remove lane from edge
149 }
150 // enable save networkElements
151 myEdge->getNet()->requireSaveNet(true);
152}
153
154
155std::string
157 if (myForward) {
158 return ("Undo create " + toString(SUMO_TAG_LANE) + " '" + myLane->getID() + "'");
159 } else {
160 return ("Undo delete " + toString(SUMO_TAG_LANE) + " '" + myLane->getID() + "'");
161 }
162}
163
164
165std::string
167 if (myForward) {
168 return ("Redo create " + toString(SUMO_TAG_LANE) + " '" + myLane->getID() + "'");
169 } else {
170 return ("Redo delete " + toString(SUMO_TAG_LANE) + " '" + myLane->getID() + "'");
171 }
172}
Supermode
@brie enum for supermodes
@ NETWORK
Network mode (Edges, junctions, etc..)
#define WRITE_DEBUG(msg)
Definition: MsgHandler.h:276
@ 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)
const std::string & getTagStr() const
get tag assigned to this object in string format
void unselectAttributeCarrier(const bool changeFlag=true)
unselect attribute carrier using GUIGlobalSelection
GNENet * getNet() const
get pointer to net
void selectAttributeCarrier(const bool changeFlag=true)
select attribute carrier using GUIGlobalSelection
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:60
bool myForward
we group antagonistic commands (create junction/delete junction) and keep them apart by this flag
Definition: GNEChange.h:216
const bool mySelectedElement
flag for check if element is selected
Definition: GNEChange.h:219
void addElementInParentsAndChildren(T *element)
add given element into parents and children (only use in redo() function)
Definition: GNEChange.h:128
void removeElementFromParentsAndChildren(T *element)
remove given element from parents and children (only use in redo() function)
Definition: GNEChange.h:171
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:1946
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:1893
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
Definition: GNELane.h:46
void requireSaveNet(bool value)
inform that net has to be saved
Definition: GNENet.cpp:1179
void decRef(const std::string &debugMsg="")
Decrease reference.
void incRef(const std::string &debugMsg="")
Increase reference.
bool unreferenced()
check if object ins't referenced
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