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

Added test for getAllStages() versus delete. #2645

Merged
merged 3 commits into from
Oct 27, 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
14 changes: 14 additions & 0 deletions lib/mayaUsd/ufe/wrapUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <mayaUsd/ufe/UsdSceneItem.h>
#include <mayaUsd/ufe/Utils.h>

#include <pxr/base/tf/pyResultConversions.h>
#include <pxr/base/tf/stringUtils.h>
#include <pxr/usd/sdf/path.h>
#include <pxr/usdImaging/usdImaging/delegate.h>
Expand All @@ -30,6 +31,7 @@
#include <ufe/pathString.h>
#endif

#include <boost/python.hpp>
#include <boost/python/def.hpp>

#include <string>
Expand Down Expand Up @@ -90,6 +92,17 @@ PXR_NS::UsdStageWeakPtr getStage(const std::string& ufePathString)
#endif
}

std::vector<PXR_NS::UsdStageRefPtr> getAllStages()
{
auto allStages = ufe::getAllStages();
std::vector<PXR_NS::UsdStageRefPtr> output;
for (auto stage : allStages) {
PXR_NS::UsdStageRefPtr stageRefPtr { stage };
output.push_back(stageRefPtr);
}
return output;
}

std::string stagePath(PXR_NS::UsdStageWeakPtr stage)
{
// Proxy shape node's UFE path is a single segment, so no need to separate
Expand Down Expand Up @@ -236,6 +249,7 @@ void wrapUtils()
// representation of Ufe::Path as comma-separated segments. We know that
// the USD path separator is '/'. PPT, 8-Dec-2019.
def("getStage", getStage);
def("getAllStages", getAllStages, return_value_policy<PXR_NS::TfPySequenceToList>());
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Return value policy from example Pixar USD code, e.g.
https://github.com/PixarAnimationStudios/USD/blob/dc710925675f7f58f7a37f6c18d046a687b09271/pxr/usd/usd/wrapStageCache.cpp#L63
otherwise Boost Python complains at run-time that there is no converter for a vector of stages.

def("stagePath", stagePath);
def("usdPathToUfePathSegment",
usdPathToUfePathSegment,
Expand Down
25 changes: 24 additions & 1 deletion test/lib/ufe/testPythonWrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def setUp(self):

def testWrappers(self):

''' Verify the python wappers.'''
''' Verify the python wrappers.'''

# Create empty stage and add a prim.
import mayaUsd_createStageWithNewLayer
Expand Down Expand Up @@ -118,5 +118,28 @@ def testWrappers(self):
# a worker thread.
cmds.file(new=True, force=True)

def testGetAllStages(self):

# Create two stages.
import mayaUsd_createStageWithNewLayer
proxyShape1 = mayaUsd_createStageWithNewLayer.createStageWithNewLayer()
proxyShape2 = mayaUsd_createStageWithNewLayer.createStageWithNewLayer()

# Test maya-usd getAllStages() wrapper.
self.assertEqual(len(mayaUsd.ufe.getAllStages()), 2)

# Delete one of the stages.
cmds.delete(proxyShape1)

self.assertEqual(len(mayaUsd.ufe.getAllStages()), 1)

cmds.undo()

self.assertEqual(len(mayaUsd.ufe.getAllStages()), 2)

cmds.redo()

self.assertEqual(len(mayaUsd.ufe.getAllStages()), 1)

if __name__ == '__main__':
unittest.main(verbosity=2)