Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GNEChange_TLS.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 traffic light is created or deleted
19/****************************************************************************/
20
21#include <netedit/GNENet.h>
22#include <netedit/GNEViewNet.h>
26#include <netbuild/NBOwnTLDef.h>
27
28#include "GNEChange_TLS.h"
29
30// ===========================================================================
31// FOX-declarations
32// ===========================================================================
33
34FXIMPLEMENT_ABSTRACT(GNEChange_TLS, GNEChange, nullptr, 0)
35
36// ===========================================================================
37// member method definitions
38// ===========================================================================
39
40GNEChange_TLS::GNEChange_TLS(GNEJunction* junction, NBTrafficLightDefinition* tlDef, bool forward, bool forceInsert, const std::string tlID) :
41 GNEChange(Supermode::NETWORK, forward, false),
42 myJunction(junction),
43 myTlDef(tlDef),
44 myForceInsert(forceInsert) {
45 myJunction->incRef("GNEChange_TLS");
46 if (myTlDef == nullptr) {
47 // check forward
48 if (!forward) {
49 throw ProcessError("If myTlDef is null, forward cannot be false");
50 }
51 // potential memory leak if this change is never executed
53 if (myJunction->getNBNode()->isTLControlled()) {
54 // copy existing type
55 type = (*myJunction->getNBNode()->getControllingTLS().begin())->getType();
56 }
57 myTlDef = new NBOwnTLDef(tlID == "" ? myJunction->getMicrosimID() : tlID, 0, type);
58 }
59}
60
61
63 bool forceInsert, const std::string tlID) :
64 GNEChange(Supermode::NETWORK, forward, false),
65 myJunction(junction),
66 myTlDef(tlDef),
67 myForceInsert(forceInsert) {
68 myJunction->incRef("GNEChange_TLS");
69 if (myTlDef == nullptr) {
70 // check forward
71 if (!forward) {
72 throw ProcessError("If myTlDef is null, forward cannot be false");
73 }
75 // copy existing type
76 type = (*myJunction->getNBNode()->getControllingTLS().begin())->getType();
77 }
78 myTlDef = new NBOwnTLDef(tlID == "" ? myJunction->getMicrosimID() : tlID, 0, type);
79 }
80}
81
82
83GNEChange_TLS::GNEChange_TLS(GNEJunction* junction, NBTrafficLightDefinition* tlDef, const std::string& newID) :
84 GNEChange(Supermode::NETWORK, true, false),
85 myJunction(junction),
86 myTlDef(tlDef),
87 myForceInsert(false),
88 myOldID(tlDef->getID()),
89 myNewID(newID) {
90 myJunction->incRef("GNEChange_TLS");
91}
92
93
95 // only continue we have undo-redo mode enabled
97 myJunction->decRef("GNEChange_TLS");
98 if (myJunction->unreferenced()) {
99 delete myJunction;
100 }
101 }
102}
103
104
105void
107 if (myForward) {
108 if (myNewID.empty()) {
109 // remove traffic light from junction
111 } else {
112 // set old ID
114 }
115 } else {
116 if (myNewID.empty()) {
117 // add traffic light to junction
119 } else {
120 // set new ID
122 }
123 }
124 // enable save networkElements
126}
127
128
129void
131 if (myForward) {
132 if (myNewID.empty()) {
133 // add traffic light to junction
135 } else {
136 // set new ID
138 }
139 } else {
140 if (myNewID.empty()) {
141 // remove traffic light from junction
143 } else {
144 // set old ID
146 }
147 }
148 // enable save networkElements
150}
151
152
153std::string
155 if (myForward) {
156 return (TL("Undo create TLS '") + myJunction->getID() + "'");
157 } else {
158 return (TL("Undo delete TLS '") + myJunction->getID() + "'");
159 }
160}
161
162
163std::string
165 if (myForward) {
166 return (TL("Redo create TLS '") + myJunction->getID() + "'");
167 } else {
168 return (TL("Redo delete TLS '") + myJunction->getID() + "'");
169 }
170}
Supermode
@brie enum for supermodes
@ NETWORK
Network mode (Edges, junctions, etc..)
#define TL(string)
Definition MsgHandler.h:305
const std::string getID() const
get ID (all Attribute Carriers have one)
GNENet * getNet() const
get pointer to net
GNEJunction * myJunction
we need the junction because it is the target of our change commands
void undo()
undo action
GNEChange_TLS(GNEJunction *junction, NBTrafficLightDefinition *tlDef, bool forward, bool forceInsert=false, const std::string tlID="")
Constructor for creating/deleting a TLS.
const std::string myNewID
void redo()
redo action
std::string undoName() const
return undoName
~GNEChange_TLS()
Destructor.
const std::string myOldID
variables used for renaming TLS
std::string redoName() const
get Redo name
NBTrafficLightDefinition * myTlDef
the traffic light to be created/deleted. We assume no responsibility for the pointer
const bool myForceInsert
check if forceInsert is enabled
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
void addTrafficLight(NBTrafficLightDefinition *tlDef, bool forceInsert)
adds a traffic light
NBNode * getNBNode() const
Return net build node.
void removeTrafficLight(NBTrafficLightDefinition *tlDef)
removes a traffic light
void requireSaveNetwork()
inform that network has to be saved
NBTrafficLightLogicCont & getTLLogicCont()
returns the tllcont of the underlying netbuilder
Definition GNENet.cpp:2199
GNENetHelper::SavingStatus * getSavingStatus() const
get saving status
Definition GNENet.cpp:162
GNEViewNet * getViewNet() const
get view net
Definition GNENet.cpp:2193
void decRef(const std::string &debugMsg="")
Decrease reference.
void incRef(const std::string &debugMsg="")
Increase reference.
bool unreferenced()
check if object ins't referenced
GNEViewParent * getViewParent() const
get the net object
GNEApplicationWindow * getGNEAppWindows() const
get GNE Application Windows
const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
const std::set< NBTrafficLightDefinition * > & getControllingTLS() const
Returns the traffic lights that were assigned to this node (The set of tls that control this node)
Definition NBNode.h:340
bool isTLControlled() const
Returns whether this node is controlled by any tls.
Definition NBNode.h:331
A traffic light logics which must be computed (only nodes/edges are given)
Definition NBOwnTLDef.h:44
The base class for traffic light logic definitions.
void rename(NBTrafficLightDefinition *tlDef, const std::string &newID)
rename traffic light
static OptionsCont & getOptions()
Retrieves the options.
static StringBijection< TrafficLightType > TrafficLightTypes
traffic light types
T get(const std::string &str) const
get key
Definition json.hpp:4471