SUMO - Simulation of Urban MObility
GNEChange_Lane.cpp
Go to the documentation of this file.
1 /****************************************************************************/
7 // A network change in which a single lane is created or deleted
8 /****************************************************************************/
9 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
10 // Copyright (C) 2001-2017 DLR (http://www.dlr.de/) and contributors
11 /****************************************************************************/
12 //
13 // This file is part of SUMO.
14 // SUMO is free software: you can redistribute it and/or modify
15 // it under the terms of the GNU General Public License as published by
16 // the Free Software Foundation, either version 3 of the License, or
17 // (at your option) any later version.
18 //
19 /****************************************************************************/
20 
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #ifdef _MSC_VER
25 #include <windows_config.h>
26 #else
27 #include <config.h>
28 #endif
29 
31 #include <cassert>
32 
33 #include "GNEChange_Lane.h"
34 #include "GNEEdge.h"
35 #include "GNELane.h"
36 #include "GNENet.h"
37 #include "GNEViewNet.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  } 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
74  WRITE_WARNING("Deleting unreferenced " + toString(myEdge->getTag()) + " '" + myEdge->getID() + "'");
75  }
76  delete myEdge;
77  }
78  if (myLane) {
79  myLane->decRef("GNEChange_Lane");
80  if (myLane->unreferenced()) {
81  // show extra information for tests
83  WRITE_WARNING("Deleting unreferenced " + toString(myLane->getTag()) + " '" + myLane->getID() + "'");
84  }
85  delete myLane;
86  }
87  }
88 }
89 
90 
91 void
93  if (myForward) {
94  // show extra information for tests
96  if (myLane != NULL) {
97  WRITE_WARNING("Deleting " + toString(myLane->getTag()) + " '" + myLane->getID() + "'");
98  } else {
99  WRITE_WARNING("Deleting NULL " + toString(SUMO_TAG_LANE));
100  }
101  }
102  // remove lane from edge
104  // Remove additional sets vinculated with this lane of net
105  for (std::vector<GNEAdditional*>::iterator i = myAdditionalChilds.begin(); i != myAdditionalChilds.end(); i++) {
106  myNet->deleteAdditional(*i);
107  }
108  } else {
109  // show extra information for tests
111  if (myLane != NULL) {
112  WRITE_WARNING("Adding " + toString(myLane->getTag()) + " '" + myLane->getID() + "'");
113  } else {
114  WRITE_WARNING("Adding NULL " + toString(SUMO_TAG_LANE));
115  }
116  }
117  // add lane and their attributes to edge
119  // add additional sets vinculated with this lane of net
120  for (std::vector<GNEAdditional*>::iterator i = myAdditionalChilds.begin(); i != myAdditionalChilds.end(); i++) {
121  myNet->insertAdditional(*i);
122  }
123  }
124 }
125 
126 
127 void
129  if (myForward) {
130  // show extra information for tests
132  if (myLane != NULL) {
133  WRITE_WARNING("Adding " + toString(myLane->getTag()) + " '" + myLane->getID() + "'");
134  } else {
135  WRITE_WARNING("Adding NULL " + toString(SUMO_TAG_LANE));
136  }
137  }
138  // add lane and their attributes to edge
140  // add additional sets vinculated with this lane of net
141  for (std::vector<GNEAdditional*>::iterator i = myAdditionalChilds.begin(); i != myAdditionalChilds.end(); i++) {
142  myNet->insertAdditional(*i);
143  }
144  } else {
145  // show extra information for tests
147  if (myLane != NULL) {
148  WRITE_WARNING("Deleting " + toString(myLane->getTag()) + " '" + myLane->getID() + "'");
149  } else {
150  WRITE_WARNING("Deleting NULL " + toString(SUMO_TAG_LANE));
151  }
152  }
153  // remove lane from edge
155  // Remove additional sets vinculated with this lane of net
156  for (std::vector<GNEAdditional*>::iterator i = myAdditionalChilds.begin(); i != myAdditionalChilds.end(); i++) {
157  myNet->deleteAdditional(*i);
158  }
159  }
160 }
161 
162 
163 FXString
165  if (myForward) {
166  return ("Undo create " + toString(SUMO_TAG_LANE)).c_str();
167  } else {
168  return ("Undo delete " + toString(SUMO_TAG_LANE)).c_str();
169  }
170 }
171 
172 
173 FXString
175  if (myForward) {
176  return ("Redo create " + toString(SUMO_TAG_LANE)).c_str();
177  } else {
178  return ("Redo delete " + toString(SUMO_TAG_LANE)).c_str();
179  }
180 }
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:910
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:49
begin/end of the description of a single lane
FXString redoName() const
get Redo name
GNENet * getNet() const
get Net in which this element is placed
FXString undoName() const
return undoName
The representation of a single edge during network building.
Definition: NBEdge.h:71
void undo()
undo action
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
Definition: GNELane.h:54
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:200
bool isTestingModeEnabled() const
check if netedit is running in testing mode
Definition: GNEViewNet.cpp:405
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:56
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:948
void redo()
redo action
void decRef(const std::string &debugMsg="")
std::vector< GNEAdditional * > myAdditionalChilds
we need to preserve the list of additionals vinculated with this lane
A road/street connecting two junctions (netedit-version)
Definition: GNEEdge.h:57
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:82
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:87
void deleteAdditional(GNEAdditional *additional)
delete additional element previously inserted
Definition: GNENet.cpp:1275
void insertAdditional(GNEAdditional *additional, bool hardFail=true)
Insert a additional element previously created in GNEAdditionalHandler.
Definition: GNENet.cpp:1258
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:1165
SumoXMLTag getTag() const
get XML Tag assigned to this object