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-2024 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#include <config.h>
21
22#include <netedit/GNENet.h>
23#include <netedit/GNEViewNet.h>
27#include <netbuild/NBOwnTLDef.h>
28
29#include "GNEChange_TLS.h"
30
31
32// ===========================================================================
33// FOX-declarations
34// ===========================================================================
35FXIMPLEMENT_ABSTRACT(GNEChange_TLS, GNEChange, nullptr, 0)
36
37// ===========================================================================
38// member method definitions
39// ===========================================================================
40
41
42
43GNEChange_TLS::GNEChange_TLS(GNEJunction* junction, NBTrafficLightDefinition* tlDef, bool forward, bool forceInsert, const std::string tlID) :
44 GNEChange(Supermode::NETWORK, forward, false),
45 myJunction(junction),
46 myTlDef(tlDef),
47 myForceInsert(forceInsert) {
48 myJunction->incRef("GNEChange_TLS");
49 if (myTlDef == nullptr) {
50 // check forward
51 if (!forward) {
52 throw ProcessError("If myTlDef is null, forward cannot be false");
53 }
54 // potential memory leak if this change is never executed
56 if (myJunction->getNBNode()->isTLControlled()) {
57 // copy existing type
58 type = (*myJunction->getNBNode()->getControllingTLS().begin())->getType();
59 }
60 myTlDef = new NBOwnTLDef(tlID == "" ? myJunction->getMicrosimID() : tlID, 0, type);
61 }
62}
63
64
66 bool forceInsert, const std::string tlID) :
67 GNEChange(Supermode::NETWORK, forward, false),
68 myJunction(junction),
69 myTlDef(tlDef),
70 myForceInsert(forceInsert) {
71 myJunction->incRef("GNEChange_TLS");
72 if (myTlDef == nullptr) {
73 // check forward
74 if (!forward) {
75 throw ProcessError("If myTlDef is null, forward cannot be false");
76 }
78 // copy existing type
79 type = (*myJunction->getNBNode()->getControllingTLS().begin())->getType();
80 }
81 myTlDef = new NBOwnTLDef(tlID == "" ? myJunction->getMicrosimID() : tlID, 0, type);
82 }
83}
84
85
86GNEChange_TLS::GNEChange_TLS(GNEJunction* junction, NBTrafficLightDefinition* tlDef, const std::string& newID) :
87 GNEChange(Supermode::NETWORK, true, false),
88 myJunction(junction),
89 myTlDef(tlDef),
90 myForceInsert(false),
91 myOldID(tlDef->getID()),
92 myNewID(newID) {
93 myJunction->incRef("GNEChange_TLS");
94}
95
96
98 // only continue we have undo-redo mode enabled
100 myJunction->decRef("GNEChange_TLS");
101 if (myJunction->unreferenced()) {
102 // show extra information for tests
103 WRITE_DEBUG("Deleting unreferenced " + myJunction->getTagStr() + " '" + myJunction->getID() + "' in GNEChange_TLS");
104 delete myJunction;
105 }
106 }
107}
108
109
110void
112 if (myForward) {
113 if (myNewID.empty()) {
114 // show extra information for tests
115 WRITE_DEBUG("Removing TLS from " + myJunction->getTagStr() + " '" + myJunction->getID() + "'");
116 // remove traffic light from junction
118 } else {
119 // show extra information for tests
120 WRITE_DEBUG("Renaming Traffic Light: " + myOldID);
121 // set old ID
123 }
124 } else {
125 if (myNewID.empty()) {
126 // show extra information for tests
127 WRITE_DEBUG("Adding TLS into " + myJunction->getTagStr() + " '" + myJunction->getID() + "'");
128 // add traffic light to junction
130 } else {
131 // show extra information for tests
132 WRITE_DEBUG("Renaming Traffic Light: " + myNewID);
133 // set new ID
135 }
136 }
137 // enable save networkElements
139}
140
141
142void
144 if (myForward) {
145 if (myNewID.empty()) {
146 // show extra information for tests
147 WRITE_DEBUG("Adding TLS into " + myJunction->getTagStr() + " '" + myJunction->getID() + "'");
148 // add traffic light to junction
150 } else {
151 // show extra information for tests
152 WRITE_DEBUG("Renaming Traffic Light: " + myNewID);
153 // set new ID
155 }
156 } else {
157 if (myNewID.empty()) {
158 // show extra information for tests
159 WRITE_DEBUG("Deleting TLS from " + myJunction->getTagStr() + " '" + myJunction->getID() + "'");
160 // remove traffic light from junction
162 } else {
163 // show extra information for tests
164 WRITE_DEBUG("Renaming Traffic Light: " + myOldID);
165 // set old ID
167 }
168 }
169 // enable save networkElements
171}
172
173
174std::string
176 if (myForward) {
177 return (TL("Undo create TLS '") + myJunction->getID() + "'");
178 } else {
179 return (TL("Undo delete TLS '") + myJunction->getID() + "'");
180 }
181}
182
183
184std::string
186 if (myForward) {
187 return (TL("Redo create TLS '") + myJunction->getID() + "'");
188 } else {
189 return (TL("Redo delete TLS '") + myJunction->getID() + "'");
190 }
191}
Supermode
@brie enum for supermodes
@ NETWORK
Network mode (Edges, junctions, etc..)
#define WRITE_DEBUG(msg)
Definition MsgHandler.h:306
#define TL(string)
Definition MsgHandler.h:315
const std::string getID() const
get ID (all Attribute Carriers have one)
const std::string & getTagStr() const
get tag assigned to this object in string format
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:212
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:2153
GNENetHelper::SavingStatus * getSavingStatus() const
get saving status
Definition GNENet.cpp:131
GNEViewNet * getViewNet() const
get view net
Definition GNENet.cpp:2147
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:336
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
Definition json.hpp:4471