Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netedit/changes/GNEChange_Crossing.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_Crossing.cpp
15
/// @author Pablo Alvarez Lopez
16
/// @date Oct 2016
17
///
18
// A network change in which a single junction is created or deleted
19
/****************************************************************************/
20
21
#include <netedit/GNENet.h>
22
#include <netedit/elements/network/GNECrossing.h>
23
#include <netbuild/NBNetBuilder.h>
24
25
#include "GNEChange_Crossing.h"
26
27
// ===========================================================================
28
// FOX-declarations
29
// ===========================================================================
30
31
FXIMPLEMENT_ABSTRACT(GNEChange_Crossing, GNEChange, nullptr, 0)
32
33
// ===========================================================================
34
// member method definitions
35
// ===========================================================================
36
37
38
GNEChange_Crossing::GNEChange_Crossing(GNEJunction* junctionParent, const std::vector<NBEdge*>& edges,
39
double width, bool priority, int customTLIndex, int customTLIndex2, const PositionVector& customShape, bool selected, bool forward):
40
GNEChange(Supermode::NETWORK, junctionParent, forward, selected),
41
myJunctionParent(junctionParent),
42
myEdges(edges),
43
myWidth(width),
44
myPriority(priority),
45
myCustomTLIndex(customTLIndex),
46
myCustomTLIndex2(customTLIndex2),
47
myCustomShape(customShape) {
48
}
49
50
51
GNEChange_Crossing::GNEChange_Crossing(GNEJunction* junctionParent, const NBNode::Crossing& crossing, bool forward):
52
GNEChange(Supermode::NETWORK, forward, false),
53
myJunctionParent(junctionParent),
54
myEdges(crossing.edges),
55
myWidth(crossing.width),
56
myPriority(crossing.priority),
57
myCustomTLIndex(crossing.customTLIndex),
58
myCustomTLIndex2(crossing.customTLIndex2),
59
myCustomShape(crossing.customShape) {
60
}
61
62
63
GNEChange_Crossing::~GNEChange_Crossing() {
64
}
65
66
67
void GNEChange_Crossing::undo() {
68
if (myForward) {
69
// unselect if mySelectedElement is enabled
70
if (mySelectedElement) {
71
GNECrossing* crossing = myJunctionParent->retrieveGNECrossing(myJunctionParent->getNBNode()->getCrossing(myEdges), false);
72
if (crossing) {
73
crossing->unselectAttributeCarrier();
74
} else {
75
#ifdef _DEBUG
76
WRITE_WARNINGF("Unable to deselect crossing at junction '%' after undo", myJunctionParent->getID());
77
#endif
78
}
79
}
80
// remove crossing of NBNode
81
myJunctionParent->getNBNode()->removeCrossing(myEdges);
82
// rebuild GNECrossings
83
myJunctionParent->rebuildGNECrossings();
84
// clean walking areas
85
myJunctionParent->clearWalkingAreas();
86
// Check if Flag "haveNetworkCrossings" has to be disabled
87
if (myJunctionParent->getNet()->getAttributeCarriers()->getCrossings().empty() && (myJunctionParent->getNet()->getNetBuilder()->haveNetworkCrossings())) {
88
// change flag of NetBuilder (For build GNECrossing)
89
myJunctionParent->getNet()->getNetBuilder()->setHaveNetworkCrossings(false);
90
}
91
} else {
92
// add crossing of NBNode
93
NBNode::Crossing* c = myJunctionParent->getNBNode()->addCrossing(myEdges, myWidth, myPriority, myCustomTLIndex, myCustomTLIndex2, myCustomShape);
94
// Check if Flag "haveNetworkCrossings" has to be enabled
95
if (!myJunctionParent->getNet()->getNetBuilder()->haveNetworkCrossings() == false) {
96
myJunctionParent->getNet()->getNetBuilder()->setHaveNetworkCrossings(true);
97
}
98
// rebuild GNECrossings
99
myJunctionParent->rebuildGNECrossings();
100
// clean walking areas
101
myJunctionParent->clearWalkingAreas();
102
// select if mySelectedElement is enabled
103
if (mySelectedElement) {
104
if (mySelectedElement) {
105
GNECrossing* crossing = myJunctionParent->retrieveGNECrossing(c, false);
106
if (crossing) {
107
crossing->selectAttributeCarrier();
108
} else {
109
#ifdef _DEBUG
110
WRITE_WARNINGF("Unable to select crossing at junction '%' after undo", myJunctionParent->getID());
111
#endif
112
}
113
}
114
}
115
}
116
// enable save networkElements
117
myJunctionParent->getNet()->getSavingStatus()->requireSaveNetwork();
118
}
119
120
121
void GNEChange_Crossing::redo() {
122
if (myForward) {
123
// add crossing of NBNode and update geometry
124
NBNode::Crossing* c = myJunctionParent->getNBNode()->addCrossing(myEdges, myWidth, myPriority, myCustomTLIndex, myCustomTLIndex2, myCustomShape);
125
// Check if Flag "haveNetworkCrossings" has to be enabled
126
if (myJunctionParent->getNet()->getNetBuilder()->haveNetworkCrossings() == false) {
127
myJunctionParent->getNet()->getNetBuilder()->setHaveNetworkCrossings(true);
128
}
129
// rebuild GNECrossings
130
myJunctionParent->rebuildGNECrossings();
131
// clean walking areas
132
myJunctionParent->clearWalkingAreas();
133
// select if mySelectedElement is enabled
134
if (mySelectedElement) {
135
if (mySelectedElement) {
136
GNECrossing* crossing = myJunctionParent->retrieveGNECrossing(c, false);
137
if (crossing) {
138
crossing->selectAttributeCarrier();
139
} else {
140
#ifdef _DEBUG
141
WRITE_WARNINGF("Unable to select crossing at junction '%' after undo", myJunctionParent->getID());
142
#endif
143
}
144
}
145
}
146
} else {
147
// unselect if mySelectedElement is enabled
148
if (mySelectedElement) {
149
GNECrossing* crossing = myJunctionParent->retrieveGNECrossing(myJunctionParent->getNBNode()->getCrossing(myEdges), false);
150
if (crossing) {
151
crossing->unselectAttributeCarrier();
152
} else {
153
#ifdef _DEBUG
154
WRITE_WARNINGF("Unable to deselect crossing at junction '%' after undo", myJunctionParent->getID());
155
#endif
156
}
157
}
158
// remove crossing of NBNode and update geometry
159
myJunctionParent->getNBNode()->removeCrossing(myEdges);
160
// rebuild GNECrossings
161
myJunctionParent->rebuildGNECrossings();
162
// clean walking areas
163
myJunctionParent->clearWalkingAreas();
164
// Check if Flag "haveNetworkCrossings" has to be disabled
165
if (myJunctionParent->getNet()->getAttributeCarriers()->getCrossings().empty() && (myJunctionParent->getNet()->getNetBuilder()->haveNetworkCrossings())) {
166
// change flag of NetBuilder (For build GNECrossing)
167
myJunctionParent->getNet()->getNetBuilder()->setHaveNetworkCrossings(false);
168
}
169
}
170
// enable save networkElements
171
myJunctionParent->getNet()->getSavingStatus()->requireSaveNetwork();
172
}
173
174
175
std::string
176
GNEChange_Crossing::undoName() const {
177
if (myForward) {
178
return TL("Undo create crossing");
179
} else {
180
return TL("Undo delete crossing");
181
}
182
}
183
184
185
std::string
186
GNEChange_Crossing::redoName() const {
187
if (myForward) {
188
return TL("Redo create crossing");
189
} else {
190
return TL("Redo delete crossing");
191
}
192
}
193
194