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-2016 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 
30 #include <cassert>
31 #include "GNEChange_Lane.h"
32 #include "GNEEdge.h"
33 #include "GNELane.h"
34 #include "GNENet.h"
35 #include "GNEAdditionalSet.h"
36 
37 #ifdef CHECK_MEMORY_LEAKS
38 #include <foreign/nvwa/debug_new.h>
39 #endif
40 
41 
42 // ===========================================================================
43 // FOX-declarations
44 // ===========================================================================
45 FXIMPLEMENT_ABSTRACT(GNEChange_Lane, GNEChange, NULL, 0)
46 
47 // ===========================================================================
48 // member method definitions
49 // ===========================================================================
50 
51 
52 // Constructor for creating an edge
53 GNEChange_Lane::GNEChange_Lane(GNEEdge* edge, GNELane* lane, const NBEdge::Lane& laneAttrs, bool forward):
54  GNEChange(edge->getNet(), forward),
55  myEdge(edge),
56  myLane(lane),
57  myLaneAttrs(laneAttrs) {
58  myEdge->incRef("GNEChange_Lane");
59  if (myLane) {
60  // non-zero pointer is passsed in case of removal or duplication
61  myLane->incRef("GNEChange_Lane");
62  // Save additionals of lane
63  myAdditionalChilds = myLane->getAdditionalChilds();
64  myAdditionalSetParents = myLane->getAdditionalSetParents();
65  } else {
66  assert(forward);
67  }
68 }
69 
70 
72  assert(myEdge);
73  myEdge->decRef("GNEChange_Lane");
74  if (myEdge->unreferenced()) {
75  delete myEdge;
76  }
77  if (myLane) {
78  myLane->decRef("GNEChange_Lane");
79  if (myLane->unreferenced()) {
80  delete myLane;
81  }
82  }
83 }
84 
85 
87  if (myForward) {
89  // Remove additional sets vinculated with this lane of net
90  for (std::vector<GNEAdditional*>::iterator i = myAdditionalChilds.begin(); i != myAdditionalChilds.end(); i++) {
92  }
93  // Remove references to this edge in their AdditionalSets
94  for (std::vector<GNEAdditionalSet*>::iterator i = myAdditionalSetParents.begin(); i != myAdditionalSetParents.end(); i++) {
95  (*i)->removeLaneChild(myLane);
96  // Remove additional from net if the number of childs is >= 0
97  if ((*i)->getNumberOfEdgeChilds() == 0) {
99  }
100  }
101  } else {
103  // add additional sets vinculated with this lane of net
104  for (std::vector<GNEAdditional*>::iterator i = myAdditionalChilds.begin(); i != myAdditionalChilds.end(); i++) {
105  myNet->insertAdditional(*i);
106  }
107  // Add references to this edge in their AdditionalSets
108  for (std::vector<GNEAdditionalSet*>::iterator i = myAdditionalSetParents.begin(); i != myAdditionalSetParents.end(); i++) {
109  myNet->insertAdditional(*i, false);
110  (*i)->addLaneChild(myLane);
111  }
112  }
113 }
114 
115 
117  if (myForward) {
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  // Add references to this edge in their AdditionalSets
124  for (std::vector<GNEAdditionalSet*>::iterator i = myAdditionalSetParents.begin(); i != myAdditionalSetParents.end(); i++) {
125  myNet->insertAdditional(*i, false);
126  (*i)->addLaneChild(myLane);
127  }
128  } else {
130  // Remove additional sets vinculated with this lane of net
131  for (std::vector<GNEAdditional*>::iterator i = myAdditionalChilds.begin(); i != myAdditionalChilds.end(); i++) {
132  myNet->deleteAdditional(*i);
133  }
134  // Remove references to this edge in their AdditionalSets
135  for (std::vector<GNEAdditionalSet*>::iterator i = myAdditionalSetParents.begin(); i != myAdditionalSetParents.end(); i++) {
136  (*i)->removeLaneChild(myLane);
137  // Remove additional from net if the number of childs is >= 0
138  if ((*i)->getNumberOfEdgeChilds() == 0) {
139  myNet->deleteAdditional(*i);
140  }
141  }
142  }
143 }
144 
145 
146 FXString GNEChange_Lane::undoName() const {
147  if (myForward) {
148  return ("Undo create lane");
149  } else {
150  return ("Undo delete lane");
151  }
152 }
153 
154 
155 FXString GNEChange_Lane::redoName() const {
156  if (myForward) {
157  return ("Redo create lane");
158  } else {
159  return ("Redo delete lane");
160  }
161 }
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:801
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
FXString redoName() const
get Redo name
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:55
std::vector< GNEAdditionalSet * > myAdditionalSetParents
we need to preserve the list of additional sets in which this lane is a child
void removeLane(GNELane *lane)
the number of lanes by one. argument is only used to increase robustness (assertions) ...
Definition: GNEEdge.cpp:839
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:55
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:1214
void insertAdditional(GNEAdditional *additional, bool hardFail=true)
Insert a additional element previously created in GNEAdditionalHandler.
Definition: GNENet.cpp:1187