SUMO - Simulation of Urban MObility
GNEChange_TLS.cpp
Go to the documentation of this file.
1 /****************************************************************************/
7 // A network change in which a traffic light is created or deleted
8 /****************************************************************************/
9 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
10 // Copyright (C) 2001-2017 DLR (http://www.dlr.de/) and contributors
11 /****************************************************************************/
12 //
13 // This file is part of SUMO.
14 // SUMO is free software: you can redistribute it and/or modify
15 // it under the terms of the GNU General Public License as published by
16 // the Free Software Foundation, either version 3 of the License, or
17 // (at your option) any later version.
18 //
19 /****************************************************************************/
20 
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #ifdef _MSC_VER
25 #include <windows_config.h>
26 #else
27 #include <config.h>
28 #endif
29 
31 
32 #include <cassert>
35 #include <netbuild/NBOwnTLDef.h>
36 #include "GNEChange_TLS.h"
37 #include "GNEJunction.h"
38 #include "GNENet.h"
39 #include "GNEViewNet.h"
40 
41 
42 // ===========================================================================
43 // FOX-declarations
44 // ===========================================================================
45 FXIMPLEMENT_ABSTRACT(GNEChange_TLS, GNEChange, NULL, 0)
46 
47 // ===========================================================================
48 // member method definitions
49 // ===========================================================================
50 
51 
52 GNEChange_TLS::GNEChange_TLS(GNEJunction* junction, NBTrafficLightDefinition* tlDef, bool forward, bool forceInsert, const std::string tlID):
54  GNEChange(junction->getNet(), forward),
55  myJunction(junction),
56  myTlDef(tlDef),
57  myForceInsert(forceInsert) {
58  assert(myNet);
59  myJunction->incRef("GNEChange_TLS");
60  if (myTlDef == 0) {
61  assert(forward);
62  // potential memory leak if this change is never executed
64  myTlDef = new NBOwnTLDef(tlID == "" ? myJunction->getMicrosimID() : tlID, 0, type);
65  }
66 }
67 
68 
70  assert(myJunction);
71  myJunction->decRef("GNEChange_TLS");
72  if (myJunction->unreferenced()) {
73  // show extra information for tests
75  WRITE_WARNING("Deleting unreferenced " + toString(myJunction->getTag()) + " '" + myJunction->getID() + "'");
76  }
77  delete myJunction;
78  }
79 }
80 
81 
82 void
84  if (myForward) {
85  // show extra information for tests
87  WRITE_WARNING("Deleting " + toString(myJunction->getTag()) + " '" + myJunction->getID() + "'");
88  }
89  // remove traffic light from junction
91  } else {
92  // show extra information for tests
94  WRITE_WARNING("Adding " + toString(myJunction->getTag()) + " '" + myJunction->getID() + "'");
95  }
96  // add traffic light to junction
98  }
99 }
100 
101 
102 void
104  if (myForward) {
105  // show extra information for tests
107  WRITE_WARNING("Adding " + toString(myJunction->getTag()) + " '" + myJunction->getID() + "'");
108  }
109  // add traffic light to junction
111  } else {
112  // show extra information for tests
114  WRITE_WARNING("Deleting " + toString(myJunction->getTag()) + " '" + myJunction->getID() + "'");
115  }
116  // remove traffic light from junction
118  }
119 }
120 
121 
122 FXString
124  if (myForward) {
125  return ("Undo create " + toString(SUMO_TAG_TRAFFIC_LIGHT)).c_str();
126  } else {
127  return ("Undo delete " + toString(SUMO_TAG_TRAFFIC_LIGHT)).c_str();
128  }
129 }
130 
131 
132 FXString
134  if (myForward) {
135  return ("Redo create " + toString(SUMO_TAG_TRAFFIC_LIGHT)).c_str();
136  } else {
137  return ("Redo delete " + toString(SUMO_TAG_TRAFFIC_LIGHT)).c_str();
138  }
139 }
GNEJunction * myJunction
we need the junction because it is the target of our change commands
Definition: GNEChange_TLS.h:85
the function-object for an editing operation (abstract base)
Definition: GNEChange.h:49
void redo()
redo action
GNENet * getNet() const
get Net in which this element is placed
The base class for traffic light logic definitions.
bool myForceInsert
check if forceInsert is enabled
Definition: GNEChange_TLS.h:93
NBTrafficLightDefinition * myTlDef
the traffic light to be created/deleted. We assume no responsiblity for the pointer ...
Definition: GNEChange_TLS.h:90
~GNEChange_TLS()
Destructor.
void removeTrafficLight(NBTrafficLightDefinition *tlDef)
removes a traffic light
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:200
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:65
bool isTestingModeEnabled() const
check if netedit is running in testing mode
Definition: GNEViewNet.cpp:405
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:56
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="")
GNENet * myNet
the net to which operations shall be applied or which shall be informed about gui updates (we are not...
Definition: GNEChange.h:82
bool myForward
we group antagonistic commands (create junction/delete junction) and keep them apart by this flag ...
Definition: GNEChange.h:87
A traffic light logics which must be computed (only nodes/edges are given)
Definition: NBOwnTLDef.h:54
void addTrafficLight(NBTrafficLightDefinition *tlDef, bool forceInsert)
adds a traffic light
FXString undoName() const
return undoName
FXString redoName() const
get Redo name
TrafficLightType
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:1165
SumoXMLTag getTag() const
get XML Tag assigned to this object