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 /****************************************************************************/
14 // A network change in which a single lane is created or deleted
15 /****************************************************************************/
16 
17 // ===========================================================================
18 // included modules
19 // ===========================================================================
20 #include <config.h>
21 
22 #include <netedit/GNENet.h>
28 
29 #include "GNEChange_Lane.h"
30 
31 
32 // ===========================================================================
33 // FOX-declarations
34 // ===========================================================================
35 FXIMPLEMENT_ABSTRACT(GNEChange_Lane, GNEChange, nullptr, 0)
36 
37 // ===========================================================================
38 // member method definitions
39 // ===========================================================================
40 
41 
42 GNEChange_Lane::GNEChange_Lane(GNEEdge* edge, GNELane* lane, const NBEdge::Lane& laneAttrs, bool forward, bool recomputeConnections):
44  GNEChange(edge->getNet(), forward),
45  myEdge(edge),
46  myLane(lane),
47  myLaneAttrs(laneAttrs),
48  myRecomputeConnections(recomputeConnections) {
49  assert(myNet);
50  myEdge->incRef("GNEChange_Lane");
51  if (myLane) {
52  // non-zero pointer is passsed in case of removal or duplication
53  myLane->incRef("GNEChange_Lane");
54  // Save hierarchy elements of lane
55  myParentShapes = myLane->getParentShapes();
56  myParentAdditionals = myLane->getParentAdditionals();
57  myParentDemandElements = myLane->getParentDemandElements();
58  myChildShapes = myLane->getChildShapes();
59  myChildAdditionals = myLane->getChildAdditionals();
60  myChildDemandElements = myLane->getChildDemandElements();
61  } else {
62  assert(forward);
63  }
64 }
65 
66 
68  assert(myEdge);
69  myEdge->decRef("GNEChange_Lane");
70  if (myEdge->unreferenced()) {
71  // show extra information for tests
72  WRITE_DEBUG("Deleting unreferenced " + myEdge->getTagStr() + " '" + myEdge->getID() + "' in GNEChange_Lane");
73  delete myEdge;
74  }
75  if (myLane) {
76  myLane->decRef("GNEChange_Lane");
77  if (myLane->unreferenced()) {
78  // show extra information for tests
79  WRITE_DEBUG("Deleting unreferenced " + myLane->getTagStr() + " '" + myLane->getID() + "' in GNEChange_Lane");
80  delete myLane;
81  }
82  }
83 }
84 
85 
86 void
88  if (myForward) {
89  // show extra information for tests
90  if (myLane != nullptr) {
91  WRITE_DEBUG("Removing " + myLane->getTagStr() + " '" + myLane->getID() + "' from " + toString(SUMO_TAG_EDGE));
92  } else {
93  WRITE_DEBUG("Removing nullptr " + toString(SUMO_TAG_LANE) + " from " + toString(SUMO_TAG_EDGE));
94  }
95  // remove lane from edge
96  myEdge->removeLane(myLane, false);
97  // Remove lane from parent elements
98  for (const auto& i : myParentShapes) {
99  i->removeChildLane(myLane);
100  }
101  for (const auto& i : myParentAdditionals) {
102  i->removeChildLane(myLane);
103  }
104  for (const auto& i : myParentDemandElements) {
105  i->removeChildLane(myLane);
106  }
107  // Remove lane from child elements
108  for (const auto& i : myChildShapes) {
109  i->removeParentLane(myLane);
110  }
111  for (const auto& i : myChildAdditionals) {
112  i->removeParentLane(myLane);
113  }
114  for (const auto& i : myChildDemandElements) {
115  i->removeParentLane(myLane);
116  }
117  } else {
118  // show extra information for tests
119  if (myLane != nullptr) {
120  WRITE_DEBUG("Adding " + myLane->getTagStr() + " '" + myLane->getID() + "' into " + toString(SUMO_TAG_EDGE));
121  } else {
122  WRITE_DEBUG("Adding nullptr " + toString(SUMO_TAG_LANE) + " into " + toString(SUMO_TAG_EDGE));
123  }
124  // add lane and their attributes to edge
125  // (lane removal is reverted, no need to recompute connections)
126  myEdge->addLane(myLane, myLaneAttrs, false);
127  // add lane in parent elements
128  for (const auto& i : myParentShapes) {
129  i->addChildLane(myLane);
130  }
131  for (const auto& i : myParentAdditionals) {
132  i->addChildLane(myLane);
133  }
134  for (const auto& i : myParentDemandElements) {
135  i->addChildLane(myLane);
136  }
137  // add lane in child elements
138  for (const auto& i : myChildShapes) {
139  i->addParentLane(myLane);
140  }
141  for (const auto& i : myChildAdditionals) {
142  i->addParentLane(myLane);
143  }
144  for (const auto& i : myChildDemandElements) {
145  i->addParentLane(myLane);
146  }
147  }
148  // enable save netElements
149  myNet->requireSaveNet(true);
150 }
151 
152 
153 void
155  if (myForward) {
156  // show extra information for tests
157  if (myLane != nullptr) {
158  WRITE_DEBUG("Adding " + myLane->getTagStr() + " '" + myLane->getID() + "' into " + toString(SUMO_TAG_EDGE));
159  } else {
160  WRITE_DEBUG("Adding nullptr " + toString(SUMO_TAG_LANE) + " into " + toString(SUMO_TAG_EDGE));
161  }
162  // add lane and their attributes to edge
164  // add lane in parent elements
165  for (const auto& i : myParentShapes) {
166  i->addChildLane(myLane);
167  }
168  for (const auto& i : myParentAdditionals) {
169  i->addChildLane(myLane);
170  }
171  for (const auto& i : myParentDemandElements) {
172  i->addChildLane(myLane);
173  }
174  // add additional in child elements
175  for (const auto& i : myChildShapes) {
176  i->addParentLane(myLane);
177  }
178  for (const auto& i : myChildAdditionals) {
179  i->addParentLane(myLane);
180  }
181  for (const auto& i : myChildDemandElements) {
182  i->addParentLane(myLane);
183  }
184  } else {
185  // show extra information for tests
186  if (myLane != nullptr) {
187  WRITE_DEBUG("Removing " + myLane->getTagStr() + " '" + myLane->getID() + "' from " + toString(SUMO_TAG_EDGE));
188  } else {
189  WRITE_DEBUG("Removing nullptr " + toString(SUMO_TAG_LANE) + " from " + toString(SUMO_TAG_EDGE));
190  }
191  // Remove lane from parent elements
192  for (const auto& i : myParentShapes) {
193  i->removeChildLane(myLane);
194  }
195  for (const auto& i : myParentAdditionals) {
196  i->removeChildLane(myLane);
197  }
198  for (const auto& i : myParentDemandElements) {
199  i->removeChildLane(myLane);
200  }
201  // Remove additional from child elements
202  for (const auto& i : myChildShapes) {
203  i->removeParentLane(myLane);
204  }
205  for (const auto& i : myChildAdditionals) {
206  i->removeParentLane(myLane);
207  }
208  for (const auto& i : myChildDemandElements) {
209  i->removeParentLane(myLane);
210  }
211  // remove lane from edge
213  }
214  // enable save netElements
215  myNet->requireSaveNet(true);
216 }
217 
218 
219 FXString
221  if (myForward) {
222  return ("Undo create " + toString(SUMO_TAG_LANE)).c_str();
223  } else {
224  return ("Undo delete " + toString(SUMO_TAG_LANE)).c_str();
225  }
226 }
227 
228 
229 FXString
231  if (myForward) {
232  return ("Redo create " + toString(SUMO_TAG_LANE)).c_str();
233  } else {
234  return ("Redo delete " + toString(SUMO_TAG_LANE)).c_str();
235  }
236 }
GNENet::requireSaveNet
void requireSaveNet(bool value)
inform that net has to be saved
Definition: GNENet.cpp:982
GNEChange_Lane::myChildAdditionals
std::vector< GNEAdditional * > myChildAdditionals
vector of child additional
Definition: GNEChange_Lane.h:104
GNEEdge::addLane
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:1666
GNEReferenceCounter::unreferenced
bool unreferenced()
check if object ins't referenced
Definition: GNEReferenceCounter.h:78
GNEAdditional.h
GNEAttributeCarrier::getID
const std::string getID() const
function to support debugging
Definition: GNEAttributeCarrier.cpp:1289
GNEChange_Lane::~GNEChange_Lane
~GNEChange_Lane()
Destructor.
Definition: GNEChange_Lane.cpp:67
GNEChange::myForward
bool myForward
we group antagonistic commands (create junction/delete junction) and keep them apart by this flag
Definition: GNEChange.h:80
GNEChange_Lane::myChildShapes
std::vector< GNEShape * > myChildShapes
vector of child shapes
Definition: GNEChange_Lane.h:101
SUMO_TAG_LANE
begin/end of the description of a single lane
Definition: SUMOXMLDefinitions.h:49
GNEEdge::removeLane
void removeLane(GNELane *lane, bool recomputeConnections)
@briefdecrease the number of lanes by one. argument is only used to increase robustness (assertions)
Definition: GNEEdge.cpp:1723
GNEChange_Lane::redoName
FXString redoName() const
get Redo name
Definition: GNEChange_Lane.cpp:230
NBEdge
The representation of a single edge during network building.
Definition: NBEdge.h:91
GNEChange_Lane::myLaneAttrs
const NBEdge::Lane myLaneAttrs
we need to preserve the attributes explicitly because they are not contained withing GNELane itself
Definition: GNEChange_Lane.h:86
GNEEdge
A road/street connecting two junctions (netedit-version)
Definition: GNEEdge.h:51
GNEChange_Lane::undo
void undo()
undo action
Definition: GNEChange_Lane.cpp:87
GNEDemandElement.h
SUMO_TAG_EDGE
begin/end of the description of an edge
Definition: SUMOXMLDefinitions.h:47
GNEChange_Lane
Definition: GNEChange_Lane.h:46
GNEEdge.h
GNEChange::myNet
GNENet * myNet
the net to which operations shall be applied or which shall be informed about gui updates (we are not...
Definition: GNEChange.h:75
GNEReferenceCounter::decRef
void decRef(const std::string &debugMsg="")
Decrease reference.
Definition: GNEReferenceCounter.h:52
GNELane.h
GNEShape.h
GNEChange_Lane::myLane
GNELane * myLane
we need to preserve the lane because it maybe the target of GNEChange_Attribute commands
Definition: GNEChange_Lane.h:83
toString
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:47
GNEChange_Lane::myChildDemandElements
std::vector< GNEDemandElement * > myChildDemandElements
vector of child demand elements
Definition: GNEChange_Lane.h:107
config.h
GNEChange_Lane::undoName
FXString undoName() const
return undoName
Definition: GNEChange_Lane.cpp:220
GNEChange_Lane.h
Lane
C++ TraCI client API implementation.
GNEAttributeCarrier::getTagStr
const std::string & getTagStr() const
get tag assigned to this object in string format
Definition: GNEAttributeCarrier.cpp:1267
GNEChange_Lane::myEdge
GNEEdge * myEdge
we need the edge because it is the target of our change commands
Definition: GNEChange_Lane.h:80
GNEChange_Lane::myParentShapes
std::vector< GNEShape * > myParentShapes
vector of parent shapes
Definition: GNEChange_Lane.h:92
GNEChange_Lane::myRecomputeConnections
bool myRecomputeConnections
@bried whether to recompute connection when adding a new lane
Definition: GNEChange_Lane.h:89
GNEChange
the function-object for an editing operation (abstract base)
Definition: GNEChange.h:42
GNEChange_Lane::myParentAdditionals
std::vector< GNEAdditional * > myParentAdditionals
vector of parent additionals
Definition: GNEChange_Lane.h:95
GNELane
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
Definition: GNELane.h:45
GNEChange_Lane::redo
void redo()
redo action
Definition: GNEChange_Lane.cpp:154
WRITE_DEBUG
#define WRITE_DEBUG(msg)
Definition: MsgHandler.h:284
GNENet.h
GNEChange_Lane::myParentDemandElements
std::vector< GNEDemandElement * > myParentDemandElements
vector of parent demand elements
Definition: GNEChange_Lane.h:98