Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netedit/changes/GNEChange_TAZSourceSink.cpp
169678 views
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
/****************************************************************************/
14
/// @file GNEChange_TAZSourceSink.cpp
15
/// @author Pablo Alvarez Lopez
16
/// @date Nov 2015
17
///
18
// A network change in which a busStop is created or deleted
19
/****************************************************************************/
20
21
#include <netedit/GNENet.h>
22
#include <netedit/GNEViewNet.h>
23
#include <netedit/GNEViewParent.h>
24
#include <netedit/GNEApplicationWindow.h>
25
26
#include "GNEChange_TAZSourceSink.h"
27
28
// ===========================================================================
29
// FOX-declarations
30
// ===========================================================================
31
32
FXIMPLEMENT_ABSTRACT(GNEChange_TAZSourceSink, GNEChange, nullptr, 0)
33
34
// ===========================================================================
35
// member method definitions
36
// ===========================================================================
37
38
GNEChange_TAZSourceSink::GNEChange_TAZSourceSink(GNETAZSourceSink* sourceSink, bool forward) :
39
GNEChange(Supermode::NETWORK, sourceSink, forward, sourceSink->isAttributeCarrierSelected()),
40
mySourceSink(sourceSink) {
41
mySourceSink->incRef("GNEChange_TAZSourceSink");
42
}
43
44
45
GNEChange_TAZSourceSink::~GNEChange_TAZSourceSink() {
46
// only continue we have undo-redo mode enabled
47
if (mySourceSink->getNet()->getViewNet()->getViewParent()->getGNEAppWindows()->isUndoRedoAllowed()) {
48
mySourceSink->decRef("GNEChange_TAZSourceSink");
49
if (mySourceSink->unreferenced()) {
50
// make sure that sourceSink isn't in net before removing
51
if (mySourceSink->getNet()->getAttributeCarriers()->retrieveTAZSourceSink(mySourceSink, false)) {
52
// delete sourceSink from net
53
mySourceSink->getNet()->getAttributeCarriers()->deleteTAZSourceSink(mySourceSink);
54
}
55
delete mySourceSink;
56
}
57
}
58
}
59
60
61
void
62
GNEChange_TAZSourceSink::undo() {
63
if (myForward) {
64
// delete sourceSink from net
65
mySourceSink->getNet()->getAttributeCarriers()->deleteTAZSourceSink(mySourceSink);
66
// remove element from parent and children
67
removeElementFromParentsAndChildren(mySourceSink);
68
} else {
69
// add element in parent and children
70
addElementInParentsAndChildren(mySourceSink);
71
// insert sourceSink into net
72
mySourceSink->getNet()->getAttributeCarriers()->insertTAZSourceSink(mySourceSink);
73
}
74
// require always save sourceSinks
75
mySourceSink->getNet()->getSavingStatus()->requireSaveAdditionals();
76
}
77
78
79
void
80
GNEChange_TAZSourceSink::redo() {
81
if (myForward) {
82
// select if mySelectedElement is enabled
83
if (mySelectedElement) {
84
mySourceSink->selectAttributeCarrier();
85
}
86
// add element in parent and children
87
addElementInParentsAndChildren(mySourceSink);
88
// insert sourceSink into net
89
mySourceSink->getNet()->getAttributeCarriers()->insertTAZSourceSink(mySourceSink);
90
} else {
91
// delete sourceSink from net
92
mySourceSink->getNet()->getAttributeCarriers()->deleteTAZSourceSink(mySourceSink);
93
// remove element from parent and children
94
removeElementFromParentsAndChildren(mySourceSink);
95
}
96
// require always save sourceSinks
97
mySourceSink->getNet()->getSavingStatus()->requireSaveAdditionals();
98
}
99
100
101
std::string
102
GNEChange_TAZSourceSink::undoName() const {
103
if (myForward) {
104
return (TL("Undo create ") + mySourceSink->getTagStr() + " '" + mySourceSink->getID() + "'");
105
} else {
106
return (TL("Undo delete ") + mySourceSink->getTagStr() + " '" + mySourceSink->getID() + "'");
107
}
108
}
109
110
111
std::string
112
GNEChange_TAZSourceSink::redoName() const {
113
if (myForward) {
114
return (TL("Redo create ") + mySourceSink->getTagStr() + " '" + mySourceSink->getID() + "'");
115
} else {
116
return (TL("Redo delete ") + mySourceSink->getTagStr() + " '" + mySourceSink->getID() + "'");
117
}
118
}
119
120