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 
30 #include <cassert>
31 #include "GNEChange_Lane.h"
32 #include "GNEEdge.h"
33 #include "GNELane.h"
34 #include "GNENet.h"
35 
36 #ifdef CHECK_MEMORY_LEAKS
37 #include <foreign/nvwa/debug_new.h>
38 #endif
39 
40 
41 // ===========================================================================
42 // FOX-declarations
43 // ===========================================================================
44 FXIMPLEMENT_ABSTRACT(GNEChange_Lane, GNEChange, NULL, 0)
45 
46 // ===========================================================================
47 // member method definitions
48 // ===========================================================================
49 
50 
51 GNEChange_Lane::GNEChange_Lane(GNEEdge* edge, GNELane* lane, const NBEdge::Lane& laneAttrs, bool forward):
53  GNEChange(edge->getNet(), forward),
54  myEdge(edge),
55  myLane(lane),
56  myLaneAttrs(laneAttrs) {
57  assert(myNet);
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  } 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 
85 void
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  } else {
95  // add additional sets vinculated with this lane of net
96  for (std::vector<GNEAdditional*>::iterator i = myAdditionalChilds.begin(); i != myAdditionalChilds.end(); i++) {
98  }
99  }
100 }
101 
102 
103 void
105  if (myForward) {
107  // add additional sets vinculated with this lane of net
108  for (std::vector<GNEAdditional*>::iterator i = myAdditionalChilds.begin(); i != myAdditionalChilds.end(); i++) {
109  myNet->insertAdditional(*i);
110  }
111  } else {
113  // Remove additional sets vinculated with this lane of net
114  for (std::vector<GNEAdditional*>::iterator i = myAdditionalChilds.begin(); i != myAdditionalChilds.end(); i++) {
115  myNet->deleteAdditional(*i);
116  }
117  }
118 }
119 
120 
121 FXString
123  if (myForward) {
124  return ("Undo create " + toString(SUMO_TAG_LANE)).c_str();
125  } else {
126  return ("Undo delete " + toString(SUMO_TAG_LANE)).c_str();
127  }
128 }
129 
130 
131 FXString
133  if (myForward) {
134  return ("Redo create " + toString(SUMO_TAG_LANE)).c_str();
135  } else {
136  return ("Redo delete " + toString(SUMO_TAG_LANE)).c_str();
137  }
138 }
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:820
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
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
FXString redoName() const
get Redo name
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:55
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:858
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: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:1223
void insertAdditional(GNEAdditional *additional, bool hardFail=true)
Insert a additional element previously created in GNEAdditionalHandler.
Definition: GNENet.cpp:1207