Enzo
Loading...
Searching...
No Matches
CreateNodeCommand.h
1#pragma once
2
3#include "Engine/Core/Types.h"
4#include "Engine/Network/NetworkManager.h"
5#include "Engine/Network/OperatorTable.h"
6#include "Engine/UndoRedo/UndoCommand.h"
7#include <icecream.hpp>
8#include <string>
9#include <vector>
10
11namespace enzo::nt {
12
14{
15 public:
16 CreateNodeCommand(OpId opId) : opId_(opId) {}
17
18 void undo() override
19 {
20 GeometryOperator& op = nm().getGeoOperator(opId_);
21 typeName_ = op.getType().getName();
22 position_ = op.getPosition();
23
24 nm().removeOperator(opId_, false);
25 }
26
27 void redo() override
28 {
29 // Restore operator
30 auto opInfo = op::OperatorTable::getOpInfo(typeName_);
31 nm().restoreOperator(opId_, opInfo.value());
32
33 // Restore position
34 GeometryOperator& op = nm().getGeoOperator(opId_);
35 nm().moveNode(opId_, position_, true);
36 }
37
38 UndoCommandType type() const override { return UndoCommandType::CreateNode; }
39
40 private:
41 OpId opId_;
42 std::string typeName_;
43 Vector2 position_;
44};
45
46} // 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
Definition CreateNodeCommand.h:14
The unique runtime representation of a node.
Definition GeometryOperator.h:16
const op::OpInfo & getType() const
Returns the static type definition this node was created from.
Definition GeometryOperator.cpp:163
Vector2 getPosition() const
Returns the node's position in the network graph.
Definition GeometryOperator.h:116
void restoreOperator(OpId opId, op::OpInfo opInfo)
Restores a previously removed operator with a specific OpId.
Definition NetworkManager.cpp:74
void removeOperator(OpId opId, bool removeConnections=true)
Removes an operator from the network.
Definition NetworkManager.cpp:87
void moveNode(OpId opId, Vector2 newPos, bool skipUndo=false)
Moves a node to a new position, pushing an undo command.
Definition NetworkManager.cpp:42
GeometryOperator & getGeoOperator(nt::OpId opId)
Returns a reference to the GeometryOperator with the given OpId.
Definition NetworkManager.cpp:141
Definition UndoCommand.h:8
const std::string & getName() const
Returns the internal type name shared by all nodes of this type (eg. "copy_to_points")
Definition OpInfo.h:30