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-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 
31 
32 #include "GNEChange_Edge.h"
33 #include "GNENet.h"
34 #include "GNEEdge.h"
35 #include "GNELane.h"
36 #include "GNERerouter.h"
37 #include "GNEViewNet.h"
38 
39 
40 // ===========================================================================
41 // FOX-declarations
42 // ===========================================================================
43 FXIMPLEMENT_ABSTRACT(GNEChange_Edge, GNEChange, NULL, 0)
44 
45 // ===========================================================================
46 // member method definitions
47 // ===========================================================================
48 
49 
50 GNEChange_Edge::GNEChange_Edge(GNEEdge* edge, bool forward):
52  GNEChange(edge->getNet(), forward),
53  myEdge(edge) {
54  assert(myNet);
55  edge->incRef("GNEChange_Edge");
56  // Save additionals of edge
57  myAdditionalChilds = myEdge->getAdditionalChilds();
58  // save rerouters of edge
59  myGNERerouters = myEdge->getGNERerouters();
60 }
61 
62 
64  assert(myEdge);
65  myEdge->decRef("GNEChange_Edge");
66  if (myEdge->unreferenced()) {
67  // show extra information for tests
69  WRITE_WARNING("Deleting unreferenced " + toString(myEdge->getTag()) + " '" + myEdge->getID() + "'");
70  }
71  delete myEdge;
72  }
73 }
74 
75 
76 void
78  if (myForward) {
79  // show extra information for tests
81  WRITE_WARNING("Deleting " + toString(myEdge->getTag()) + " '" + myEdge->getID() + "'");
82  }
83  // delete edge from net
85  // 1 - Remove additionals childs of this edge
86  for (std::vector<GNEAdditional*>::iterator i = myAdditionalChilds.begin(); i != myAdditionalChilds.end(); i++) {
88  }
89  // 2 - Remove references to this edge in GNERerouters
90  for (std::vector<GNERerouter*>::iterator i = myGNERerouters.begin(); i != myGNERerouters.end(); i++) {
91  (*i)->removeEdgeChild(myEdge);
92  }
93  } else {
94  // show extra information for tests
96  WRITE_WARNING("Adding " + toString(myEdge->getTag()) + " '" + myEdge->getID() + "'");
97  }
98  // insert edge into net
100  // 1 - add additionals childs of this edge
101  for (std::vector<GNEAdditional*>::iterator i = myAdditionalChilds.begin(); i != myAdditionalChilds.end(); i++) {
102  myNet->insertAdditional(*i);
103  }
104  // 2 - Add references to this edge in GNERerouters
105  for (std::vector<GNERerouter*>::iterator i = myGNERerouters.begin(); i != myGNERerouters.end(); i++) {
106  (*i)->addEdgeChild(myEdge);
107  }
108  }
109 }
110 
111 
112 void
114  if (myForward) {
115  // show extra information for tests
117  WRITE_WARNING("Adding " + toString(myEdge->getTag()) + " '" + myEdge->getID() + "'");
118  }
119  // insert edge into net
121  // 1 - Add additionals childs of this edge
122  for (std::vector<GNEAdditional*>::iterator i = myAdditionalChilds.begin(); i != myAdditionalChilds.end(); i++) {
123  myNet->insertAdditional(*i);
124  }
125  // 2 - Add references to this edge in GNERerouters
126  for (std::vector<GNERerouter*>::iterator i = myGNERerouters.begin(); i != myGNERerouters.end(); i++) {
127  (*i)->addEdgeChild(myEdge);
128  }
129  } else {
130  // show extra information for tests
132  WRITE_WARNING("Deleting " + toString(myEdge->getTag()) + " '" + myEdge->getID() + "'");
133  }
134  // delte edge from net
136  // 1 - Remove additionals childs of this edge
137  for (std::vector<GNEAdditional*>::iterator i = myAdditionalChilds.begin(); i != myAdditionalChilds.end(); i++) {
138  myNet->deleteAdditional(*i);
139  }
140  // 2 - Remove references to this edge in GNERerouters
141  for (std::vector<GNERerouter*>::iterator i = myGNERerouters.begin(); i != myGNERerouters.end(); i++) {
142  (*i)->removeEdgeChild(myEdge);
143  }
144  }
145 }
146 
147 
148 FXString
150  if (myForward) {
151  return ("Undo create " + toString(SUMO_TAG_EDGE)).c_str();
152  } else {
153  return ("Undo delete " + toString(SUMO_TAG_EDGE)).c_str();
154  }
155 }
156 
157 
158 FXString
160  if (myForward) {
161  return ("Redo create " + toString(SUMO_TAG_EDGE)).c_str();
162  } else {
163  return ("Redo delete " + toString(SUMO_TAG_EDGE)).c_str();
164  }
165 }
the function-object for an editing operation (abstract base)
Definition: GNEChange.h:49
void undo()
undo action
GNENet * getNet() const
get Net in which this element is placed
void insertEdge(GNEEdge *edge)
inserts a single edge into the net and into the underlying netbuild-container
Definition: GNENet.cpp:1466
std::vector< GNEAdditional * > myAdditionalChilds
we need to preserve the list of additionals vinculated with this edge
FXString undoName() const
return undoName
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:200
bool isTestingModeEnabled() const
check if netedit is running in testing mode
Definition: GNEViewNet.cpp:405
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:56
const std::string getID() const
function to support debugging
void decRef(const std::string &debugMsg="")
begin/end of the description of an edge
A road/street connecting two junctions (netedit-version)
Definition: GNEEdge.h:57
FXString redoName() const
get Redo name
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
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:1275
void deleteSingleEdge(GNEEdge *edge)
deletes a single edge
Definition: GNENet.cpp:1525
std::vector< GNERerouter * > myGNERerouters
we need to preserve the list of rerouters in which this edge is a child
void insertAdditional(GNEAdditional *additional, bool hardFail=true)
Insert a additional element previously created in GNEAdditionalHandler.
Definition: GNENet.cpp:1258
~GNEChange_Edge()
Destructor.
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:1165
SumoXMLTag getTag() const
get XML Tag assigned to this object