Eclipse SUMO - Simulation of Urban MObility
GNEChange_Edge.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 edge is created or deleted
19 /****************************************************************************/
20 #include <config.h>
21 
22 #include <netedit/GNENet.h>
23 
24 
25 #include "GNEChange_Edge.h"
26 
27 // ===========================================================================
28 // FOX-declarations
29 // ===========================================================================
30 FXIMPLEMENT_ABSTRACT(GNEChange_Edge, GNEChange, nullptr, 0)
31 
32 // ===========================================================================
33 // member method definitions
34 // ===========================================================================
35 
36 
37 GNEChange_Edge::GNEChange_Edge(GNEEdge* edge, bool forward):
39  GNEChange(Supermode::NETWORK, edge, forward, edge->isAttributeCarrierSelected()),
40  myEdge(edge) {
41  edge->incRef("GNEChange_Edge");
42  // save all hierarchical elements of edge's lane
43  for (const auto& lane : edge->getLanes()) {
44  myLaneParentShapes.push_back(lane->getParentShapes());
45  myLaneParentAdditionals.push_back(lane->getParentAdditionals());
46  myLaneParentDemandElements.push_back(lane->getParentDemandElements());
47  myLaneParentGenericData.push_back(lane->getParentGenericDatas());
48  myChildLaneShapes.push_back(lane->getChildShapes());
49  myChildLaneAdditionals.push_back(lane->getChildAdditionals());
50  myChildLaneDemandElements.push_back(lane->getChildDemandElements());
51  myChildLaneGenericData.push_back(lane->getChildGenericDatas());
52  }
53 }
54 
55 
57  myEdge->decRef("GNEChange_Edge");
58  if (myEdge->unreferenced()) {
59  // show extra information for tests
60  WRITE_DEBUG("Deleting unreferenced " + myEdge->getTagStr() + " '" + myEdge->getID() + "' GNEChange_Edge");
61  // delete edge
62  delete myEdge;
63  }
64 }
65 
66 
67 void
69  if (myForward) {
70  // show extra information for tests
71  WRITE_DEBUG("Removing " + myEdge->getTagStr() + " '" + myEdge->getID() + "' from " + toString(SUMO_TAG_NET));
72  // unselect if mySelectedElement is enabled
73  if (mySelectedElement) {
75  }
76  // restore container
78  // remove edge lanes from parents and children
80  // delete edge from net
82  } else {
83  // show extra information for tests
84  WRITE_DEBUG("Adding " + myEdge->getTagStr() + " '" + myEdge->getID() + "' from " + toString(SUMO_TAG_NET));
85  // select if mySelectedElement is enabled
86  if (mySelectedElement) {
88  }
89  // insert edge into net
91  // restore container
93  // add edge lanes into parents and children
94  addEdgeLanes();
95  }
96  // enable save networkElements
97  myEdge->getNet()->requireSaveNet(true);
98 }
99 
100 
101 void
103  if (myForward) {
104  // show extra information for tests
105  WRITE_DEBUG("Adding " + myEdge->getTagStr() + " '" + myEdge->getID() + "' from " + toString(SUMO_TAG_NET));
106  // select if mySelectedElement is enabled
107  if (mySelectedElement) {
109  }
110  // insert edge into net
112  // add edge into parents and children
114  // add edge lanes into parents and children
115  addEdgeLanes();
116  } else {
117  // show extra information for tests
118  WRITE_DEBUG("Removing " + myEdge->getTagStr() + " '" + myEdge->getID() + "' from " + toString(SUMO_TAG_NET));
119  // unselect if mySelectedElement is enabled
120  if (mySelectedElement) {
122  }
123  // remove edge from parents and children
125  // remove edge lanes from parents and children
126  removeEdgeLanes();
127  // delete edge from net
129  }
130  // enable save networkElements
131  myEdge->getNet()->requireSaveNet(true);
132 }
133 
134 
135 std::string
137  if (myForward) {
138  return ("Undo create " + toString(SUMO_TAG_EDGE));
139  } else {
140  return ("Undo delete " + toString(SUMO_TAG_EDGE));
141  }
142 }
143 
144 
145 std::string
147  if (myForward) {
148  return ("Redo create " + toString(SUMO_TAG_EDGE));
149  } else {
150  return ("Redo delete " + toString(SUMO_TAG_EDGE));
151  }
152 }
153 
154 
155 
156 void
158  // iterate over edge lanes
159  for (int i = 0; i < (int)myEdge->getLanes().size(); i++) {
160  // add lane's edge in parent elements
161  for (const auto& j : myLaneParentShapes.at(i)) {
162  j->addChildElement(myEdge->getLanes().at(i));
163  }
164  for (const auto& j : myLaneParentAdditionals.at(i)) {
165  j->addChildElement(myEdge->getLanes().at(i));
166  }
167  for (const auto& j : myLaneParentDemandElements.at(i)) {
168  j->addChildElement(myEdge->getLanes().at(i));
169  }
170  for (const auto& j : myLaneParentGenericData.at(i)) {
171  j->addChildElement(myEdge->getLanes().at(i));
172  }
173  // add lane's edge in child elements
174  for (const auto& j : myChildLaneShapes.at(i)) {
175  j->addParentElement(myEdge->getLanes().at(i));
176  }
177  for (const auto& j : myChildLaneAdditionals.at(i)) {
178  j->addParentElement(myEdge->getLanes().at(i));
179  }
180  for (const auto& j : myChildLaneDemandElements.at(i)) {
181  j->addParentElement(myEdge->getLanes().at(i));
182  }
183  for (const auto& j : myChildLaneGenericData.at(i)) {
184  j->addParentElement(myEdge->getLanes().at(i));
185  }
186  }
187 }
188 
189 
190 void
192  // iterate over edge lanes
193  for (int i = 0; i < (int)myEdge->getLanes().size(); i++) {
194  // Remove every lane's edge from parent elements
195  for (const auto& j : myLaneParentShapes.at(i)) {
196  j->removeChildElement(myEdge->getLanes().at(i));
197  }
198  for (const auto& j : myLaneParentAdditionals.at(i)) {
199  j->removeChildElement(myEdge->getLanes().at(i));
200  }
201  for (const auto& j : myLaneParentDemandElements.at(i)) {
202  j->removeChildElement(myEdge->getLanes().at(i));
203  }
204  for (const auto& j : myLaneParentGenericData.at(i)) {
205  j->removeChildElement(myEdge->getLanes().at(i));
206  }
207  // Remove every lane's edge from child elements
208  for (const auto& j : myChildLaneShapes.at(i)) {
209  j->removeParentElement(myEdge->getLanes().at(i));
210  }
211  for (const auto& j : myChildLaneAdditionals.at(i)) {
212  j->removeParentElement(myEdge->getLanes().at(i));
213  }
214  for (const auto& j : myChildLaneDemandElements.at(i)) {
215  j->removeParentElement(myEdge->getLanes().at(i));
216  }
217  for (const auto& j : myChildLaneGenericData.at(i)) {
218  j->removeParentElement(myEdge->getLanes().at(i));
219  }
220  }
221 }
Supermode
@brie enum for supermodes
#define WRITE_DEBUG(msg)
Definition: MsgHandler.h:290
@ SUMO_TAG_NET
root element of a network file
@ 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 & 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
std::vector< std::vector< GNEShape * > > myLaneParentShapes
vector of references to vector of parent shapes (used by edge lanes)
void undo()
undo action
std::string redoName() const
get Redo name
std::vector< std::vector< GNEShape * > > myChildLaneShapes
vector of references to vector of child shapes (used by edge lanes)
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:64
bool myForward
we group antagonistic commands (create junction/delete junction) and keep them apart by this flag
Definition: GNEChange.h:244
const bool mySelectedElement
flag for check if element is selected
Definition: GNEChange.h:247
void addElementInParentsAndChildren(T *element)
add given element into parents and children (only use in redo() function)
Definition: GNEChange.h:132
void removeElementFromParentsAndChildren(T *element)
remove given element from parents and children (only use in redo() function)
Definition: GNEChange.h:187
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:782
void deleteSingleEdge(GNEEdge *edge)
deletes a single edge
void requireSaveNet(bool value)
inform that net has to be saved
Definition: GNENet.cpp:1144
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
get all attribute carriers used in this net
Definition: GNENet.cpp:125
const std::string & getID() const
get ID
void decRef(const std::string &debugMsg="")
Decrease reference.
bool unreferenced()
check if object ins't referenced