SUMO - Simulation of Urban MObility
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  myAdditionalSetsEdge(myEdge->getAdditionalSets()) {
56  for (std::vector<GNELane*>::const_iterator i = myEdge->getLanes().begin(); i != myEdge->getLanes().end(); i++) {
57  myAdditionalSetsLanes[*i] = (*i)->getAdditionalSets();
58  }
59  assert(myNet);
60  edge->incRef("GNEChange_Edge");
61 }
62 
63 
65  assert(myEdge);
66  myEdge->decRef("GNEChange_Edge");
67  if (myEdge->unreferenced()) {
68  delete myEdge;
69  }
70 }
71 
72 
74  if (myForward) {
76  // Remove references to this edge in their AdditionalSets
77  for (std::vector<GNEAdditionalSet*>::iterator i = myAdditionalSetsEdge.begin(); i != myAdditionalSetsEdge.end(); i++) {
78  (*i)->removeEdgeChild(myEdge);
79  // Remove additional from net if the number of childs is >= 0
80  if ((*i)->getNumberOfEdgeChilds() == 0) {
82  }
83  }
84  // Remove references to every lane of edge in their additionalSets
85  for (std::map<GNELane*, std::vector<GNEAdditionalSet*> >::iterator i = myAdditionalSetsLanes.begin(); i != myAdditionalSetsLanes.end(); i++) {
86  for (std::vector<GNEAdditionalSet*>::iterator j = i->second.begin(); j != i->second.end(); j++) {
87  (*j)->removeLaneChild(i->first);
88  // Remove additional from net if the number of childs is >= 0
89  if ((*j)->getNumberOfLaneChilds() == 0) {
91  }
92  }
93  }
94  } else {
96  // Add references to this edge in their AdditionalSets
97  for (std::vector<GNEAdditionalSet*>::iterator i = myAdditionalSetsEdge.begin(); i != myAdditionalSetsEdge.end(); i++) {
98  myNet->insertAdditional(*i, false);
99  (*i)->addEdgeChild(myEdge);
100  }
101  // Add references to every lane of edge in their additionalSets
102  for (std::map<GNELane*, std::vector<GNEAdditionalSet*> >::iterator i = myAdditionalSetsLanes.begin(); i != myAdditionalSetsLanes.end(); i++) {
103  for (std::vector<GNEAdditionalSet*>::iterator j = i->second.begin(); j != i->second.end(); j++) {
104  myNet->insertAdditional(*j, false);
105  (*j)->addLaneChild(i->first);
106  }
107  }
108  }
109 }
110 
111 
113  if (myForward) {
115  // Add references to this edge in their AdditionalSets
116  for (std::vector<GNEAdditionalSet*>::iterator i = myAdditionalSetsEdge.begin(); i != myAdditionalSetsEdge.end(); i++) {
117  myNet->insertAdditional(*i, false);
118  (*i)->addEdgeChild(myEdge);
119  }
120  // Add references to every lane of edge in their additionalSets
121  for (std::map<GNELane*, std::vector<GNEAdditionalSet*> >::iterator i = myAdditionalSetsLanes.begin(); i != myAdditionalSetsLanes.end(); i++) {
122  for (std::vector<GNEAdditionalSet*>::iterator j = i->second.begin(); j != i->second.end(); j++) {
123  myNet->insertAdditional(*j, false);
124  (*j)->addLaneChild(i->first);
125  }
126  }
127  } else {
129  // Remove references to this edge in their AdditionalSets
130  for (std::vector<GNEAdditionalSet*>::iterator i = myAdditionalSetsEdge.begin(); i != myAdditionalSetsEdge.end(); i++) {
131  (*i)->removeEdgeChild(myEdge);
132  // Remove additional from net if the number of childs is >= 0
133  if ((*i)->getNumberOfEdgeChilds() == 0) {
134  myNet->deleteAdditional(*i);
135  }
136  }
137  // Remove references to every lane of edge in their additionalSets
138  for (std::map<GNELane*, std::vector<GNEAdditionalSet*> >::iterator i = myAdditionalSetsLanes.begin(); i != myAdditionalSetsLanes.end(); i++) {
139  for (std::vector<GNEAdditionalSet*>::iterator j = i->second.begin(); j != i->second.end(); j++) {
140  (*j)->removeLaneChild(i->first);
141  // Remove if from net if the number of childs is >= 0
142  if ((*j)->getNumberOfLaneChilds() == 0) {
143  myNet->deleteAdditional(*j);
144  }
145  }
146  }
147  }
148 }
149 
150 
151 FXString GNEChange_Edge::undoName() const {
152  if (myForward) {
153  return ("Undo create edge");
154  } else {
155  return ("Undo delete edge");
156  }
157 }
158 
159 
160 FXString GNEChange_Edge::redoName() const {
161  if (myForward) {
162  return ("Redo create edge");
163  } else {
164  return ("Redo delete edge");
165  }
166 }
the function-object for an editing operation (abstract base)
Definition: GNEChange.h:49
void undo()
undo action
std::map< GNELane *, std::vector< GNEAdditionalSet * > > myAdditionalSetsLanes
additional sets vinculated with the lanes of edge
A NBNetBuilder extended by visualisation and editing capabilities.
Definition: GNENet.h:86
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
Definition: GNELane.h:54
void insertEdge(GNEEdge *edge)
inserts a single edge into the net and into the underlying netbuild-container
Definition: GNENet.cpp:1150
FXString redoName() const
get Redo name
FXString undoName() const
return undoName
void decRef(const std::string &debugMsg="")
A road/street connecting two junctions (netedit-version)
Definition: GNEEdge.h:54
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::vector< GNEAdditionalSet * > myAdditionalSetsEdge
additional sets vinculated with this 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:1065
void deleteSingleEdge(GNEEdge *edge)
deletes a single edge
Definition: GNENet.cpp:1202
void insertAdditional(GNEAdditional *additional, bool hardFail=true)
Insert a additional element previously created in GNEAdditionalHandler.
Definition: GNENet.cpp:1046
~GNEChange_Edge()
Destructor.