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.dev/sumo
3 // Copyright (C) 2001-2024 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());
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  const auto parentEdges = myOriginalHierarchicalContainer.getParents<std::vector<GNEEdge*> >();
91  if (parentEdges.size() > 0) {
92  parentEdges.front()->updateVehicleStackLabels();
93  parentEdges.front()->updatePersonStackLabels();
94  parentEdges.front()->updateContainerStackLabels();
95  }
96  // require always save elements
98 }
99 
100 
101 void
103  if (myForward) {
104  // show extra information for tests
105  WRITE_DEBUG("Adding " + myDemandElement->getTagStr() + " '" + myDemandElement->getID() + "' in GNEChange_DemandElement");
106  // select if mySelectedElement is enabled
107  if (mySelectedElement) {
109  }
110  // insert demand element into net
112  // add demand element in parents and children
114  } else {
115  // show extra information for tests
116  WRITE_DEBUG("Removing " + myDemandElement->getTagStr() + " '" + myDemandElement->getID() + "' in GNEChange_DemandElement");
117  // unselect if mySelectedElement is enabled
118  if (mySelectedElement) {
120  }
121  // delete demand element from net
123  // remove demand element from parents and children
125  }
126  // update vehicle type selector if demand element is a VType and vehicle type Frame is shown
129  }
130  // update stack labels
131  const auto parentEdges = myOriginalHierarchicalContainer.getParents<std::vector<GNEEdge*> >();
132  if (parentEdges.size() > 0) {
133  parentEdges.front()->updateVehicleStackLabels();
134  parentEdges.front()->updatePersonStackLabels();
135  parentEdges.front()->updateContainerStackLabels();
136  }
137  // require always save elements
139 }
140 
141 
142 std::string
144  if (myForward) {
145  return (TL("Undo create ") + myDemandElement->getTagStr() + " '" + myDemandElement->getID() + "'");
146  } else {
147  return (TL("Undo delete ") + myDemandElement->getTagStr() + " '" + myDemandElement->getID() + "'");
148  }
149 }
150 
151 
152 std::string
154  if (myForward) {
155  return (TL("Redo create ") + myDemandElement->getTagStr() + " '" + myDemandElement->getID() + "'");
156  } else {
157  return (TL("Redo delete ") + myDemandElement->getTagStr() + " '" + myDemandElement->getID() + "'");
158  }
159 }
Supermode
@brie enum for supermodes
#define WRITE_DEBUG(msg)
Definition: MsgHandler.h:306
#define TL(string)
Definition: MsgHandler.h:315
@ SUMO_TAG_VTYPE
description of a vehicle/person/container type
const std::string getID() const
get ID (all Attribute Carriers have one)
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:56
bool myForward
we group antagonistic commands (create junction/delete junction) and keep them apart by this flag
Definition: GNEChange.h:212
const bool mySelectedElement
flag for check if element is selected
Definition: GNEChange.h:215
void addElementInParentsAndChildren(T *element)
add given element into parents and children (only use in redo() function)
Definition: GNEChange.h:124
void removeElementFromParentsAndChildren(T *element)
remove given element from parents and children (only use in redo() function)
Definition: GNEChange.h:167
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:218
const T & getParents() const
get parents
void deleteDemandElement(GNEDemandElement *demandElement, const bool updateFrames)
delete demand element of container
void insertDemandElement(GNEDemandElement *demandElement)
Insert a demand element in container.
GNEDemandElement * retrieveDemandElement(SumoXMLTag type, const std::string &id, bool hardFail=true) const
Returns the named demand element.
void requireSaveDemandElements()
inform that demand elements has to be saved
GNENetHelper::SavingStatus * getSavingStatus() const
get saving status
Definition: GNENet.cpp:129
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
get all attribute carriers used in this net
Definition: GNENet.cpp:123
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:2069
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(const bool updateModuls)
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_TYPE