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-2018 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>
27 #include <netedit/GNEViewParent.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 additionals of lane
55  myAdditionalChilds = myLane->getAdditionalChilds();
56  // Save POILanes of lane
57  myShapeChilds = myLane->getShapeChilds();
58  } else {
59  assert(forward);
60  }
61 }
62 
63 
65  assert(myEdge);
66  myEdge->decRef("GNEChange_Lane");
67  if (myEdge->unreferenced()) {
68  // show extra information for tests
69  WRITE_DEBUG("Deleting unreferenced " + myEdge->getTagStr() + " '" + myEdge->getID() + "' in GNEChange_Lane");
70  delete myEdge;
71  }
72  if (myLane) {
73  myLane->decRef("GNEChange_Lane");
74  if (myLane->unreferenced()) {
75  // show extra information for tests
76  WRITE_DEBUG("Deleting unreferenced " + myLane->getTagStr() + " '" + myLane->getID() + "' in GNEChange_Lane");
77  delete myLane;
78  }
79  }
80 }
81 
82 
83 void
85  if (myForward) {
86  // show extra information for tests
87  if (myLane != nullptr) {
88  WRITE_DEBUG("Removing " + myLane->getTagStr() + " '" + myLane->getID() + "' from " + toString(SUMO_TAG_EDGE));
89  } else {
90  WRITE_DEBUG("Removing nullptr " + toString(SUMO_TAG_LANE) + " from " + toString(SUMO_TAG_EDGE));
91  }
92  // remove lane from edge
93  myEdge->removeLane(myLane, false);
94  // Remove additionals vinculated with this lane
95  for (auto i : myAdditionalChilds) {
97  }
98  // Remove Shapes vinculated with this lane of net
99  for (auto i : myShapeChilds) {
100  myNet->removeShape(i);
101  }
102  } else {
103  // show extra information for tests
104  if (myLane != nullptr) {
105  WRITE_DEBUG("Adding " + myLane->getTagStr() + " '" + myLane->getID() + "' into " + toString(SUMO_TAG_EDGE));
106  } else {
107  WRITE_DEBUG("Adding nullptr " + toString(SUMO_TAG_LANE) + " into " + toString(SUMO_TAG_EDGE));
108  }
109  // add lane and their attributes to edge
110  // (lane removal is reverted, no need to recompute connections)
111  myEdge->addLane(myLane, myLaneAttrs, false);
112  // add additional sets vinculated with this lane of net
113  for (auto i : myAdditionalChilds) {
115  }
116  // add Shapes vinculated with this lane in net
117  for (auto i : myShapeChilds) {
118  myNet->removeShape(i);
119  }
120  }
121  // check if inspector frame has to be updated
122  if (myNet->getViewNet()->getViewParent()->getInspectorFrame()->shown()) {
124  }
125  // enable save netElements
126  myNet->requiereSaveNet(true);
127 }
128 
129 
130 void
132  if (myForward) {
133  // show extra information for tests
134  if (myLane != nullptr) {
135  WRITE_DEBUG("Adding " + myLane->getTagStr() + " '" + myLane->getID() + "' into " + toString(SUMO_TAG_EDGE));
136  } else {
137  WRITE_DEBUG("Adding nullptr " + toString(SUMO_TAG_LANE) + " into " + toString(SUMO_TAG_EDGE));
138  }
139  // add lane and their attributes to edge
141  // add additional vinculated with this lane of net
142  for (auto i : myAdditionalChilds) {
144  }
145  // add shapes vinculated with this lane in net
146  for (auto i : myShapeChilds) {
147  myNet->removeShape(i);
148  }
149  } else {
150  // show extra information for tests
151  if (myLane != nullptr) {
152  WRITE_DEBUG("Removing " + myLane->getTagStr() + " '" + myLane->getID() + "' from " + toString(SUMO_TAG_EDGE));
153  } else {
154  WRITE_DEBUG("Removing nullptr " + toString(SUMO_TAG_LANE) + " from " + toString(SUMO_TAG_EDGE));
155  }
156  // remove lane from edge
158  // Remove additional vinculated with this lane of net
159  for (auto i : myAdditionalChilds) {
161  }
162  // Remove shapes vinculated with this lane of net
163  for (auto i : myShapeChilds) {
164  myNet->removeShape(i);
165  }
166  }
167  // check if inspector frame has to be updated
168  if (myNet->getViewNet()->getViewParent()->getInspectorFrame()->shown()) {
170  }
171  // enable save netElements
172  myNet->requiereSaveNet(true);
173 }
174 
175 
176 FXString
178  if (myForward) {
179  return ("Undo create " + toString(SUMO_TAG_LANE)).c_str();
180  } else {
181  return ("Undo delete " + toString(SUMO_TAG_LANE)).c_str();
182  }
183 }
184 
185 
186 FXString
188  if (myForward) {
189  return ("Redo create " + toString(SUMO_TAG_LANE)).c_str();
190  } else {
191  return ("Redo delete " + toString(SUMO_TAG_LANE)).c_str();
192  }
193 }
void insertAdditional(GNEAdditional *additional)
Insert a additional element int GNENet container.
Definition: GNENet.cpp:2144
const NBEdge::Lane myLaneAttrs
we need to preserve the attributes explicitly because they are not contained withing GNELane itself ...
~GNEChange_Lane()
Destructor.
GNEInspectorFrame * getInspectorFrame() const
get frame for GNE_MODE_INSPECT
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:1360
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:2370
GNEViewParent * getViewParent() const
get the net object
The representation of a single edge during network building.
Definition: NBEdge.h:65
void undo()
undo action
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
Definition: GNELane.h:47
void removeLane(GNELane *lane, bool recomputeConnections)
the number of lanes by one. argument is only used to increase robustness (assertions) ...
Definition: GNEEdge.cpp:1413
bool deleteAdditional(GNEAdditional *additional)
delete additional element of GNENet container
Definition: GNENet.cpp:2167
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:49
GNEFrame::ACHierarchy * getACHierarchy() const
get ACHierarchy
void refreshACHierarchy()
refresh ACHierarchy
Definition: GNEFrame.cpp:594
C++ TraCI client API implementation.
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
#define WRITE_DEBUG(msg)
Definition: MsgHandler.h:248
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: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
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:837
bool myForward
we group antagonistic commands (create junction/delete junction) and keep them apart by this flag ...
Definition: GNEChange.h:81
bool unreferenced()
check if object ins&#39;t referenced
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:1730