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-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
15 // A network change in which a traffic light is created or deleted
16 /****************************************************************************/
17 
18 // ===========================================================================
19 // included modules
20 // ===========================================================================
21 #include <config.h>
22 
23 
25 #include <netbuild/NBOwnTLDef.h>
27 #include <netedit/GNENet.h>
28 
29 #include "GNEChange_TLS.h"
30 
31 
32 // ===========================================================================
33 // FOX-declarations
34 // ===========================================================================
35 FXIMPLEMENT_ABSTRACT(GNEChange_TLS, GNEChange, nullptr, 0)
36 
37 // ===========================================================================
38 // member method definitions
39 // ===========================================================================
40 
41 
42 GNEChange_TLS::GNEChange_TLS(GNEJunction* junction, NBTrafficLightDefinition* tlDef, bool forward, bool forceInsert, const std::string tlID):
44  GNEChange(junction->getNet(), forward),
45  myJunction(junction),
46  myTlDef(tlDef),
47  myForceInsert(forceInsert) {
48  assert(myNet);
49  myJunction->incRef("GNEChange_TLS");
50  if (myTlDef == nullptr) {
51  assert(forward);
52  // potential memory leak if this change is never executed
54  myTlDef = new NBOwnTLDef(tlID == "" ? myJunction->getMicrosimID() : tlID, 0, type);
55  }
56 }
57 
58 
60  assert(myJunction);
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 netElements
84  myNet->requiereSaveNet(true);
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 netElements
102  myNet->requiereSaveNet(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 }
GNEChange_TLS::redoName
FXString redoName() const
get Redo name
Definition: GNEChange_TLS.cpp:117
GNEReferenceCounter::unreferenced
bool unreferenced()
check if object ins't referenced
Definition: GNEReferenceCounter.h:79
GNEAttributeCarrier::getID
const std::string getID() const
function to support debugging
Definition: GNEAttributeCarrier.cpp:1187
GNENet::requiereSaveNet
void requiereSaveNet(bool value)
inform that net has to be saved
Definition: GNENet.cpp:933
OptionsCont.h
GNEChange::myForward
bool myForward
we group antagonistic commands (create junction/delete junction) and keep them apart by this flag
Definition: GNEChange.h:81
GNEChange_TLS::myJunction
GNEJunction * myJunction
we need the junction because it is the target of our change commands
Definition: GNEChange_TLS.h:78
TrafficLightType
TrafficLightType
Definition: SUMOXMLDefinitions.h:1192
NBOwnTLDef
A traffic light logics which must be computed (only nodes/edges are given)
Definition: NBOwnTLDef.h:47
OptionsCont::getOptions
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:58
GNEJunction.h
GNEJunction::removeTrafficLight
void removeTrafficLight(NBTrafficLightDefinition *tlDef)
removes a traffic light
Definition: GNEJunction.cpp:1498
StringBijection::get
T get(const std::string &str) const
Definition: StringBijection.h:98
GNEChange_TLS.h
GNEChange_TLS::myTlDef
NBTrafficLightDefinition * myTlDef
the traffic light to be created/deleted. We assume no responsiblity for the pointer
Definition: GNEChange_TLS.h:83
GNEChange::myNet
GNENet * myNet
the net to which operations shall be applied or which shall be informed about gui updates (we are not...
Definition: GNEChange.h:76
GNEChange_TLS
Definition: GNEChange_TLS.h:43
GNEReferenceCounter::decRef
void decRef(const std::string &debugMsg="")
Decrease reference.
Definition: GNEReferenceCounter.h:53
GNEChange_TLS::myForceInsert
bool myForceInsert
check if forceInsert is enabled
Definition: GNEChange_TLS.h:86
GNEJunction::addTrafficLight
void addTrafficLight(NBTrafficLightDefinition *tlDef, bool forceInsert)
adds a traffic light
Definition: GNEJunction.cpp:1490
toString
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:48
SUMO_TAG_TRAFFIC_LIGHT
a traffic light
Definition: SUMOXMLDefinitions.h:140
GNEChange_TLS::redo
void redo()
redo action
Definition: GNEChange_TLS.cpp:89
SUMOXMLDefinitions::TrafficLightTypes
static StringBijection< TrafficLightType > TrafficLightTypes
traffic light types
Definition: SUMOXMLDefinitions.h:1387
config.h
GNEChange_TLS::~GNEChange_TLS
~GNEChange_TLS()
Destructor.
Definition: GNEChange_TLS.cpp:59
GNEAttributeCarrier::getTagStr
const std::string & getTagStr() const
get tag assigned to this object in string format
Definition: GNEAttributeCarrier.cpp:1165
NBOwnTLDef.h
GNEChange_TLS::undoName
FXString undoName() const
return undoName
Definition: GNEChange_TLS.cpp:107
GNEJunction
Definition: GNEJunction.h:48
GNEChange_TLS::undo
void undo()
undo action
Definition: GNEChange_TLS.cpp:71
GNEChange
the function-object for an editing operation (abstract base)
Definition: GNEChange.h:43
WRITE_DEBUG
#define WRITE_DEBUG(msg)
Definition: MsgHandler.h:246
GNENet.h
NBTrafficLightDefinition
The base class for traffic light logic definitions.
Definition: NBTrafficLightDefinition.h:68