Enzo
Loading...
Searching...
No Matches
DeleteNodeCommand.h
1#pragma once
2
3#include "Engine/UndoRedo/UndoCommand.h"
4#include "Engine/Network/NetworkManager.h"
5#include "Engine/Operator/OperatorTable.h"
6#include "Engine/Types.h"
7#include <vector>
8#include <string>
9
10namespace enzo::nt {
11
13{
14
15struct SavedParameter
16{
17 std::string name;
18 prm::PrmValues values;
19};
20
21public:
22 DeleteNodeCommand(OpId opId) : opId_(opId)
23 {
24 GeometryOperator& op = nm().getGeoOperator(opId_);
25 typeName_ = op.getTypeName();
26 position_ = op.getPosition();
27
28 // Save parms
29 savedParms_ = std::vector<SavedParameter>();
30 for(auto weakPrm : op.getParameters())
31 {
32 if(auto prm = weakPrm.lock())
33 {
34 savedParms_.push_back({prm->getName(), prm->getValues()});
35 }
36 }
37 }
38
39 void undo() override
40 {
41 // Restore operator
42 auto opInfo = op::OperatorTable::getOpInfo(typeName_);
43 nm().restoreOperator(opId_, opInfo.value());
44
45 GeometryOperator& op = nm().getGeoOperator(opId_);
46
47 // Restore position
48 nm().moveNode(opId_, position_, true);
49
50 // Restore parms
51 for(const auto& saved : savedParms_)
52 {
53 if(auto prm = op.getParameter(saved.name).lock())
54 {
55 prm->setValues(saved.values);
56 }
57 }
58 }
59
60 void redo() override
61 {
62 nm().removeOperator(opId_);
63 }
64
65 UndoCommandType type() const override { return UndoCommandType::DeleteNode; }
66
67private:
68 OpId opId_;
69 std::string typeName_;
70 bt::Vector2f position_;
71 std::vector<SavedParameter> savedParms_;
72};
73
74}
Basic attribute, parameter, and node types for Enzo.
uint64_t OpId
The unique ID assigned to each node in the network.
Definition Types.h:87
Definition DeleteNodeCommand.h:13
The unique runtime representation of a node.
Definition GeometryOperator.h:20
std::weak_ptr< prm::Parameter > getParameter(std::string parameterName)
Returns a parameter with the given name belonging to this node.
Definition GeometryOperator.cpp:163
std::string getTypeName()
Returns the name belonging to this type of node (eg. grid or transform). Not to be confused with the ...
Definition GeometryOperator.cpp:196
bt::Vector2f getPosition() const
Returns the node's position in the network graph.
Definition GeometryOperator.h:156
std::vector< std::weak_ptr< prm::Parameter > > getParameters()
Returns all parameters belonging to this node.
Definition GeometryOperator.cpp:180
void restoreOperator(OpId opId, op::OpInfo opInfo)
Restores a previously removed operator with a specific OpId.
Definition NetworkManager.cpp:69
void removeOperator(OpId opId)
Removes an operator and all its connections from the network.
Definition NetworkManager.cpp:84
GeometryOperator & getGeoOperator(nt::OpId opId)
Returns a reference to the GeometryOperator with the given OpId.
Definition NetworkManager.cpp:140
void moveNode(OpId opId, bt::Vector2f newPos, bool skipUndo=false)
Moves a node to a new position, pushing an undo command.
Definition NetworkManager.cpp:45
Definition UndoCommand.h:8