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(0, 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  myAdditionalSets = myLane->getAdditionalSets();
63  } else {
64  assert(forward);
65  }
66 }
67 
68 
70  assert(myEdge);
71  myEdge->decRef("GNEChange_Lane");
72  if (myEdge->unreferenced()) {
73  delete myEdge;
74  }
75  if (myLane) {
76  myLane->decRef("GNEChange_Lane");
77  if (myLane->unreferenced()) {
78  delete myLane;
79  }
80  }
81 }
82 
83 
85  if (myForward) {
87  // Remove references to this edge in their AdditionalSets
88  for (std::vector<GNEAdditionalSet*>::iterator i = myAdditionalSets.begin(); i != myAdditionalSets.end(); i++) {
89  (*i)->removeLaneChild(myLane);
90  // Remove additional from net if the number of childs is >= 0
91  if ((*i)->getNumberOfEdgeChilds() == 0) {
93  }
94  }
95  } else {
97  // Add references to this edge in their AdditionalSets
98  for (std::vector<GNEAdditionalSet*>::iterator i = myAdditionalSets.begin(); i != myAdditionalSets.end(); i++) {
99  myNet->insertAdditional(*i, false);
100  (*i)->addLaneChild(myLane);
101  }
102  }
103 }
104 
105 
107  if (myForward) {
109  // Add references to this edge in their AdditionalSets
110  for (std::vector<GNEAdditionalSet*>::iterator i = myAdditionalSets.begin(); i != myAdditionalSets.end(); i++) {
111  myNet->insertAdditional(*i, false);
112  (*i)->addLaneChild(myLane);
113  }
114  } else {
116  // Remove references to this edge in their AdditionalSets
117  for (std::vector<GNEAdditionalSet*>::iterator i = myAdditionalSets.begin(); i != myAdditionalSets.end(); i++) {
118  (*i)->removeLaneChild(myLane);
119  // Remove additional from net if the number of childs is >= 0
120  if ((*i)->getNumberOfEdgeChilds() == 0) {
121  myNet->deleteAdditional(*i);
122  }
123  }
124  }
125 }
126 
127 
128 FXString GNEChange_Lane::undoName() const {
129  if (myForward) {
130  return ("Undo create lane");
131  } else {
132  return ("Undo delete lane");
133  }
134 }
135 
136 
137 FXString GNEChange_Lane::redoName() const {
138  if (myForward) {
139  return ("Redo create lane");
140  } else {
141  return ("Redo delete lane");
142  }
143 }
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:734
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
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:54
std::vector< GNEAdditionalSet * > myAdditionalSets
additional sets vinculated with this lane
FXString redoName() const
get Redo name
FXString undoName() const
return undoName
void removeLane(GNELane *lane)
the number of lanes by one. argument is only used to increase robustness (assertions) ...
Definition: GNEEdge.cpp:767
void redo()
redo action
void decRef(const std::string &debugMsg="")
A road/street connecting two junctions (netedit-version)
Definition: GNEEdge.h:54
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:1065
void insertAdditional(GNEAdditional *additional, bool hardFail=true)
Insert a additional element previously created in GNEAdditionalHandler.
Definition: GNENet.cpp:1046