SUMO - Simulation of Urban MObility
GNEChange_Additional.cpp
Go to the documentation of this file.
1 /****************************************************************************/
7 // A network change in which a busStop 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 "GNEChange_Additional.h"
33 #include "GNENet.h"
34 #include "GNELane.h"
35 #include "GNEEdge.h"
36 #include "GNEAdditional.h"
37 #include "GNEViewNet.h"
38 #include "GNEDetectorE3.h"
39 #include "GNEDetectorEntry.h"
40 #include "GNEDetectorExit.h"
41 #include "GNEStoppingPlace.h"
42 #include "GNERerouter.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  myE3Parent(NULL) {
60  assert(myNet);
61  myAdditional->incRef("GNEChange_Additional");
62  // handle additionals with lane parent
63  if (myAdditional->getLane() != NULL) {
64  myLaneParent = myAdditional->getLane();
65  }
66  // handle additionals with edge parent
67  if (myAdditional->getEdge() != NULL) {
68  myEdgeParent = myAdditional->getEdge();
69  }
70  // handle additional with childs
71  if (myAdditional->getTag() == SUMO_TAG_E3DETECTOR) {
72  GNEDetectorE3* E3 = dynamic_cast<GNEDetectorE3*>(myAdditional);
73  myEntryChilds = E3->myGNEDetectorEntrys;
74  myExitChilds = E3->myGNEDetectorExits;
75  } else if (myAdditional->getTag() == SUMO_TAG_DET_ENTRY) {
76  myE3Parent = dynamic_cast<GNEDetectorEntry*>(myAdditional)->getE3Parent();
77  } else if (myAdditional->getTag() == SUMO_TAG_DET_EXIT) {
78  myE3Parent = dynamic_cast<GNEDetectorExit*>(myAdditional)->getE3Parent();
79  }
80  // handle additional with edge chidls
81  if (myAdditional->getTag() == SUMO_TAG_REROUTER) {
82  myEdgeChilds = dynamic_cast<GNERerouter*>(myAdditional)->getEdgeChilds();
83  }
84 }
85 
86 
88  assert(myAdditional);
89  myAdditional->decRef("GNEChange_Additional");
90  if (myAdditional->unreferenced()) {
91  // show extra information for tests
92  if (OptionsCont::getOptions().getBool("gui-testing-debug")) {
93  WRITE_WARNING("Deleting unreferenced " + toString(myAdditional->getTag()) + " '" + myAdditional->getID() + "'");
94  }
95  delete myAdditional;
96  }
97 }
98 
99 
100 void
102  if (myForward) {
103  // show extra information for tests
104  if (OptionsCont::getOptions().getBool("gui-testing-debug")) {
105  WRITE_WARNING("Removing " + toString(myAdditional->getTag()) + " '" + myAdditional->getID() + "' in GNEChange_Additional");
106  }
107  // delete additional of test
109  // 1 - If additional own a lane parent, remove it from lane
110  if (myAdditional->getLane() != NULL) {
111  assert(myLaneParent);
113  }
114  // 2 - If additional own a lane parent, remove it from edge
115  if (myAdditional->getEdge() != NULL) {
116  assert(myEdgeParent);
118  }
119  // 3 - If additional is an E3 Detector, delete Entry/Exit childs
121  for (std::vector<GNEDetectorEntry*>::iterator i = myEntryChilds.begin(); i != myEntryChilds.end(); i++) {
122  // delete entry of their lane parent before remove
123  (*i)->getLane()->removeAdditionalChild(*i);
124  myNet->deleteAdditional(*i);
125  }
126  for (std::vector<GNEDetectorExit*>::iterator i = myExitChilds.begin(); i != myExitChilds.end(); i++) {
127  // delete entry of their lane parent before remove
128  (*i)->getLane()->removeAdditionalChild(*i);
129  myNet->deleteAdditional(*i);
130  }
131  }
132  // 4 - If additiona is an Entry detector, remove it from E3 parent
134  assert(myE3Parent);
135  myE3Parent->removeEntryChild(dynamic_cast<GNEDetectorEntry*>(myAdditional));
137  myNet->getViewNet()->update();
138  }
139  // 5 - If additiona is an Exit detector, remove it from E3 parent
141  assert(myE3Parent);
142  myE3Parent->removeExitChild(dynamic_cast<GNEDetectorExit*>(myAdditional));
144  myNet->getViewNet()->update();
145  }
146  // 6 - if Additional if a rerouter, remove it of all of their edge childs
148  GNERerouter* rerouter = dynamic_cast<GNERerouter*>(myAdditional);
149  for (std::vector<GNEEdge*>::iterator i = myEdgeChilds.begin(); i != myEdgeChilds.end(); i++) {
150  (*i)->removeGNERerouter(rerouter);
151  }
152  }
153  } else {
154  // show extra information for tests
155  if (OptionsCont::getOptions().getBool("gui-testing-debug")) {
156  WRITE_WARNING("Adding " + toString(myAdditional->getTag()) + " '" + myAdditional->getID() + "' in GNEChange_Additional");
157  }
158  // insert additional of test
160  // 1 - If additional own a Lane parent, add it to lane
161  if (myAdditional->getLane() != NULL) {
162  assert(myLaneParent);
164  }
165  // 2 - If additional own a lane parent, add it to edge
166  if (myAdditional->getEdge() != NULL) {
167  assert(myEdgeParent);
169  }
170  // 3 - If additional is an E3 detector, add it their Entry/Exit childs
172  for (std::vector<GNEDetectorEntry*>::iterator i = myEntryChilds.begin(); i != myEntryChilds.end(); i++) {
173  // add entry of their lane parent before insert
174  (*i)->getLane()->addAdditionalChild(*i);
175  myNet->insertAdditional(*i);
176  }
177  for (std::vector<GNEDetectorExit*>::iterator i = myExitChilds.begin(); i != myExitChilds.end(); i++) {
178  // add entry of their lane parent before insert
179  (*i)->getLane()->addAdditionalChild(*i);
180  myNet->insertAdditional(*i);
181  }
182  }
183  // 4 - If additional is an Exit detector, add id to E3 parent
185  assert(myE3Parent);
186  myE3Parent->addEntryChild(dynamic_cast<GNEDetectorEntry*>(myAdditional));
188  myNet->getViewNet()->update();
189  }
190  // 5 - If additional is an Exit detector, add id to E3 parent
192  assert(myE3Parent);
193  myE3Parent->addExitChild(dynamic_cast<GNEDetectorExit*>(myAdditional));
195  myNet->getViewNet()->update();
196  }
197  // 6 - if Additional if a rerouter, add it of all of their edge childs
199  GNERerouter* rerouter = dynamic_cast<GNERerouter*>(myAdditional);
200  for (std::vector<GNEEdge*>::iterator i = myEdgeChilds.begin(); i != myEdgeChilds.end(); i++) {
201  (*i)->addGNERerouter(rerouter);
202  }
203  }
204  }
205  // Requiere always save additionals
207 }
208 
209 
210 void
212  if (myForward) {
213  // show extra information for tests
214  if (OptionsCont::getOptions().getBool("gui-testing-debug")) {
215  WRITE_WARNING("Adding " + toString(myAdditional->getTag()) + " '" + myAdditional->getID() + "' in GNEChange_Additional");
216  }
217  // insert additional into net
219  // 1 - If additional own a Lane parent, add it to lane
220  if (myAdditional->getLane() != NULL) {
221  assert(myLaneParent);
223  }
224  // 2 - If additional own a lane parent, add it to edge
225  if (myAdditional->getEdge() != NULL) {
226  assert(myEdgeParent);
228  }
229  // 3 - If additional is an E3 detector, add it their Entry/Exit childs
231  for (std::vector<GNEDetectorEntry*>::iterator i = myEntryChilds.begin(); i != myEntryChilds.end(); i++) {
232  // add entry of their lane parent before insert
233  (*i)->getLane()->addAdditionalChild(*i);
234  myNet->insertAdditional(*i);
235  }
236  for (std::vector<GNEDetectorExit*>::iterator i = myExitChilds.begin(); i != myExitChilds.end(); i++) {
237  // add entry of their lane parent before insert
238  (*i)->getLane()->addAdditionalChild(*i);
239  myNet->insertAdditional(*i);
240  }
241  }
242  // 4 - If additional is an Entry detector, add id to E3 parent
244  assert(myE3Parent);
245  myE3Parent->addEntryChild(dynamic_cast<GNEDetectorEntry*>(myAdditional));
247  myNet->getViewNet()->update();
248  }
249  // 5 - If additional is an Exit detector, add id to E3 parent
251  assert(myE3Parent);
252  myE3Parent->addExitChild(dynamic_cast<GNEDetectorExit*>(myAdditional));
254  myNet->getViewNet()->update();
255  }
256  // 6 - if Additional if a rerouter, add it of all of their edge childs
258  GNERerouter* rerouter = dynamic_cast<GNERerouter*>(myAdditional);
259  for (std::vector<GNEEdge*>::iterator i = myEdgeChilds.begin(); i != myEdgeChilds.end(); i++) {
260  (*i)->addGNERerouter(rerouter);
261  }
262  }
263  } else {
264  // show extra information for tests
265  if (OptionsCont::getOptions().getBool("gui-testing-debug")) {
266  WRITE_WARNING("Removing " + toString(myAdditional->getTag()) + " '" + myAdditional->getID() + "' in GNEChange_Additional");
267  }
269  // 1 - If additionl own a Lane Parent, remove it from lane
270  if (myAdditional->getLane() != NULL) {
271  assert(myLaneParent);
273  }
274  // 2 - If additional own a lane parent, remove it from lane
275  if (myAdditional->getEdge() != NULL) {
276  assert(myEdgeParent);
278  }
279  // 3 - If additional is an E3 Detector, delete Entry/Exit childs
281  for (std::vector<GNEDetectorEntry*>::iterator i = myEntryChilds.begin(); i != myEntryChilds.end(); i++) {
282  // delete entry of their lane parent before remove
283  (*i)->getLane()->removeAdditionalChild(*i);
284  myNet->deleteAdditional(*i);
285  }
286  for (std::vector<GNEDetectorExit*>::iterator i = myExitChilds.begin(); i != myExitChilds.end(); i++) {
287  // delete entry of their lane parent before remove
288  (*i)->getLane()->removeAdditionalChild(*i);
289  myNet->deleteAdditional(*i);
290  }
291  }
292  // 4 - If additiona is an Entry detector, remove it from E3 parent
294  assert(myE3Parent);
295  myE3Parent->removeEntryChild(dynamic_cast<GNEDetectorEntry*>(myAdditional));
297  myNet->getViewNet()->update();
298  }
299  // 5 - If additiona is an Exit detector, remove it from E3 parent
301  assert(myE3Parent);
302  myE3Parent->removeExitChild(dynamic_cast<GNEDetectorExit*>(myAdditional));
304  myNet->getViewNet()->update();
305  }
306  // 6 - if Additional if a rerouter, remove it of all of their edge childs
308  GNERerouter* rerouter = dynamic_cast<GNERerouter*>(myAdditional);
309  for (std::vector<GNEEdge*>::iterator i = myEdgeChilds.begin(); i != myEdgeChilds.end(); i++) {
310  (*i)->removeGNERerouter(rerouter);
311  }
312  }
313  }
314  // Requiere always save additionals
316 }
317 
318 
319 FXString
321  if (myForward) {
322  return ("Undo create " + toString(myAdditional->getTag())).c_str();
323  } else {
324  return ("Undo delete " + toString(myAdditional->getTag())).c_str();
325  }
326 }
327 
328 
329 FXString
331  if (myForward) {
332  return ("Redo create " + toString(myAdditional->getTag())).c_str();
333  } else {
334  return ("Redo delete " + toString(myAdditional->getTag())).c_str();
335  }
336 }
GNEEdge * myEdgeParent
pointer to edge (used by additionals with edge parent)
void requiereSaveAdditionals()
inform that additionals has to be saved
Definition: GNENet.cpp:1237
the function-object for an editing operation (abstract base)
Definition: GNEChange.h:49
std::vector< GNEDetectorEntry * > myEntryChilds
list of Entry detectors child (used by E3 Detector)
void addExitChild(GNEDetectorExit *exit)
add an Exit child
void removeAdditionalChild(GNEAdditional *additional)
remove additional child to this lane
Definition: GNELane.cpp:746
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
std::vector< GNEEdge * > myEdgeChilds
list of Edge childs (used by Rerouters)
std::vector< GNEDetectorEntry * > myGNEDetectorEntrys
vector with the GNEDetectorE3EntryExits of the detector
~GNEChange_Additional()
Destructor.
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:200
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:65
an e3 entry point
GNEAdditional * myAdditional
full information regarding the additional element that is to be created/deleted
void addAdditionalChild(GNEAdditional *additional)
add additional child to this edge
Definition: GNEEdge.cpp:1185
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:56
GNEEdge * getEdge() const
get edge of additional, or NULL if additional isn&#39;t placed over an edge
GNELane * getLane() const
get lane of additional, or NULL if additional isn&#39;t placed over a Lane
void updateGeometry()
update pre-computed geometry information
void addAdditionalChild(GNEAdditional *additional)
add additional child to this lane
Definition: GNELane.cpp:735
an e3 exit point
std::vector< GNEDetectorExit * > myGNEDetectorExits
vector with the GNEDetectorE3EntryExits of the detector
std::vector< GNEDetectorExit * > myExitChilds
list of Exit detectors child used (used by E3 Detector)
const std::string getID() const
function to support debugging
FXString undoName() const
return undoName
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:82
An Element which don&#39;t belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:62
GNEDetectorE3 * myE3Parent
pointer to E3 parent (used by Entry/exits)
bool myForward
we group antagonistic commands (create junction/delete junction) and keep them apart by this flag ...
Definition: GNEChange.h:87
void deleteAdditional(GNEAdditional *additional)
delete additional element previously inserted
Definition: GNENet.cpp:1622
SumoXMLTag getTag() const
get XML Tag assigned to this object
void addEntryChild(GNEDetectorEntry *entry)
add an Entry child
void removeEntryChild(GNEDetectorEntry *entry)
delete an Entry child
void removeAdditionalChild(GNEAdditional *additional)
remove additional child from this edge
Definition: GNEEdge.cpp:1198
FXString redoName() const
get Redo name
void removeExitChild(GNEDetectorExit *exit)
delete an Exit child
GNELane * myLaneParent
pointer to lane (used by additionals with lane parent)
void insertAdditional(GNEAdditional *additional, bool hardFail=true)
Insert a additional element previously created in GNEAdditionalHandler.
Definition: GNENet.cpp:1604
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:1519
bool unreferenced()
check if object ins&#39;t referenced