Eclipse SUMO - Simulation of Urban MObility
GNEChange_Additional.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
14 // A network change in which a busStop is created or deleted
15 /****************************************************************************/
16 
17 // ===========================================================================
18 // included modules
19 // ===========================================================================
20 #include <config.h>
21 
22 #include <netedit/GNENet.h>
28 #include <netedit/GNEViewNet.h>
29 
30 #include "GNEChange_Additional.h"
31 
32 // ===========================================================================
33 // FOX-declarations
34 // ===========================================================================
35 FXIMPLEMENT_ABSTRACT(GNEChange_Additional, GNEChange, nullptr, 0)
36 
37 // ===========================================================================
38 // member method definitions
39 // ===========================================================================
40 
42  GNEChange(additional->getViewNet()->getNet(), forward),
43  myAdditional(additional),
44  myParentEdges(myAdditional->getParentEdges()),
45  myParentLanes(myAdditional->getParentLanes()),
46  myParentShapes(myAdditional->getParentShapes()),
47  myParentAdditionals(myAdditional->getParentAdditionals()),
48  myParentDemandElements(myAdditional->getParentDemandElements()),
49  myChildEdges(myAdditional->getChildEdges()),
50  myChildLanes(myAdditional->getChildLanes()),
51  myChildShapes(myAdditional->getChildShapes()),
52  myChildAdditionals(myAdditional->getChildAdditionals()),
53  myChildDemandElements(myAdditional->getChildDemandElements()) {
54  myAdditional->incRef("GNEChange_Additional");
55 }
56 
57 
59  assert(myAdditional);
60  myAdditional->decRef("GNEChange_Additional");
61  if (myAdditional->unreferenced()) {
62  // show extra information for tests
63  WRITE_DEBUG("Deleting unreferenced " + myAdditional->getTagStr() + " '" + myAdditional->getID() + "'");
64  // make sure that additional isn't in net before removing
67  // Remove additional from parent elements
68  for (const auto& i : myParentEdges) {
69  i->removeChildAdditional(myAdditional);
70  }
71  for (const auto& i : myParentLanes) {
72  i->removeChildAdditional(myAdditional);
73  }
74  for (const auto& i : myParentShapes) {
75  i->removeChildAdditional(myAdditional);
76  }
77  for (const auto& i : myParentAdditionals) {
78  i->removeChildAdditional(myAdditional);
79  }
80  for (const auto& i : myParentDemandElements) {
81  i->removeChildAdditional(myAdditional);
82  }
83  // Remove additional from child elements
84  for (const auto& i : myChildEdges) {
85  i->removeParentAdditional(myAdditional);
86  }
87  for (const auto& i : myChildLanes) {
88  i->removeParentAdditional(myAdditional);
89  }
90  for (const auto& i : myChildShapes) {
91  i->removeChildAdditional(myAdditional);
92  }
93  for (const auto& i : myChildAdditionals) {
94  i->removeParentAdditional(myAdditional);
95  }
96  for (const auto& i : myChildDemandElements) {
97  i->removeParentAdditional(myAdditional);
98  }
99  }
100  delete myAdditional;
101  }
102 }
103 
104 
105 void
107  if (myForward) {
108  // show extra information for tests
109  WRITE_DEBUG("Removing " + myAdditional->getTagStr() + " '" + myAdditional->getID() + "' in GNEChange_Additional");
110  // delete additional from net
112  // Remove additional from parent elements
113  for (const auto& i : myParentEdges) {
114  i->removeChildAdditional(myAdditional);
115  }
116  for (const auto& i : myParentLanes) {
117  i->removeChildAdditional(myAdditional);
118  }
119  for (const auto& i : myParentShapes) {
120  i->removeChildAdditional(myAdditional);
121  }
122  for (const auto& i : myParentAdditionals) {
123  i->removeChildAdditional(myAdditional);
124  }
125  for (const auto& i : myParentDemandElements) {
126  i->removeChildAdditional(myAdditional);
127  }
128  // Remove additional from child elements
129  for (const auto& i : myChildEdges) {
130  i->removeParentAdditional(myAdditional);
131  }
132  for (const auto& i : myChildLanes) {
133  i->removeParentAdditional(myAdditional);
134  }
135  for (const auto& i : myChildShapes) {
136  i->removeChildAdditional(myAdditional);
137  }
138  for (const auto& i : myChildAdditionals) {
139  i->removeParentAdditional(myAdditional);
140  }
141  for (const auto& i : myChildDemandElements) {
142  i->removeParentAdditional(myAdditional);
143  }
144  } else {
145  // show extra information for tests
146  WRITE_DEBUG("Adding " + myAdditional->getTagStr() + " '" + myAdditional->getID() + "' in GNEChange_Additional");
147  // insert additional into net
149  // add additional in parent elements
150  for (const auto& i : myParentEdges) {
151  i->addChildAdditional(myAdditional);
152  }
153  for (const auto& i : myParentLanes) {
154  i->addChildAdditional(myAdditional);
155  }
156  for (const auto& i : myParentShapes) {
157  i->addChildAdditional(myAdditional);
158  }
159  for (const auto& i : myParentAdditionals) {
160  i->addChildAdditional(myAdditional);
161  }
162  for (const auto& i : myParentDemandElements) {
163  i->addChildAdditional(myAdditional);
164  }
165  // add additional in child elements
166  for (const auto& i : myChildEdges) {
167  i->addParentAdditional(myAdditional);
168  }
169  for (const auto& i : myChildLanes) {
170  i->addParentAdditional(myAdditional);
171  }
172  for (const auto& i : myChildShapes) {
173  i->addParentAdditional(myAdditional);
174  }
175  for (const auto& i : myChildAdditionals) {
176  i->addParentAdditional(myAdditional);
177  }
178  for (const auto& i : myChildDemandElements) {
179  i->addParentAdditional(myAdditional);
180  }
181  }
182  // Requiere always save additionals
184 }
185 
186 
187 void
189  if (myForward) {
190  // show extra information for tests
191  WRITE_DEBUG("Adding " + myAdditional->getTagStr() + " '" + myAdditional->getID() + "' in GNEChange_Additional");
192  // insert additional into net
194  // add additional in parent elements
195  for (const auto& i : myParentEdges) {
196  i->addChildAdditional(myAdditional);
197  }
198  for (const auto& i : myParentLanes) {
199  i->addChildAdditional(myAdditional);
200  }
201  for (const auto& i : myParentShapes) {
202  i->addChildAdditional(myAdditional);
203  }
204  for (const auto& i : myParentAdditionals) {
205  i->addChildAdditional(myAdditional);
206  }
207  for (const auto& i : myParentDemandElements) {
208  i->addChildAdditional(myAdditional);
209  }
210  // add additional in child elements
211  for (const auto& i : myChildEdges) {
212  i->addParentAdditional(myAdditional);
213  }
214  for (const auto& i : myChildLanes) {
215  i->addParentAdditional(myAdditional);
216  }
217  for (const auto& i : myChildShapes) {
218  i->addParentAdditional(myAdditional);
219  }
220  for (const auto& i : myChildAdditionals) {
221  i->addParentAdditional(myAdditional);
222  }
223  for (const auto& i : myChildDemandElements) {
224  i->addParentAdditional(myAdditional);
225  }
226  } else {
227  // show extra information for tests
228  WRITE_DEBUG("Removing " + myAdditional->getTagStr() + " '" + myAdditional->getID() + "' in GNEChange_Additional");
229  // delete additional from net
231  // Remove additional from parent elements
232  for (const auto& i : myParentEdges) {
233  i->removeChildAdditional(myAdditional);
234  }
235  for (const auto& i : myParentLanes) {
236  i->removeChildAdditional(myAdditional);
237  }
238  for (const auto& i : myParentShapes) {
239  i->removeChildAdditional(myAdditional);
240  }
241  for (const auto& i : myParentAdditionals) {
242  i->removeChildAdditional(myAdditional);
243  }
244  for (const auto& i : myParentDemandElements) {
245  i->removeChildAdditional(myAdditional);
246  }
247  // Remove additional from child elements
248  for (const auto& i : myChildEdges) {
249  i->removeParentAdditional(myAdditional);
250  }
251  for (const auto& i : myChildLanes) {
252  i->removeParentAdditional(myAdditional);
253  }
254  for (const auto& i : myChildShapes) {
255  i->removeChildAdditional(myAdditional);
256  }
257  for (const auto& i : myChildAdditionals) {
258  i->removeParentAdditional(myAdditional);
259  }
260  for (const auto& i : myChildDemandElements) {
261  i->removeParentAdditional(myAdditional);
262  }
263  }
264  // Requiere always save additionals
266 }
267 
268 
269 FXString
271  if (myForward) {
272  return ("Undo create " + myAdditional->getTagStr()).c_str();
273  } else {
274  return ("Undo delete " + myAdditional->getTagStr()).c_str();
275  }
276 }
277 
278 
279 FXString
281  if (myForward) {
282  return ("Redo create " + myAdditional->getTagStr()).c_str();
283  } else {
284  return ("Redo delete " + myAdditional->getTagStr()).c_str();
285  }
286 }
GNENet::insertAdditional
void insertAdditional(GNEAdditional *additional)
Insert a additional element int GNENet container.
Definition: GNENet.cpp:2709
GNEAdditional
An Element which don't belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:48
GNEReferenceCounter::unreferenced
bool unreferenced()
check if object ins't referenced
Definition: GNEReferenceCounter.h:78
GNEAdditional.h
GNEAttributeCarrier::getID
const std::string getID() const
function to support debugging
Definition: GNEAttributeCarrier.cpp:1289
GNEChange_Additional::redo
void redo()
redo action
Definition: GNEChange_Additional.cpp:188
GNEChange::myForward
bool myForward
we group antagonistic commands (create junction/delete junction) and keep them apart by this flag
Definition: GNEChange.h:80
GNEChange_Additional
Definition: GNEChange_Additional.h:44
GNENet::deleteAdditional
void deleteAdditional(GNEAdditional *additional, GNEUndoList *undoList)
remove additional
Definition: GNENet.cpp:628
GNEChange_Additional::myChildLanes
const std::vector< GNELane * > & myChildLanes
reference to vector of child lanes
Definition: GNEChange_Additional.h:97
GNEChange_Additional::myParentAdditionals
const std::vector< GNEAdditional * > & myParentAdditionals
reference to vector of parent additionals
Definition: GNEChange_Additional.h:88
GNEChange_Additional::myParentEdges
const std::vector< GNEEdge * > & myParentEdges
reference to vector of parent edges
Definition: GNEChange_Additional.h:79
GNEChange_Additional::myParentDemandElements
const std::vector< GNEDemandElement * > & myParentDemandElements
reference to vector of parent demand elements
Definition: GNEChange_Additional.h:91
GNEChange_Additional.h
GNEChange_Additional::myChildAdditionals
const std::vector< GNEAdditional * > & myChildAdditionals
reference to vector of child additional
Definition: GNEChange_Additional.h:103
GNENet::requireSaveAdditionals
void requireSaveAdditionals(bool value)
inform that additionals has to be saved
Definition: GNENet.cpp:2236
GNEDemandElement.h
GNEViewNet.h
GNEEdge.h
GNEChange::myNet
GNENet * myNet
the net to which operations shall be applied or which shall be informed about gui updates (we are not...
Definition: GNEChange.h:75
GNEReferenceCounter::decRef
void decRef(const std::string &debugMsg="")
Decrease reference.
Definition: GNEReferenceCounter.h:52
GNELane.h
GNEChange_Additional::myParentLanes
const std::vector< GNELane * > & myParentLanes
reference to vector of parent lanes
Definition: GNEChange_Additional.h:82
GNEChange_Additional::~GNEChange_Additional
~GNEChange_Additional()
Destructor.
Definition: GNEChange_Additional.cpp:58
GNEShape.h
GNENet::additionalExist
bool additionalExist(GNEAdditional *additional) const
return true if additional exist (use pointer instead ID)
Definition: GNENet.cpp:2697
GNEChange_Additional::myChildDemandElements
const std::vector< GNEDemandElement * > & myChildDemandElements
reference to vector of child demand elements
Definition: GNEChange_Additional.h:106
GNEChange_Additional::myParentShapes
const std::vector< GNEShape * > & myParentShapes
reference to vector of parent shapes
Definition: GNEChange_Additional.h:85
GNEChange_Additional::myChildShapes
const std::vector< GNEShape * > & myChildShapes
reference to vector of child shapes
Definition: GNEChange_Additional.h:100
GNEChange_Additional::myAdditional
GNEAdditional * myAdditional
full information regarding the additional element that is to be created/deleted
Definition: GNEChange_Additional.h:76
config.h
GNEChange_Additional::undoName
FXString undoName() const
return undoName
Definition: GNEChange_Additional.cpp:270
GNEAttributeCarrier::getTagStr
const std::string & getTagStr() const
get tag assigned to this object in string format
Definition: GNEAttributeCarrier.cpp:1267
GNEChange_Additional::undo
void undo()
undo action
Definition: GNEChange_Additional.cpp:106
GNEChange
the function-object for an editing operation (abstract base)
Definition: GNEChange.h:42
GNEChange_Additional::myChildEdges
const std::vector< GNEEdge * > & myChildEdges
reference to vector of child edges
Definition: GNEChange_Additional.h:94
GNEChange_Additional::redoName
FXString redoName() const
get Redo name
Definition: GNEChange_Additional.cpp:280
WRITE_DEBUG
#define WRITE_DEBUG(msg)
Definition: MsgHandler.h:284
GNENet.h