diff --git a/lib/mayaUsd/ufe/ProxyShapeHierarchy.cpp b/lib/mayaUsd/ufe/ProxyShapeHierarchy.cpp index 9a6b66f8a1..af4ff72f3c 100644 --- a/lib/mayaUsd/ufe/ProxyShapeHierarchy.cpp +++ b/lib/mayaUsd/ufe/ProxyShapeHierarchy.cpp @@ -133,6 +133,8 @@ const UsdPrim& ProxyShapeHierarchy::getUsdRootPrim() const Ufe::SceneItem::Ptr ProxyShapeHierarchy::sceneItem() const { return fItem; } +#if (UFE_PREVIEW_VERSION_NUM >= 4004) + bool ProxyShapeHierarchy::hasChildren() const { // We have an extra logic in createUFEChildList to remap and filter @@ -143,6 +145,35 @@ bool ProxyShapeHierarchy::hasChildren() const return !children().empty(); } +bool ProxyShapeHierarchy::hasFilteredChildren(const ChildFilter& childFilter) const +{ + // We have an extra logic in createUFEChildList to remap and filter + // prims. Going this direction is more costly, but easier to maintain. + // + // I don't have data that proves we need to worry about performance in here, + // so going after maintainability. + return !filteredChildren(childFilter).empty(); +} + +#else + +bool ProxyShapeHierarchy::hasChildren() const +{ + // Return children of the USD root. + const UsdPrim& rootPrim = getUsdRootPrim(); + if (!rootPrim.IsValid()) + return false; + + // We have an extra logic in createUFEChildList to remap and filter + // prims. Going this direction is more costly, but easier to maintain. + // + // I don't have data that proves we need to worry about performance in here, + // so going after maintainability. + return !createUFEChildList(getUSDFilteredChildren(rootPrim), false /*filterInactive*/).empty(); +} + +#endif + Ufe::SceneItemList ProxyShapeHierarchy::children() const { // Return children of the USD root. diff --git a/lib/mayaUsd/ufe/ProxyShapeHierarchy.h b/lib/mayaUsd/ufe/ProxyShapeHierarchy.h index 3185c0e62e..92009ee63d 100644 --- a/lib/mayaUsd/ufe/ProxyShapeHierarchy.h +++ b/lib/mayaUsd/ufe/ProxyShapeHierarchy.h @@ -57,6 +57,9 @@ class MAYAUSD_CORE_PUBLIC ProxyShapeHierarchy : public Ufe::Hierarchy Ufe::SceneItem::Ptr sceneItem() const override; bool hasChildren() const override; Ufe::SceneItemList children() const override; +#if (UFE_PREVIEW_VERSION_NUM >= 4004) + bool hasFilteredChildren(const ChildFilter&) const override; +#endif UFE_V2(Ufe::SceneItemList filteredChildren(const ChildFilter&) const override;) Ufe::SceneItem::Ptr parent() const override; #ifndef UFE_V2_FEATURES_AVAILABLE diff --git a/lib/mayaUsd/ufe/PulledObjectHierarchy.cpp b/lib/mayaUsd/ufe/PulledObjectHierarchy.cpp index 67f55edfb5..574bc20b75 100644 --- a/lib/mayaUsd/ufe/PulledObjectHierarchy.cpp +++ b/lib/mayaUsd/ufe/PulledObjectHierarchy.cpp @@ -52,6 +52,13 @@ PulledObjectHierarchy::Ptr PulledObjectHierarchy::create( Ufe::SceneItem::Ptr PulledObjectHierarchy::sceneItem() const { return _mayaHierarchy->sceneItem(); } +#if (UFE_PREVIEW_VERSION_NUM >= 4004) +bool PulledObjectHierarchy::hasFilteredChildren(const ChildFilter& childFilter) const +{ + return _mayaHierarchy->hasFilteredChildren(childFilter); +} +#endif + bool PulledObjectHierarchy::hasChildren() const { return _mayaHierarchy->hasChildren(); } Ufe::SceneItemList PulledObjectHierarchy::children() const { return _mayaHierarchy->children(); } diff --git a/lib/mayaUsd/ufe/PulledObjectHierarchy.h b/lib/mayaUsd/ufe/PulledObjectHierarchy.h index ba7101e0e5..b3e92377cb 100644 --- a/lib/mayaUsd/ufe/PulledObjectHierarchy.h +++ b/lib/mayaUsd/ufe/PulledObjectHierarchy.h @@ -58,6 +58,9 @@ class MAYAUSD_CORE_PUBLIC PulledObjectHierarchy : public Ufe::Hierarchy Ufe::SceneItem::Ptr sceneItem() const override; bool hasChildren() const override; Ufe::SceneItemList children() const override; +#if (UFE_PREVIEW_VERSION_NUM >= 4004) + bool hasFilteredChildren(const ChildFilter&) const override; +#endif Ufe::SceneItemList filteredChildren(const ChildFilter&) const override; Ufe::SceneItem::Ptr parent() const override; diff --git a/lib/mayaUsd/ufe/UsdHierarchy.cpp b/lib/mayaUsd/ufe/UsdHierarchy.cpp index 45ec40b46b..c7bea791ae 100644 --- a/lib/mayaUsd/ufe/UsdHierarchy.cpp +++ b/lib/mayaUsd/ufe/UsdHierarchy.cpp @@ -117,6 +117,8 @@ UsdSceneItem::Ptr UsdHierarchy::usdSceneItem() const { return fItem; } Ufe::SceneItem::Ptr UsdHierarchy::sceneItem() const { return fItem; } +#if (UFE_PREVIEW_VERSION_NUM >= 4004) + bool UsdHierarchy::hasChildren() const { // We have an extra logic in createUFEChildList to remap and filter @@ -127,6 +129,31 @@ bool UsdHierarchy::hasChildren() const return !children().empty(); } +bool UsdHierarchy::hasFilteredChildren(const ChildFilter& childFilter) const +{ + // We have an extra logic in createUFEChildList to remap and filter + // prims. Going this direction is more costly, but easier to maintain. + // + // I don't have data that proves we need to worry about performance in here, + // so going after maintainability. + return !filteredChildren(childFilter).empty(); +} + +#else + +bool UsdHierarchy::hasChildren() const +{ + // We have an extra logic in createUFEChildList to remap and filter + // prims. Going this direction is more costly, but easier to maintain. + // + // I don't have data that proves we need to worry about performance in here, + // so going after maintainability. + const bool isFilteringInactive = false; + return !createUFEChildList(getUSDFilteredChildren(fItem), isFilteringInactive).empty(); +} + +#endif + Ufe::SceneItemList UsdHierarchy::children() const { return createUFEChildList(getUSDFilteredChildren(fItem), true /*filterInactive*/); diff --git a/lib/mayaUsd/ufe/UsdHierarchy.h b/lib/mayaUsd/ufe/UsdHierarchy.h index 716b292da2..8ee22cfc77 100644 --- a/lib/mayaUsd/ufe/UsdHierarchy.h +++ b/lib/mayaUsd/ufe/UsdHierarchy.h @@ -63,6 +63,9 @@ class MAYAUSD_CORE_PUBLIC UsdHierarchy : public Ufe::Hierarchy Ufe::SceneItem::Ptr sceneItem() const override; bool hasChildren() const override; Ufe::SceneItemList children() const override; +#if (UFE_PREVIEW_VERSION_NUM >= 4004) + bool hasFilteredChildren(const ChildFilter&) const override; +#endif UFE_V2(Ufe::SceneItemList filteredChildren(const ChildFilter&) const override;) Ufe::SceneItem::Ptr parent() const override; #ifndef UFE_V2_FEATURES_AVAILABLE diff --git a/test/lib/ufe/testChildFilter.py b/test/lib/ufe/testChildFilter.py index 50e74ec9cb..8f97856291 100644 --- a/test/lib/ufe/testChildFilter.py +++ b/test/lib/ufe/testChildFilter.py @@ -102,6 +102,13 @@ def testFilteredChildren(self): usdHierHndlr = ufe.RunTimeMgr.instance().hierarchyHandler(ball3Item.runTimeId()) cf = usdHierHndlr.childFilter() + # Toggle "Inactive Prims" off and get the filtered children + # Props filtered children should have 5 children and ball3 should not be one of them. + cf[0].value = False + children = propsHier.filteredChildren(cf) + self.assertEqual(5, len(children)) + self.assertNotIn(ball3Item, children) + # Toggle "Inactive Prims" on and get the filtered children # (with inactive prims) and verify ball3 is one of them. cf[0].value = True diff --git a/test/lib/ufe/testContextOps.py b/test/lib/ufe/testContextOps.py index f5742cb13a..bd65cb997a 100644 --- a/test/lib/ufe/testContextOps.py +++ b/test/lib/ufe/testContextOps.py @@ -19,6 +19,7 @@ import fixturesUtils import mayaUtils import usdUtils +import ufeUtils from pxr import UsdGeom @@ -358,12 +359,25 @@ def testAddNewPrimWithDelete(self): self.assertEqual(len(proxyShapehier.children()), 1) # Using UFE, delete this new prim (which doesn't actually delete it but - # instead makes it inactive). + # instead makes it inactive). In Maya 2023 and greater, delete really + # deletes so deactivate instead to make the test act the same for all + # versions. cmds.pickWalk(d='down') - cmds.delete() - - # The proxy shape should now have no UFE child items (since we skip inactive). - self.assertFalse(proxyShapehier.hasChildren()) + if mayaUtils.mayaMajorVersion() >= 2023: + ufeItem = ufe.GlobalSelection.get().front() + item = usdUtils.getPrimFromSceneItem(ufeItem) + item.SetActive(False) + else: + cmds.delete() + + # The proxy shape should now have no UFE child items (since we skip inactive + # when returning the children list) but hasChildren still reports true in + # UFE version before 0.4.4 for inactive to allow the caller to do conditional + # inactive filtering, so we test that hasChildren is true for those versions. + if (os.getenv('UFE_PREVIEW_VERSION_NUM', '0000') >= '4004'): + self.assertFalse(proxyShapehier.hasChildren()) + else: + self.assertTrue(proxyShapehier.hasChildren()) self.assertEqual(len(proxyShapehier.children()), 0) # Add another Xform prim (which should get a unique name taking into