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 /****************************************************************************/
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>
29 #include <netedit/GNEViewParent.h>
30 #include <netedit/GNEViewNet.h>
31 
33 
34 // ===========================================================================
35 // FOX-declarations
36 // ===========================================================================
37 FXIMPLEMENT_ABSTRACT(GNEChange_DemandElement, GNEChange, nullptr, 0)
38 
39 // ===========================================================================
40 // member method definitions
41 // ===========================================================================
42 
44  GNEChange(demandElement->getViewNet()->getNet(), forward),
45  myDemandElement(demandElement),
46  myEdgePath(demandElement->getPathEdges()),
47  myParentEdges(demandElement->getParentEdges()),
48  myParentLanes(demandElement->getParentLanes()),
49  myParentShapes(demandElement->getParentShapes()),
50  myParentAdditionals(demandElement->getParentAdditionals()),
51  myParentDemandElements(demandElement->getParentDemandElements()),
52  myChildEdges(demandElement->getChildEdges()),
53  myChildLanes(demandElement->getChildLanes()),
54  myChildShapes(demandElement->getChildShapes()),
55  myChildAdditionals(demandElement->getChildAdditionals()),
56  myChildDemandElements(demandElement->getChildDemandElements()) {
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 path
71  for (const auto& i : myEdgePath) {
72  i->removePathElement(myDemandElement);
73  }
74  // Remove element from parent elements
75  for (const auto& i : myParentEdges) {
76  i->removeChildDemandElement(myDemandElement);
77  }
78  for (const auto& i : myParentLanes) {
79  i->removeChildDemandElement(myDemandElement);
80  }
81  for (const auto& i : myParentShapes) {
82  i->removeChildDemandElement(myDemandElement);
83  }
84  for (const auto& i : myParentAdditionals) {
85  i->removeChildDemandElement(myDemandElement);
86  }
87  for (const auto& i : myParentDemandElements) {
88  i->removeChildDemandElement(myDemandElement);
89  }
90  // Remove element from child elements
91  for (const auto& i : myChildEdges) {
92  i->removeParentDemandElement(myDemandElement);
93  }
94  for (const auto& i : myChildLanes) {
95  i->removeParentDemandElement(myDemandElement);
96  }
97  for (const auto& i : myChildShapes) {
98  i->removeParentDemandElement(myDemandElement);
99  }
100  for (const auto& i : myChildAdditionals) {
101  i->removeParentDemandElement(myDemandElement);
102  }
103  for (const auto& i : myChildDemandElements) {
104  i->removeParentDemandElement(myDemandElement);
105  }
106  }
107  delete myDemandElement;
108  }
109 }
110 
111 
112 void
114  if (myForward) {
115  // show extra information for tests
116  WRITE_DEBUG("Removing " + myDemandElement->getTagStr() + " '" + myDemandElement->getID() + "' in GNEChange_DemandElement");
117  // delete demand element from net
119  // remove element from path
120  for (const auto& i : myEdgePath) {
121  i->removePathElement(myDemandElement);
122  }
123  // Remove element from parent elements
124  for (const auto& i : myParentEdges) {
125  i->removeChildDemandElement(myDemandElement);
126  }
127  for (const auto& i : myParentLanes) {
128  i->removeChildDemandElement(myDemandElement);
129  }
130  for (const auto& i : myParentShapes) {
131  i->removeChildDemandElement(myDemandElement);
132  }
133  for (const auto& i : myParentAdditionals) {
134  i->removeChildDemandElement(myDemandElement);
135  }
136  for (const auto& i : myParentDemandElements) {
137  i->removeChildDemandElement(myDemandElement);
138  }
139  // Remove element from child elements
140  for (const auto& i : myChildEdges) {
141  i->removeParentDemandElement(myDemandElement);
142  }
143  for (const auto& i : myChildLanes) {
144  i->removeParentDemandElement(myDemandElement);
145  }
146  for (const auto& i : myChildShapes) {
147  i->removeParentDemandElement(myDemandElement);
148  }
149  for (const auto& i : myChildAdditionals) {
150  i->removeParentDemandElement(myDemandElement);
151  }
152  for (const auto& i : myChildDemandElements) {
153  i->removeParentDemandElement(myDemandElement);
154  }
155  } else {
156  // show extra information for tests
157  WRITE_DEBUG("Adding " + myDemandElement->getTagStr() + " '" + myDemandElement->getID() + "' in GNEChange_DemandElement");
158  // insert demand element into net
160  // add element in parent elements
161  for (const auto& i : myParentEdges) {
162  i->addChildDemandElement(myDemandElement);
163  }
164  for (const auto& i : myParentLanes) {
165  i->addChildDemandElement(myDemandElement);
166  }
167  for (const auto& i : myParentShapes) {
168  i->addChildDemandElement(myDemandElement);
169  }
170  for (const auto& i : myParentAdditionals) {
171  i->addChildDemandElement(myDemandElement);
172  }
173  for (const auto& i : myParentDemandElements) {
174  i->addChildDemandElement(myDemandElement);
175  }
176  // add element in child elements
177  for (const auto& i : myChildEdges) {
178  i->addParentDemandElement(myDemandElement);
179  }
180  for (const auto& i : myChildLanes) {
181  i->addParentDemandElement(myDemandElement);
182  }
183  for (const auto& i : myChildShapes) {
184  i->addParentDemandElement(myDemandElement);
185  }
186  for (const auto& i : myChildAdditionals) {
187  i->addParentDemandElement(myDemandElement);
188  }
189  for (const auto& i : myChildDemandElements) {
190  i->addParentDemandElement(myDemandElement);
191  }
192  }
193  // update vehicle type selector if demand element is a VType and vehicle type Frame is shown
196  }
197  // Requiere always save elements
199 }
200 
201 
202 void
204  if (myForward) {
205  // show extra information for tests
206  WRITE_DEBUG("Adding " + myDemandElement->getTagStr() + " '" + myDemandElement->getID() + "' in GNEChange_DemandElement");
207  // insert demand element into net
209  // add element in parent elements
210  for (const auto& i : myParentEdges) {
211  i->addChildDemandElement(myDemandElement);
212  }
213  for (const auto& i : myParentLanes) {
214  i->addChildDemandElement(myDemandElement);
215  }
216  for (const auto& i : myParentShapes) {
217  i->addChildDemandElement(myDemandElement);
218  }
219  for (const auto& i : myParentAdditionals) {
220  i->addChildDemandElement(myDemandElement);
221  }
222  for (const auto& i : myParentDemandElements) {
223  i->addChildDemandElement(myDemandElement);
224  }
225  // add element in child elements
226  for (const auto& i : myChildEdges) {
227  i->addParentDemandElement(myDemandElement);
228  }
229  for (const auto& i : myChildLanes) {
230  i->addParentDemandElement(myDemandElement);
231  }
232  for (const auto& i : myChildShapes) {
233  i->addParentDemandElement(myDemandElement);
234  }
235  for (const auto& i : myChildAdditionals) {
236  i->addParentDemandElement(myDemandElement);
237  }
238  for (const auto& i : myChildDemandElements) {
239  i->addParentDemandElement(myDemandElement);
240  }
241  } else {
242  // show extra information for tests
243  WRITE_DEBUG("Removing " + myDemandElement->getTagStr() + " '" + myDemandElement->getID() + "' in GNEChange_DemandElement");
244  // delete demand element from net
246  // remove element from path
247  for (const auto& i : myEdgePath) {
248  i->removePathElement(myDemandElement);
249  }
250  // Remove element from parent elements
251  for (const auto& i : myParentEdges) {
252  i->removeChildDemandElement(myDemandElement);
253  }
254  for (const auto& i : myParentLanes) {
255  i->removeChildDemandElement(myDemandElement);
256  }
257  for (const auto& i : myParentShapes) {
258  i->removeChildDemandElement(myDemandElement);
259  }
260  for (const auto& i : myParentAdditionals) {
261  i->removeChildDemandElement(myDemandElement);
262  }
263  for (const auto& i : myParentDemandElements) {
264  i->removeChildDemandElement(myDemandElement);
265  }
266  // Remove element from child elements
267  for (const auto& i : myChildEdges) {
268  i->removeParentDemandElement(myDemandElement);
269  }
270  for (const auto& i : myChildLanes) {
271  i->removeParentDemandElement(myDemandElement);
272  }
273  for (const auto& i : myChildShapes) {
274  i->removeParentDemandElement(myDemandElement);
275  }
276  for (const auto& i : myChildAdditionals) {
277  i->removeParentDemandElement(myDemandElement);
278  }
279  for (const auto& i : myChildDemandElements) {
280  i->removeParentDemandElement(myDemandElement);
281  }
282  }
283  // update vehicle type selector if demand element is a VType and vehicle type Frame is shown
286  }
287  // Requiere always save elements
289 }
290 
291 
292 FXString
294  if (myForward) {
295  return ("Undo create " + myDemandElement->getTagStr()).c_str();
296  } else {
297  return ("Undo delete " + myDemandElement->getTagStr()).c_str();
298  }
299 }
300 
301 
302 FXString
304  if (myForward) {
305  return ("Redo create " + myDemandElement->getTagStr()).c_str();
306  } else {
307  return ("Redo delete " + myDemandElement->getTagStr()).c_str();
308  }
309 }
GNEViewParent::getVehicleTypeFrame
GNEVehicleTypeFrame * getVehicleTypeFrame() const
get frame for GNE_DMODE_VEHICLETYPE
Definition: GNEViewParent.cpp:258
GNEDemandElement
An Element which don't belongs to GNENet but has influency in the simulation.
Definition: GNEDemandElement.h:55
GNEReferenceCounter::unreferenced
bool unreferenced()
check if object ins't referenced
Definition: GNEReferenceCounter.h:78
GNEAdditional.h
GNEChange_DemandElement
Definition: GNEChange_DemandElement.h:45
GNEAttributeCarrier::getID
const std::string getID() const
function to support debugging
Definition: GNEAttributeCarrier.cpp:1289
GNEChange_DemandElement::myEdgePath
const std::vector< GNEEdge * > & myEdgePath
reference to edge path vector
Definition: GNEChange_DemandElement.h:80
GNEChange_DemandElement.h
GNEChange::myForward
bool myForward
we group antagonistic commands (create junction/delete junction) and keep them apart by this flag
Definition: GNEChange.h:80
GNEChange_DemandElement::myChildShapes
const std::vector< GNEShape * > & myChildShapes
reference to vector of child shapes
Definition: GNEChange_DemandElement.h:104
GNEChange_DemandElement::undo
void undo()
undo action
Definition: GNEChange_DemandElement.cpp:113
GNEChange_DemandElement::myParentShapes
const std::vector< GNEShape * > & myParentShapes
reference to vector of parent shapes
Definition: GNEChange_DemandElement.h:89
SUMO_TAG_VTYPE
@ SUMO_TAG_VTYPE
description of a vehicle type
Definition: SUMOXMLDefinitions.h:121
GNEChange_DemandElement::myParentAdditionals
const std::vector< GNEAdditional * > & myParentAdditionals
reference to vector of parent additionals
Definition: GNEChange_DemandElement.h:92
GNEChange_DemandElement::undoName
FXString undoName() const
return undoName
Definition: GNEChange_DemandElement.cpp:293
GNEAttributeCarrier::TagProperties::getTag
SumoXMLTag getTag() const
get Tag vinculated with this attribute Property
Definition: GNEAttributeCarrier.cpp:523
GNEAttributeCarrier::getTagProperty
const TagProperties & getTagProperty() const
get Tag Property assigned to this object
Definition: GNEAttributeCarrier.cpp:1273
GNEChange_DemandElement::myParentLanes
const std::vector< GNELane * > & myParentLanes
reference to vector of parent lanes
Definition: GNEChange_DemandElement.h:86
GNENet::requireSaveDemandElements
void requireSaveDemandElements(bool value)
inform that demand elements has to be saved
Definition: GNENet.cpp:2392
GNEDemandElement.h
GNEViewNet.h
GNEChange_DemandElement::redo
void redo()
redo action
Definition: GNEChange_DemandElement.cpp:203
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
GNEChange_DemandElement::myChildDemandElements
const std::vector< GNEDemandElement * > & myChildDemandElements
reference to vector of child demand elements
Definition: GNEChange_DemandElement.h:110
GNELane.h
GNEChange_DemandElement::redoName
FXString redoName() const
get Redo name
Definition: GNEChange_DemandElement.cpp:303
GNENet::getViewNet
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:2117
GNEShape.h
GNEViewParent.h
GNEChange_DemandElement::myDemandElement
GNEDemandElement * myDemandElement
full information regarding the demand element element that is to be created/deleted
Definition: GNEChange_DemandElement.h:77
GNEChange_DemandElement::~GNEChange_DemandElement
~GNEChange_DemandElement()
Destructor.
Definition: GNEChange_DemandElement.cpp:61
GNEVehicleTypeFrame::getVehicleTypeSelector
VehicleTypeSelector * getVehicleTypeSelector() const
get vehicle type selector
Definition: GNEVehicleTypeFrame.cpp:407
GNEChange_DemandElement::myParentDemandElements
const std::vector< GNEDemandElement * > & myParentDemandElements
reference to vector of parent demand elements
Definition: GNEChange_DemandElement.h:95
GNEChange_DemandElement::myChildLanes
const std::vector< GNELane * > & myChildLanes
reference to vector of child lanes
Definition: GNEChange_DemandElement.h:101
GNEVehicleTypeFrame.h
GNEChange_DemandElement::myParentEdges
const std::vector< GNEEdge * > & myParentEdges
reference to vector of parent edges
Definition: GNEChange_DemandElement.h:83
config.h
GNENet::demandElementExist
bool demandElementExist(GNEDemandElement *demandElement) const
return true if demand element exist (use pointer instead ID)
Definition: GNENet.cpp:2765
GNEAttributeCarrier::getTagStr
const std::string & getTagStr() const
get tag assigned to this object in string format
Definition: GNEAttributeCarrier.cpp:1267
GNEChange_DemandElement::myChildEdges
const std::vector< GNEEdge * > & myChildEdges
reference to vector of child edges
Definition: GNEChange_DemandElement.h:98
GNENet::deleteDemandElement
void deleteDemandElement(GNEDemandElement *demandElement, GNEUndoList *undoList)
remove demand element
Definition: GNENet.cpp:645
GNENet::insertDemandElement
void insertDemandElement(GNEDemandElement *demandElement)
Insert a demand element element int GNENet container.
Definition: GNENet.cpp:2777
GNEChange
the function-object for an editing operation (abstract base)
Definition: GNEChange.h:42
GNEVehicleTypeFrame::VehicleTypeSelector::refreshVehicleTypeSelector
void refreshVehicleTypeSelector()
refresh vehicle type selector
Definition: GNEVehicleTypeFrame.cpp:106
WRITE_DEBUG
#define WRITE_DEBUG(msg)
Definition: MsgHandler.h:284
GNEChange_DemandElement::myChildAdditionals
const std::vector< GNEAdditional * > & myChildAdditionals
reference to vector of child additional
Definition: GNEChange_DemandElement.h:107
GNENet.h
GNEViewNet::getViewParent
GNEViewParent * getViewParent() const
get the net object
Definition: GNEViewNet.cpp:1008