12#include <openswmm/engine/openswmm_heat.h>
15#include <QUndoCommand>
28 void operator()(
void *snapshot)
const { swmm_heat_snapshot_destroy(snapshot); }
37 void operator()(
void *snapshot)
const { swmm_config_snapshot_destroy(snapshot); }
45template <
class Snapshot,
int (*Restore)(SWMM_Engine,
void *)>
65 Snapshot after, QString beforeIdentity, QString afterIdentity,
68 std::function<
void(QString)>
failed)
69 : owner_(
owner), engine_(engine), before_(std::move(before)), after_(std::move(after)),
70 beforeIdentity_(std::move(beforeIdentity)), afterIdentity_(std::move(afterIdentity)),
71 current_(std::move(current)), identity_(std::move(identity)),
81 void undo()
override { restore(
false); }
100 void restore(
bool after)
102 if (!owner_ || !current_ || current_() != engine_ ||
103 identity_(engine_) != (after ? beforeIdentity_ : afterIdentity_) ||
104 Restore(engine_, after ? after_.
get() : before_.
get()) != SWMM_OK) {
109 "%1: the settings changed outside Undo, or the simulation is initialized. The saved edit was not restored.")
116 QPointer<QObject> owner_;
118 Snapshot before_, after_;
119 QString beforeIdentity_, afterIdentity_;
122 std::function<void()> changed_;
123 std::function<void(QString)> failed_;
145 HeatSnapshot after, QString beforeIdentity, QString afterIdentity,
148 std::function<
void()>
changed, std::function<
void(QString)>
failed)
150 std::move(before), std::move(after), std::move(beforeIdentity),
151 std::move(afterIdentity), std::move(current), std::move(identity),
const QList< QColor > &(* get)()
Definition categoricalpalette.cpp:177
Definition heatconfigurationundo.h:47
void undo() override
Restore the prior snapshot only when owner/engine/current identity still match the command's applied ...
Definition heatconfigurationundo.h:81
EngineSnapshotUndo(const QString &text, QObject *owner, SWMM_Engine engine, Snapshot before, Snapshot after, QString beforeIdentity, QString afterIdentity, std::function< SWMM_Engine()> current, std::function< QString(SWMM_Engine)> identity, std::function< void()> changed, std::function< void(QString)> failed)
Own exact before/after snapshots for an already-applied engine edit.
Definition heatconfigurationundo.h:64
void redo() override
Skip the initial QUndoStack push, otherwise restore the applied snapshot under the same conflict chec...
Definition heatconfigurationundo.h:85
Definition heatconfigurationundo.h:129
HeatConfigurationUndo(QObject *owner, SWMM_Engine engine, HeatSnapshot before, HeatSnapshot after, QString beforeIdentity, QString afterIdentity, std::function< SWMM_Engine()> current, std::function< QString(SWMM_Engine)> identity, std::function< void()> changed, std::function< void(QString)> failed)
Specialize exact engine snapshot undo for an already-applied heat edit with a translated default labe...
Definition heatconfigurationundo.h:144
bool failed
Suppress repeated exceptions until an explicit refresh.
Definition extensionattributes.cpp:38
std::function< void(bool)> changed
Guarded layer refresh callback.
Definition extensionattributes.cpp:36
std::vector< int > owner
containing cell per pixel (-1 = outside)
Definition mesh2dresultsexport.cpp:766
Definition heatassignment.h:15
std::unique_ptr< void, ConfigSnapshotDeleter > ConfigSnapshot
Definition heatconfigurationundo.h:41
std::unique_ptr< void, HeatSnapshotDeleter > HeatSnapshot
Definition heatconfigurationundo.h:30
void * SWMM_Engine
Definition objectdefaultsapplier.h:23
QString text
Definition queryparser.cpp:54
Definition heatconfigurationundo.h:32
void operator()(void *snapshot) const
Release a uniquely owned configuration snapshot through the engine API.
Definition heatconfigurationundo.h:37
Definition heatconfigurationundo.h:23
void operator()(void *snapshot) const
Release a uniquely owned heat snapshot through the engine API.
Definition heatconfigurationundo.h:28