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 
24 #include <netedit/GNENet.h>
25 #include <netedit/GNEViewNet.h>
29 #include <netedit/GNEViewParent.h>
30 #include <cassert>
31 
32 #include "GNEChange_Lane.h"
33 
34 
35 // ===========================================================================
36 // FOX-declarations
37 // ===========================================================================
38 FXIMPLEMENT_ABSTRACT(GNEChange_Lane, GNEChange, nullptr, 0)
39 
40 // ===========================================================================
41 // member method definitions
42 // ===========================================================================
43 
44 
45 GNEChange_Lane::GNEChange_Lane(GNEEdge* edge, GNELane* lane, const NBEdge::Lane& laneAttrs, bool forward, bool recomputeConnections):
47  GNEChange(edge->getNet(), forward),
48  myEdge(edge),
49  myLane(lane),
50  myLaneAttrs(laneAttrs),
51  myRecomputeConnections(recomputeConnections) {
52  assert(myNet);
53  myEdge->incRef("GNEChange_Lane");
54  if (myLane) {
55  // non-zero pointer is passsed in case of removal or duplication
56  myLane->incRef("GNEChange_Lane");
57  // Save additionals of lane
58  myAdditionalChilds = myLane->getAdditionalChilds();
59  // Save POILanes of lane
60  myShapeChilds = myLane->getShapeChilds();
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 " + toString(myEdge->getTag()) + " '" + 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 " + toString(myLane->getTag()) + " '" + 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 " + toString(myLane->getTag()) + " '" + 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 additionals vinculated with this lane
98  for (auto i : myAdditionalChilds) {
100  }
101  // Remove Shapes vinculated with this lane of net
102  for (auto i : myShapeChilds) {
103  myNet->removeShape(i);
104  }
105  } else {
106  // show extra information for tests
107  if (myLane != nullptr) {
108  WRITE_DEBUG("Adding " + toString(myLane->getTag()) + " '" + myLane->getID() + "' into " + toString(SUMO_TAG_EDGE));
109  } else {
110  WRITE_DEBUG("Adding nullptr " + toString(SUMO_TAG_LANE) + " into " + toString(SUMO_TAG_EDGE));
111  }
112  // add lane and their attributes to edge
113  // (lane removal is reverted, no need to recompute connections)
114  myEdge->addLane(myLane, myLaneAttrs, false);
115  // add additional sets vinculated with this lane of net
116  for (auto i : myAdditionalChilds) {
118  }
119  // add Shapes vinculated with this lane in net
120  for (auto i : myShapeChilds) {
121  myNet->removeShape(i);
122  }
123  }
124  // check if inspector frame has to be updated
125  if (myNet->getViewNet()->getViewParent()->getInspectorFrame()->shown()) {
127  }
128  // enable save netElements
129  myNet->requiereSaveNet(true);
130 }
131 
132 
133 void
135  if (myForward) {
136  // show extra information for tests
137  if (myLane != nullptr) {
138  WRITE_DEBUG("Adding " + toString(myLane->getTag()) + " '" + myLane->getID() + "' into " + toString(SUMO_TAG_EDGE));
139  } else {
140  WRITE_DEBUG("Adding nullptr " + toString(SUMO_TAG_LANE) + " into " + toString(SUMO_TAG_EDGE));
141  }
142  // add lane and their attributes to edge
144  // add additional vinculated with this lane of net
145  for (auto i : myAdditionalChilds) {
147  }
148  // add shapes vinculated with this lane in net
149  for (auto i : myShapeChilds) {
150  myNet->removeShape(i);
151  }
152  } else {
153  // show extra information for tests
154  if (myLane != nullptr) {
155  WRITE_DEBUG("Removing " + toString(myLane->getTag()) + " '" + myLane->getID() + "' from " + toString(SUMO_TAG_EDGE));
156  } else {
157  WRITE_DEBUG("Removing nullptr " + toString(SUMO_TAG_LANE) + " from " + toString(SUMO_TAG_EDGE));
158  }
159  // remove lane from edge
161  // Remove additional vinculated with this lane of net
162  for (auto i : myAdditionalChilds) {
164  }
165  // Remove shapes vinculated with this lane of net
166  for (auto i : myShapeChilds) {
167  myNet->removeShape(i);
168  }
169  }
170  // check if inspector frame has to be updated
171  if (myNet->getViewNet()->getViewParent()->getInspectorFrame()->shown()) {
173  }
174  // enable save netElements
175  myNet->requiereSaveNet(true);
176 }
177 
178 
179 FXString
181  if (myForward) {
182  return ("Undo create " + toString(SUMO_TAG_LANE)).c_str();
183  } else {
184  return ("Undo delete " + toString(SUMO_TAG_LANE)).c_str();
185  }
186 }
187 
188 
189 FXString
191  if (myForward) {
192  return ("Redo create " + toString(SUMO_TAG_LANE)).c_str();
193  } else {
194  return ("Redo delete " + toString(SUMO_TAG_LANE)).c_str();
195  }
196 }
void insertAdditional(GNEAdditional *additional)
Insert a additional element int GNENet container.
Definition: GNENet.cpp:2132
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:42
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:1376
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:2348
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:1429
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:117
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:249
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:75
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
void requiereSaveNet(bool value)
inform that net has to be saved
Definition: GNENet.cpp:844
bool myForward
we group antagonistic commands (create junction/delete junction) and keep them apart by this flag ...
Definition: GNEChange.h:80
void deleteAdditional(GNEAdditional *additional)
delete additional element of GNENet container
Definition: GNENet.cpp:2155
bool unreferenced()
check if object ins&#39;t referenced
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:1737
SumoXMLTag getTag() const
get XML Tag assigned to this object