diff --git a/app/node/input.cpp b/app/node/input.cpp index d43a986d7..7e6fa6153 100644 --- a/app/node/input.cpp +++ b/app/node/input.cpp @@ -280,7 +280,7 @@ void NodeInput::set_maximum(const QVariant &max) has_maximum_ = true; } -void NodeInput::CopyValues(NodeInput *source, NodeInput *dest) +void NodeInput::CopyValues(NodeInput *source, NodeInput *dest, bool include_connections) { // Copy values dest->keyframes_ = source->keyframes_; @@ -289,7 +289,7 @@ void NodeInput::CopyValues(NodeInput *source, NodeInput *dest) dest->set_is_keyframing(source->is_keyframing()); // Copy connections - if (source->get_connected_output() != nullptr) { + if (include_connections && source->get_connected_output() != nullptr) { ConnectEdge(source->get_connected_output(), dest); } } diff --git a/app/node/input.h b/app/node/input.h index 5a9029ed2..5cc0bbfea 100644 --- a/app/node/input.h +++ b/app/node/input.h @@ -131,7 +131,7 @@ public: /** * @brief Copy all values including keyframe information and connections from another NodeInput */ - static void CopyValues(NodeInput* source, NodeInput* dest); + static void CopyValues(NodeInput* source, NodeInput* dest, bool include_connections = true); signals: void ValueChanged(const rational& start, const rational& end); diff --git a/app/node/node.cpp b/app/node/node.cpp index fa1f0f649..cdcd3a811 100644 --- a/app/node/node.cpp +++ b/app/node/node.cpp @@ -152,7 +152,7 @@ bool Node::IsProcessingLocked() } } -void Node::CopyInputs(Node *source, Node *destination) +void Node::CopyInputs(Node *source, Node *destination, bool include_connections) { Q_ASSERT(source->id() == destination->id()); @@ -166,7 +166,39 @@ void Node::CopyInputs(Node *source, Node *destination) if (src->dependent()) { NodeInput* dst = static_cast(dst_param.at(i)); - NodeInput::CopyValues(src, dst); + NodeInput::CopyValues(src, dst, include_connections); + } + } + } +} + +void Node::DuplicateConnectionsBetweenLists(const QList &source, const QList &destination) +{ + Q_ASSERT(source.size() == destination.size()); + + for (int i=0;iparams_.size();j++) { + NodeParam* source_param = source_node->params_.at(j); + + if (source_param->type() == NodeInput::kInput && source_param->IsConnected()) { + NodeInput* source_input = static_cast(source_param); + NodeInput* dest_input = static_cast(dest_node->params_.at(j)); + + // Get this input's connected outputs + NodeOutput* connected_output = source_input->get_connected_output(); + Node* connected_node = connected_output->parent(); + + // Find index of connected output in source list + int connection_index = source.indexOf(connected_node); + + // Find equivalent in destination list + Node* dest_output_node = destination.at(connection_index); + NodeOutput* dest_output = static_cast(dest_output_node->params_.at(connected_output->index())); + + NodeParam::ConnectEdge(dest_output, dest_input); } } } diff --git a/app/node/node.h b/app/node/node.h index 77eea10a7..9cdfccf13 100644 --- a/app/node/node.h +++ b/app/node/node.h @@ -214,7 +214,12 @@ public: * * Nodes must be of the same types (i.e. have the same ID) */ - static void CopyInputs(Node* source, Node* destination); + static void CopyInputs(Node* source, Node* destination, bool include_connections = true); + + /** + * @brief For a list of copies nodes, this function will duplicate all the connections in the source list to the destination list + */ + static void DuplicateConnectionsBetweenLists(const QList& source, const QList &destination); /** * @brief Return whether this Node can be deleted or not