Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GNEChange_Crossing.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 single junction is created or deleted
19/****************************************************************************/
20
21#include <netedit/GNENet.h>
24
25#include "GNEChange_Crossing.h"
26
27// ===========================================================================
28// FOX-declarations
29// ===========================================================================
30
31FXIMPLEMENT_ABSTRACT(GNEChange_Crossing, GNEChange, nullptr, 0)
32
33// ===========================================================================
34// member method definitions
35// ===========================================================================
36
37
38GNEChange_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
51GNEChange_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
65
66
68 if (myForward) {
69 // unselect if mySelectedElement is enabled
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
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
122 if (myForward) {
123 // add crossing of NBNode and update geometry
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
175std::string
177 if (myForward) {
178 return TL("Undo create crossing");
179 } else {
180 return TL("Undo delete crossing");
181 }
182}
183
184
185std::string
187 if (myForward) {
188 return TL("Redo create crossing");
189 } else {
190 return TL("Redo delete crossing");
191 }
192}
Supermode
@brie enum for supermodes
@ NETWORK
Network mode (Edges, junctions, etc..).
#define WRITE_WARNINGF(...)
Definition MsgHandler.h:287
#define TL(string)
Definition MsgHandler.h:304
void selectAttributeCarrier()
select attribute carrier using GUIGlobalSelection
void unselectAttributeCarrier()
unselect attribute carrier using GUIGlobalSelection
double myWidth
width of GNECrossing
int myCustomTLIndex
custom index of GNECrossing
bool myPriority
priority of GNECrossing
~GNEChange_Crossing()
Destructor.
std::vector< NBEdge * > myEdges
vector to save all edges of GNECrossing
PositionVector myCustomShape
priority of GNECrossing
std::string undoName() const
return undoName
GNEChange_Crossing(GNEJunction *junctionParent, const std::vector< NBEdge * > &edges, double width, bool priority, int customTLIndex, int customTLIndex2, const PositionVector &customShape, bool selected, bool forward)
Constructor for creating/deleting an crossing.
void undo()
undo action
std::string redoName() const
get Redo name
GNEJunction * myJunctionParent
full information regarding the Junction in which GNECRossing is created
int myCustomTLIndex2
custom index of GNECrossing (reverse direction)
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
The representation of a single edge during network building.
Definition NBEdge.h:92
A definition of a pedestrian crossing.
Definition NBNode.h:135
A list of positions.
Definition json.hpp:4471