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 
30 #include <cassert>
33 #include <netbuild/NBOwnTLDef.h>
34 #include "GNEChange_TLS.h"
35 #include "GNEJunction.h"
36 
37 #ifdef CHECK_MEMORY_LEAKS
38 #include <foreign/nvwa/debug_new.h>
39 #endif
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  delete myJunction;
74  }
75 }
76 
77 
78 void
80  if (myForward) {
82  } else {
84  }
85 }
86 
87 
88 void
90  if (myForward) {
92  } else {
94  }
95 }
96 
97 
98 FXString
100  if (myForward) {
101  return ("Undo create " + toString(SUMO_TAG_TRAFFIC_LIGHT)).c_str();
102  } else {
103  return ("Undo delete " + toString(SUMO_TAG_TRAFFIC_LIGHT)).c_str();
104  }
105 }
106 
107 
108 FXString
110  if (myForward) {
111  return ("Redo create " + toString(SUMO_TAG_TRAFFIC_LIGHT)).c_str();
112  } else {
113  return ("Redo delete " + toString(SUMO_TAG_TRAFFIC_LIGHT)).c_str();
114  }
115 }
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
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
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:69
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
FXString redoName() const
get Redo name
void decRef(const std::string &debugMsg="")
FXString undoName() const
return undoName
T get(const std::string &str) const
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
TrafficLightType