Eclipse SUMO - Simulation of Urban MObility
GNEChange_DataSet.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 // Copyright (C) 2001-2024 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 data set element is created or deleted
19 /****************************************************************************/
20 #include <config.h>
21 
22 #include <netedit/GNENet.h>
24 
25 #include "GNEChange_DataSet.h"
26 
27 // ===========================================================================
28 // FOX-declarations
29 // ===========================================================================
30 FXIMPLEMENT_ABSTRACT(GNEChange_DataSet, GNEChange, nullptr, 0)
31 
32 // ===========================================================================
33 // member method definitions
34 // ===========================================================================
35 
37  GNEChange(Supermode::DATA, forward, dataSet->isAttributeCarrierSelected()),
38  myDataSet(dataSet) {
39  myDataSet->incRef("GNEChange_DataSet");
40 }
41 
42 
44  assert(myDataSet);
45  myDataSet->decRef("GNEChange_DataSet");
46  if (myDataSet->unreferenced() &&
48  // show extra information for tests
49  WRITE_DEBUG("Deleting unreferenced " + myDataSet->getTagStr() + " '" + myDataSet->getID() + "'");
50  // make sure that element isn't in net before removing
52  // delete data set
53  delete myDataSet;
54  }
55 }
56 
57 
58 void
60  if (myForward) {
61  // show extra information for tests
62  WRITE_DEBUG("Removing " + myDataSet->getTagStr() + " '" + myDataSet->getID() + "' in GNEChange_DataSet");
63  // delete data set from net
65  } else {
66  // show extra information for tests
67  WRITE_DEBUG("Adding " + myDataSet->getTagStr() + " '" + myDataSet->getID() + "' in GNEChange_DataSet");
68  // insert data set into net
70  }
71  // require always save elements
73 }
74 
75 
76 void
78  if (myForward) {
79  // show extra information for tests
80  WRITE_DEBUG("Adding " + myDataSet->getTagStr() + " '" + myDataSet->getID() + "' in GNEChange_DataSet");
81  // insert data set into net
83  } else {
84  // show extra information for tests
85  WRITE_DEBUG("Removing " + myDataSet->getTagStr() + " '" + myDataSet->getID() + "' in GNEChange_DataSet");
86  // delete data set from net
88  }
89  // require always save elements
91 }
92 
93 
94 std::string
96  if (myForward) {
97  return (TL("Undo create ") + myDataSet->getTagStr() + " '" + myDataSet->getID() + "'");
98  } else {
99  return (TL("Undo delete ") + myDataSet->getTagStr() + " '" + myDataSet->getID() + "'");
100  }
101 }
102 
103 
104 std::string
106  if (myForward) {
107  return (TL("Redo create ") + myDataSet->getTagStr() + " '" + myDataSet->getID() + "'");
108  } else {
109  return (TL("Redo delete ") + myDataSet->getTagStr() + " '" + myDataSet->getID() + "'");
110  }
111 }
112 
113 
114 /****************************************************************************/
Supermode
@brie enum for supermodes
#define WRITE_DEBUG(msg)
Definition: MsgHandler.h:306
#define TL(string)
Definition: MsgHandler.h:315
const std::string getID() const
get ID (all Attribute Carriers have one)
const std::string & getTagStr() const
get tag assigned to this object in string format
GNENet * getNet() const
get pointer to net
std::string redoName() const
get Redo name
void undo()
undo action
~GNEChange_DataSet()
Destructor.
void redo()
redo action
std::string undoName() const
return undoName
GNEDataSet * myDataSet
full information regarding the data set element that is to be created/deleted
the function-object for an editing operation (abstract base)
Definition: GNEChange.h:56
bool myForward
we group antagonistic commands (create junction/delete junction) and keep them apart by this flag
Definition: GNEChange.h:212
void deleteDataSet(GNEDataSet *dataSet)
delete data set of container
void insertDataSet(GNEDataSet *dataSet)
Insert a data set in container.
GNEDataSet * retrieveDataSet(const std::string &id, bool hardFail=true) const
Returns the named data set.
void requireSaveDataElements()
inform that data elements has to be saved
GNENetHelper::SavingStatus * getSavingStatus() const
get saving status
Definition: GNENet.cpp:127
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
get all attribute carriers used in this net
Definition: GNENet.cpp:121
void decRef(const std::string &debugMsg="")
Decrease reference.
bool unreferenced()
check if object ins't referenced