Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GNEChange_Edge.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 edge is created or deleted
19/****************************************************************************/
20#include <config.h>
21
22#include <netedit/GNENet.h>
23#include <netedit/GNEViewNet.h>
26
27#include "GNEChange_Edge.h"
28
29// ===========================================================================
30// FOX-declarations
31// ===========================================================================
32FXIMPLEMENT_ABSTRACT(GNEChange_Edge, GNEChange, nullptr, 0)
33
34// ===========================================================================
35// member method definitions
36// ===========================================================================
37
38
39
41 GNEChange(Supermode::NETWORK, edge, forward, edge->isAttributeCarrierSelected()),
42 myEdge(edge) {
43 edge->incRef("GNEChange_Edge");
44 // save all hierarchical elements of edge's lane
45 for (const auto& lane : edge->getLanes()) {
46 myLaneParentAdditionals.push_back(lane->getParentAdditionals());
47 myLaneParentDemandElements.push_back(lane->getParentDemandElements());
48 myLaneParentGenericData.push_back(lane->getParentGenericDatas());
49 myChildLaneAdditionals.push_back(lane->getChildAdditionals());
50 myChildLaneDemandElements.push_back(lane->getChildDemandElements());
51 myChildLaneGenericData.push_back(lane->getChildGenericDatas());
52 }
53}
54
55
57 // only continue we have undo-redo mode enabled
59 myEdge->decRef("GNEChange_Edge");
60 if (myEdge->unreferenced()) {
61 // show extra information for tests
62 WRITE_DEBUG("Deleting unreferenced " + myEdge->getTagStr() + " '" + myEdge->getID() + "' GNEChange_Edge");
63 // delete edge
64 delete myEdge;
65 }
66 }
67}
68
69
70void
72 if (myForward) {
73 // show extra information for tests
74 WRITE_DEBUG("Removing " + myEdge->getTagStr() + " '" + myEdge->getID() + "' from " + toString(SUMO_TAG_NET));
75 // unselect if mySelectedElement is enabled
78 }
79 // restore container
81 // remove edge lanes from parents and children
83 // delete edge from net
85 } else {
86 // show extra information for tests
87 WRITE_DEBUG("Adding " + myEdge->getTagStr() + " '" + myEdge->getID() + "' from " + toString(SUMO_TAG_NET));
88 // select if mySelectedElement is enabled
91 }
92 // insert edge into net
94 // restore container
96 // add edge lanes into parents and children
98 }
99 // enable save networkElements
101}
102
103
104void
106 if (myForward) {
107 // show extra information for tests
108 WRITE_DEBUG("Adding " + myEdge->getTagStr() + " '" + myEdge->getID() + "' from " + toString(SUMO_TAG_NET));
109 // select if mySelectedElement is enabled
110 if (mySelectedElement) {
112 }
113 // insert edge into net
115 // add edge into parents and children
117 // add edge lanes into parents and children
118 addEdgeLanes();
119 } else {
120 // show extra information for tests
121 WRITE_DEBUG("Removing " + myEdge->getTagStr() + " '" + myEdge->getID() + "' from " + toString(SUMO_TAG_NET));
122 // unselect if mySelectedElement is enabled
123 if (mySelectedElement) {
125 }
126 // remove edge from parents and children
128 // remove edge lanes from parents and children
130 // delete edge from net
132 }
133 // enable save networkElements
135}
136
137
138std::string
140 if (myForward) {
141 return (TL("Undo create edge '") + myEdge->getID() + "'");
142 } else {
143 return (TL("Undo delete edge '") + myEdge->getID() + "'");
144 }
145}
146
147
148std::string
150 if (myForward) {
151 return (TL("Redo create edge '") + myEdge->getID() + "'");
152 } else {
153 return (TL("Redo delete edge '") + myEdge->getID() + "'");
154 }
155}
156
157
158
159void
161 // iterate over edge lanes
162 for (int i = 0; i < (int)myEdge->getLanes().size(); i++) {
163 // add lane's edge in parent elements
164 for (const auto& additionalParent : myLaneParentAdditionals.at(i)) {
165 additionalParent->addChildElement(myEdge->getLanes().at(i));
166 }
167 for (const auto& demandParent : myLaneParentDemandElements.at(i)) {
168 demandParent->addChildElement(myEdge->getLanes().at(i));
169 }
170 for (const auto& genericParent : myLaneParentGenericData.at(i)) {
171 genericParent->addChildElement(myEdge->getLanes().at(i));
172 }
173 // add lane's edge in child elements
174 for (const auto& additionalChild : myChildLaneAdditionals.at(i)) {
175 additionalChild->addParentElement(myEdge->getLanes().at(i));
176 }
177 for (const auto& demandChild : myChildLaneDemandElements.at(i)) {
178 demandChild->addParentElement(myEdge->getLanes().at(i));
179 }
180 for (const auto& genericChild : myChildLaneGenericData.at(i)) {
181 genericChild->addParentElement(myEdge->getLanes().at(i));
182 }
183 }
184}
185
186
187void
189 // iterate over edge lanes
190 for (int i = 0; i < (int)myEdge->getLanes().size(); i++) {
191 // Remove every lane's edge from parent elements
192 for (const auto& additionalParent : myLaneParentAdditionals.at(i)) {
193 additionalParent->removeChildElement(myEdge->getLanes().at(i));
194 }
195 for (const auto& demandParent : myLaneParentDemandElements.at(i)) {
196 demandParent->removeChildElement(myEdge->getLanes().at(i));
197 }
198 for (const auto& genericParent : myLaneParentGenericData.at(i)) {
199 genericParent->removeChildElement(myEdge->getLanes().at(i));
200 }
201 // Remove every lane's edge from child elements
202 for (const auto& additionalChild : myChildLaneAdditionals.at(i)) {
203 additionalChild->removeParentElement(myEdge->getLanes().at(i));
204 }
205 for (const auto& demandChild : myChildLaneDemandElements.at(i)) {
206 demandChild->removeParentElement(myEdge->getLanes().at(i));
207 }
208 for (const auto& genericChild : myChildLaneGenericData.at(i)) {
209 genericChild->removeParentElement(myEdge->getLanes().at(i));
210 }
211 }
212}
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_NET
root element of a network file
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
void undo()
undo action
std::string redoName() const
get Redo name
void addEdgeLanes()
add given lane into parents and children
std::vector< std::vector< GNEDemandElement * > > myLaneParentDemandElements
vector of references to vector of parent demand elements (used by edge lanes)
void removeEdgeLanes()
remove given lane from parents and children
GNEEdge * myEdge
full information regarding the edge that is to be created/deleted
std::vector< std::vector< GNEAdditional * > > myLaneParentAdditionals
vector of references to vector of parent additionals (used by edge lanes)
void redo()
redo action
~GNEChange_Edge()
Destructor.
std::vector< std::vector< GNEGenericData * > > myChildLaneGenericData
vector of references to vector of child generic datas (used by edge lanes)
std::vector< std::vector< GNEDemandElement * > > myChildLaneDemandElements
vector of references to vector of child demand elements (used by edge lanes)
std::vector< std::vector< GNEGenericData * > > myLaneParentGenericData
vector of references to vector of parent generic datas (used by edge lanes)
std::vector< std::vector< GNEAdditional * > > myChildLaneAdditionals
vector of references to vector of child additional (used by edge lanes)
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
const std::vector< GNELane * > & getLanes() const
returns a reference to the lane vector
Definition GNEEdge.cpp:1118
void deleteSingleEdge(GNEEdge *edge)
delete edge from container
void requireSaveNetwork()
inform that network has to be saved
GNENetHelper::SavingStatus * getSavingStatus() const
get saving status
Definition GNENet.cpp:133
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
get all attribute carriers used in this net
Definition GNENet.cpp:127
GNEViewNet * getViewNet() const
get view net
Definition GNENet.cpp:2163
void decRef(const std::string &debugMsg="")
Decrease reference.
bool unreferenced()
check if object ins't referenced
GNEViewParent * getViewParent() const
get the net object
GNEApplicationWindow * getGNEAppWindows() const
get GNE Application Windows