1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217
|
/***
Olive - Non-Linear Video Editor
Copyright (C) 2019 Olive Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
***/
#include "nodeviewundo.h"
#include "project/item/sequence/sequence.h"
OLIVE_NAMESPACE_ENTER
NodeEdgeAddCommand::NodeEdgeAddCommand(NodeOutput *output, NodeInput *input, QUndoCommand *parent) :
UndoCommand(parent),
output_(output),
input_(input),
old_edge_(nullptr),
done_(false)
{
}
void NodeEdgeAddCommand::redo_internal()
{
if (done_) {
return;
}
old_edge_ = NodeParam::DisconnectForNewOutput(input_);
NodeParam::ConnectEdge(output_, input_);
done_ = true;
}
void NodeEdgeAddCommand::undo_internal()
{
if (!done_) {
return;
}
NodeParam::DisconnectEdge(output_, input_);
if (old_edge_ != nullptr) {
NodeParam::ConnectEdge(old_edge_->output(), old_edge_->input());
}
done_ = false;
}
Project *NodeEdgeAddCommand::GetRelevantProject() const
{
return static_cast<Sequence*>(output_->parentNode()->parent())->project();
}
NodeEdgeRemoveCommand::NodeEdgeRemoveCommand(NodeOutput *output, NodeInput *input, QUndoCommand *parent) :
UndoCommand(parent),
output_(output),
input_(input),
done_(false)
{
}
NodeEdgeRemoveCommand::NodeEdgeRemoveCommand(NodeEdgePtr edge, QUndoCommand *parent) :
UndoCommand(parent),
output_(edge->output()),
input_(edge->input()),
done_(false)
{
}
void NodeEdgeRemoveCommand::redo_internal()
{
if (done_) {
return;
}
NodeParam::DisconnectEdge(output_, input_);
done_ = true;
}
void NodeEdgeRemoveCommand::undo_internal()
{
if (!done_) {
return;
}
NodeParam::ConnectEdge(output_, input_);
done_ = false;
}
Project *NodeEdgeRemoveCommand::GetRelevantProject() const
{
return static_cast<Sequence*>(output_->parentNode()->parent())->project();
}
NodeAddCommand::NodeAddCommand(NodeGraph *graph, Node *node, QUndoCommand *parent) :
UndoCommand(parent),
graph_(graph),
node_(node)
{
// Ensures that when this command is destroyed, if redo() is never called again, the node will be destroyed too
node_->setParent(&memory_manager_);
}
void NodeAddCommand::redo_internal()
{
graph_->AddNode(node_);
}
void NodeAddCommand::undo_internal()
{
graph_->TakeNode(node_, &memory_manager_);
}
Project *NodeAddCommand::GetRelevantProject() const
{
return static_cast<Sequence*>(graph_)->project();
}
NodeRemoveCommand::NodeRemoveCommand(NodeGraph *graph, const QList<Node *> &nodes, QUndoCommand *parent) :
UndoCommand(parent),
graph_(graph),
nodes_(nodes)
{
}
void NodeRemoveCommand::redo_internal()
{
// Cache edges for undoing
foreach (Node* n, nodes_) {
foreach (NodeParam* param, n->parameters()) {
foreach (NodeEdgePtr edge, param->edges()) {
// Ensures the same edge isn't added twice (prevents double connecting when undoing)
if (!edges_.contains(edge)) {
edges_.append(edge);
}
}
}
}
// Take nodes from graph (TakeNode() will automatically disconnect edges)
foreach (Node* n, nodes_) {
graph_->TakeNode(n, &memory_manager_);
}
}
void NodeRemoveCommand::undo_internal()
{
// Re-add nodes to graph
foreach (Node* n, nodes_) {
graph_->AddNode(n);
}
// Re-connect edges
foreach (NodeEdgePtr edge, edges_) {
NodeParam::ConnectEdge(edge->output(), edge->input());
}
edges_.clear();
}
Project *NodeRemoveCommand::GetRelevantProject() const
{
return static_cast<Sequence*>(graph_)->project();
}
NodeRemoveWithExclusiveDeps::NodeRemoveWithExclusiveDeps(NodeGraph *graph, Node *node, QUndoCommand *parent) :
UndoCommand(parent)
{
QList<Node*> node_and_its_deps;
node_and_its_deps.append(node);
node_and_its_deps.append(node->GetExclusiveDependencies());
remove_command_ = new NodeRemoveCommand(graph, node_and_its_deps, this);
}
Project *NodeRemoveWithExclusiveDeps::GetRelevantProject() const
{
return remove_command_->GetRelevantProject();
}
NodeCopyInputsCommand::NodeCopyInputsCommand(Node *src, Node *dest, bool include_connections, QUndoCommand *parent) :
QUndoCommand(parent),
src_(src),
dest_(dest),
include_connections_(include_connections)
{
}
NodeCopyInputsCommand::NodeCopyInputsCommand(Node *src, Node *dest, QUndoCommand *parent) :
QUndoCommand(parent),
src_(src),
dest_(dest),
include_connections_(true)
{
}
void NodeCopyInputsCommand::redo()
{
Node::CopyInputs(src_, dest_, include_connections_);
}
OLIVE_NAMESPACE_EXIT
|