Enzo
Loading...
Searching...
No Matches
ChangeConnectionCommand.h
1#pragma once
2
3#include "Engine/UndoRedo/UndoCommand.h"
4#include "Engine/Network/NetworkManager.h"
5#include "Engine/Operator/GeometryOperator.h"
6#include "Engine/Types.h"
7
8namespace enzo::nt {
9
11{
12public:
13 enum class Action { Connect, Disconnect };
14
15 ChangeConnectionCommand(OpId inputOpId, unsigned int inputIndex,
16 OpId outputOpId, unsigned int outputIndex,
17 Action action)
18 : inputOpId_(inputOpId), inputIndex_(inputIndex),
19 outputOpId_(outputOpId), outputIndex_(outputIndex),
20 action_(action) {}
21
22 void undo() override
23 {
24 if (action_ == Action::Connect)
25 disconnect();
26 else
27 connect();
28 }
29
30 void redo() override
31 {
32 if (action_ == Action::Connect)
33 connect();
34 else
35 disconnect();
36 }
37
38 UndoCommandType type() const override { return UndoCommandType::ChangeConnection; }
39
40private:
41 void connect()
42 {
43 connectOperators(inputOpId_, inputIndex_, outputOpId_, outputIndex_);
44 }
45
46 void disconnect()
47 {
48 auto& outputOp = nm().getGeoOperator(outputOpId_);
49 if (auto conn = outputOp.getInputConnection(outputIndex_).lock())
50 {
51 conn->remove();
52 }
53 }
54
55 OpId inputOpId_;
56 unsigned int inputIndex_;
57 OpId outputOpId_;
58 unsigned int outputIndex_;
59 Action action_;
60};
61
62}
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 ChangeConnectionCommand.h:11
GeometryOperator & getGeoOperator(nt::OpId opId)
Returns a reference to the GeometryOperator with the given OpId.
Definition NetworkManager.cpp:140
Definition UndoCommand.h:8