Eclipse SUMO - Simulation of Urban MObility
GNEChange_GenericData.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 generic data set is created or deleted
19 /****************************************************************************/
20 
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #include <config.h>
25 
26 #include <netedit/GNENet.h>
28 
29 #include "GNEChange_GenericData.h"
30 
31 // ===========================================================================
32 // FOX-declarations
33 // ===========================================================================
34 FXIMPLEMENT_ABSTRACT(GNEChange_GenericData, GNEChange, nullptr, 0)
35 
36 // ===========================================================================
37 // member method definitions
38 // ===========================================================================
39 
41  GNEChange(genericData, forward, genericData->isAttributeCarrierSelected()),
42  myGenericData(genericData),
43  myDataSetParent(genericData->getDataIntervalParent()->getDataSetParent()),
44  myDataIntervalParent(genericData->getDataIntervalParent()),
45  myPath(genericData->getPath()) {
46  myGenericData->incRef("GNEChange_GenericData");
47 }
48 
49 
51  assert(myGenericData);
52  myGenericData->decRef("GNEChange_GenericData");
53  if (myGenericData->unreferenced()) {
54  // show extra information for tests
55  WRITE_DEBUG("Deleting unreferenced " + myGenericData->getTagStr() + " '" + myGenericData->getID() + "'");
56  // check that generic data don't exist
60  // delete generic data from interval parent
62  // remove element from path
63  for (const auto& pathElement : myPath) {
64  pathElement.getLane()->removePathGenericData(myGenericData);
65  if (pathElement.getJunction()) {
66  pathElement.getJunction()->removePathGenericData(myGenericData);
67  }
68  }
69  }
70  // delete generic data
71  delete myGenericData;
72  }
73 }
74 
75 
76 void
78  if (myForward) {
79  // show extra information for tests
80  WRITE_DEBUG("Removing " + myGenericData->getTagStr() + " '" + myGenericData->getID() + "' in GNEChange_GenericData");
81  // unselect if mySelectedElement is enabled
82  if (mySelectedElement) {
84  }
85  // delete generic data from interval parent
87  // remove element from path
88  for (const auto& pathElement : myPath) {
89  pathElement.getLane()->removePathGenericData(myGenericData);
90  if (pathElement.getJunction()) {
91  pathElement.getJunction()->removePathGenericData(myGenericData);
92  }
93  }
94  // restore container
96  } else {
97  // show extra information for tests
98  WRITE_DEBUG("Adding " + myGenericData->getTagStr() + " '" + myGenericData->getID() + "' in GNEChange_GenericData");
99  // select if mySelectedElement is enabled
100  if (mySelectedElement) {
102  }
103  // insert generic data into interval parent
105  // restore container
107  }
108  // Requiere always save elements
110 }
111 
112 
113 void
115  if (myForward) {
116  // show extra information for tests
117  WRITE_DEBUG("Adding " + myGenericData->getTagStr() + " '" + myGenericData->getID() + "' in GNEChange_GenericData");
118  // select if mySelectedElement is enabled
119  if (mySelectedElement) {
121  }
122  // insert generic data into interval parent
124  // add genericData in parents and children
126  } else {
127  // show extra information for tests
128  WRITE_DEBUG("Removing " + myGenericData->getTagStr() + " '" + myGenericData->getID() + "' in GNEChange_GenericData");
129  // unselect if mySelectedElement is enabled
130  if (mySelectedElement) {
132  }
133  // delete generic data from interval parent
135  // remove element from path
136  for (const auto& pathElement : myPath) {
137  pathElement.getLane()->removePathGenericData(myGenericData);
138  if (pathElement.getJunction()) {
139  pathElement.getJunction()->removePathGenericData(myGenericData);
140  }
141  }
142  // remove genericData from parents and children
144  }
145  // Requiere always save elements
147 }
148 
149 
150 FXString
152  if (myForward) {
153  return ("Undo create " + myGenericData->getTagStr()).c_str();
154  } else {
155  return ("Undo delete " + myGenericData->getTagStr()).c_str();
156  }
157 }
158 
159 
160 FXString
162  if (myForward) {
163  return ("Redo create " + myGenericData->getTagStr()).c_str();
164  } else {
165  return ("Redo delete " + myGenericData->getTagStr()).c_str();
166  }
167 }
#define WRITE_DEBUG(msg)
Definition: MsgHandler.h:286
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
FXString redoName() const
get Redo name
GNEDataSet * myDataSetParent
data set parent
GNEGenericData * myGenericData
full information regarding the generic data set that is to be created/deleted
const std::vector< GNEPathElements::PathElement > & myPath
reference to path vector
GNEDataInterval * myDataIntervalParent
data interval parent
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 removeGenericDataChild(GNEGenericData *genericData)
add generic data child
bool hasGenericDataChild(GNEGenericData *genericData) const
check if given generic data is child of this data interval
void addGenericDataChild(GNEGenericData *genericData)
add generic data child
bool dataIntervalChildrenExist(GNEDataInterval *dataInterval) const
check if given data interval exist
Definition: GNEDataSet.cpp:238
An Element which don't belongs to GNENet but has influency in the simulation.
const std::string & getID() const
get ID
bool dataSetExist(const GNEDataSet *dataSet) const
return true if given demand element exist
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
retrieve all attribute carriers of Net
Definition: GNENet.cpp:130
void requireSaveDataElements(bool value)
inform that data sets has to be saved
Definition: GNENet.cpp:2645
void decRef(const std::string &debugMsg="")
Decrease reference.
bool unreferenced()
check if object ins't referenced