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.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 
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  myLaneParentAdditionals.push_back(lane->getParentAdditionals());
45  myLaneParentDemandElements.push_back(lane->getParentDemandElements());
46  myLaneParentGenericData.push_back(lane->getParentGenericDatas());
47  myChildLaneAdditionals.push_back(lane->getChildAdditionals());
48  myChildLaneDemandElements.push_back(lane->getChildDemandElements());
49  myChildLaneGenericData.push_back(lane->getChildGenericDatas());
50  }
51 }
52 
53 
55  myEdge->decRef("GNEChange_Edge");
56  if (myEdge->unreferenced()) {
57  // show extra information for tests
58  WRITE_DEBUG("Deleting unreferenced " + myEdge->getTagStr() + " '" + myEdge->getID() + "' GNEChange_Edge");
59  // delete edge
60  delete myEdge;
61  }
62 }
63 
64 
65 void
67  if (myForward) {
68  // show extra information for tests
69  WRITE_DEBUG("Removing " + myEdge->getTagStr() + " '" + myEdge->getID() + "' from " + toString(SUMO_TAG_NET));
70  // unselect if mySelectedElement is enabled
71  if (mySelectedElement) {
73  }
74  // restore container
76  // remove edge lanes from parents and children
78  // delete edge from net
80  } else {
81  // show extra information for tests
82  WRITE_DEBUG("Adding " + myEdge->getTagStr() + " '" + myEdge->getID() + "' from " + toString(SUMO_TAG_NET));
83  // select if mySelectedElement is enabled
84  if (mySelectedElement) {
86  }
87  // insert edge into net
89  // restore container
91  // add edge lanes into parents and children
92  addEdgeLanes();
93  }
94  // enable save networkElements
96 }
97 
98 
99 void
101  if (myForward) {
102  // show extra information for tests
103  WRITE_DEBUG("Adding " + myEdge->getTagStr() + " '" + myEdge->getID() + "' from " + toString(SUMO_TAG_NET));
104  // select if mySelectedElement is enabled
105  if (mySelectedElement) {
107  }
108  // insert edge into net
110  // add edge into parents and children
112  // add edge lanes into parents and children
113  addEdgeLanes();
114  } else {
115  // show extra information for tests
116  WRITE_DEBUG("Removing " + myEdge->getTagStr() + " '" + myEdge->getID() + "' from " + toString(SUMO_TAG_NET));
117  // unselect if mySelectedElement is enabled
118  if (mySelectedElement) {
120  }
121  // remove edge from parents and children
123  // remove edge lanes from parents and children
124  removeEdgeLanes();
125  // delete edge from net
127  }
128  // enable save networkElements
130 }
131 
132 
133 std::string
135  if (myForward) {
136  return (TL("Undo create edge '") + myEdge->getID() + "'");
137  } else {
138  return (TL("Undo delete edge '") + myEdge->getID() + "'");
139  }
140 }
141 
142 
143 std::string
145  if (myForward) {
146  return (TL("Redo create edge '") + myEdge->getID() + "'");
147  } else {
148  return (TL("Redo delete edge '") + myEdge->getID() + "'");
149  }
150 }
151 
152 
153 
154 void
156  // iterate over edge lanes
157  for (int i = 0; i < (int)myEdge->getLanes().size(); i++) {
158  // add lane's edge in parent elements
159  for (const auto& additionalParent : myLaneParentAdditionals.at(i)) {
160  additionalParent->addChildElement(myEdge->getLanes().at(i));
161  }
162  for (const auto& demandParent : myLaneParentDemandElements.at(i)) {
163  demandParent->addChildElement(myEdge->getLanes().at(i));
164  }
165  for (const auto& genericParent : myLaneParentGenericData.at(i)) {
166  genericParent->addChildElement(myEdge->getLanes().at(i));
167  }
168  // add lane's edge in child elements
169  for (const auto& additionalChild : myChildLaneAdditionals.at(i)) {
170  additionalChild->addParentElement(myEdge->getLanes().at(i));
171  }
172  for (const auto& demandChild : myChildLaneDemandElements.at(i)) {
173  demandChild->addParentElement(myEdge->getLanes().at(i));
174  }
175  for (const auto& genericChild : myChildLaneGenericData.at(i)) {
176  genericChild->addParentElement(myEdge->getLanes().at(i));
177  }
178  }
179 }
180 
181 
182 void
184  // iterate over edge lanes
185  for (int i = 0; i < (int)myEdge->getLanes().size(); i++) {
186  // Remove every lane's edge from parent elements
187  for (const auto& additionalParent : myLaneParentAdditionals.at(i)) {
188  additionalParent->removeChildElement(myEdge->getLanes().at(i));
189  }
190  for (const auto& demandParent : myLaneParentDemandElements.at(i)) {
191  demandParent->removeChildElement(myEdge->getLanes().at(i));
192  }
193  for (const auto& genericParent : myLaneParentGenericData.at(i)) {
194  genericParent->removeChildElement(myEdge->getLanes().at(i));
195  }
196  // Remove every lane's edge from child elements
197  for (const auto& additionalChild : myChildLaneAdditionals.at(i)) {
198  additionalChild->removeParentElement(myEdge->getLanes().at(i));
199  }
200  for (const auto& demandChild : myChildLaneDemandElements.at(i)) {
201  demandChild->removeParentElement(myEdge->getLanes().at(i));
202  }
203  for (const auto& genericChild : myChildLaneGenericData.at(i)) {
204  genericChild->removeParentElement(myEdge->getLanes().at(i));
205  }
206  }
207 }
Supermode
@brie enum for supermodes
#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)
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
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:1047
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:127
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
get all attribute carriers used in this net
Definition: GNENet.cpp:121
void decRef(const std::string &debugMsg="")
Decrease reference.
bool unreferenced()
check if object ins't referenced