Eclipse SUMO - Simulation of Urban MObility
GNEChange_DemandElement.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 /****************************************************************************/
15 // A network change in which a busStop is created or deleted
16 /****************************************************************************/
17 
18 // ===========================================================================
19 // included modules
20 // ===========================================================================
21 #include <config.h>
22 
23 #include <netedit/GNENet.h>
30 #include <netedit/GNEViewParent.h>
31 #include <netedit/GNEViewNet.h>
32 
34 
35 // ===========================================================================
36 // FOX-declarations
37 // ===========================================================================
38 FXIMPLEMENT_ABSTRACT(GNEChange_DemandElement, GNEChange, nullptr, 0)
39 
40 // ===========================================================================
41 // member method definitions
42 // ===========================================================================
43 
45  GNEChange(demandElement->getViewNet()->getNet(), forward),
46  myDemandElement(demandElement),
47  myEdgeParents(demandElement->getEdgeParents()),
48  myLaneParents(demandElement->getLaneParents()),
49  myShapeParents(demandElement->getShapeParents()),
50  myAdditionalParents(demandElement->getAdditionalParents()),
51  myDemandElementParents(demandElement->getDemandElementParents()),
52  myEdgeChildren(demandElement->getEdgeChildren()),
53  myLaneChildren(demandElement->getLaneChildren()),
54  myShapeChildren(demandElement->getShapeChildren()),
55  myAdditionalChildren(demandElement->getAdditionalChildren()),
56  myDemandElementChildren(demandElement->getDemandElementChildren()) {
57  myDemandElement->incRef("GNEChange_DemandElement");
58 }
59 
60 
62  assert(myDemandElement);
63  myDemandElement->decRef("GNEChange_DemandElement");
65  // show extra information for tests
66  WRITE_DEBUG("Deleting unreferenced " + myDemandElement->getTagStr() + " '" + myDemandElement->getID() + "'");
67  // make sure that element isn't in net before removing
70  // Remove element from parent elements
71  for (const auto& i : myEdgeParents) {
72  i->removeDemandElementChild(myDemandElement);
73  }
74  for (const auto& i : myLaneParents) {
75  i->removeDemandElementChild(myDemandElement);
76  }
77  for (const auto& i : myShapeParents) {
78  i->removeDemandElementChild(myDemandElement);
79  }
80  for (const auto& i : myAdditionalParents) {
81  i->removeDemandElementChild(myDemandElement);
82  }
83  for (const auto& i : myDemandElementParents) {
84  i->removeDemandElementChild(myDemandElement);
85  }
86  // Remove element from child elements
87  for (const auto& i : myEdgeChildren) {
88  i->removeDemandElementParent(myDemandElement);
89  }
90  for (const auto& i : myLaneChildren) {
91  i->removeDemandElementParent(myDemandElement);
92  }
93  for (const auto& i : myShapeChildren) {
94  i->removeDemandElementParent(myDemandElement);
95  }
96  for (const auto& i : myAdditionalChildren) {
97  i->removeDemandElementParent(myDemandElement);
98  }
99  for (const auto& i : myDemandElementChildren) {
100  i->removeDemandElementParent(myDemandElement);
101  }
102  }
103  delete myDemandElement;
104  }
105 }
106 
107 
108 void
110  if (myForward) {
111  // show extra information for tests
112  WRITE_DEBUG("Removing " + myDemandElement->getTagStr() + " '" + myDemandElement->getID() + "' in GNEChange_DemandElement");
113  // delete demand element from net
115  // Remove element from parent elements
116  for (const auto& i : myEdgeParents) {
117  i->removeDemandElementChild(myDemandElement);
118  }
119  for (const auto& i : myLaneParents) {
120  i->removeDemandElementChild(myDemandElement);
121  }
122  for (const auto& i : myShapeParents) {
123  i->removeDemandElementChild(myDemandElement);
124  }
125  for (const auto& i : myAdditionalParents) {
126  i->removeDemandElementChild(myDemandElement);
127  }
128  for (const auto& i : myDemandElementParents) {
129  i->removeDemandElementChild(myDemandElement);
130  }
131  // Remove element from child elements
132  for (const auto& i : myEdgeChildren) {
133  i->removeDemandElementParent(myDemandElement);
134  }
135  for (const auto& i : myLaneChildren) {
136  i->removeDemandElementParent(myDemandElement);
137  }
138  for (const auto& i : myShapeChildren) {
139  i->removeDemandElementParent(myDemandElement);
140  }
141  for (const auto& i : myAdditionalChildren) {
142  i->removeDemandElementParent(myDemandElement);
143  }
144  for (const auto& i : myDemandElementChildren) {
145  i->removeDemandElementParent(myDemandElement);
146  }
147  } else {
148  // show extra information for tests
149  WRITE_DEBUG("Adding " + myDemandElement->getTagStr() + " '" + myDemandElement->getID() + "' in GNEChange_DemandElement");
150  // insert demand element into net
152  // add element in parent elements
153  for (const auto& i : myEdgeParents) {
154  i->addDemandElementChild(myDemandElement);
155  }
156  for (const auto& i : myLaneParents) {
157  i->addDemandElementChild(myDemandElement);
158  }
159  for (const auto& i : myShapeParents) {
160  i->addDemandElementChild(myDemandElement);
161  }
162  for (const auto& i : myAdditionalParents) {
163  i->addDemandElementChild(myDemandElement);
164  }
165  for (const auto& i : myDemandElementParents) {
166  i->addDemandElementChild(myDemandElement);
167  }
168  // add element in child elements
169  for (const auto& i : myEdgeChildren) {
170  i->addDemandElementParent(myDemandElement);
171  }
172  for (const auto& i : myLaneChildren) {
173  i->addDemandElementParent(myDemandElement);
174  }
175  for (const auto& i : myShapeChildren) {
176  i->addDemandElementParent(myDemandElement);
177  }
178  for (const auto& i : myAdditionalChildren) {
179  i->addDemandElementParent(myDemandElement);
180  }
181  for (const auto& i : myDemandElementChildren) {
182  i->addDemandElementParent(myDemandElement);
183  }
184  }
185  // update vehicle type selector if demand element is a VType and vehicle type Frame is shown
188  }
189  // Requiere always save elements
191 }
192 
193 
194 void
196  if (myForward) {
197  // show extra information for tests
198  WRITE_DEBUG("Adding " + myDemandElement->getTagStr() + " '" + myDemandElement->getID() + "' in GNEChange_DemandElement");
199  // insert demand element into net
201  // add element in parent elements
202  for (const auto& i : myEdgeParents) {
203  i->addDemandElementChild(myDemandElement);
204  }
205  for (const auto& i : myLaneParents) {
206  i->addDemandElementChild(myDemandElement);
207  }
208  for (const auto& i : myShapeParents) {
209  i->addDemandElementChild(myDemandElement);
210  }
211  for (const auto& i : myAdditionalParents) {
212  i->addDemandElementChild(myDemandElement);
213  }
214  for (const auto& i : myDemandElementParents) {
215  i->addDemandElementChild(myDemandElement);
216  }
217  // add element in child elements
218  for (const auto& i : myEdgeChildren) {
219  i->addDemandElementParent(myDemandElement);
220  }
221  for (const auto& i : myLaneChildren) {
222  i->addDemandElementParent(myDemandElement);
223  }
224  for (const auto& i : myShapeChildren) {
225  i->addDemandElementParent(myDemandElement);
226  }
227  for (const auto& i : myAdditionalChildren) {
228  i->addDemandElementParent(myDemandElement);
229  }
230  for (const auto& i : myDemandElementChildren) {
231  i->addDemandElementParent(myDemandElement);
232  }
233  } else {
234  // show extra information for tests
235  WRITE_DEBUG("Removing " + myDemandElement->getTagStr() + " '" + myDemandElement->getID() + "' in GNEChange_DemandElement");
236  // delete demand element from net
238  // Remove element from parent elements
239  for (const auto& i : myEdgeParents) {
240  i->removeDemandElementChild(myDemandElement);
241  }
242  for (const auto& i : myLaneParents) {
243  i->removeDemandElementChild(myDemandElement);
244  }
245  for (const auto& i : myShapeParents) {
246  i->removeDemandElementChild(myDemandElement);
247  }
248  for (const auto& i : myAdditionalParents) {
249  i->removeDemandElementChild(myDemandElement);
250  }
251  for (const auto& i : myDemandElementParents) {
252  i->removeDemandElementChild(myDemandElement);
253  }
254  // Remove element from child elements
255  for (const auto& i : myEdgeChildren) {
256  i->removeDemandElementParent(myDemandElement);
257  }
258  for (const auto& i : myLaneChildren) {
259  i->removeDemandElementParent(myDemandElement);
260  }
261  for (const auto& i : myShapeChildren) {
262  i->removeDemandElementParent(myDemandElement);
263  }
264  for (const auto& i : myAdditionalChildren) {
265  i->removeDemandElementParent(myDemandElement);
266  }
267  for (const auto& i : myDemandElementChildren) {
268  i->removeDemandElementParent(myDemandElement);
269  }
270  }
271  // update vehicle type selector if demand element is a VType and vehicle type Frame is shown
274  }
275  // Requiere always save elements
277 }
278 
279 
280 FXString
282  if (myForward) {
283  return ("Undo create " + myDemandElement->getTagStr()).c_str();
284  } else {
285  return ("Undo delete " + myDemandElement->getTagStr()).c_str();
286  }
287 }
288 
289 
290 FXString
292  if (myForward) {
293  return ("Redo create " + myDemandElement->getTagStr()).c_str();
294  } else {
295  return ("Redo delete " + myDemandElement->getTagStr()).c_str();
296  }
297 }
const std::vector< GNEAdditional * > & myAdditionalChildren
reference to vector of additional children
the function-object for an editing operation (abstract base)
Definition: GNEChange.h:43
const std::vector< GNEAdditional * > & myAdditionalParents
reference to vector of additional parents
description of a vehicle type
const std::vector< GNEShape * > & myShapeChildren
reference to vector of shape children
GNEVehicleTypeFrame * getVehicleTypeFrame() const
get frame for GNE_DMODE_VEHICLETYPE
void deleteDemandElement(GNEDemandElement *demandElement, GNEUndoList *undoList)
remove demand element
Definition: GNENet.cpp:638
GNEViewParent * getViewParent() const
get the net object
Definition: GNEViewNet.cpp:921
const std::vector< GNEEdge * > & myEdgeParents
reference to vector of edge parents
VehicleTypeSelector * getVehicleTypeSelector() const
get vehicle type selector
const std::vector< GNEDemandElement * > & myDemandElementParents
reference to vector of demand element parents
const std::vector< GNELane * > & myLaneChildren
reference to vector of lane children
const std::vector< GNELane * > & myLaneParents
reference to vector of lane parents
const std::vector< GNEDemandElement * > & myDemandElementChildren
reference to vector of demand element children
void refreshVehicleTypeSelector()
refresh vehicle type selector
FXString undoName() const
return undoName
SumoXMLTag getTag() const
get Tag vinculated with this attribute Property
void requiereSaveDemandElements(bool value)
inform that demand elements has to be saved
Definition: GNENet.cpp:2342
const std::string getID() const
function to support debugging
const std::vector< GNEShape * > & myShapeParents
reference to vector of shape parents
#define WRITE_DEBUG(msg)
Definition: MsgHandler.h:246
const std::vector< GNEEdge * > & myEdgeChildren
reference to vector of edge children
void decRef(const std::string &debugMsg="")
Decrease reference.
GNENet * myNet
the net to which operations shall be applied or which shall be informed about gui updates (we are not...
Definition: GNEChange.h:76
const std::string & getTagStr() const
get tag assigned to this object in string format
FXString redoName() const
get Redo name
GNEDemandElement * myDemandElement
full information regarding the demand element element 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:81
const TagProperties & getTagProperty() const
get Tag Property assigned to this object
bool demandElementExist(GNEDemandElement *demandElement) const
return true if demand element exist (use pointer instead ID)
Definition: GNENet.cpp:2715
void insertDemandElement(GNEDemandElement *demandElement)
Insert a demand element element int GNENet container.
Definition: GNENet.cpp:2727
bool unreferenced()
check if object ins&#39;t referenced
An Element which don&#39;t belongs to GNENet but has influency in the simulation.
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:2067