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-2018 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 }
GNEJunction * myJunction
we need the junction because it is the target of our change commands
Definition: GNEChange_TLS.h:78
the function-object for an editing operation (abstract base)
Definition: GNEChange.h:43
void redo()
redo action
The base class for traffic light logic definitions.
bool myForceInsert
check if forceInsert is enabled
Definition: GNEChange_TLS.h:86
NBTrafficLightDefinition * myTlDef
the traffic light to be created/deleted. We assume no responsiblity for the pointer ...
Definition: GNEChange_TLS.h:83
~GNEChange_TLS()
Destructor.
void removeTrafficLight(NBTrafficLightDefinition *tlDef)
removes a traffic light
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:58
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:49
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
#define WRITE_DEBUG(msg)
Definition: MsgHandler.h:248
void decRef(const std::string &debugMsg="")
Decrease reference.
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
const std::string & getTagStr() const
get tag assigned to this object in string format
void requiereSaveNet(bool value)
inform that net has to be saved
Definition: GNENet.cpp:837
bool myForward
we group antagonistic commands (create junction/delete junction) and keep them apart by this flag ...
Definition: GNEChange.h:81
A traffic light logics which must be computed (only nodes/edges are given)
Definition: NBOwnTLDef.h:47
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