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 
24 
25 #include <cassert>
28 #include <netbuild/NBOwnTLDef.h>
30 #include <netedit/GNENet.h>
31 #include <netedit/GNEViewNet.h>
32 #include <netedit/GNEViewParent.h>
33 
34 #include "GNEChange_TLS.h"
35 
36 
37 // ===========================================================================
38 // FOX-declarations
39 // ===========================================================================
40 FXIMPLEMENT_ABSTRACT(GNEChange_TLS, GNEChange, nullptr, 0)
41 
42 // ===========================================================================
43 // member method definitions
44 // ===========================================================================
45 
46 
47 GNEChange_TLS::GNEChange_TLS(GNEJunction* junction, NBTrafficLightDefinition* tlDef, bool forward, bool forceInsert, const std::string tlID):
49  GNEChange(junction->getNet(), forward),
50  myJunction(junction),
51  myTlDef(tlDef),
52  myForceInsert(forceInsert) {
53  assert(myNet);
54  myJunction->incRef("GNEChange_TLS");
55  if (myTlDef == 0) {
56  assert(forward);
57  // potential memory leak if this change is never executed
59  myTlDef = new NBOwnTLDef(tlID == "" ? myJunction->getMicrosimID() : tlID, 0, type);
60  }
61 }
62 
63 
65  assert(myJunction);
66  myJunction->decRef("GNEChange_TLS");
67  if (myJunction->unreferenced()) {
68  // show extra information for tests
69  WRITE_DEBUG("Deleting unreferenced " + toString(myJunction->getTag()) + " '" + myJunction->getID() + "' in GNEChange_TLS");
70  delete myJunction;
71  }
72 }
73 
74 
75 void
77  if (myForward) {
78  // show extra information for tests
79  WRITE_DEBUG("Removing TLS from " + toString(myJunction->getTag()) + " '" + myJunction->getID() + "'");
80  // remove traffic light from junction
82  } else {
83  // show extra information for tests
84  WRITE_DEBUG("Adding TLS into " + toString(myJunction->getTag()) + " '" + myJunction->getID() + "'");
85  // add traffic light to junction
87  }
88  // enable save netElements
89  myNet->requiereSaveNet(true);
90 }
91 
92 
93 void
95  if (myForward) {
96  // show extra information for tests
97  WRITE_DEBUG("Adding TLS into " + toString(myJunction->getTag()) + " '" + myJunction->getID() + "'");
98  // add traffic light to junction
100  } else {
101  // show extra information for tests
102  WRITE_DEBUG("Deleting TLS from " + toString(myJunction->getTag()) + " '" + myJunction->getID() + "'");
103  // remove traffic light from junction
105  }
106  // enable save netElements
107  myNet->requiereSaveNet(true);
108 }
109 
110 
111 FXString
113  if (myForward) {
114  return ("Undo create " + toString(SUMO_TAG_TRAFFIC_LIGHT)).c_str();
115  } else {
116  return ("Undo delete " + toString(SUMO_TAG_TRAFFIC_LIGHT)).c_str();
117  }
118 }
119 
120 
121 FXString
123  if (myForward) {
124  return ("Redo create " + toString(SUMO_TAG_TRAFFIC_LIGHT)).c_str();
125  } else {
126  return ("Redo delete " + toString(SUMO_TAG_TRAFFIC_LIGHT)).c_str();
127  }
128 }
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:42
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:249
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:75
void requiereSaveNet(bool value)
inform that net has to be saved
Definition: GNENet.cpp:844
bool myForward
we group antagonistic commands (create junction/delete junction) and keep them apart by this flag ...
Definition: GNEChange.h:80
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
SumoXMLTag getTag() const
get XML Tag assigned to this object