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-2022 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(Supermode::DEMAND, demandElement, forward, demandElement->isAttributeCarrierSelected()),
40  myDemandElement(demandElement) {
41  myDemandElement->incRef("GNEChange_DemandElement");
42 }
43 
44 
46  myDemandElement->decRef("GNEChange_DemandElement");
48  // show extra information for tests
49  WRITE_DEBUG("Deleting unreferenced " + myDemandElement->getTagStr() + " '" + myDemandElement->getID() + "'");
50  // make sure that element isn't in net before removing
52  // remove demand element of network
54  }
55  delete myDemandElement;
56  }
57 }
58 
59 
60 void
62  if (myForward) {
63  // show extra information for tests
64  WRITE_DEBUG("Removing " + myDemandElement->getTagStr() + " '" + myDemandElement->getID() + "' in GNEChange_DemandElement");
65  // unselect if mySelectedElement is enabled
66  if (mySelectedElement) {
68  }
69  // delete demand element from net
71  // restore container
73  } else {
74  // show extra information for tests
75  WRITE_DEBUG("Adding " + myDemandElement->getTagStr() + " '" + myDemandElement->getID() + "' in GNEChange_DemandElement");
76  // select if mySelectedElement is enabled
77  if (mySelectedElement) {
79  }
80  // insert demand element into net
82  // restore container
84  }
85  // update vehicle type selector if demand element is a VType and vehicle type Frame is shown
88  }
89  // update stack labels
90  if (myOriginalHierarchicalContainer.getParents<std::vector<GNEEdge*> >().size() > 0) {
91  myOriginalHierarchicalContainer.getParents<std::vector<GNEEdge*> >().front()->updateVehicleStackLabels();
92  }
93  // require always save elements
95 }
96 
97 
98 void
100  if (myForward) {
101  // show extra information for tests
102  WRITE_DEBUG("Adding " + myDemandElement->getTagStr() + " '" + myDemandElement->getID() + "' in GNEChange_DemandElement");
103  // select if mySelectedElement is enabled
104  if (mySelectedElement) {
106  }
107  // insert demand element into net
109  // add demand element in parents and children
111  } else {
112  // show extra information for tests
113  WRITE_DEBUG("Removing " + myDemandElement->getTagStr() + " '" + myDemandElement->getID() + "' in GNEChange_DemandElement");
114  // unselect if mySelectedElement is enabled
115  if (mySelectedElement) {
117  }
118  // delete demand element from net
120  // remove demand element from parents and children
122  }
123  // update vehicle type selector if demand element is a VType and vehicle type Frame is shown
126  }
127  // update stack labels
128  if (myOriginalHierarchicalContainer.getParents<std::vector<GNEEdge*> >().size() > 0) {
129  myOriginalHierarchicalContainer.getParents<std::vector<GNEEdge*> >().front()->updateVehicleStackLabels();
130  }
131  // require always save elements
133 }
134 
135 
136 std::string
138  if (myForward) {
139  return ("Undo create " + myDemandElement->getTagStr());
140  } else {
141  return ("Undo delete " + myDemandElement->getTagStr());
142  }
143 }
144 
145 
146 std::string
148  if (myForward) {
149  return ("Redo create " + myDemandElement->getTagStr());
150  } else {
151  return ("Redo delete " + myDemandElement->getTagStr());
152  }
153 }
Supermode
@brie enum for supermodes
#define WRITE_DEBUG(msg)
Definition: MsgHandler.h:290
@ SUMO_TAG_VTYPE
description of a vehicle/person/container type
const std::string & getTagStr() const
get tag assigned to this object in string format
const GNETagProperties & getTagProperty() const
get tagProperty associated with this Attribute Carrier
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
std::string redoName() const
get Redo name
std::string undoName() const
return undoName
GNEDemandElement * myDemandElement
full information regarding the demand element element that is to be created/deleted
the function-object for an editing operation (abstract base)
Definition: GNEChange.h:64
bool myForward
we group antagonistic commands (create junction/delete junction) and keep them apart by this flag
Definition: GNEChange.h:244
const bool mySelectedElement
flag for check if element is selected
Definition: GNEChange.h:247
void addElementInParentsAndChildren(T *element)
add given element into parents and children (only use in redo() function)
Definition: GNEChange.h:132
void removeElementFromParentsAndChildren(T *element)
remove given element from parents and children (only use in redo() function)
Definition: GNEChange.h:187
void restoreHierarchicalContainers()
restore container (only use in undo() function)
Definition: GNEChange.cpp:94
const GNEHierarchicalContainer myOriginalHierarchicalContainer
Hierarchical container with parent and children.
Definition: GNEChange.h:250
An Element which don't belongs to GNENet but has influency in the simulation.
const std::string & getID() const
get ID
const T & getParents() const
get parents
bool demandElementExist(GNEDemandElement *demandElement) const
return true if given demand element exist
void deleteDemandElement(GNEDemandElement *demandElement)
delete demand element element of GNENet container
void insertDemandElement(GNEDemandElement *demandElement)
Insert a demand element element int GNENet container.
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
get all attribute carriers used in this net
Definition: GNENet.cpp:125
void requireSaveDemandElements(bool value)
inform that demand elements has to be saved
Definition: GNENet.cpp:2058
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:1964
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 refreshTypeSelector()
refresh vehicle type selector
TypeSelector * getTypeSelector() const
get vehicle type selector
GNEViewParent * getViewParent() const
get the net object
GNETypeFrame * getTypeFrame() const
get frame for DEMAND_VEHICLETYPE