Enzo
Loading...
Searching...
No Matches
ChangeParameterCommand.h
1#pragma once
2
3#include "Engine/Core/Types.h"
4#include "Engine/Network/NetworkManager.h"
5#include "Engine/Parameter/Parameter.h"
6#include "Engine/Serializer/ParameterSerializable.h"
7#include "Engine/UndoRedo/UndoCommand.h"
8#include <icecream.hpp>
9#include <string>
10
11namespace enzo::nt {
12
16{
17 public:
19 enzo::nt::OpId opId,
20 std::string paramName,
23 )
24 : opId_(opId), paramName_(paramName), before_(std::move(before)), after_(std::move(after))
25 {
26 }
27
28 // Flat parameters hand over their value vectors and the snapshot is built here.
30 enzo::nt::OpId opId,
31 std::string paramName,
32 const enzo::prm::PrmValues& before,
33 const enzo::prm::PrmValues& after
34 )
35 : opId_(opId), paramName_(paramName), before_(toSerializable(paramName, before)),
36 after_(toSerializable(paramName, after))
37 {
38 }
39
40 void undo() override { restore_(before_); }
41 void redo() override { restore_(after_); }
42
43 UndoCommandType type() const override { return UndoCommandType::ChangeParameter; }
44
45 private:
46 void restore_(const ParameterSerializable& snapshot)
47 {
48 IC(opId_, paramName_);
49 if (!nm().isValidOp(opId_))
50 {
51 IC("ChangeParameterCommand — operator not found", opId_);
52 return;
53 }
54 if (auto prm = nm().getGeoOperator(opId_).getParameter(paramName_).lock())
55 applySerializable(*prm, snapshot);
56 else
57 IC("ChangeParameterCommand — parameter not found", opId_, paramName_);
58 }
59
60 enzo::nt::OpId opId_;
61 std::string paramName_;
64};
65
66} // namespace enzo::nt
Basic attribute, parameter, and node types for Enzo.
uint64_t OpId
The unique ID assigned to each node in the network.
Definition Types.h:137
Undo step for a parameter edit. Restores the whole parameter from a snapshot so flat values and multi...
Definition ChangeParameterCommand.h:16
Definition UndoCommand.h:8
Definition ParameterSerializable.h:12