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-2020 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials are made available under the
5 // terms of the Eclipse Public License 2.0 which is available at
6 // https://www.eclipse.org/legal/epl-2.0/
7 // This Source Code may also be made available under the following Secondary
8 // Licenses when the conditions for such availability set forth in the Eclipse
9 // Public License 2.0 are satisfied: GNU General Public License, version 2
10 // or later which is available at
11 // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 /****************************************************************************/
18 // A network change in which a busStop is created or deleted
19 /****************************************************************************/
20 #include <config.h>
21 
22 #include <netedit/GNENet.h>
24 #include <netedit/GNEViewParent.h>
25 #include <netedit/GNEViewNet.h>
26 
28 
29 // ===========================================================================
30 // FOX-declarations
31 // ===========================================================================
32 FXIMPLEMENT_ABSTRACT(GNEChange_DemandElement, GNEChange, nullptr, 0)
33 
34 // ===========================================================================
35 // member method definitions
36 // ===========================================================================
37 
39  GNEChange(demandElement, forward, demandElement->isAttributeCarrierSelected()),
40  myDemandElement(demandElement),
41  myPath(demandElement->getPath()) {
42  myDemandElement->incRef("GNEChange_DemandElement");
43 }
44 
45 
47  myDemandElement->decRef("GNEChange_DemandElement");
49  // show extra information for tests
50  WRITE_DEBUG("Deleting unreferenced " + myDemandElement->getTagStr() + " '" + myDemandElement->getID() + "'");
51  // make sure that element isn't in net before removing
53  // remove demand element of network
55  // remove element from path
56  for (const auto& pathElement : myPath) {
57  pathElement.getLane()->removePathDemandElement(myDemandElement);
58  if (pathElement.getJunction()) {
59  pathElement.getJunction()->removePathDemandElement(myDemandElement);
60  }
61  }
62  }
63  delete myDemandElement;
64  }
65 }
66 
67 
68 void
70  if (myForward) {
71  // show extra information for tests
72  WRITE_DEBUG("Removing " + myDemandElement->getTagStr() + " '" + myDemandElement->getID() + "' in GNEChange_DemandElement");
73  // unselect if mySelectedElement is enabled
74  if (mySelectedElement) {
76  }
77  // delete demand element from net
79  // remove element from path
80  for (const auto& pathElement : myPath) {
81  pathElement.getLane()->removePathDemandElement(myDemandElement);
82  if (pathElement.getJunction()) {
83  pathElement.getJunction()->removePathDemandElement(myDemandElement);
84  }
85  }
86  // restore container
88  } else {
89  // show extra information for tests
90  WRITE_DEBUG("Adding " + myDemandElement->getTagStr() + " '" + myDemandElement->getID() + "' in GNEChange_DemandElement");
91  // select if mySelectedElement is enabled
92  if (mySelectedElement) {
94  }
95  // insert demand element into net
97  // compute demand element path
99  // restore container
101  }
102  // update vehicle type selector if demand element is a VType and vehicle type Frame is shown
105  }
106  // update stack labels
107  if (myOriginalHierarchicalContainer.getParents<std::vector<GNEEdge*> >().size() > 0) {
108  myOriginalHierarchicalContainer.getParents<std::vector<GNEEdge*> >().front()->updateVehicleStackLabels();
109  }
110  // Requiere always save elements
112 }
113 
114 
115 void
117  if (myForward) {
118  // show extra information for tests
119  WRITE_DEBUG("Adding " + myDemandElement->getTagStr() + " '" + myDemandElement->getID() + "' in GNEChange_DemandElement");
120  // select if mySelectedElement is enabled
121  if (mySelectedElement) {
123  }
124  // insert demand element into net
126  // compute demand element path
128  // add demand element in parents and children
130  } else {
131  // show extra information for tests
132  WRITE_DEBUG("Removing " + myDemandElement->getTagStr() + " '" + myDemandElement->getID() + "' in GNEChange_DemandElement");
133  // unselect if mySelectedElement is enabled
134  if (mySelectedElement) {
136  }
137  // delete demand element from net
139  // remove element from path
140  for (const auto& pathElement : myPath) {
141  pathElement.getLane()->removePathDemandElement(myDemandElement);
142  if (pathElement.getJunction()) {
143  pathElement.getJunction()->removePathDemandElement(myDemandElement);
144  }
145  }
146  // remove demand element from parents and children
148  }
149  // update vehicle type selector if demand element is a VType and vehicle type Frame is shown
152  }
153  // update stack labels
154  if (myOriginalHierarchicalContainer.getParents<std::vector<GNEEdge*> >().size() > 0) {
155  myOriginalHierarchicalContainer.getParents<std::vector<GNEEdge*> >().front()->updateVehicleStackLabels();
156  }
157  // Requiere always save elements
159 }
160 
161 
162 FXString
164  if (myForward) {
165  return ("Undo create " + myDemandElement->getTagStr()).c_str();
166  } else {
167  return ("Undo delete " + myDemandElement->getTagStr()).c_str();
168  }
169 }
170 
171 
172 FXString
174  if (myForward) {
175  return ("Redo create " + myDemandElement->getTagStr()).c_str();
176  } else {
177  return ("Redo delete " + myDemandElement->getTagStr()).c_str();
178  }
179 }
#define WRITE_DEBUG(msg)
Definition: MsgHandler.h:286
@ SUMO_TAG_VTYPE
description of a vehicle type
const std::string & getTagStr() const
get tag assigned to this object in string format
const GNETagProperties & getTagProperty() const
get Tag Property assigned to this object
void unselectAttributeCarrier(const bool changeFlag=true)
unselect attribute carrier using GUIGlobalSelection
GNENet * getNet() const
get pointer to net
void selectAttributeCarrier(const bool changeFlag=true)
select attribute carrier using GUIGlobalSelection
const std::vector< GNEPathElements::PathElement > & myPath
reference to path vector
FXString redoName() const
get Redo name
GNEDemandElement * myDemandElement
full information regarding the demand element element that is to be created/deleted
FXString undoName() const
return undoName
the function-object for an editing operation (abstract base)
Definition: GNEChange.h:65
bool myForward
we group antagonistic commands (create junction/delete junction) and keep them apart by this flag
Definition: GNEChange.h:215
const bool mySelectedElement
flag for check if element is selected
Definition: GNEChange.h:218
void addElementInParentsAndChildren(T *element)
add given element into parents and children (only use in redo() function)
Definition: GNEChange.h:106
void removeElementFromParentsAndChildren(T *element)
remove given element from parents and children (only use in redo() function)
Definition: GNEChange.h:161
void restoreHierarchicalContainers()
restore container (only use in undo() function)
Definition: GNEChange.cpp:82
const GNEHierarchicalContainer myOriginalHierarchicalContainer
Hierarchical container with parent and children.
Definition: GNEChange.h:221
An Element which don't belongs to GNENet but has influency in the simulation.
virtual void computePath()=0
compute path
const std::string & getID() const
get ID
const T & getParents() const
get parents
void deleteDemandElement(GNEDemandElement *demandElement)
delete demand element element of GNENet container
bool demandElementExist(const GNEDemandElement *demandElement) const
return true if given demand element exist
void insertDemandElement(GNEDemandElement *demandElement)
Insert a demand element element int GNENet container.
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
retrieve all attribute carriers of Net
Definition: GNENet.cpp:130
void requireSaveDemandElements(bool value)
inform that demand elements has to be saved
Definition: GNENet.cpp:2474
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:2245
void decRef(const std::string &debugMsg="")
Decrease reference.
bool unreferenced()
check if object ins't referenced
SumoXMLTag getTag() const
get Tag vinculated with this attribute Property
void refreshVehicleTypeSelector()
refresh vehicle type selector
VehicleTypeSelector * getVehicleTypeSelector() const
get vehicle type selector
GNEViewParent * getViewParent() const
get the net object
GNEVehicleTypeFrame * getVehicleTypeFrame() const
get frame for DEMAND_VEHICLETYPE