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 
23 #include <netedit/GNENet.h>
28 #include <netedit/GNEViewParent.h>
29 
30 #include "GNEChange_Additional.h"
31 
32 // ===========================================================================
33 // FOX-declarations
34 // ===========================================================================
35 FXIMPLEMENT_ABSTRACT(GNEChange_Additional, GNEChange, nullptr, 0)
36 
37 // ===========================================================================
38 // member method definitions
39 // ===========================================================================
40 
42  GNEChange(additional->getViewNet()->getNet(), forward),
43  myAdditional(additional),
44  myFirstAdditionalParent(myAdditional->getFirstAdditionalParent()),
45  mySecondAdditionalParent(myAdditional->getSecondAdditionalParent()),
46  myEdgeChilds(myAdditional->getEdgeChilds()),
47  myLaneChilds(myAdditional->getLaneChilds()) {
48  myAdditional->incRef("GNEChange_Additional");
49  // handle additionals with lane parent
50  if (additional->getTagProperty().canBePlacedOverLane()) {
51  myLaneParents.push_back(myNet->retrieveLane(myAdditional->getAttribute(SUMO_ATTR_LANE)));
52  }
53  if (additional->getTagProperty().canBePlacedOverLanes()) {
54  myLaneParents = GNEAttributeCarrier::parse<std::vector<GNELane*> >(additional->getViewNet()->getNet(), myAdditional->getAttribute(SUMO_ATTR_LANES));
55  }
56  // handle additionals with edge parent (with an exception)
57  if (additional->getTagProperty().canBePlacedOverEdge() && (additional->getTagProperty().getTag() != SUMO_TAG_VAPORIZER)) {
58  myEdgeParents.push_back(myNet->retrieveEdge(myAdditional->getAttribute(SUMO_ATTR_EDGE)));
59  }
60  if (additional->getTagProperty().canBePlacedOverEdges()) {
61  myEdgeParents = GNEAttributeCarrier::parse<std::vector<GNEEdge*> >(additional->getViewNet()->getNet(), myAdditional->getAttribute(SUMO_ATTR_EDGES));
62  }
63  // special case for Vaporizers
64  if (myAdditional->getTagProperty().getTag() == SUMO_TAG_VAPORIZER) {
65  myEdgeParents.push_back(myNet->retrieveEdge(myAdditional->getAttribute(SUMO_ATTR_ID)));
66  }
67 }
68 
69 
71  assert(myAdditional);
72  myAdditional->decRef("GNEChange_Additional");
73  if (myAdditional->unreferenced()) {
74  // show extra information for tests
75  WRITE_DEBUG("Deleting unreferenced " + myAdditional->getTagStr() + " '" + myAdditional->getID() + "'");
76  // make sure that additional isn't in net before removing
79  }
80  delete myAdditional;
81  }
82 }
83 
84 
85 void
87  if (myForward) {
88  // show extra information for tests
89  WRITE_DEBUG("Removing " + myAdditional->getTagStr() + " '" + myAdditional->getID() + "' in GNEChange_Additional");
90  // delete additional of test
92  // 1 - If additional own a lane parent, remove it from lane
93  for (auto i : myLaneParents) {
94  i->removeAdditionalChild(myAdditional);
95  }
96  // 2 - If additional own a edge parent, remove it from edge
97  for (auto i : myEdgeParents) {
98  i->removeAdditionalChild(myAdditional);
99  }
100  // 3 - If additional has a first parent, remove it from their additional childs
103  }
104  // 4 - If additiona has a second parent, remove it from their additional childs
107  }
108  // 5 - if Additional has edge childs, remove it of their additional parents
109  for (auto i : myEdgeChilds) {
110  i->removeAdditionalParent(myAdditional);
111  }
112  // 6 - if Additional has lane childs, remove it of their additional parents
113  for (auto i : myLaneChilds) {
114  i->removeAdditionalParent(myAdditional);
115  }
116  } else {
117  // show extra information for tests
118  WRITE_DEBUG("Adding " + myAdditional->getTagStr() + " '" + myAdditional->getID() + "' in GNEChange_Additional");
119  // insert additional of test
121  // 1 - If additional own a Lane parent, add it to lane
122  for (auto i : myLaneParents) {
123  i->addAdditionalChild(myAdditional);
124  }
125  // 2 - If additional own a edge parent, add it to edge
126  for (auto i : myEdgeParents) {
127  i->addAdditionalChild(myAdditional);
128  }
129  // 3 - If additional has a parent, add it into additional parent
132  }
133  // 4 - If additional has a parent, add it into additional parent
136  }
137  // 5 - if Additional has edge childs, add id into additional parents
138  for (auto i : myEdgeChilds) {
139  i->addAdditionalParent(myAdditional);
140  }
141  // 6 - if Additional has lane childs, add id into additional parents
142  for (auto i : myLaneChilds) {
143  i->addAdditionalParent(myAdditional);
144  }
145  }
146  // Requiere always save additionals
148  // check if inspector frame has to be updated
149  if (myNet->getViewNet()->getViewParent()->getInspectorFrame()->shown()) {
151  }
152 }
153 
154 
155 void
157  if (myForward) {
158  // show extra information for tests
159  WRITE_DEBUG("Adding " + myAdditional->getTagStr() + " '" + myAdditional->getID() + "' in GNEChange_Additional");
160  // insert additional into net
162  // 1 - If additional own a Lane parent, add it to lane
163  for (auto i : myLaneParents) {
164  i->addAdditionalChild(myAdditional);
165  }
166  // 2 - If additional own a edge parent, add it to edge
167  for (auto i : myEdgeParents) {
168  i->addAdditionalChild(myAdditional);
169  }
170  // 3 - If additional has a parent, add it into additional parent
173  }
174  // 4 - If additional has a parent, add it into additional parent
177  }
178  // 5 - if Additional has edge childs, add id into additional parents
179  for (auto i : myEdgeChilds) {
180  i->addAdditionalParent(myAdditional);
181  }
182  // 6 - if Additional has lane childs, add id into additional parents
183  for (auto i : myLaneChilds) {
184  i->addAdditionalParent(myAdditional);
185  }
186  } else {
187  // show extra information for tests
188  WRITE_DEBUG("Removing " + myAdditional->getTagStr() + " '" + myAdditional->getID() + "' in GNEChange_Additional");
189  // delete additional of test
191  // 1 - If additional own a lane parent, remove it from lane
192  for (auto i : myLaneParents) {
193  i->removeAdditionalChild(myAdditional);
194  }
195  // 2 - If additional own a edge parent, remove it from edge
196  for (auto i : myEdgeParents) {
197  i->removeAdditionalChild(myAdditional);
198  }
199  // 3 - If additiona has a first parent, remove it from their additional childs
202  }
203  // 4 - If additiona has a second parent, remove it from their additional childs
206  }
207  // 5 - if Additional has edge childs, remove it of their additional parents
208  for (auto i : myEdgeChilds) {
209  i->removeAdditionalParent(myAdditional);
210  }
211  // 6 - if Additional has lane childs, remove it of their additional parents
212  for (auto i : myLaneChilds) {
213  i->removeAdditionalParent(myAdditional);
214  }
215  }
216  // Requiere always save additionals
218  // check if inspector frame has to be updated
219  if (myNet->getViewNet()->getViewParent()->getInspectorFrame()->shown()) {
221  }
222 }
223 
224 
225 FXString
227  if (myForward) {
228  return ("Undo create " + myAdditional->getTagStr()).c_str();
229  } else {
230  return ("Undo delete " + myAdditional->getTagStr()).c_str();
231  }
232 }
233 
234 
235 FXString
237  if (myForward) {
238  return ("Redo create " + myAdditional->getTagStr()).c_str();
239  } else {
240  return ("Redo delete " + myAdditional->getTagStr()).c_str();
241  }
242 }
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:2144
GNEInspectorFrame * getInspectorFrame() const
get frame for GNE_MODE_INSPECT
the function-object for an editing operation (abstract base)
Definition: GNEChange.h:43
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
bool additionalExist(GNEAdditional *additional)
return true if additional exist (use pointer instead ID)
Definition: GNENet.cpp:2127
FXString redoName() const
get Redo name
std::vector< GNEEdge * > myEdgeParents
pointer to edge parents (used by additionals with edge parents)
GNEViewParent * getViewParent() const
get the net object
std::vector< GNEEdge * > myEdgeChilds
list of Edge childs (used by Rerouters)
~GNEChange_Additional()
Destructor.
bool deleteAdditional(GNEAdditional *additional)
delete additional element of GNENet container
Definition: GNENet.cpp:2167
FXString undoName() const
return undoName
GNEAdditional * myAdditional
full information regarding the additional element that is to be created/deleted
the edges of a route
GNEFrame::ACHierarchy * getACHierarchy() const
get ACHierarchy
void refreshACHierarchy()
refresh ACHierarchy
Definition: GNEFrame.cpp:594
void requiereSaveAdditionals(bool value)
inform that additionals has to be saved
Definition: GNENet.cpp:1844
const std::string getID() const
function to support debugging
#define WRITE_DEBUG(msg)
Definition: MsgHandler.h:248
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:76
std::vector< GNELane * > myLaneParents
pointer to lane parents (used by additionals with lane parent)
An Element which don&#39;t belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:48
const std::string & getTagStr() const
get tag assigned to this object in string format
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:81
void addAdditionalChild(GNEAdditional *additional)
add additional child to this additional
bool unreferenced()
check if object ins&#39;t referenced
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:1730