Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
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/GNEViewNet.h>
26#include <netedit/GNEUndoList.h>
27
29
30// ===========================================================================
31// FOX-declarations
32// ===========================================================================
33FXIMPLEMENT_ABSTRACT(GNEChange_Distribution, GNEChange, nullptr, 0)
34
35// ===========================================================================
36// member method definitions
37// ===========================================================================
38
39void
40GNEChange_Distribution::addKey(GNEDemandElement* distribution, const GNEDemandElement* key, const double value, GNEUndoList* undoList) {
41 // create change
42 auto change = new GNEChange_Distribution(distribution, key, value, true);
43 // add into undoList
44 undoList->begin(distribution, TLF("add '%' key in % '%'", key->getID(), distribution->getTagStr(), distribution->getID()));
45 undoList->add(change, true);
46 undoList->end();
47}
48
49
50void
52 // create change
53 auto change = new GNEChange_Distribution(distribution, key, 0, false);
54 // add into undoList
55 undoList->begin(distribution, TLF("remove '%' key from % '%'", key->getID(), distribution->getTagStr(), distribution->getID()));
56 undoList->add(change, true);
57 undoList->end();
58}
59
60
61void
62GNEChange_Distribution::editValue(GNEDemandElement* distribution, const GNEDemandElement* key, const double newValue, GNEUndoList* undoList) {
63 // create change
64 auto change = new GNEChange_Distribution(distribution, key, distribution->getAttributeDistributionValue(key), newValue);
65 // add into undoList
66 undoList->begin(distribution, TLF("change '%' key value from % to %", key->getID(), newValue, newValue));
67 undoList->add(change, true);
68 undoList->end();
69}
70
71
73 // only continue we have undo-redo mode enabled
75 // decrease reference
76 myDistribution->decRef("GNEChange_Distribution " + myDistribution->getTagProperty().getTagStr());
77 // remove if is unreferenced
79 // show extra information for tests
80 WRITE_DEBUG("Deleting unreferenced " + myDistribution->getTagStr() + " '" + myDistribution->getID() + "' in GNEChange_Distribution");
81 // delete distribution
82 delete myDistribution;
83 }
84 }
85}
86
87
88void
90 // show extra information for tests
91 WRITE_DEBUG("Setting previous distribution into " + myDistribution->getTagStr() + " '" + myDistribution->getID() + "'");
92 // continue depending of flags
95 } else if (myAddKey) {
97 } else {
99 }
100 // mark demand elements as unsaved
102}
103
104
105void
107 // show extra information for tests
108 WRITE_DEBUG("Setting new distribution into " + myDistribution->getTagStr() + " '" + myDistribution->getID() + "'");
109 // continue depending of flags
112 } else if (myAddKey) {
114 } else {
116 }
117 // mark demand elements as unsaved
119}
120
121
122std::string
124 return TLF("Undo edit distribution in '%'", myDistribution->getID());
125}
126
127
128std::string
130 return TLF("Redo edit distribution in '%'", myDistribution->getID());
131}
132
133
134GNEChange_Distribution::GNEChange_Distribution(GNEDemandElement* distribution, const GNEDemandElement* key, const double value, const bool addKey) :
135 GNEChange(Supermode::DEMAND, true, false),
136 myDistribution(distribution),
137 myKey(key),
138 myOriginalProbability(-1),
139 myNewProbability(value),
140 myAddKey(addKey),
141 myEditingProbability(false) {
142 myDistribution->incRef("GNEChange_Distribution " + myDistribution->getTagProperty().getTagStr());
143}
144
145
146GNEChange_Distribution::GNEChange_Distribution(GNEDemandElement* distribution, const GNEDemandElement* key, const double originalValue, const double newValue) :
147 GNEChange(Supermode::DEMAND, true, false),
148 myDistribution(distribution),
149 myKey(key),
150 myOriginalProbability(originalValue),
151 myNewProbability(newValue),
152 myAddKey(false),
153 myEditingProbability(true) {
154 myDistribution->incRef("GNEChange_Distribution " + myDistribution->getTagProperty().getTagStr());
155}
156
157/****************************************************************************/
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:131
GNEViewNet * getViewNet() const
get view net
Definition GNENet.cpp:2147
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...
GNEViewParent * getViewParent() const
get the net object
GNEApplicationWindow * getGNEAppWindows() const
get GNE Application Windows