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-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
15 // A network change in which a single lane is created or deleted
16 /****************************************************************************/
17 
18 // ===========================================================================
19 // included modules
20 // ===========================================================================
21 #include <config.h>
22 
23 #include <netedit/GNENet.h>
29 
30 #include "GNEChange_Lane.h"
31 
32 
33 // ===========================================================================
34 // FOX-declarations
35 // ===========================================================================
36 FXIMPLEMENT_ABSTRACT(GNEChange_Lane, GNEChange, nullptr, 0)
37 
38 // ===========================================================================
39 // member method definitions
40 // ===========================================================================
41 
42 
43 GNEChange_Lane::GNEChange_Lane(GNEEdge* edge, GNELane* lane, const NBEdge::Lane& laneAttrs, bool forward, bool recomputeConnections):
45  GNEChange(edge->getNet(), forward),
46  myEdge(edge),
47  myLane(lane),
48  myLaneAttrs(laneAttrs),
49  myRecomputeConnections(recomputeConnections) {
50  assert(myNet);
51  myEdge->incRef("GNEChange_Lane");
52  if (myLane) {
53  // non-zero pointer is passsed in case of removal or duplication
54  myLane->incRef("GNEChange_Lane");
55  // Save hierarchy elements of lane
56  myShapeParents = myLane->getShapeParents();
57  myAdditionalParents = myLane->getAdditionalParents();
58  myDemandElementParents = myLane->getDemandElementParents();
59  myShapeChildren = myLane->getShapeChildren();
60  myAdditionalChildren = myLane->getAdditionalChildren();
61  myDemandElementChildren = myLane->getDemandElementChildren();
62  } else {
63  assert(forward);
64  }
65 }
66 
67 
69  assert(myEdge);
70  myEdge->decRef("GNEChange_Lane");
71  if (myEdge->unreferenced()) {
72  // show extra information for tests
73  WRITE_DEBUG("Deleting unreferenced " + myEdge->getTagStr() + " '" + myEdge->getID() + "' in GNEChange_Lane");
74  delete myEdge;
75  }
76  if (myLane) {
77  myLane->decRef("GNEChange_Lane");
78  if (myLane->unreferenced()) {
79  // show extra information for tests
80  WRITE_DEBUG("Deleting unreferenced " + myLane->getTagStr() + " '" + myLane->getID() + "' in GNEChange_Lane");
81  delete myLane;
82  }
83  }
84 }
85 
86 
87 void
89  if (myForward) {
90  // show extra information for tests
91  if (myLane != nullptr) {
92  WRITE_DEBUG("Removing " + myLane->getTagStr() + " '" + myLane->getID() + "' from " + toString(SUMO_TAG_EDGE));
93  } else {
94  WRITE_DEBUG("Removing nullptr " + toString(SUMO_TAG_LANE) + " from " + toString(SUMO_TAG_EDGE));
95  }
96  // remove lane from edge
97  myEdge->removeLane(myLane, false);
98  // Remove lane from parent elements
99  for (const auto& i : myShapeParents) {
100  i->removeLaneChild(myLane);
101  }
102  for (const auto& i : myAdditionalParents) {
103  i->removeLaneChild(myLane);
104  }
105  for (const auto& i : myDemandElementParents) {
106  i->removeLaneChild(myLane);
107  }
108  // Remove lane from child elements
109  for (const auto& i : myShapeChildren) {
110  i->removeLaneParent(myLane);
111  }
112  for (const auto& i : myAdditionalChildren) {
113  i->removeLaneParent(myLane);
114  }
115  for (const auto& i : myDemandElementChildren) {
116  i->removeLaneParent(myLane);
117  }
118  } else {
119  // show extra information for tests
120  if (myLane != nullptr) {
121  WRITE_DEBUG("Adding " + myLane->getTagStr() + " '" + myLane->getID() + "' into " + toString(SUMO_TAG_EDGE));
122  } else {
123  WRITE_DEBUG("Adding nullptr " + toString(SUMO_TAG_LANE) + " into " + toString(SUMO_TAG_EDGE));
124  }
125  // add lane and their attributes to edge
126  // (lane removal is reverted, no need to recompute connections)
127  myEdge->addLane(myLane, myLaneAttrs, false);
128  // add lane in parent elements
129  for (const auto& i : myShapeParents) {
130  i->addLaneChild(myLane);
131  }
132  for (const auto& i : myAdditionalParents) {
133  i->addLaneChild(myLane);
134  }
135  for (const auto& i : myDemandElementParents) {
136  i->addLaneChild(myLane);
137  }
138  // add lane in child elements
139  for (const auto& i : myShapeChildren) {
140  i->addLaneParent(myLane);
141  }
142  for (const auto& i : myAdditionalChildren) {
143  i->addLaneParent(myLane);
144  }
145  for (const auto& i : myDemandElementChildren) {
146  i->addLaneParent(myLane);
147  }
148  }
149  // enable save netElements
150  myNet->requiereSaveNet(true);
151 }
152 
153 
154 void
156  if (myForward) {
157  // show extra information for tests
158  if (myLane != nullptr) {
159  WRITE_DEBUG("Adding " + myLane->getTagStr() + " '" + myLane->getID() + "' into " + toString(SUMO_TAG_EDGE));
160  } else {
161  WRITE_DEBUG("Adding nullptr " + toString(SUMO_TAG_LANE) + " into " + toString(SUMO_TAG_EDGE));
162  }
163  // add lane and their attributes to edge
165  // add lane in parent elements
166  for (const auto& i : myShapeParents) {
167  i->addLaneChild(myLane);
168  }
169  for (const auto& i : myAdditionalParents) {
170  i->addLaneChild(myLane);
171  }
172  for (const auto& i : myDemandElementParents) {
173  i->addLaneChild(myLane);
174  }
175  // add additional in child elements
176  for (const auto& i : myShapeChildren) {
177  i->addLaneParent(myLane);
178  }
179  for (const auto& i : myAdditionalChildren) {
180  i->addLaneParent(myLane);
181  }
182  for (const auto& i : myDemandElementChildren) {
183  i->addLaneParent(myLane);
184  }
185  } else {
186  // show extra information for tests
187  if (myLane != nullptr) {
188  WRITE_DEBUG("Removing " + myLane->getTagStr() + " '" + myLane->getID() + "' from " + toString(SUMO_TAG_EDGE));
189  } else {
190  WRITE_DEBUG("Removing nullptr " + toString(SUMO_TAG_LANE) + " from " + toString(SUMO_TAG_EDGE));
191  }
192  // Remove lane from parent elements
193  for (const auto& i : myShapeParents) {
194  i->removeLaneChild(myLane);
195  }
196  for (const auto& i : myAdditionalParents) {
197  i->removeLaneChild(myLane);
198  }
199  for (const auto& i : myDemandElementParents) {
200  i->removeLaneChild(myLane);
201  }
202  // Remove additional from child elements
203  for (const auto& i : myShapeChildren) {
204  i->removeLaneParent(myLane);
205  }
206  for (const auto& i : myAdditionalChildren) {
207  i->removeLaneParent(myLane);
208  }
209  for (const auto& i : myDemandElementChildren) {
210  i->removeLaneParent(myLane);
211  }
212  // remove lane from edge
214  }
215  // enable save netElements
216  myNet->requiereSaveNet(true);
217 }
218 
219 
220 FXString
222  if (myForward) {
223  return ("Undo create " + toString(SUMO_TAG_LANE)).c_str();
224  } else {
225  return ("Undo delete " + toString(SUMO_TAG_LANE)).c_str();
226  }
227 }
228 
229 
230 FXString
232  if (myForward) {
233  return ("Redo create " + toString(SUMO_TAG_LANE)).c_str();
234  } else {
235  return ("Redo delete " + toString(SUMO_TAG_LANE)).c_str();
236  }
237 }
const NBEdge::Lane myLaneAttrs
we need to preserve the attributes explicitly because they are not contained withing GNELane itself ...
~GNEChange_Lane()
Destructor.
std::vector< GNEShape * > myShapeParents
vector of shape parents
the function-object for an editing operation (abstract base)
Definition: GNEChange.h:43
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:1652
begin/end of the description of a single lane
FXString redoName() const
get Redo name
FXString undoName() const
return undoName
The representation of a single edge during network building.
Definition: NBEdge.h:86
void undo()
undo action
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
Definition: GNELane.h:46
std::vector< GNEAdditional * > myAdditionalChildren
vector of additional children
std::vector< GNEAdditional * > myAdditionalParents
vector of additional parents
void removeLane(GNELane *lane, bool recomputeConnections)
the number of lanes by one. argument is only used to increase robustness (assertions) ...
Definition: GNEEdge.cpp:1705
std::vector< GNEShape * > myShapeChildren
vector of shape children
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:48
C++ TraCI client API implementation.
const std::string getID() const
function to support debugging
#define WRITE_DEBUG(msg)
Definition: MsgHandler.h:246
void redo()
redo action
void decRef(const std::string &debugMsg="")
Decrease reference.
begin/end of the description of an edge
A road/street connecting two junctions (netedit-version)
Definition: GNEEdge.h:50
GNEEdge * myEdge
we need the edge because it is the target of our change commands
GNENet * myNet
the net to which operations shall be applied or which shall be informed about gui updates (we are not...
Definition: GNEChange.h:76
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
std::vector< GNEDemandElement * > myDemandElementParents
vector of demand element parents
const std::string & getTagStr() const
get tag assigned to this object in string format
void requiereSaveNet(bool value)
inform that net has to be saved
Definition: GNENet.cpp:933
bool myForward
we group antagonistic commands (create junction/delete junction) and keep them apart by this flag ...
Definition: GNEChange.h:81
std::vector< GNEDemandElement * > myDemandElementChildren
vector of demand element children
bool unreferenced()
check if object ins&#39;t referenced