node: implement find path utility function

This commit is contained in:
itsmattkc
2022-05-01 10:47:58 -07:00
parent 67f1a1ad0c
commit 004c66a073
2 changed files with 46 additions and 0 deletions
+44
View File
@@ -2002,6 +2002,50 @@ void Node::SetValueAtTime(const NodeInput &input, const rational &time, const QV
}
}
void FindPathInternal(std::list<Node *> &vec, Node *to, int &path_index)
{
Node *from = vec.back();
for (auto it=from->input_connections().cbegin(); it!=from->input_connections().cend(); it++) {
vec.push_back(it->second);
if (it->second == to) {
// Found a path, determine if it's the one we want
if (path_index == 0) {
// It is!
break;
} else {
path_index--;
}
}
// Recurse to see if we can find it here
FindPathInternal(vec, to, path_index);
if (vec.back() == to) {
// Found through recursion
break;
} else {
// Must not be available through this path
vec.pop_back();
}
}
}
std::list<Node *> Node::FindPath(Node *from, Node *to, int path_index)
{
std::list<Node *> v;
v.push_back(from);
FindPathInternal(v, to, path_index);
if (v.size() == 1) {
// Failed to find path, return empty list
v.pop_back();
}
return v;
}
Project *Node::ArrayInsertCommand::GetRelevantProject() const
{
return node_->project();
+2
View File
@@ -956,6 +956,8 @@ public:
static void SetValueAtTime(const NodeInput &input, const rational &time, const QVariant &value, int track, MultiUndoCommand *command, bool insert_on_all_tracks_if_no_key);
static std::list<Node*> FindPath(Node *from, Node *to, int path_index = 0);
static const QString kEnabledInput;
protected: