Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
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-2025 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
21#include <netedit/GNENet.h>
23#include <netedit/GNEViewNet.h>
27
29
30// ===========================================================================
31// FOX-declarations
32// ===========================================================================
33FXIMPLEMENT_ABSTRACT(GNEChange_DemandElement, GNEChange, nullptr, 0)
34
35// ===========================================================================
36// member method definitions
37// ===========================================================================
38
40 GNEChange(Supermode::DEMAND, demandElement, forward, demandElement->isAttributeCarrierSelected()),
41 myDemandElement(demandElement) {
42 myDemandElement->incRef("GNEChange_DemandElement");
43}
44
45
47 // only continue we have undo-redo mode enabled
48 if (myDemandElement->getNet()->getViewNet()->getViewParent()->getGNEAppWindows()->isUndoRedoAllowed()) {
49 myDemandElement->decRef("GNEChange_DemandElement");
50 if (myDemandElement->unreferenced()) {
51 // make sure that element isn't in net before removing
52 if (myDemandElement->getNet()->getAttributeCarriers()->retrieveDemandElement(myDemandElement, false)) {
53 // remove demand element of network
54 myDemandElement->getNet()->getAttributeCarriers()->deleteDemandElement(myDemandElement, false);
55 }
56 delete myDemandElement;
57 }
58 }
59}
60
61
62void
64 if (myForward) {
65 // unselect if mySelectedElement is enabled
67 myDemandElement->unselectAttributeCarrier();
68 }
69 // remove element from parent and children
71 // delete demand element from net
72 myDemandElement->getNet()->getAttributeCarriers()->deleteDemandElement(myDemandElement, true);
73 } else {
74 // select if mySelectedElement is enabled
76 myDemandElement->selectAttributeCarrier();
77 }
78 // add element in parent and children
80 // insert demand element into net
81 myDemandElement->getNet()->getAttributeCarriers()->insertDemandElement(myDemandElement);
82 }
83 // update vehicle type selector if demand element is a VType and vehicle type Frame is shown
84 if ((myDemandElement->getTagProperty()->getTag() == SUMO_TAG_VTYPE) && myDemandElement->getNet()->getViewNet()->getViewParent()->getTypeFrame()->shown()) {
85 myDemandElement->getNet()->getViewNet()->getViewParent()->getTypeFrame()->getTypeSelector()->refreshTypeSelector(true);
86 }
87 // update stack labels
88 const auto parentEdges = myParents.get<GNEEdge*>();
89 if (parentEdges.size() > 0) {
90 parentEdges.front()->updateVehicleStackLabels();
91 parentEdges.front()->updatePersonStackLabels();
92 parentEdges.front()->updateContainerStackLabels();
93 }
94 // require always save elements
95 myDemandElement->getNet()->getSavingStatus()->requireSaveDemandElements();
96}
97
98
99void
101 if (myForward) {
102 // select if mySelectedElement is enabled
103 if (mySelectedElement) {
104 myDemandElement->selectAttributeCarrier();
105 }
106 // add element in parent and children
108 // insert demand element into net
109 myDemandElement->getNet()->getAttributeCarriers()->insertDemandElement(myDemandElement);
110 } else {
111 // unselect if mySelectedElement is enabled
112 if (mySelectedElement) {
113 myDemandElement->unselectAttributeCarrier();
114 }
115 // remove element from parent and children
117 // delete demand element from net
118 myDemandElement->getNet()->getAttributeCarriers()->deleteDemandElement(myDemandElement, true);
119 }
120 // update vehicle type selector if demand element is a VType and vehicle type Frame is shown
121 if ((myDemandElement->getTagProperty()->getTag() == SUMO_TAG_VTYPE) && myDemandElement->getNet()->getViewNet()->getViewParent()->getTypeFrame()->shown()) {
122 myDemandElement->getNet()->getViewNet()->getViewParent()->getTypeFrame()->getTypeSelector()->refreshTypeSelector(true);
123 }
124 // update stack labels
125 const auto parentEdges = myParents.get<GNEEdge*>();
126 if (parentEdges.size() > 0) {
127 parentEdges.front()->updateVehicleStackLabels();
128 parentEdges.front()->updatePersonStackLabels();
129 parentEdges.front()->updateContainerStackLabels();
130 }
131 // require always save elements
132 myDemandElement->getNet()->getSavingStatus()->requireSaveDemandElements();
133}
134
135
136std::string
138 if (myForward) {
139 return (TL("Undo create ") + myDemandElement->getTagStr() + " '" + myDemandElement->getID() + "'");
140 } else {
141 return (TL("Undo delete ") + myDemandElement->getTagStr() + " '" + myDemandElement->getID() + "'");
142 }
143}
144
145
146std::string
148 if (myForward) {
149 return (TL("Redo create ") + myDemandElement->getTagStr() + " '" + myDemandElement->getID() + "'");
150 } else {
151 return (TL("Redo delete ") + myDemandElement->getTagStr() + " '" + myDemandElement->getID() + "'");
152 }
153}
Supermode
@brie enum for supermodes
@ DEMAND
Demand mode (Routes, Vehicles etc..).
#define TL(string)
Definition MsgHandler.h:304
@ SUMO_TAG_VTYPE
description of a vehicle/person/container type
GNEChange_DemandElement(GNEDemandElement *demandElement, bool forward)
Constructor for creating/deleting an demand element element.
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:180
const bool mySelectedElement
flag for check if element is selected
Definition GNEChange.h:183
GNEChange(Supermode supermode, bool forward, const bool selectedElement)
Constructor.
Definition GNEChange.cpp:34
void addElementInParentsAndChildren(T *element)
add given element in parents and children
Definition GNEChange.h:121
void removeElementFromParentsAndChildren(T *element)
remove given element from parents and children
Definition GNEChange.h:148
const GNEHierarchicalStructureParents myParents
Hierarchical container with parents.
Definition GNEChange.h:177