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  myAdditionalSets(myLane->getAdditionalSets()) {
59  myEdge->incRef("GNEChange_Lane");
60  if (myLane) {
61  // non-zero pointer is only passsed in case of removal
62  assert(!forward);
63  myLane->incRef("GNEChange_Lane");
64  } else {
65  assert(forward);
66  }
67 }
68 
69 
71  assert(myEdge);
72  myEdge->decRef("GNEChange_Lane");
73  if (myEdge->unreferenced()) {
74  delete myEdge;
75  }
76  if (myLane) {
77  myLane->decRef("GNEChange_Lane");
78  if (myLane->unreferenced()) {
79  delete myLane;
80  }
81  }
82 }
83 
84 
86  if (myForward) {
88  // Remove references to this edge in their AdditionalSets
89  for(std::vector<GNEAdditionalSet*>::iterator i = myAdditionalSets.begin(); i != myAdditionalSets.end(); i++) {
90  (*i)->removeLaneChild(myLane);
91  // Remove additional from net if the number of childs is >= 0
92  if((*i)->getNumberOfEdgeChilds() == 0) {
94  }
95  }
96  } else {
98  // Add references to this edge in their AdditionalSets
99  for(std::vector<GNEAdditionalSet*>::iterator i = myAdditionalSets.begin(); i != myAdditionalSets.end(); i++) {
100  myNet->insertAdditional(*i, false);
101  (*i)->addLaneChild(myLane);
102  }
103  }
104 }
105 
106 
108  if (myForward) {
110  // Add references to this edge in their AdditionalSets
111  for(std::vector<GNEAdditionalSet*>::iterator i = myAdditionalSets.begin(); i != myAdditionalSets.end(); i++) {
112  myNet->insertAdditional(*i, false);
113  (*i)->addLaneChild(myLane);
114  }
115  } else {
117  // Remove references to this edge in their AdditionalSets
118  for(std::vector<GNEAdditionalSet*>::iterator i = myAdditionalSets.begin(); i != myAdditionalSets.end(); i++) {
119  (*i)->removeLaneChild(myLane);
120  // Remove additional from net if the number of childs is >= 0
121  if((*i)->getNumberOfEdgeChilds() == 0) {
122  myNet->deleteAdditional(*i);
123  }
124  }
125  }
126 }
127 
128 
129 FXString GNEChange_Lane::undoName() const {
130  if (myForward) {
131  return ("Undo create lane");
132  } else {
133  return ("Undo delete lane");
134  }
135 }
136 
137 
138 FXString GNEChange_Lane::redoName() const {
139  if (myForward) {
140  return ("Redo create lane");
141  } else {
142  return ("Redo delete lane");
143  }
144 }
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