SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
GNEChange_Edge.cpp
Go to the documentation of this file.
1 /****************************************************************************/
7 // A network change in which a single junction 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 "GNEChange_Edge.h"
31 #include "GNENet.h"
32 #include "GNEEdge.h"
33 #include "GNELane.h"
34 #include "GNEAdditionalSet.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_Edge, GNEChange, NULL, 0)
45 
46 // ===========================================================================
47 // member method definitions
48 // ===========================================================================
49 
50 
51 // Constructor for creating an edge
52 GNEChange_Edge::GNEChange_Edge(GNENet* net, GNEEdge* edge, bool forward):
53  GNEChange(net, forward),
54  myEdge(edge) {
55  assert(myNet);
56  edge->incRef("GNEChange_Edge");
57  // Save additionals of edge
58  myAdditionalChilds = myEdge->getAdditionalChilds();
59  myAdditionalSetParents = myEdge->getAdditionalSets();
60  // Iterate over lanes vinculated to edge
61  for (std::vector<GNELane*>::const_iterator i = myEdge->getLanes().begin(); i != myEdge->getLanes().end(); i++) {
62  // Save additionals vinculated to lane
63  myAdditionalLanes[*i] = (*i)->getAdditionalChilds();
64  myAdditionalSetsLanes[*i] = (*i)->getAdditionalSetParents();
65  }
66 }
67 
68 
70  assert(myEdge);
71  myEdge->decRef("GNEChange_Edge");
72  if (myEdge->unreferenced()) {
73  delete myEdge;
74  }
75 }
76 
77 
79  if (myForward) {
81  // 1 - Remove additional sets vinculated with this edge of net
82  for (std::vector<GNEAdditional*>::iterator i = myAdditionalChilds.begin(); i != myAdditionalChilds.end(); i++) {
84  }
85  // 2 - Remove references to this edge in their AdditionalSets
86  for (std::vector<GNEAdditionalSet*>::iterator i = myAdditionalSetParents.begin(); i != myAdditionalSetParents.end(); i++) {
87  (*i)->removeEdgeChild(myEdge);
88  // Remove additional from net if the number of childs is >= 0
89  if ((*i)->getNumberOfEdgeChilds() == 0) {
91  }
92  }
93  // 3 - Remove of the net all additional child of the lanes of edge
94  for (std::map<GNELane*, std::vector<GNEAdditional*> >::iterator i = myAdditionalLanes.begin(); i != myAdditionalLanes.end(); i++) {
95  for (std::vector<GNEAdditional*>::iterator j = i->second.begin(); j != i->second.end(); j++) {
97  }
98  }
99  // 4 - Remove references to every lane of edge in their additionalSets
100  for (std::map<GNELane*, std::vector<GNEAdditionalSet*> >::iterator i = myAdditionalSetsLanes.begin(); i != myAdditionalSetsLanes.end(); i++) {
101  for (std::vector<GNEAdditionalSet*>::iterator j = i->second.begin(); j != i->second.end(); j++) {
102  (*j)->removeLaneChild(i->first);
103  // Remove additional from net if the number of childs is >= 0
104  if ((*j)->getNumberOfLaneChilds() == 0) {
105  myNet->deleteAdditional(*j);
106  }
107  }
108  }
109  } else {
111  // 1 - add additional sets vinculated with this edge to the net
112  for (std::vector<GNEAdditional*>::iterator i = myAdditionalChilds.begin(); i != myAdditionalChilds.end(); i++) {
113  myNet->insertAdditional(*i);
114  }
115  // 2 - Add references to this edge in their AdditionalSets
116  for (std::vector<GNEAdditionalSet*>::iterator i = myAdditionalSetParents.begin(); i != myAdditionalSetParents.end(); i++) {
117  myNet->insertAdditional(*i, false);
118  (*i)->addEdgeChild(myEdge);
119  }
120  // 3 - add in the net all additional child of the lanes of edge
121  for (std::map<GNELane*, std::vector<GNEAdditional*> >::iterator i = myAdditionalLanes.begin(); i != myAdditionalLanes.end(); i++) {
122  for (std::vector<GNEAdditional*>::iterator j = i->second.begin(); j != i->second.end(); j++) {
123  myNet->insertAdditional(*j);
124  }
125  }
126  // 4 - Add references to every lane of edge in their additionalSets
127  for (std::map<GNELane*, std::vector<GNEAdditionalSet*> >::iterator i = myAdditionalSetsLanes.begin(); i != myAdditionalSetsLanes.end(); i++) {
128  for (std::vector<GNEAdditionalSet*>::iterator j = i->second.begin(); j != i->second.end(); j++) {
129  myNet->insertAdditional(*j, false);
130  (*j)->addLaneChild(i->first);
131  }
132  }
133  }
134 }
135 
136 
138  if (myForward) {
140  // 1 - Add additional sets vinculated with this edge to the net
141  for (std::vector<GNEAdditional*>::iterator i = myAdditionalChilds.begin(); i != myAdditionalChilds.end(); i++) {
142  myNet->insertAdditional(*i);
143  }
144  // 2 - Add references to this edge in their AdditionalSets
145  for (std::vector<GNEAdditionalSet*>::iterator i = myAdditionalSetParents.begin(); i != myAdditionalSetParents.end(); i++) {
146  myNet->insertAdditional(*i, false);
147  (*i)->addEdgeChild(myEdge);
148  }
149  // 3 - Add in the net all additional child of the lanes of edge
150  for (std::map<GNELane*, std::vector<GNEAdditional*> >::iterator i = myAdditionalLanes.begin(); i != myAdditionalLanes.end(); i++) {
151  for (std::vector<GNEAdditional*>::iterator j = i->second.begin(); j != i->second.end(); j++) {
152  myNet->insertAdditional(*j);
153  }
154  }
155  // 4 - Add references to every lane of edge in their additionalSets
156  for (std::map<GNELane*, std::vector<GNEAdditionalSet*> >::iterator i = myAdditionalSetsLanes.begin(); i != myAdditionalSetsLanes.end(); i++) {
157  for (std::vector<GNEAdditionalSet*>::iterator j = i->second.begin(); j != i->second.end(); j++) {
158  myNet->insertAdditional(*j, false);
159  (*j)->addLaneChild(i->first);
160  }
161  }
162  } else {
164  // 1 - Remove additional sets vinculated with this edge of net
165  for (std::vector<GNEAdditional*>::iterator i = myAdditionalChilds.begin(); i != myAdditionalChilds.end(); i++) {
166  myNet->deleteAdditional(*i);
167  }
168  // 2 - Remove references to this edge in their AdditionalSets
169  for (std::vector<GNEAdditionalSet*>::iterator i = myAdditionalSetParents.begin(); i != myAdditionalSetParents.end(); i++) {
170  (*i)->removeEdgeChild(myEdge);
171  // Remove additional from net if the number of childs is >= 0
172  if ((*i)->getNumberOfEdgeChilds() == 0) {
173  myNet->deleteAdditional(*i);
174  }
175  }
176  // 3 - Remove of the net all additional child of the lanes of edge
177  for (std::map<GNELane*, std::vector<GNEAdditional*> >::iterator i = myAdditionalLanes.begin(); i != myAdditionalLanes.end(); i++) {
178  for (std::vector<GNEAdditional*>::iterator j = i->second.begin(); j != i->second.end(); j++) {
179  myNet->deleteAdditional(*j);
180  }
181  }
182  // 4 - Remove references to every lane of edge in their additionalSets
183  for (std::map<GNELane*, std::vector<GNEAdditionalSet*> >::iterator i = myAdditionalSetsLanes.begin(); i != myAdditionalSetsLanes.end(); i++) {
184  for (std::vector<GNEAdditionalSet*>::iterator j = i->second.begin(); j != i->second.end(); j++) {
185  (*j)->removeLaneChild(i->first);
186  // Remove if from net if the number of childs is >= 0
187  if ((*j)->getNumberOfLaneChilds() == 0) {
188  myNet->deleteAdditional(*j);
189  }
190  }
191  }
192  }
193 }
194 
195 
196 FXString GNEChange_Edge::undoName() const {
197  if (myForward) {
198  return ("Undo create edge");
199  } else {
200  return ("Undo delete edge");
201  }
202 }
203 
204 
205 FXString GNEChange_Edge::redoName() const {
206  if (myForward) {
207  return ("Redo create edge");
208  } else {
209  return ("Redo delete edge");
210  }
211 }
the function-object for an editing operation (abstract base)
Definition: GNEChange.h:49
void undo()
undo action
std::map< GNELane *, std::vector< GNEAdditionalSet * > > myAdditionalSetsLanes
we need to preserve the additional sets in which the edge of lanes are childs
A NBNetBuilder extended by visualisation and editing capabilities.
Definition: GNENet.h:87
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
Definition: GNELane.h:55
void insertEdge(GNEEdge *edge)
inserts a single edge into the net and into the underlying netbuild-container
Definition: GNENet.cpp:1307
std::vector< GNEAdditional * > myAdditionalChilds
we need to preserve the list of additionals vinculated with this edge
FXString redoName() const
get Redo name
FXString undoName() const
return undoName
std::vector< GNEAdditionalSet * > myAdditionalSetParents
we need to preserve the list of additional sets in which this edge is a child
void decRef(const std::string &debugMsg="")
A road/street connecting two junctions (netedit-version)
Definition: GNEEdge.h:55
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
void redo()
redo action
std::map< GNELane *, std::vector< GNEAdditional * > > myAdditionalLanes
we need to preserve additional vinculated with the lanes of edge
GNEEdge * myEdge
full information regarding the edge that is to be created/deleted
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 deleteSingleEdge(GNEEdge *edge)
deletes a single edge
Definition: GNENet.cpp:1361
void insertAdditional(GNEAdditional *additional, bool hardFail=true)
Insert a additional element previously created in GNEAdditionalHandler.
Definition: GNENet.cpp:1187
~GNEChange_Edge()
Destructor.