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-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
17 // A network change in which a single lane is created or deleted
18 /****************************************************************************/
19 
20 // ===========================================================================
21 // included modules
22 // ===========================================================================
23 #ifdef _MSC_VER
24 #include <windows_config.h>
25 #else
26 #include <config.h>
27 #endif
28 
30 #include <cassert>
31 
32 #include "GNEChange_Lane.h"
33 #include "GNEEdge.h"
34 #include "GNELane.h"
35 #include "GNENet.h"
36 #include "GNEViewNet.h"
37 #include "GNEPOILane.h"
38 
39 // ===========================================================================
40 // FOX-declarations
41 // ===========================================================================
42 FXIMPLEMENT_ABSTRACT(GNEChange_Lane, GNEChange, NULL, 0)
43 
44 // ===========================================================================
45 // member method definitions
46 // ===========================================================================
47 
48 
49 GNEChange_Lane::GNEChange_Lane(GNEEdge* edge, GNELane* lane, const NBEdge::Lane& laneAttrs, bool forward):
51  GNEChange(edge->getNet(), forward),
52  myEdge(edge),
53  myLane(lane),
54  myLaneAttrs(laneAttrs) {
55  assert(myNet);
56  myEdge->incRef("GNEChange_Lane");
57  if (myLane) {
58  // non-zero pointer is passsed in case of removal or duplication
59  myLane->incRef("GNEChange_Lane");
60  // Save additionals of lane
61  myAdditionalChilds = myLane->getAdditionalChilds();
62  // Save POILanes of lane
63  myShapeChilds = myLane->getShapeChilds();
64  } else {
65  assert(forward);
66  }
67 }
68 
69 
71  assert(myEdge);
72  myEdge->decRef("GNEChange_Lane");
73  if (myEdge->unreferenced()) {
74  // show extra information for tests
75  if (OptionsCont::getOptions().getBool("gui-testing-debug")) {
76  WRITE_WARNING("Deleting unreferenced " + toString(myEdge->getTag()) + " '" + myEdge->getID() + "' in GNEChange_Lane");
77  }
78  delete myEdge;
79  }
80  if (myLane) {
81  myLane->decRef("GNEChange_Lane");
82  if (myLane->unreferenced()) {
83  // show extra information for tests
84  if (OptionsCont::getOptions().getBool("gui-testing-debug")) {
85  WRITE_WARNING("Deleting unreferenced " + toString(myLane->getTag()) + " '" + myLane->getID() + "' in GNEChange_Lane");
86  }
87  delete myLane;
88  }
89  }
90 }
91 
92 
93 void
95  if (myForward) {
96  // show extra information for tests
97  if (OptionsCont::getOptions().getBool("gui-testing-debug")) {
98  if (myLane != NULL) {
99  WRITE_WARNING("Removing " + toString(myLane->getTag()) + " '" + myLane->getID() + "' from " + toString(SUMO_TAG_EDGE));
100  } else {
101  WRITE_WARNING("Removing NULL " + toString(SUMO_TAG_LANE) + " from " + toString(SUMO_TAG_EDGE));
102  }
103  }
104  // remove lane from edge
106  // Remove additionals vinculated with this lane
107  for (auto i : myAdditionalChilds) {
109  }
110  // Remove Shapes vinculated with this lane of net
111  for (auto i : myShapeChilds) {
112  myNet->removeShape(i);
113  }
114  } else {
115  // show extra information for tests
116  if (OptionsCont::getOptions().getBool("gui-testing-debug")) {
117  if (myLane != NULL) {
118  WRITE_WARNING("Adding " + toString(myLane->getTag()) + " '" + myLane->getID() + "' into " + toString(SUMO_TAG_EDGE));
119  } else {
120  WRITE_WARNING("Adding NULL " + toString(SUMO_TAG_LANE) + " into " + toString(SUMO_TAG_EDGE));
121  }
122  }
123  // add lane and their attributes to edge
125  // add additional sets vinculated with this lane of net
126  for (auto i : myAdditionalChilds) {
128  }
129  // add Shapes vinculated with this lane in net
130  for (auto i : myShapeChilds) {
131  myNet->removeShape(i);
132  }
133  }
134 }
135 
136 
137 void
139  if (myForward) {
140  // show extra information for tests
141  if (OptionsCont::getOptions().getBool("gui-testing-debug")) {
142  if (myLane != NULL) {
143  WRITE_WARNING("Adding " + toString(myLane->getTag()) + " '" + myLane->getID() + "' into " + toString(SUMO_TAG_EDGE));
144  } else {
145  WRITE_WARNING("Adding NULL " + toString(SUMO_TAG_LANE) + " into " + toString(SUMO_TAG_EDGE));
146  }
147  }
148  // add lane and their attributes to edge
150  // add additional vinculated with this lane of net
151  for (auto i : myAdditionalChilds) {
153  }
154  // add shapes vinculated with this lane in net
155  for (auto i : myShapeChilds) {
156  myNet->removeShape(i);
157  }
158  } else {
159  // show extra information for tests
160  if (OptionsCont::getOptions().getBool("gui-testing-debug")) {
161  if (myLane != NULL) {
162  WRITE_WARNING("Removing " + toString(myLane->getTag()) + " '" + myLane->getID() + "' from " + toString(SUMO_TAG_EDGE));
163  } else {
164  WRITE_WARNING("Removing NULL " + toString(SUMO_TAG_LANE) + " from " + toString(SUMO_TAG_EDGE));
165  }
166  }
167  // remove lane from edge
169  // Remove additional vinculated with this lane of net
170  for (auto i : myAdditionalChilds) {
172  }
173  // Remove shapes vinculated with this lane of net
174  for (auto i : myShapeChilds) {
175  myNet->removeShape(i);
176  }
177  }
178 }
179 
180 
181 FXString
183  if (myForward) {
184  return ("Undo create " + toString(SUMO_TAG_LANE)).c_str();
185  } else {
186  return ("Undo delete " + toString(SUMO_TAG_LANE)).c_str();
187  }
188 }
189 
190 
191 FXString
193  if (myForward) {
194  return ("Redo create " + toString(SUMO_TAG_LANE)).c_str();
195  } else {
196  return ("Redo delete " + toString(SUMO_TAG_LANE)).c_str();
197  }
198 }
void addLane(GNELane *lane, const NBEdge::Lane &laneAttrs)
increase number of lanes by one use the given attributes and restore the GNELane
Definition: GNEEdge.cpp:1071
void insertAdditional(GNEAdditional *additional)
Insert a additional element int GNENet container.
Definition: GNENet.cpp:2020
const NBEdge::Lane myLaneAttrs
we need to preserve the attributes explicitly because they are not contained withing GNELane itself ...
~GNEChange_Lane()
Destructor.
the function-object for an editing operation (abstract base)
Definition: GNEChange.h:48
begin/end of the description of a single lane
FXString redoName() const
get Redo name
FXString undoName() const
return undoName
void removeShape(GNEShape *shape)
remove created shape (but NOT delete)
Definition: GNENet.cpp:2252
The representation of a single edge during network building.
Definition: NBEdge.h:70
void undo()
undo action
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
Definition: GNELane.h:53
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:199
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:64
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:55
C++ TraCI client API implementation.
Definition: Lane.h:42
std::vector< GNEShape * > myShapeChilds
we need to preserve the list of shapes vinculated with this lane
const std::string getID() const
function to support debugging
void removeLane(GNELane *lane)
the number of lanes by one. argument is only used to increase robustness (assertions) ...
Definition: GNEEdge.cpp:1115
void redo()
redo action
void decRef(const std::string &debugMsg="")
Decrease reference.
std::vector< GNEAdditional * > myAdditionalChilds
we need to preserve the list of additionals vinculated with this lane
begin/end of the description of an edge
A road/street connecting two junctions (netedit-version)
Definition: GNEEdge.h:56
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:81
GNELane * myLane
we need to preserve the lane because it maybe the target of GNEChange_Attribute commands ...
bool myForward
we group antagonistic commands (create junction/delete junction) and keep them apart by this flag ...
Definition: GNEChange.h:86
void deleteAdditional(GNEAdditional *additional)
delete additional element of GNENet container
Definition: GNENet.cpp:2036
bool unreferenced()
check if object ins&#39;t referenced
SumoXMLTag getTag() const
get XML Tag assigned to this object