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 
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
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
105  WRITE_WARNING("Deleting " + toString(myAdditional->getTag()) + " '" + myAdditional->getID() + "'");
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
156  WRITE_WARNING("Inserting " + toString(myAdditional->getTag()) + " '" + myAdditional->getID() + "'");
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 }
206 
207 
208 void
210  if (myForward) {
211  // show extra information for tests
213  WRITE_WARNING("Inserting " + toString(myAdditional->getTag()) + " '" + myAdditional->getID() + "'");
214  }
215  // insert additional into net
217  // 1 - If additional own a Lane parent, add it to lane
218  if (myAdditional->getLane() != NULL) {
219  assert(myLaneParent);
221  }
222  // 2 - If additional own a lane parent, add it to edge
223  if (myAdditional->getEdge() != NULL) {
224  assert(myEdgeParent);
226  }
227  // 3 - If additional is an E3 detector, add it their Entry/Exit childs
229  for (std::vector<GNEDetectorEntry*>::iterator i = myEntryChilds.begin(); i != myEntryChilds.end(); i++) {
230  // add entry of their lane parent before insert
231  (*i)->getLane()->addAdditionalChild(*i);
232  myNet->insertAdditional(*i);
233  }
234  for (std::vector<GNEDetectorExit*>::iterator i = myExitChilds.begin(); i != myExitChilds.end(); i++) {
235  // add entry of their lane parent before insert
236  (*i)->getLane()->addAdditionalChild(*i);
237  myNet->insertAdditional(*i);
238  }
239  }
240  // 4 - If additional is an Entry detector, add id to E3 parent
242  assert(myE3Parent);
243  myE3Parent->addEntryChild(dynamic_cast<GNEDetectorEntry*>(myAdditional));
245  myNet->getViewNet()->update();
246  }
247  // 5 - If additional is an Exit detector, add id to E3 parent
249  assert(myE3Parent);
250  myE3Parent->addExitChild(dynamic_cast<GNEDetectorExit*>(myAdditional));
252  myNet->getViewNet()->update();
253  }
254  // 6 - if Additional if a rerouter, add it of all of their edge childs
256  GNERerouter* rerouter = dynamic_cast<GNERerouter*>(myAdditional);
257  for (std::vector<GNEEdge*>::iterator i = myEdgeChilds.begin(); i != myEdgeChilds.end(); i++) {
258  (*i)->addGNERerouter(rerouter);
259  }
260  }
261  } else {
262  // show extra information for tests
264  WRITE_WARNING("Deleting " + toString(myAdditional->getTag()) + " '" + myAdditional->getID() + "'");
265  }
267  // 1 - If additionl own a Lane Parent, remove it from lane
268  if (myAdditional->getLane() != NULL) {
269  assert(myLaneParent);
271  }
272  // 2 - If additional own a lane parent, remove it from lane
273  if (myAdditional->getEdge() != NULL) {
274  assert(myEdgeParent);
276  }
277  // 3 - If additional is an E3 Detector, delete Entry/Exit childs
279  for (std::vector<GNEDetectorEntry*>::iterator i = myEntryChilds.begin(); i != myEntryChilds.end(); i++) {
280  // delete entry of their lane parent before remove
281  (*i)->getLane()->removeAdditionalChild(*i);
282  myNet->deleteAdditional(*i);
283  }
284  for (std::vector<GNEDetectorExit*>::iterator i = myExitChilds.begin(); i != myExitChilds.end(); i++) {
285  // delete entry of their lane parent before remove
286  (*i)->getLane()->removeAdditionalChild(*i);
287  myNet->deleteAdditional(*i);
288  }
289  }
290  // 4 - If additiona is an Entry detector, remove it from E3 parent
292  assert(myE3Parent);
293  myE3Parent->removeEntryChild(dynamic_cast<GNEDetectorEntry*>(myAdditional));
295  myNet->getViewNet()->update();
296  }
297  // 5 - If additiona is an Exit detector, remove it from E3 parent
299  assert(myE3Parent);
300  myE3Parent->removeExitChild(dynamic_cast<GNEDetectorExit*>(myAdditional));
302  myNet->getViewNet()->update();
303  }
304  // 6 - if Additional if a rerouter, remove it of all of their edge childs
306  GNERerouter* rerouter = dynamic_cast<GNERerouter*>(myAdditional);
307  for (std::vector<GNEEdge*>::iterator i = myEdgeChilds.begin(); i != myEdgeChilds.end(); i++) {
308  (*i)->removeGNERerouter(rerouter);
309  }
310  }
311  }
312 }
313 
314 
315 FXString
317  if (myForward) {
318  return ("Undo create " + toString(myAdditional->getTag())).c_str();
319  } else {
320  return ("Undo delete " + toString(myAdditional->getTag())).c_str();
321  }
322 }
323 
324 
325 FXString
327  if (myForward) {
328  return ("Redo create " + toString(myAdditional->getTag())).c_str();
329  } else {
330  return ("Redo delete " + toString(myAdditional->getTag())).c_str();
331  }
332 }
GNEEdge * myEdgeParent
pointer to edge (used by additionals with edge parent)
GNELane * getLane() const
get lane of additional, or NULL if additional isn&#39;t placed over a Lane
the function-object for an editing operation (abstract base)
Definition: GNEChange.h:49
FXString redoName() const
get Redo name
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:751
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
an e3 entry point
bool isTestingModeEnabled() const
check if netedit is running in testing mode
Definition: GNEViewNet.cpp:405
FXString undoName() const
return undoName
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:1035
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:56
void updateGeometry()
update pre-computed geometry information
void addAdditionalChild(GNEAdditional *additional)
add additional child to this lane
Definition: GNELane.cpp:739
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
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:1275
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:1048
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:1258
GNEEdge * getEdge() const
get edge of additional, or NULL if additional isn&#39;t placed over an edge
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:1165
SumoXMLTag getTag() const
get XML Tag assigned to this object