Eclipse SUMO - Simulation of Urban MObility
GNEChange_TLS.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2020 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 
24 #include <netbuild/NBOwnTLDef.h>
25 #include <netedit/GNENet.h>
26 
27 #include "GNEChange_TLS.h"
28 
29 
30 // ===========================================================================
31 // FOX-declarations
32 // ===========================================================================
33 FXIMPLEMENT_ABSTRACT(GNEChange_TLS, GNEChange, nullptr, 0)
34 
35 // ===========================================================================
36 // member method definitions
37 // ===========================================================================
38 
39 
40 GNEChange_TLS::GNEChange_TLS(GNEJunction* junction, NBTrafficLightDefinition* tlDef, bool forward, bool forceInsert, const std::string tlID):
42  GNEChange(forward, false),
43  myJunction(junction),
44  myTlDef(tlDef),
45  myForceInsert(forceInsert) {
46  myJunction->incRef("GNEChange_TLS");
47  if (myTlDef == nullptr) {
48  assert(forward);
49  // potential memory leak if this change is never executed
51  if (myJunction->getNBNode()->isTLControlled()) {
52  // copy existing type
53  type = (*myJunction->getNBNode()->getControllingTLS().begin())->getType();
54  }
55  myTlDef = new NBOwnTLDef(tlID == "" ? myJunction->getMicrosimID() : tlID, 0, type);
56  }
57 }
58 
59 
61  myJunction->decRef("GNEChange_TLS");
62  if (myJunction->unreferenced()) {
63  // show extra information for tests
64  WRITE_DEBUG("Deleting unreferenced " + myJunction->getTagStr() + " '" + myJunction->getID() + "' in GNEChange_TLS");
65  delete myJunction;
66  }
67 }
68 
69 
70 void
72  if (myForward) {
73  // show extra information for tests
74  WRITE_DEBUG("Removing TLS from " + myJunction->getTagStr() + " '" + myJunction->getID() + "'");
75  // remove traffic light from junction
77  } else {
78  // show extra information for tests
79  WRITE_DEBUG("Adding TLS into " + myJunction->getTagStr() + " '" + myJunction->getID() + "'");
80  // add traffic light to junction
82  }
83  // enable save networkElements
85 }
86 
87 
88 void
90  if (myForward) {
91  // show extra information for tests
92  WRITE_DEBUG("Adding TLS into " + myJunction->getTagStr() + " '" + myJunction->getID() + "'");
93  // add traffic light to junction
95  } else {
96  // show extra information for tests
97  WRITE_DEBUG("Deleting TLS from " + myJunction->getTagStr() + " '" + myJunction->getID() + "'");
98  // remove traffic light from junction
100  }
101  // enable save networkElements
102  myJunction->getNet()->requireSaveNet(true);
103 }
104 
105 
106 FXString
108  if (myForward) {
109  return ("Undo create " + toString(SUMO_TAG_TRAFFIC_LIGHT)).c_str();
110  } else {
111  return ("Undo delete " + toString(SUMO_TAG_TRAFFIC_LIGHT)).c_str();
112  }
113 }
114 
115 
116 FXString
118  if (myForward) {
119  return ("Redo create " + toString(SUMO_TAG_TRAFFIC_LIGHT)).c_str();
120  } else {
121  return ("Redo delete " + toString(SUMO_TAG_TRAFFIC_LIGHT)).c_str();
122  }
123 }
#define WRITE_DEBUG(msg)
Definition: MsgHandler.h:286
TrafficLightType
@ SUMO_TAG_TRAFFIC_LIGHT
a traffic light
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:44
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
Definition: GNEChange_TLS.h:69
void undo()
undo action
FXString redoName() const
get Redo name
void redo()
redo action
FXString undoName() const
return undoName
~GNEChange_TLS()
Destructor.
NBTrafficLightDefinition * myTlDef
the traffic light to be created/deleted. We assume no responsiblity for the pointer
Definition: GNEChange_TLS.h:74
bool myForceInsert
check if forceInsert is enabled
Definition: GNEChange_TLS.h:77
the function-object for an editing operation (abstract base)
Definition: GNEChange.h:65
bool myForward
we group antagonistic commands (create junction/delete junction) and keep them apart by this flag
Definition: GNEChange.h:215
void addTrafficLight(NBTrafficLightDefinition *tlDef, bool forceInsert)
adds a traffic light
void removeTrafficLight(NBTrafficLightDefinition *tlDef)
removes a traffic light
void requireSaveNet(bool value)
inform that net has to be saved
Definition: GNENet.cpp:1047
const std::string & getID() const
get ID
void decRef(const std::string &debugMsg="")
Decrease reference.
bool unreferenced()
check if object ins't referenced
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.
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:58
static StringBijection< TrafficLightType > TrafficLightTypes
traffic light types
T get(const std::string &str) const