Enzo
Loading...
Searching...
No Matches
CreateNodeCommand.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#include <icecream.hpp>
10
11namespace enzo::nt {
12
14{
15public:
16 CreateNodeCommand(OpId opId) : opId_(opId)
17 {
18 }
19
20 void undo() override
21 {
22 GeometryOperator& op = nm().getGeoOperator(opId_);
23 typeName_ = op.getTypeName();
24 position_ = op.getPosition();
25
26 nm().removeOperator(opId_);
27 }
28
29 void redo() override
30 {
31 // Restore operator
32 auto opInfo = op::OperatorTable::getOpInfo(typeName_);
33 nm().restoreOperator(opId_, opInfo.value());
34
35 // Restore position
36 GeometryOperator& op = nm().getGeoOperator(opId_);
37 nm().moveNode(opId_, position_, true);
38 }
39
40 UndoCommandType type() const override { return UndoCommandType::CreateNode; }
41
42private:
43 OpId opId_;
44 std::string typeName_;
45 bt::Vector2f position_;
46};
47
48}
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 CreateNodeCommand.h:14
The unique runtime representation of a node.
Definition GeometryOperator.h:20
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
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