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 /****************************************************************************/
14 // A network change in which a traffic light is created or deleted
15 /****************************************************************************/
16 
17 // ===========================================================================
18 // included modules
19 // ===========================================================================
20 #include <config.h>
21 
22 
24 #include <netbuild/NBOwnTLDef.h>
26 #include <netedit/GNENet.h>
27 
28 #include "GNEChange_TLS.h"
29 
30 
31 // ===========================================================================
32 // FOX-declarations
33 // ===========================================================================
34 FXIMPLEMENT_ABSTRACT(GNEChange_TLS, GNEChange, nullptr, 0)
35 
36 // ===========================================================================
37 // member method definitions
38 // ===========================================================================
39 
40 
41 GNEChange_TLS::GNEChange_TLS(GNEJunction* junction, NBTrafficLightDefinition* tlDef, bool forward, bool forceInsert, const std::string tlID):
43  GNEChange(junction->getNet(), forward),
44  myJunction(junction),
45  myTlDef(tlDef),
46  myForceInsert(forceInsert) {
47  assert(myNet);
48  myJunction->incRef("GNEChange_TLS");
49  if (myTlDef == nullptr) {
50  assert(forward);
51  // potential memory leak if this change is never executed
53  myTlDef = new NBOwnTLDef(tlID == "" ? myJunction->getMicrosimID() : tlID, 0, type);
54  }
55 }
56 
57 
59  assert(myJunction);
60  myJunction->decRef("GNEChange_TLS");
61  if (myJunction->unreferenced()) {
62  // show extra information for tests
63  WRITE_DEBUG("Deleting unreferenced " + myJunction->getTagStr() + " '" + myJunction->getID() + "' in GNEChange_TLS");
64  delete myJunction;
65  }
66 }
67 
68 
69 void
71  if (myForward) {
72  // show extra information for tests
73  WRITE_DEBUG("Removing TLS from " + myJunction->getTagStr() + " '" + myJunction->getID() + "'");
74  // remove traffic light from junction
76  } else {
77  // show extra information for tests
78  WRITE_DEBUG("Adding TLS into " + myJunction->getTagStr() + " '" + myJunction->getID() + "'");
79  // add traffic light to junction
81  }
82  // enable save netElements
83  myNet->requireSaveNet(true);
84 }
85 
86 
87 void
89  if (myForward) {
90  // show extra information for tests
91  WRITE_DEBUG("Adding TLS into " + myJunction->getTagStr() + " '" + myJunction->getID() + "'");
92  // add traffic light to junction
94  } else {
95  // show extra information for tests
96  WRITE_DEBUG("Deleting TLS from " + myJunction->getTagStr() + " '" + myJunction->getID() + "'");
97  // remove traffic light from junction
99  }
100  // enable save netElements
101  myNet->requireSaveNet(true);
102 }
103 
104 
105 FXString
107  if (myForward) {
108  return ("Undo create " + toString(SUMO_TAG_TRAFFIC_LIGHT)).c_str();
109  } else {
110  return ("Undo delete " + toString(SUMO_TAG_TRAFFIC_LIGHT)).c_str();
111  }
112 }
113 
114 
115 FXString
117  if (myForward) {
118  return ("Redo create " + toString(SUMO_TAG_TRAFFIC_LIGHT)).c_str();
119  } else {
120  return ("Redo delete " + toString(SUMO_TAG_TRAFFIC_LIGHT)).c_str();
121  }
122 }
GNEChange_TLS::redoName
FXString redoName() const
get Redo name
Definition: GNEChange_TLS.cpp:116
GNENet::requireSaveNet
void requireSaveNet(bool value)
inform that net has to be saved
Definition: GNENet.cpp:982
GNEReferenceCounter::unreferenced
bool unreferenced()
check if object ins't referenced
Definition: GNEReferenceCounter.h:78
GNEAttributeCarrier::getID
const std::string getID() const
function to support debugging
Definition: GNEAttributeCarrier.cpp:1289
OptionsCont.h
GNEChange::myForward
bool myForward
we group antagonistic commands (create junction/delete junction) and keep them apart by this flag
Definition: GNEChange.h:80
GNEChange_TLS::myJunction
GNEJunction * myJunction
we need the junction because it is the target of our change commands
Definition: GNEChange_TLS.h:77
TrafficLightType
TrafficLightType
Definition: SUMOXMLDefinitions.h:1197
NBOwnTLDef
A traffic light logics which must be computed (only nodes/edges are given)
Definition: NBOwnTLDef.h:46
OptionsCont::getOptions
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:57
GNEJunction.h
GNEJunction::removeTrafficLight
void removeTrafficLight(NBTrafficLightDefinition *tlDef)
removes a traffic light
Definition: GNEJunction.cpp:1514
StringBijection::get
T get(const std::string &str) const
Definition: StringBijection.h:97
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:82
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:75
GNEChange_TLS
Definition: GNEChange_TLS.h:42
GNEReferenceCounter::decRef
void decRef(const std::string &debugMsg="")
Decrease reference.
Definition: GNEReferenceCounter.h:52
GNEChange_TLS::myForceInsert
bool myForceInsert
check if forceInsert is enabled
Definition: GNEChange_TLS.h:85
GNEJunction::addTrafficLight
void addTrafficLight(NBTrafficLightDefinition *tlDef, bool forceInsert)
adds a traffic light
Definition: GNEJunction.cpp:1506
toString
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:47
SUMO_TAG_TRAFFIC_LIGHT
a traffic light
Definition: SUMOXMLDefinitions.h:139
GNEChange_TLS::redo
void redo()
redo action
Definition: GNEChange_TLS.cpp:88
SUMOXMLDefinitions::TrafficLightTypes
static StringBijection< TrafficLightType > TrafficLightTypes
traffic light types
Definition: SUMOXMLDefinitions.h:1392
config.h
GNEChange_TLS::~GNEChange_TLS
~GNEChange_TLS()
Destructor.
Definition: GNEChange_TLS.cpp:58
GNEAttributeCarrier::getTagStr
const std::string & getTagStr() const
get tag assigned to this object in string format
Definition: GNEAttributeCarrier.cpp:1267
NBOwnTLDef.h
GNEChange_TLS::undoName
FXString undoName() const
return undoName
Definition: GNEChange_TLS.cpp:106
GNEJunction
Definition: GNEJunction.h:47
GNEChange_TLS::undo
void undo()
undo action
Definition: GNEChange_TLS.cpp:70
GNEChange
the function-object for an editing operation (abstract base)
Definition: GNEChange.h:42
WRITE_DEBUG
#define WRITE_DEBUG(msg)
Definition: MsgHandler.h:284
GNENet.h
NBTrafficLightDefinition
The base class for traffic light logic definitions.
Definition: NBTrafficLightDefinition.h:67