Eclipse SUMO - Simulation of Urban MObility
GNEChange_Distribution.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 change in which the distribution attribute of some object is modified
19 /****************************************************************************/
20 #include <config.h>
21 
22 #include <netedit/GNENet.h>
23 #include <netedit/GNEUndoList.h>
24 
25 #include "GNEChange_Distribution.h"
26 
27 // ===========================================================================
28 // FOX-declarations
29 // ===========================================================================
30 FXIMPLEMENT_ABSTRACT(GNEChange_Distribution, GNEChange, nullptr, 0)
31 
32 // ===========================================================================
33 // member method definitions
34 // ===========================================================================
35 
36 void
37 GNEChange_Distribution::addKey(GNEDemandElement* distribution, const GNEDemandElement* key, const double value, GNEUndoList* undoList) {
38  // create change
39  auto change = new GNEChange_Distribution(distribution, key, value, true);
40  // add into undoList
41  undoList->begin(distribution, TLF("add '%' key in % '%'", key->getID(), distribution->getTagStr(), distribution->getID()));
42  undoList->add(change, true);
43  undoList->end();
44 }
45 
46 
47 void
49  // create change
50  auto change = new GNEChange_Distribution(distribution, key, 0, false);
51  // add into undoList
52  undoList->begin(distribution, TLF("remove '%' key from % '%'", key->getID(), distribution->getTagStr(), distribution->getID()));
53  undoList->add(change, true);
54  undoList->end();
55 }
56 
57 
58 void
59 GNEChange_Distribution::editValue(GNEDemandElement* distribution, const GNEDemandElement* key, const double newValue, GNEUndoList* undoList) {
60  // create change
61  auto change = new GNEChange_Distribution(distribution, key, distribution->getAttributeDistributionValue(key), newValue);
62  // add into undoList
63  undoList->begin(distribution, TLF("change '%' key value from % to %", key->getID(), newValue, newValue));
64  undoList->add(change, true);
65  undoList->end();
66 }
67 
68 
70  // decrease reference
71  myDistribution->decRef("GNEChange_Distribution " + myDistribution->getTagProperty().getTagStr());
72  // remove if is unreferenced
74  // show extra information for tests
75  WRITE_DEBUG("Deleting unreferenced " + myDistribution->getTagStr() + " '" + myDistribution->getID() + "' in GNEChange_Distribution");
76  // delete distribution
77  delete myDistribution;
78  }
79 }
80 
81 
82 void
84  // show extra information for tests
85  WRITE_DEBUG("Setting previous distribution into " + myDistribution->getTagStr() + " '" + myDistribution->getID() + "'");
86  // continue depending of flags
89  } else if (myAddKey) {
91  } else {
93  }
94  // mark demand elements as unsaved
96 }
97 
98 
99 void
101  // show extra information for tests
102  WRITE_DEBUG("Setting new distribution into " + myDistribution->getTagStr() + " '" + myDistribution->getID() + "'");
103  // continue depending of flags
104  if (myEditingProbability) {
106  } else if (myAddKey) {
108  } else {
110  }
111  // mark demand elements as unsaved
113 }
114 
115 
116 std::string
118  return TLF("Undo edit distribution in '%'", myDistribution->getID());
119 }
120 
121 
122 std::string
124  return TLF("Redo edit distribution in '%'", myDistribution->getID());
125 }
126 
127 
128 GNEChange_Distribution::GNEChange_Distribution(GNEDemandElement* distribution, const GNEDemandElement* key, const double value, const bool addKey) :
129  GNEChange(Supermode::DEMAND, true, false),
130  myDistribution(distribution),
131  myKey(key),
132  myOriginalProbability(-1),
133  myNewProbability(value),
134  myAddKey(addKey),
135  myEditingProbability(false) {
136  myDistribution->incRef("GNEChange_Distribution " + myDistribution->getTagProperty().getTagStr());
137 }
138 
139 
140 GNEChange_Distribution::GNEChange_Distribution(GNEDemandElement* distribution, const GNEDemandElement* key, const double originalValue, const double newValue) :
141  GNEChange(Supermode::DEMAND, true, false),
142  myDistribution(distribution),
143  myKey(key),
144  myOriginalProbability(originalValue),
145  myNewProbability(newValue),
146  myAddKey(false),
147  myEditingProbability(true) {
148  myDistribution->incRef("GNEChange_Distribution " + myDistribution->getTagProperty().getTagStr());
149 }
150 
151 /****************************************************************************/
Supermode
@brie enum for supermodes
@ DEMAND
Demand mode (Routes, Vehicles etc..)
#define WRITE_DEBUG(msg)
Definition: MsgHandler.h:306
#define TLF(string,...)
Definition: MsgHandler.h:317
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
const GNETagProperties & getTagProperty() const
get tagProperty associated with this Attribute Carrier
GNENet * getNet() const
get pointer to net
the function-object for an editing operation (abstract base)
static void editValue(GNEDemandElement *distribution, const GNEDemandElement *key, const double newValue, GNEUndoList *undoList)
edit value
GNEDemandElement * myDistribution
the distribution to which all operations shall be applied
GNEChange_Distribution(GNEDemandElement *distribution, const GNEDemandElement *key, const double value, const bool addKey)
constructor for add/modify key
const double myNewProbability
the new value
const GNEDemandElement * myKey
the key
const bool myAddKey
flag for check if we're adding or removing key
const bool myEditingProbability
flag for check if we're editing value
const double myOriginalProbability
the original value
static void removeKey(GNEDemandElement *distribution, const GNEDemandElement *key, GNEUndoList *undoList)
remove key
std::string undoName() const
return undoName
std::string redoName() const
get Redo name
the function-object for an editing operation (abstract base)
Definition: GNEChange.h:56
double getAttributeDistributionValue(const GNEDemandElement *key)
get attribute distribution value
void removeDistributionKey(const GNEDemandElement *key, GNEUndoList *undoList)
remove distribution key
void addDistributionKey(const GNEDemandElement *key, const double value, GNEUndoList *undoList)
add distribution key
void editDistributionValue(const GNEDemandElement *key, const double newValue, GNEUndoList *undoList)
remove distribution (used in GNEDemandElementDistribution)
void requireSaveDemandElements()
inform that demand elements has to be saved
GNENetHelper::SavingStatus * getSavingStatus() const
get saving status
Definition: GNENet.cpp:129
void decRef(const std::string &debugMsg="")
Decrease reference.
void incRef(const std::string &debugMsg="")
Increase reference.
bool unreferenced()
check if object ins't referenced
const std::string & getTagStr() const
get Tag vinculated with this attribute Property in String Format (used to avoid multiple calls to toS...
void end()
End undo command sub-group. If the sub-group is still empty, it will be deleted; otherwise,...
void begin(GUIIcon icon, const std::string &description)
Begin undo command sub-group with current supermode. This begins a new group of commands that are tre...
void add(GNEChange *command, bool doit=false, bool merge=true)
Add new command, executing it if desired. The new command will be merged with the previous command if...