SUMO - Simulation of Urban MObility
GNEChange_Additional.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 busStop 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 "GNEChange_Additional.h"
32 #include "GNENet.h"
33 #include "GNELane.h"
34 #include "GNEEdge.h"
35 #include "GNEAdditional.h"
36 #include "GNEViewNet.h"
37 #include "GNEDetectorE3.h"
38 #include "GNEDetectorEntry.h"
39 #include "GNEDetectorExit.h"
40 #include "GNEStoppingPlace.h"
41 #include "GNERerouter.h"
42 #include "GNEVariableSpeedSign.h"
43 
44 
45 // ===========================================================================
46 // FOX-declarations
47 // ===========================================================================
48 FXIMPLEMENT_ABSTRACT(GNEChange_Additional, GNEChange, NULL, 0)
49 
50 // ===========================================================================
51 // member method definitions
52 // ===========================================================================
53 
55  GNEChange(additional->getViewNet()->getNet(), forward),
56  myAdditional(additional),
57  myLaneParent(NULL),
58  myEdgeParent(NULL),
59  myAdditionalParent(myAdditional->getAdditionalParent()),
60  myEdgeChilds(myAdditional->getEdgeChilds()),
61  myLaneChilds(myAdditional->getLaneChilds()) {
62  assert(myNet);
63  myAdditional->incRef("GNEChange_Additional");
64  // handle additionals with lane parent
65  if (GNEAttributeCarrier::hasAttribute(myAdditional->getTag(), SUMO_ATTR_LANE)) {
66  myLaneParent = myNet->retrieveLane(myAdditional->getAttribute(SUMO_ATTR_LANE));
67  }
68  // handle additionals with edge parent
69  if (GNEAttributeCarrier::hasAttribute(myAdditional->getTag(), SUMO_ATTR_EDGE)) {
70  myEdgeParent = myNet->retrieveEdge(myAdditional->getAttribute(SUMO_ATTR_EDGE));
71  }
72 }
73 
74 
76  assert(myAdditional);
77  myAdditional->decRef("GNEChange_Additional");
78  if (myAdditional->unreferenced()) {
79  // show extra information for tests
80  if (OptionsCont::getOptions().getBool("gui-testing-debug")) {
81  WRITE_WARNING("Deleting unreferenced " + toString(myAdditional->getTag()) + " '" + myAdditional->getID() + "'");
82  }
83  // make sure that additional isn't in net before removing
84  if (myNet->retrieveAdditional(myAdditional->getID(), false)) {
86  }
87  delete myAdditional;
88  }
89 }
90 
91 
92 void
94  if (myForward) {
95  // show extra information for tests
96  if (OptionsCont::getOptions().getBool("gui-testing-debug")) {
97  WRITE_WARNING("Removing " + toString(myAdditional->getTag()) + " '" + myAdditional->getID() + "' in GNEChange_Additional");
98  }
99  // delete additional of test
101  // 1 - If additional own a lane parent, remove it from lane
102  if (myLaneParent) {
104  }
105  // 2 - If additional own a edge parent, remove it from edge
106  if (myEdgeParent) {
108  }
109  // 3 - If additiona has a parent, remove it from their additional childs
110  if (myAdditionalParent) {
112  }
113  // 4 - if Additional has edge childs, remove it of their additional parents
114  for (auto i : myEdgeChilds) {
115  i->removeAdditionalParent(myAdditional);
116  }
117  // 5 - if Additional has lane childs, remove it of their additional parents
118  for (auto i : myLaneChilds) {
119  i->removeAdditionalParent(myAdditional);
120  }
121  } else {
122  // show extra information for tests
123  if (OptionsCont::getOptions().getBool("gui-testing-debug")) {
124  WRITE_WARNING("Adding " + toString(myAdditional->getTag()) + " '" + myAdditional->getID() + "' in GNEChange_Additional");
125  }
126  // insert additional of test
128  // 1 - If additional own a Lane parent, add it to lane
129  if (myLaneParent) {
131  }
132  // 2 - If additional own a edge parent, add it to edge
133  if (myEdgeParent != NULL) {
135  }
136  // 3 - If additional has a parent, add it into additional parent
137  if (myAdditionalParent) {
139  }
140  // 4 - if Additional has edge childs, add id into additional parents
141  for (auto i : myEdgeChilds) {
142  i->addAdditionalParent(myAdditional);
143  }
144  // 5 - if Additional has lane childs, add id into additional parents
145  for (auto i : myLaneChilds) {
146  i->addAdditionalParent(myAdditional);
147  }
148  }
149  // Requiere always save additionals
151 }
152 
153 
154 void
156  if (myForward) {
157  // show extra information for tests
158  if (OptionsCont::getOptions().getBool("gui-testing-debug")) {
159  WRITE_WARNING("Adding " + toString(myAdditional->getTag()) + " '" + myAdditional->getID() + "' in GNEChange_Additional");
160  }
161  // insert additional into net
163  // 1 - If additional own a Lane parent, add it to lane
164  if (myLaneParent) {
166  }
167  // 2 - If additional own a edge parent, add it to edge
168  if (myEdgeParent != NULL) {
170  }
171  // 3 - If additional has a parent, add it into additional parent
172  if (myAdditionalParent) {
174  }
175  // 4 - if Additional has edge childs, add id into additional parents
176  for (auto i : myEdgeChilds) {
177  i->addAdditionalParent(myAdditional);
178  }
179  // 5 - if Additional has lane childs, add id into additional parents
180  for (auto i : myLaneChilds) {
181  i->addAdditionalParent(myAdditional);
182  }
183  } else {
184  // show extra information for tests
185  if (OptionsCont::getOptions().getBool("gui-testing-debug")) {
186  WRITE_WARNING("Removing " + toString(myAdditional->getTag()) + " '" + myAdditional->getID() + "' in GNEChange_Additional");
187  }
188  // delete additional of test
190  // 1 - If additional own a lane parent, remove it from lane
191  if (myLaneParent) {
193  }
194  // 2 - If additional own a edge parent, remove it from edge
195  if (myEdgeParent) {
197  }
198  // 3 - If additiona has a parent, remove it from their additional childs
199  if (myAdditionalParent) {
201  }
202  // 4 - if Additional has edge childs, remove it of their additional parents
203  for (auto i : myEdgeChilds) {
204  i->removeAdditionalParent(myAdditional);
205  }
206  // 5 - if Additional has lane childs, remove it of their additional parents
207  for (auto i : myLaneChilds) {
208  i->removeAdditionalParent(myAdditional);
209  }
210  }
211  // Requiere always save additionals
213 }
214 
215 
216 FXString
218  if (myForward) {
219  return ("Undo create " + toString(myAdditional->getTag())).c_str();
220  } else {
221  return ("Undo delete " + toString(myAdditional->getTag())).c_str();
222  }
223 }
224 
225 
226 FXString
228  if (myForward) {
229  return ("Redo create " + toString(myAdditional->getTag())).c_str();
230  } else {
231  return ("Redo delete " + toString(myAdditional->getTag())).c_str();
232  }
233 }
GNEEdge * myEdgeParent
pointer to edge (used by additionals with edge parent)
void insertAdditional(GNEAdditional *additional)
Insert a additional element int GNENet container.
Definition: GNENet.cpp:2020
GNEAdditional * myAdditionalParent
pointer to additional (used by additional with parents, for example Entry/exits)
void requiereSaveAdditionals()
inform that additionals has to be saved
Definition: GNENet.cpp:1736
the function-object for an editing operation (abstract base)
Definition: GNEChange.h:48
void removeAdditionalChild(GNEAdditional *additional)
remove additional child from this additional
FXString redoName() const
get Redo name
std::vector< GNEEdge * > myEdgeChilds
list of Edge childs (used by Rerouters)
~GNEChange_Additional()
Destructor.
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:199
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:64
FXString undoName() const
return undoName
GNEAdditional * myAdditional
full information regarding the additional element that is to be created/deleted
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:55
static bool hasAttribute(SumoXMLTag tag, SumoXMLAttr attr)
check if an element with certain tag has a certain attribute
void addAdditionalChild(GNEAdditional *additional)
add additional child to this edge
const std::string getID() const
function to support debugging
void removeAdditionalChild(GNEAdditional *additional)
remove additional child from this edge
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:81
An Element which don&#39;t belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:59
GNEAdditional * retrieveAdditional(const std::string &id, bool hardFail=true) const
Returns the named additional.
Definition: GNENet.cpp:1640
std::vector< GNELane * > myLaneChilds
list of Edge childs (used by VSS)
bool myForward
we group antagonistic commands (create junction/delete junction) and keep them apart by this flag ...
Definition: GNEChange.h:86
void deleteAdditional(GNEAdditional *additional)
delete additional element of GNENet container
Definition: GNENet.cpp:2036
void addAdditionalChild(GNEAdditional *additional)
add additional child to this additional
GNELane * myLaneParent
pointer to lane (used by additionals with lane parent)
bool unreferenced()
check if object ins&#39;t referenced
SumoXMLTag getTag() const
get XML Tag assigned to this object