Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide orphaned pulled nodes on ancestor structure change. #2576

Merged
merged 8 commits into from
Sep 28, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 45 additions & 35 deletions lib/mayaUsd/fileio/orphanedNodesManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,26 @@ namespace MAYAUSD_NS_DEF {

OrphanedNodesManager::Memento::Memento(Ufe::Trie<PullVariantInfo>&& pulledPrims)
: _pulledPrims(std::move(pulledPrims))
{ }
{
}

OrphanedNodesManager::Memento::Memento()
: _pulledPrims()
{ }
{
}

OrphanedNodesManager::Memento::Memento(Memento&& rhs)
: _pulledPrims(std::move(rhs._pulledPrims))
{ }
{
}

OrphanedNodesManager::Memento& OrphanedNodesManager::Memento::operator=(Memento&& rhs)
{
_pulledPrims = std::move(rhs._pulledPrims);
return *this;
}

Ufe::Trie<OrphanedNodesManager::PullVariantInfo>
OrphanedNodesManager::Memento::release()
Ufe::Trie<OrphanedNodesManager::PullVariantInfo> OrphanedNodesManager::Memento::release()
{
return std::move(_pulledPrims);
}
Expand All @@ -64,12 +66,12 @@ OrphanedNodesManager::Memento::release()
// Class OrphanedNodesManager
//------------------------------------------------------------------------------

OrphanedNodesManager::OrphanedNodesManager() : _pulledPrims() { }
OrphanedNodesManager::OrphanedNodesManager()
: _pulledPrims()
{
}

void OrphanedNodesManager::add(
const Ufe::Path& pulledPath,
const MDagPath& pullParentPath
)
void OrphanedNodesManager::add(const Ufe::Path& pulledPath, const MDagPath& pullParentPath)
{
// Add the pull parent to our pulled prims prefix tree. Also add the full
// configuration of variant set selections for each ancestor, up to the USD
Expand Down Expand Up @@ -110,14 +112,31 @@ void OrphanedNodesManager::operator()(const Ufe::Notification& n)
}
}
} else if (pulledPrims().containsDescendant(changedPath)) {
#ifdef UFE_V4_FEATURES_AVAILABLE
// Use UFE v4 notification to op conversion.
handleOp(sceneNotification);
#else
// UFE v3: convert to op ourselves. Only convert supported
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maya 2023 UFE v3 did not have nice notification to notification op conversion.

// notifications.
if (auto objAdd = dynamic_cast<const Ufe::ObjectAdd*>(&sceneNotification)) {
handleOp(Ufe::SceneCompositeNotification::Op(
Ufe::SceneCompositeNotification::ObjectAdd, objAdd->item()));
} else if (auto objDel = dynamic_cast<const Ufe::ObjectDelete*>(&sceneNotification)) {
handleOp(Ufe::SceneCompositeNotification::Op(
Ufe::SceneCompositeNotification::ObjectDelete, objDel->path()));
} else if (
auto subtrInv = dynamic_cast<const Ufe::SubtreeInvalidate*>(&sceneNotification)) {
handleOp(Ufe::SceneCompositeNotification::Op(
Ufe::SceneCompositeNotification::SubtreeInvalidate, subtrInv->root()));
}
#endif
}
}

void OrphanedNodesManager::handleOp(const Ufe::SceneCompositeNotification::Op& op)
{
switch (op.opType) {
case Ufe::SceneChanged::ObjectAdd: {
case Ufe::SceneCompositeNotification::ObjectAdd: {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In UFE v3 the enumerant was in the SceneCompositeNotification derived class, in UFE v4 it's move to the base class, but the derived class scope still works, so using the derived class is UFE v3/v4 compatible, a requirement for 2023 compatibility.

// Restoring a previously-deleted scene item may restore an orphaned
// node. Traverse the trie, and show hidden pull parents that are
// descendants of the argument path. The trie node that corresponds to
Expand All @@ -127,7 +146,7 @@ void OrphanedNodesManager::handleOp(const Ufe::SceneCompositeNotification::Op& o
TF_VERIFY(ancestorNode);
recursiveSetVisibility(ancestorNode, true);
} break;
case Ufe::SceneChanged::ObjectDelete: {
case Ufe::SceneCompositeNotification::ObjectDelete: {
// The following cases will generate object delete:
// - Inactivate of ancestor USD prim sends object post delete. The
// inactive object has no children.
Expand All @@ -146,7 +165,7 @@ void OrphanedNodesManager::handleOp(const Ufe::SceneCompositeNotification::Op& o
TF_VERIFY(ancestorNode);
recursiveSetVisibility(ancestorNode, false);
} break;
case Ufe::SceneChanged::SubtreeInvalidate: {
case Ufe::SceneCompositeNotification::SubtreeInvalidate: {
// On subtree invalidate, the scene item itself has not had a structure
// change, but its children have changed. There are two cases:
// - the node has children: from a variant switch, or from a payload
Expand Down Expand Up @@ -217,35 +236,28 @@ void OrphanedNodesManager::handleOp(const Ufe::SceneCompositeNotification::Op& o
}
}
} break;
default: {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UNIX (Linux, macOS) warning as error fix.

// ObjectPathChange (reparent, rename): to be implemented (MAYA-125039).
// SceneCompositeNotification: already expanded in operator().
}
}
}

Ufe::Trie<OrphanedNodesManager::PullVariantInfo>&
OrphanedNodesManager::pulledPrims()
Ufe::Trie<OrphanedNodesManager::PullVariantInfo>& OrphanedNodesManager::pulledPrims()
{
return _pulledPrims;
}

const Ufe::Trie<OrphanedNodesManager::PullVariantInfo>&
OrphanedNodesManager::pulledPrims() const
const Ufe::Trie<OrphanedNodesManager::PullVariantInfo>& OrphanedNodesManager::pulledPrims() const
{
return _pulledPrims;
}

void OrphanedNodesManager::clear()
{
pulledPrims().clear();
}
void OrphanedNodesManager::clear() { pulledPrims().clear(); }

bool OrphanedNodesManager::empty() const
{
return pulledPrims().root()->empty();
}
bool OrphanedNodesManager::empty() const { return pulledPrims().root()->empty(); }

void OrphanedNodesManager::restore(Memento&& previous)
{
_pulledPrims = std::move(previous.release());
}
void OrphanedNodesManager::restore(Memento&& previous) { _pulledPrims = previous.release(); }

/* static */
bool OrphanedNodesManager::setVisibilityPlug(
Expand Down Expand Up @@ -345,9 +357,8 @@ OrphanedNodesManager::variantSetDescriptors(const Ufe::Path& p)
}

/* static */
Ufe::Trie<OrphanedNodesManager::PullVariantInfo> OrphanedNodesManager::deepCopy(
const Ufe::Trie<PullVariantInfo>& src
)
Ufe::Trie<OrphanedNodesManager::PullVariantInfo>
OrphanedNodesManager::deepCopy(const Ufe::Trie<PullVariantInfo>& src)
{
Ufe::Trie<PullVariantInfo> dst;
deepCopy(src.root(), dst.root());
Expand All @@ -357,12 +368,11 @@ Ufe::Trie<OrphanedNodesManager::PullVariantInfo> OrphanedNodesManager::deepCopy(
/* static */
void OrphanedNodesManager::deepCopy(
const Ufe::TrieNode<PullVariantInfo>::Ptr& src,
const Ufe::TrieNode<PullVariantInfo>::Ptr& dst
)
const Ufe::TrieNode<PullVariantInfo>::Ptr& dst)
{
for (const auto& c : src->childrenComponents()) {
const auto& srcChild = (*src)[c];
auto dstChild = std::make_shared<Ufe::TrieNode<PullVariantInfo>>(c);
auto dstChild = std::make_shared<Ufe::TrieNode<PullVariantInfo>>(c);
dst->add(dstChild);
if (srcChild->hasData()) {
dstChild->setData(srcChild->data());
Expand Down
17 changes: 7 additions & 10 deletions lib/mayaUsd/fileio/orphanedNodesManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ class OrphanedNodesManager : public Ufe::Observer
public:
typedef std::shared_ptr<OrphanedNodesManager> Ptr;

class Memento {
class Memento
{
public:

// Can create an initial empty state, for it to be overwritten later.
Memento();
~Memento() = default;
Expand All @@ -90,9 +90,8 @@ class OrphanedNodesManager : public Ufe::Observer

Memento(const Memento&) = delete;
Memento& operator=(const Memento&) = delete;

private:

private:
// Private, for opacity.
friend class OrphanedNodesManager;

Expand Down Expand Up @@ -126,10 +125,9 @@ class OrphanedNodesManager : public Ufe::Observer
bool empty() const;

private:

void handleOp(const Ufe::SceneCompositeNotification::Op& op);

Ufe::Trie<PullVariantInfo>& pulledPrims();
Ufe::Trie<PullVariantInfo>& pulledPrims();
const Ufe::Trie<PullVariantInfo>& pulledPrims() const;

static void
Expand All @@ -144,10 +142,9 @@ class OrphanedNodesManager : public Ufe::Observer
static std::list<VariantSetDescriptor> variantSetDescriptors(const Ufe::Path& path);

static Ufe::Trie<PullVariantInfo> deepCopy(const Ufe::Trie<PullVariantInfo>& src);
static void deepCopy(
const Ufe::TrieNode<PullVariantInfo>::Ptr& src,
const Ufe::TrieNode<PullVariantInfo>::Ptr& dst
);
static void deepCopy(
const Ufe::TrieNode<PullVariantInfo>::Ptr& src,
const Ufe::TrieNode<PullVariantInfo>::Ptr& dst);

// Trie for fast lookup of descendant pulled prims. The Trie key is the
// UFE pulled path, and the Trie value is the corresponding Dag pull parent
Expand Down