Eclipse 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-2020 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials are made available under the
5 // terms of the Eclipse Public License 2.0 which is available at
6 // https://www.eclipse.org/legal/epl-2.0/
7 // This Source Code may also be made available under the following Secondary
8 // Licenses when the conditions for such availability set forth in the Eclipse
9 // Public License 2.0 are satisfied: GNU General Public License, version 2
10 // or later which is available at
11 // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 /****************************************************************************/
18 // A network change in which a busStop is created or deleted
19 /****************************************************************************/
20 #include <config.h>
21 
22 #include <netedit/GNENet.h>
23 
24 #include "GNEChange_Additional.h"
25 
26 // ===========================================================================
27 // FOX-declarations
28 // ===========================================================================
29 FXIMPLEMENT_ABSTRACT(GNEChange_Additional, GNEChange, nullptr, 0)
30 
31 // ===========================================================================
32 // member method definitions
33 // ===========================================================================
34 
36  GNEChange(additional, forward, additional->isAttributeCarrierSelected()),
37  myAdditional(additional),
38  myPath(additional->getPath()) {
39  myAdditional->incRef("GNEChange_Additional");
40 }
41 
42 
44  myAdditional->decRef("GNEChange_Additional");
45  if (myAdditional->unreferenced()) {
46  // show extra information for tests
47  WRITE_DEBUG("Deleting unreferenced " + myAdditional->getTagStr() + " '" + myAdditional->getID() + "'");
48  // make sure that additional isn't in net before removing
50  // delete additional from net
52  // remove element from path (used by E2 multilane detectors)
53  for (const auto& pathElement : myPath) {
54  pathElement.getLane()->removePathAdditionalElement(myAdditional);
55  if (pathElement.getJunction()) {
56  pathElement.getJunction()->removePathAdditionalElement(myAdditional);
57  }
58  }
59  }
60  delete myAdditional;
61  }
62 }
63 
64 
65 void
67  if (myForward) {
68  // show extra information for tests
69  WRITE_DEBUG("Removing " + myAdditional->getTagStr() + " '" + myAdditional->getID() + "' in GNEChange_Additional");
70  // unselect if mySelectedElement is enabled
71  if (mySelectedElement) {
73  }
74  // delete additional from net
76  // remove element from path
77  for (const auto& pathElement : myPath) {
78  pathElement.getLane()->removePathAdditionalElement(myAdditional);
79  if (pathElement.getJunction()) {
80  pathElement.getJunction()->removePathAdditionalElement(myAdditional);
81  }
82  }
83  // restore container
85  } else {
86  // show extra information for tests
87  WRITE_DEBUG("Adding " + myAdditional->getTagStr() + " '" + myAdditional->getID() + "' in GNEChange_Additional");
88  // select if mySelectedElement is enabled
89  if (mySelectedElement) {
91  }
92  // insert additional into net
94  // restore container
96  }
97  // Requiere always save additionals
99 }
100 
101 
102 void
104  if (myForward) {
105  // show extra information for tests
106  WRITE_DEBUG("Adding " + myAdditional->getTagStr() + " '" + myAdditional->getID() + "' in GNEChange_Additional");
107  // select if mySelectedElement is enabled
108  if (mySelectedElement) {
110  }
111  // insert additional into net
113  // add additional in parent elements
115  } else {
116  // show extra information for tests
117  WRITE_DEBUG("Removing " + myAdditional->getTagStr() + " '" + myAdditional->getID() + "' in GNEChange_Additional");
118  // unselect if mySelectedElement is enabled
119  if (mySelectedElement) {
121  }
122  // delete additional from net
124  // remove element from path
125  for (const auto& pathElement : myPath) {
126  pathElement.getLane()->removePathAdditionalElement(myAdditional);
127  if (pathElement.getJunction()) {
128  pathElement.getJunction()->removePathAdditionalElement(myAdditional);
129  }
130  }
131  // remove additional from parents and children
133  }
134  // Requiere always save additionals
136 }
137 
138 
139 FXString
141  if (myForward) {
142  return ("Undo create " + myAdditional->getTagStr()).c_str();
143  } else {
144  return ("Undo delete " + myAdditional->getTagStr()).c_str();
145  }
146 }
147 
148 
149 FXString
151  if (myForward) {
152  return ("Redo create " + myAdditional->getTagStr()).c_str();
153  } else {
154  return ("Redo delete " + myAdditional->getTagStr()).c_str();
155  }
156 }
#define WRITE_DEBUG(msg)
Definition: MsgHandler.h:286
An Element which don't belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:47
const std::string & getID() const
get ID
const std::string & getTagStr() const
get tag assigned to this object in string format
void unselectAttributeCarrier(const bool changeFlag=true)
unselect attribute carrier using GUIGlobalSelection
GNENet * getNet() const
get pointer to net
void selectAttributeCarrier(const bool changeFlag=true)
select attribute carrier using GUIGlobalSelection
FXString undoName() const
return undoName
GNEAdditional * myAdditional
full information regarding the additional element that is to be created/deleted
const std::vector< GNEPathElements::PathElement > & myPath
reference to path vector
FXString redoName() const
get Redo name
the function-object for an editing operation (abstract base)
Definition: GNEChange.h:65
bool myForward
we group antagonistic commands (create junction/delete junction) and keep them apart by this flag
Definition: GNEChange.h:215
const bool mySelectedElement
flag for check if element is selected
Definition: GNEChange.h:218
void addElementInParentsAndChildren(T *element)
add given element into parents and children (only use in redo() function)
Definition: GNEChange.h:106
void removeElementFromParentsAndChildren(T *element)
remove given element from parents and children (only use in redo() function)
Definition: GNEChange.h:161
void restoreHierarchicalContainers()
restore container (only use in undo() function)
Definition: GNEChange.cpp:82
void deleteAdditional(GNEAdditional *additional)
delete additional element of GNENet container
bool additionalExist(const GNEAdditional *additional) const
return true if given additional exist
void insertAdditional(GNEAdditional *additional)
Insert a additional element int GNENet container.
void requireSaveAdditionals(bool value)
inform that additionals has to be saved
Definition: GNENet.cpp:2361
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
retrieve all attribute carriers of Net
Definition: GNENet.cpp:130
void decRef(const std::string &debugMsg="")
Decrease reference.
bool unreferenced()
check if object ins't referenced