Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netedit/changes/GNEChange_Junction.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_Junction.cpp
15
/// @author Jakob Erdmann
16
/// @date Mar 2011
17
///
18
// A network change in which a single junction 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_Junction.h"
27
28
// ===========================================================================
29
// FOX-declarations
30
// ===========================================================================
31
32
FXIMPLEMENT_ABSTRACT(GNEChange_Junction, GNEChange, nullptr, 0)
33
34
// ===========================================================================
35
// member method definitions
36
// ===========================================================================
37
38
39
/// @brief constructor for creating a junction
40
GNEChange_Junction::GNEChange_Junction(GNEJunction* junction, bool forward):
41
GNEChange(Supermode::NETWORK, junction, forward, junction->isAttributeCarrierSelected()),
42
myJunction(junction) {
43
junction->incRef("GNEChange_Junction");
44
}
45
46
47
GNEChange_Junction::~GNEChange_Junction() {
48
// only continue we have undo-redo mode enabled
49
if (myJunction->getNet()->getViewNet()->getViewParent()->getGNEAppWindows()->isUndoRedoAllowed()) {
50
myJunction->decRef("GNEChange_Junction");
51
if (myJunction->unreferenced()) {
52
delete myJunction;
53
}
54
}
55
}
56
57
58
void
59
GNEChange_Junction::undo() {
60
if (myForward) {
61
// unselect if mySelectedElement is enabled
62
if (mySelectedElement) {
63
myJunction->unselectAttributeCarrier();
64
}
65
// delete junction from net
66
myJunction->getNet()->getAttributeCarriers()->deleteSingleJunction(myJunction);
67
// remove element from parent and children
68
removeElementFromParentsAndChildren(myJunction);
69
} else {
70
// select if mySelectedElement is enabled
71
if (mySelectedElement) {
72
myJunction->selectAttributeCarrier();
73
}
74
// add element in parent and children
75
addElementInParentsAndChildren(myJunction);
76
// insert junction in net
77
myJunction->getNet()->getAttributeCarriers()->insertJunction(myJunction);
78
}
79
// enable save networkElements
80
myJunction->getNet()->getSavingStatus()->requireSaveNetwork();
81
}
82
83
84
void
85
GNEChange_Junction::redo() {
86
if (myForward) {
87
// select if mySelectedElement is enabled
88
if (mySelectedElement) {
89
myJunction->selectAttributeCarrier();
90
}
91
// add element in parent and children
92
addElementInParentsAndChildren(myJunction);
93
// add junction into net
94
myJunction->getNet()->getAttributeCarriers()->insertJunction(myJunction);
95
} else {
96
// unselect if mySelectedElement is enabled
97
if (mySelectedElement) {
98
myJunction->unselectAttributeCarrier();
99
}
100
// add element in parent and children
101
addElementInParentsAndChildren(myJunction);
102
// delete junction from net
103
myJunction->getNet()->getAttributeCarriers()->deleteSingleJunction(myJunction);
104
// remove element from parent and children
105
removeElementFromParentsAndChildren(myJunction);
106
}
107
// enable save networkElements
108
myJunction->getNet()->getSavingStatus()->requireSaveNetwork();
109
}
110
111
112
std::string
113
GNEChange_Junction::undoName() const {
114
if (myForward) {
115
return (TL("Undo create junction '") + myJunction->getID() + "'");
116
} else {
117
return (TL("Undo delete junction '") + myJunction->getID() + "'");
118
}
119
}
120
121
122
std::string
123
GNEChange_Junction::redoName() const {
124
if (myForward) {
125
return (TL("Redo create junction '") + myJunction->getID() + "'");
126
} else {
127
return (TL("Redo delete junction '") + myJunction->getID() + "'");
128
}
129
}
130
131