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-2018 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
15 // A network change in which a busStop is created or deleted
16 /****************************************************************************/
17 
18 // ===========================================================================
19 // included modules
20 // ===========================================================================
21 #include <config.h>
22 
24 #include <netedit/GNENet.h>
28 #include <netedit/GNEViewNet.h>
36 #include <netedit/GNEViewParent.h>
37 
38 #include "GNEChange_Additional.h"
39 
40 // ===========================================================================
41 // FOX-declarations
42 // ===========================================================================
43 FXIMPLEMENT_ABSTRACT(GNEChange_Additional, GNEChange, nullptr, 0)
44 
45 // ===========================================================================
46 // member method definitions
47 // ===========================================================================
48 
50  GNEChange(additional->getViewNet()->getNet(), forward),
51  myAdditional(additional),
52  myLaneParent(nullptr),
53  myEdgeParent(nullptr),
54  myFirstAdditionalParent(myAdditional->getFirstAdditionalParent()),
55  mySecondAdditionalParent(myAdditional->getSecondAdditionalParent()),
56  myEdgeChilds(myAdditional->getEdgeChilds()),
57  myLaneChilds(myAdditional->getLaneChilds()) {
58  assert(myNet);
59  myAdditional->incRef("GNEChange_Additional");
60  // handle additionals with lane parent
61  if (GNEAttributeCarrier::getTagProperties(myAdditional->getTag()).hasAttribute(SUMO_ATTR_LANE)) {
62  myLaneParent = myNet->retrieveLane(myAdditional->getAttribute(SUMO_ATTR_LANE));
63  }
64  // handle additionals with edge parent
65  if (GNEAttributeCarrier::getTagProperties(myAdditional->getTag()).hasAttribute(SUMO_ATTR_EDGE)) {
66  myEdgeParent = myNet->retrieveEdge(myAdditional->getAttribute(SUMO_ATTR_EDGE));
67  }
68  // special case for Vaporizers
69  if (myAdditional->getTag() == SUMO_TAG_VAPORIZER) {
70  myEdgeParent = myNet->retrieveEdge(myAdditional->getAttribute(SUMO_ATTR_ID));
71  }
72 }
73 
74 
76  assert(myAdditional);
77  myAdditional->decRef("GNEChange_Additional");
78  if (myAdditional->unreferenced()) {
79  // show extra information for tests
80  WRITE_DEBUG("Deleting unreferenced " + toString(myAdditional->getTag()) + " '" + myAdditional->getID() + "'");
81  // make sure that additional isn't in net before removing
84  }
85  delete myAdditional;
86  }
87 }
88 
89 
90 void
92  if (myForward) {
93  // show extra information for tests
94  WRITE_DEBUG("Removing " + toString(myAdditional->getTag()) + " '" + myAdditional->getID() + "' in GNEChange_Additional");
95  // delete additional of test
97  // 1 - If additional own a lane parent, remove it from lane
98  if (myLaneParent) {
100  }
101  // 2 - If additional own a edge parent, remove it from edge
102  if (myEdgeParent) {
104  }
105  // 3 - If additional has a first parent, remove it from their additional childs
108  }
109  // 4 - If additiona has a second parent, remove it from their additional childs
112  }
113  // 5 - if Additional has edge childs, remove it of their additional parents
114  for (auto i : myEdgeChilds) {
115  i->removeAdditionalParent(myAdditional);
116  }
117  // 6 - 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  WRITE_DEBUG("Adding " + toString(myAdditional->getTag()) + " '" + myAdditional->getID() + "' in GNEChange_Additional");
124  // insert additional of test
126  // 1 - If additional own a Lane parent, add it to lane
127  if (myLaneParent) {
129  }
130  // 2 - If additional own a edge parent, add it to edge
131  if (myEdgeParent != nullptr) {
133  }
134  // 3 - If additional has a parent, add it into additional parent
137  }
138  // 4 - If additional has a parent, add it into additional parent
141  }
142  // 5 - if Additional has edge childs, add id into additional parents
143  for (auto i : myEdgeChilds) {
144  i->addAdditionalParent(myAdditional);
145  }
146  // 6 - if Additional has lane childs, add id into additional parents
147  for (auto i : myLaneChilds) {
148  i->addAdditionalParent(myAdditional);
149  }
150  }
151  // Requiere always save additionals
153  // check if inspector frame has to be updated
154  if (myNet->getViewNet()->getViewParent()->getInspectorFrame()->shown()) {
156  }
157 }
158 
159 
160 void
162  if (myForward) {
163  // show extra information for tests
164  WRITE_DEBUG("Adding " + toString(myAdditional->getTag()) + " '" + myAdditional->getID() + "' in GNEChange_Additional");
165  // insert additional into net
167  // 1 - If additional own a Lane parent, add it to lane
168  if (myLaneParent) {
170  }
171  // 2 - If additional own a edge parent, add it to edge
172  if (myEdgeParent != nullptr) {
174  }
175  // 3 - If additional has a parent, add it into additional parent
178  }
179  // 4 - If additional has a parent, add it into additional parent
182  }
183  // 5 - if Additional has edge childs, add id into additional parents
184  for (auto i : myEdgeChilds) {
185  i->addAdditionalParent(myAdditional);
186  }
187  // 6 - if Additional has lane childs, add id into additional parents
188  for (auto i : myLaneChilds) {
189  i->addAdditionalParent(myAdditional);
190  }
191  } else {
192  // show extra information for tests
193  WRITE_DEBUG("Removing " + toString(myAdditional->getTag()) + " '" + myAdditional->getID() + "' in GNEChange_Additional");
194  // delete additional of test
196  // 1 - If additional own a lane parent, remove it from lane
197  if (myLaneParent) {
199  }
200  // 2 - If additional own a edge parent, remove it from edge
201  if (myEdgeParent) {
203  }
204  // 3 - If additiona has a first parent, remove it from their additional childs
207  }
208  // 4 - If additiona has a second parent, remove it from their additional childs
211  }
212  // 5 - if Additional has edge childs, remove it of their additional parents
213  for (auto i : myEdgeChilds) {
214  i->removeAdditionalParent(myAdditional);
215  }
216  // 6 - if Additional has lane childs, remove it of their additional parents
217  for (auto i : myLaneChilds) {
218  i->removeAdditionalParent(myAdditional);
219  }
220  }
221  // Requiere always save additionals
223  // check if inspector frame has to be updated
224  if (myNet->getViewNet()->getViewParent()->getInspectorFrame()->shown()) {
226  }
227 }
228 
229 
230 FXString
232  if (myForward) {
233  return ("Undo create " + toString(myAdditional->getTag())).c_str();
234  } else {
235  return ("Undo delete " + toString(myAdditional->getTag())).c_str();
236  }
237 }
238 
239 
240 FXString
242  if (myForward) {
243  return ("Redo create " + toString(myAdditional->getTag())).c_str();
244  } else {
245  return ("Redo delete " + toString(myAdditional->getTag())).c_str();
246  }
247 }
GNEEdge * myEdgeParent
pointer to edge (used by additionals with edge parent)
GNEAdditional * mySecondAdditionalParent
pointer to second additional parent (used by additional with parents, for example Entry/exits) ...
void insertAdditional(GNEAdditional *additional)
Insert a additional element int GNENet container.
Definition: GNENet.cpp:2140
GNEInspectorFrame * getInspectorFrame() const
get frame for GNE_MODE_INSPECT
the function-object for an editing operation (abstract base)
Definition: GNEChange.h:42
GNEAdditional * myFirstAdditionalParent
pointer to first additional parent (used by additional with parents, for example Entry/exits) ...
void removeAdditionalChild(GNEAdditional *additional)
remove additional child from this additional
FXString redoName() const
get Redo name
GNEViewParent * getViewParent() const
get the net object
std::vector< GNEEdge * > myEdgeChilds
list of Edge childs (used by Rerouters)
~GNEChange_Additional()
Destructor.
FXString undoName() const
return undoName
GNEAdditional * myAdditional
full information regarding the additional element that is to be created/deleted
GNEAdditional * retrieveAdditional(SumoXMLTag type, const std::string &id, bool hardFail=true) const
Returns the named additional.
Definition: GNENet.cpp:1795
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:49
void addAdditionalChild(GNEAdditional *additional)
add additional child to this edge
GNEFrame::ACHierarchy * getACHierarchy() const
get ACHierarchy
void refreshACHierarchy()
refresh ACHierarchy
Definition: GNEFrame.cpp:117
void requiereSaveAdditionals(bool value)
inform that additionals has to be saved
Definition: GNENet.cpp:1854
const std::string getID() const
function to support debugging
void removeAdditionalChild(GNEAdditional *additional)
remove additional child from this edge
#define WRITE_DEBUG(msg)
Definition: MsgHandler.h:249
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:75
An Element which don&#39;t belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:53
vaporizer of vehicles
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:80
void deleteAdditional(GNEAdditional *additional)
delete additional element of GNENet container
Definition: GNENet.cpp:2163
static const TagValues & getTagProperties(SumoXMLTag tag)
get Tag Properties
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
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:1745
SumoXMLTag getTag() const
get XML Tag assigned to this object