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-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
17 // A network change in which a traffic light is created or deleted
18 /****************************************************************************/
19 
20 // ===========================================================================
21 // included modules
22 // ===========================================================================
23 #ifdef _MSC_VER
24 #include <windows_config.h>
25 #else
26 #include <config.h>
27 #endif
28 
30 
31 #include <cassert>
34 #include <netbuild/NBOwnTLDef.h>
35 #include "GNEChange_TLS.h"
36 #include "GNEJunction.h"
37 #include "GNENet.h"
38 #include "GNEViewNet.h"
39 
40 
41 // ===========================================================================
42 // FOX-declarations
43 // ===========================================================================
44 FXIMPLEMENT_ABSTRACT(GNEChange_TLS, GNEChange, NULL, 0)
45 
46 // ===========================================================================
47 // member method definitions
48 // ===========================================================================
49 
50 
51 GNEChange_TLS::GNEChange_TLS(GNEJunction* junction, NBTrafficLightDefinition* tlDef, bool forward, bool forceInsert, const std::string tlID):
53  GNEChange(junction->getNet(), forward),
54  myJunction(junction),
55  myTlDef(tlDef),
56  myForceInsert(forceInsert) {
57  assert(myNet);
58  myJunction->incRef("GNEChange_TLS");
59  if (myTlDef == 0) {
60  assert(forward);
61  // potential memory leak if this change is never executed
63  myTlDef = new NBOwnTLDef(tlID == "" ? myJunction->getMicrosimID() : tlID, 0, type);
64  }
65 }
66 
67 
69  assert(myJunction);
70  myJunction->decRef("GNEChange_TLS");
71  if (myJunction->unreferenced()) {
72  // show extra information for tests
73  if (OptionsCont::getOptions().getBool("gui-testing-debug")) {
74  WRITE_WARNING("Deleting unreferenced " + toString(myJunction->getTag()) + " '" + myJunction->getID() + "' in GNEChange_TLS");
75  }
76  delete myJunction;
77  }
78 }
79 
80 
81 void
83  if (myForward) {
84  // show extra information for tests
85  if (OptionsCont::getOptions().getBool("gui-testing-debug")) {
86  WRITE_WARNING("Removing TLS from " + toString(myJunction->getTag()) + " '" + myJunction->getID() + "'");
87  }
88  // remove traffic light from junction
90  } else {
91  // show extra information for tests
92  if (OptionsCont::getOptions().getBool("gui-testing-debug")) {
93  WRITE_WARNING("Adding TLS into " + toString(myJunction->getTag()) + " '" + myJunction->getID() + "'");
94  }
95  // add traffic light to junction
97  }
98 }
99 
100 
101 void
103  if (myForward) {
104  // show extra information for tests
105  if (OptionsCont::getOptions().getBool("gui-testing-debug")) {
106  WRITE_WARNING("Adding TLS into " + toString(myJunction->getTag()) + " '" + myJunction->getID() + "'");
107  }
108  // add traffic light to junction
110  } else {
111  // show extra information for tests
112  if (OptionsCont::getOptions().getBool("gui-testing-debug")) {
113  WRITE_WARNING("Deleting TLS from " + toString(myJunction->getTag()) + " '" + myJunction->getID() + "'");
114  }
115  // remove traffic light from junction
117  }
118 }
119 
120 
121 FXString
123  if (myForward) {
124  return ("Undo create " + toString(SUMO_TAG_TRAFFIC_LIGHT)).c_str();
125  } else {
126  return ("Undo delete " + toString(SUMO_TAG_TRAFFIC_LIGHT)).c_str();
127  }
128 }
129 
130 
131 FXString
133  if (myForward) {
134  return ("Redo create " + toString(SUMO_TAG_TRAFFIC_LIGHT)).c_str();
135  } else {
136  return ("Redo delete " + toString(SUMO_TAG_TRAFFIC_LIGHT)).c_str();
137  }
138 }
GNEJunction * myJunction
we need the junction because it is the target of our change commands
Definition: GNEChange_TLS.h:84
the function-object for an editing operation (abstract base)
Definition: GNEChange.h:48
void redo()
redo action
The base class for traffic light logic definitions.
bool myForceInsert
check if forceInsert is enabled
Definition: GNEChange_TLS.h:92
NBTrafficLightDefinition * myTlDef
the traffic light to be created/deleted. We assume no responsiblity for the pointer ...
Definition: GNEChange_TLS.h:89
~GNEChange_TLS()
Destructor.
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
void removeTrafficLight(NBTrafficLightDefinition *tlDef)
removes a traffic light
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:199
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:64
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:55
void undo()
undo action
static StringBijection< TrafficLightType > TrafficLightTypes
traffic light types
T get(const std::string &str) const
const std::string getID() const
function to support debugging
void decRef(const std::string &debugMsg="")
Decrease reference.
bool myForward
we group antagonistic commands (create junction/delete junction) and keep them apart by this flag ...
Definition: GNEChange.h:86
A traffic light logics which must be computed (only nodes/edges are given)
Definition: NBOwnTLDef.h:53
bool unreferenced()
check if object ins&#39;t referenced
void addTrafficLight(NBTrafficLightDefinition *tlDef, bool forceInsert)
adds a traffic light
FXString undoName() const
return undoName
FXString redoName() const
get Redo name
TrafficLightType
SumoXMLTag getTag() const
get XML Tag assigned to this object