SUMO - Simulation of Urban MObility
GNEChange_Additional.cpp
Go to the documentation of this file.
1 /****************************************************************************/
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 "GNEChange_Additional.h"
31 #include "GNENet.h"
32 #include "GNELane.h"
33 #include "GNEAdditional.h"
34 #include "GNEViewNet.h"
35 #include "GNEDetectorE3.h"
36 #include "GNEDetectorEntry.h"
37 #include "GNEDetectorExit.h"
38 #include "GNEStoppingPlace.h"
39 
40 #ifdef CHECK_MEMORY_LEAKS
41 #include <foreign/nvwa/debug_new.h>
42 #endif
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  myE3Parent(NULL) {
59  assert(myNet);
60  myAdditional->incRef("GNEChange_Additional");
61  // handle additionals with lane parent
62  if (myAdditional->getLane() != NULL) {
63  myLaneParent = myAdditional->getLane();
64  }
65  // handle additional with childs
66  if (myAdditional->getTag() == SUMO_TAG_E3DETECTOR) {
67  GNEDetectorE3* E3 = dynamic_cast<GNEDetectorE3*>(myAdditional);
68  myEntryChilds = E3->myGNEDetectorEntrys;
69  myExitChilds = E3->myGNEDetectorExits;
70  } else if (myAdditional->getTag() == SUMO_TAG_DET_ENTRY) {
71  myE3Parent = dynamic_cast<GNEDetectorEntry*>(myAdditional)->getE3Parent();
72  } else if (myAdditional->getTag() == SUMO_TAG_DET_EXIT) {
73  myE3Parent = dynamic_cast<GNEDetectorExit*>(myAdditional)->getE3Parent();
74  }
75 }
76 
77 
79  assert(myAdditional);
80  myAdditional->decRef("GNEChange_Additional");
81  if (myAdditional->unreferenced()) {
82  delete myAdditional;
83  }
84 }
85 
86 
87 void
89  if (myForward) {
91  // If additional own a Lane parent, remove it from lane
92  if (myAdditional->getLane() != NULL) {
93  assert(myLaneParent);
95  }
96  // If additional is an E3 Detector, delete Entry/Exit childs
98  for (std::vector<GNEDetectorEntry*>::iterator i = myEntryChilds.begin(); i != myEntryChilds.end(); i++) {
100  }
101  for (std::vector<GNEDetectorExit*>::iterator i = myExitChilds.begin(); i != myExitChilds.end(); i++) {
102  myNet->deleteAdditional(*i);
103  }
104  }
105  // if additiona is an Entry detector, remove it from E3 parent
107  assert(myE3Parent);
108  myE3Parent->removeEntryChild(dynamic_cast<GNEDetectorEntry*>(myAdditional));
110  myNet->getViewNet()->update();
111  }
112  // if additiona is an Exit detector, remove it from E3 parent
114  assert(myE3Parent);
115  myE3Parent->removeExitChild(dynamic_cast<GNEDetectorExit*>(myAdditional));
117  myNet->getViewNet()->update();
118  }
119  } else {
121  // If additional own a Lane parent, add it to lane
122  if (myAdditional->getLane() != NULL) {
123  assert(myLaneParent);
125  }
126  // If additional is an E3 detector, add it their Entry/Exit childs
128  for (std::vector<GNEDetectorEntry*>::iterator i = myEntryChilds.begin(); i != myEntryChilds.end(); i++) {
129  myNet->insertAdditional(*i);
130  }
131  for (std::vector<GNEDetectorExit*>::iterator i = myExitChilds.begin(); i != myExitChilds.end(); i++) {
132  myNet->insertAdditional(*i);
133  }
134  }
135  // If additional is an Exit detector, add id to E3 parent
137  assert(myE3Parent);
138  myE3Parent->addEntryChild(dynamic_cast<GNEDetectorEntry*>(myAdditional));
140  myNet->getViewNet()->update();
141  }
142  // If additional is an Exit detector, add id to E3 parent
144  assert(myE3Parent);
145  myE3Parent->addExitChild(dynamic_cast<GNEDetectorExit*>(myAdditional));
147  myNet->getViewNet()->update();
148  }
149  }
150 }
151 
152 
153 void
155  if (myForward) {
157  // If additional own a Lane parent, add it to lane
158  if (myAdditional->getLane() != NULL) {
159  assert(myLaneParent);
161  }
162  // If additional is an E3 detector, add it their Entry/Exit childs
164  for (std::vector<GNEDetectorEntry*>::iterator i = myEntryChilds.begin(); i != myEntryChilds.end(); i++) {
165  myNet->insertAdditional(*i);
166  }
167  for (std::vector<GNEDetectorExit*>::iterator i = myExitChilds.begin(); i != myExitChilds.end(); i++) {
168  myNet->insertAdditional(*i);
169  }
170  }
171  // If additional is an Entry detector, add id to E3 parent
173  assert(myE3Parent);
174  myE3Parent->addEntryChild(dynamic_cast<GNEDetectorEntry*>(myAdditional));
176  myNet->getViewNet()->update();
177  }
178  // If additional is an Exit detector, add id to E3 parent
180  assert(myE3Parent);
181  myE3Parent->addExitChild(dynamic_cast<GNEDetectorExit*>(myAdditional));
183  myNet->getViewNet()->update();
184  }
185  } else {
187  // if additionl own a Lane Parent, remove it from lane
188  if (myAdditional->getLane() != NULL) {
189  assert(myLaneParent);
191  }
192  // If additional is an E3 Detector, delete Entry/Exit childs
194  for (std::vector<GNEDetectorEntry*>::iterator i = myEntryChilds.begin(); i != myEntryChilds.end(); i++) {
195  myNet->deleteAdditional(*i);
196  }
197  for (std::vector<GNEDetectorExit*>::iterator i = myExitChilds.begin(); i != myExitChilds.end(); i++) {
198  myNet->deleteAdditional(*i);
199  }
200  }
201  // if additiona is an Entry detector, remove it from E3 parent
203  assert(myE3Parent);
204  myE3Parent->removeEntryChild(dynamic_cast<GNEDetectorEntry*>(myAdditional));
206  myNet->getViewNet()->update();
207  }
208  // if additiona is an Exit detector, remove it from E3 parent
210  assert(myE3Parent);
211  myE3Parent->removeExitChild(dynamic_cast<GNEDetectorExit*>(myAdditional));
213  myNet->getViewNet()->update();
214  }
215  }
216 }
217 
218 
219 FXString
221  if (myForward) {
222  return ("Undo create " + toString(myAdditional->getTag())).c_str();
223  } else {
224  return ("Undo delete " + toString(myAdditional->getTag())).c_str();
225  }
226 }
227 
228 
229 FXString
231  if (myForward) {
232  return ("Redo create " + toString(myAdditional->getTag())).c_str();
233  } else {
234  return ("Redo delete " + toString(myAdditional->getTag())).c_str();
235  }
236 }
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:713
std::vector< GNEDetectorEntry * > myGNEDetectorEntrys
vector with the GNEDetectorE3EntryExits of the detector
~GNEChange_Additional()
Destructor.
an e3 entry point
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
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:701
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)
FXString undoName() const
return undoName
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
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:1223
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
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:1207
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:1114