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

Making visibility Undo/Redo correct. #1056

Merged
merged 9 commits into from
Jan 13, 2021

Conversation

HamedSabri-adsk
Copy link
Contributor

This PR makes the "visibility" in USD data model Undo/Redo correct.

@HamedSabri-adsk HamedSabri-adsk added core Related to core library workflows Related to in-context workflows labels Jan 11, 2021
auto object3d = UsdObject3d::create(fItem);
auto current = object3d->visibility();
auto cmd = object3d->setVisibleCmd(!current);
cmd->execute();
Copy link
Contributor Author

@HamedSabri-adsk HamedSabri-adsk Jan 11, 2021

Choose a reason for hiding this comment

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

Make sure setting the visibility goes through the new "setVisibleCmd"

Copy link
Collaborator

Choose a reason for hiding this comment

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

Don't need to call execute(), that's done for you by Maya. Just

return object3d->setVisibleCmd(!current);

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also you need to guard this with the UFE_PREVIEW_VERSION_NUM awful pre-processor macro, and keep the old code around... :(

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed in 7004631

#if UFE_PREVIEW_VERSION_NUM >= 2034
Ufe::UndoableCommand::Ptr setVisibleCmd(bool vis) override;
#endif

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added guard around "setVisibleCmd" since this feature is available in UFE V.2034 or later.

void UsdUndoVisibleCommand::redo() { _undoableItem.redo(); }

void UsdUndoVisibleCommand::undo() { _undoableItem.undo(); }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

On execute(), we create an undoBlock to capture the edit and then visibility is set via UsdGeomImageable MakeVisible()/MakeInvisible() methods.

@HamedSabri-adsk
Copy link
Contributor Author

As a FYI, working on the unit-test part for this PR. Should be coming up today.

Comment on lines 572 to 575
auto object3d = UsdObject3d::create(fItem);
auto current = object3d->visibility();
auto cmd = object3d->setVisibleCmd(!current);
cmd->execute();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Doesn't this new code need to be protected by UFE_PREVIEW_VERSION_NUM >= 2034 and leave the old code for the else?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ugh.... Good catch! Indeed. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed in 7004631

Copy link
Collaborator

@ppt-adsk ppt-adsk left a comment

Choose a reason for hiding this comment

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

A couple of things to fix, but really what I feel is missing from this PR are the automated tests. You can write an automated test that first tests the UsdUndoVisibleCommand, and calls undo and redo on that object, for the lowest-level test.

Then, I'd like to see tests with the Maya hide and showHidden commands, with calls to Maya undo and redo, to demonstrate the full integration of the UFE command into Maya.

Thanks for doing this!

current == UsdGeomTokens->invisible ? UsdGeomTokens->inherited
: UsdGeomTokens->invisible);
auto object3d = UsdObject3d::create(fItem);
auto current = object3d->visibility();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Shouldn't we check that the scene item supports the Object3d interface? At this point it should, because we put up the menu entry for it, so perhaps we can just assert.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

A couple of things to fix, but really what I feel is missing from this PR are the automated tests. You can write an automated test that first tests the UsdUndoVisibleCommand, and calls undo and redo on that object, for the lowest-level test.

Great point. I am working on it as we speak.

Addressed in 7004631

Copy link
Contributor Author

@HamedSabri-adsk HamedSabri-adsk Jan 11, 2021

Choose a reason for hiding this comment

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

@ppt-adsk @seando-adsk

Added a test for backing the new UsdUndoVisibleCommand :

865d479

Added a new test for backing up the UFE command integration on Maya side for both "hide" and "showHidden" commands :

43bf1b1

auto object3d = UsdObject3d::create(fItem);
auto current = object3d->visibility();
auto cmd = object3d->setVisibleCmd(!current);
cmd->execute();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Don't need to call execute(), that's done for you by Maya. Just

return object3d->setVisibleCmd(!current);

auto object3d = UsdObject3d::create(fItem);
auto current = object3d->visibility();
auto cmd = object3d->setVisibleCmd(!current);
cmd->execute();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Also you need to guard this with the UFE_PREVIEW_VERSION_NUM awful pre-processor macro, and keep the old code around... :(


#include <pxr/usd/usdGeom/tokens.h>

#include <ufe/log.h>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Unused.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed in 7004631

#include <mayaUsd/undo/UsdUndoBlock.h>
#include <mayaUsdUtils/util.h>

#include <pxr/usd/usdGeom/tokens.h>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Unused.

#include "private/Utils.h"

#include <mayaUsd/undo/UsdUndoBlock.h>
#include <mayaUsdUtils/util.h>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we need this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nope they can go away. Addressed in 7004631

//
#include "UsdUndoVisibleCommand.h"

#include "private/Utils.h"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we need this?

auto object3d = UsdObject3d::create(fItem);
assert(object3d);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Elsewhere we've been using TF_AXIOM, might want to consider that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed in 8bac473


#include <pxr/usd/usdGeom/tokens.h>

#include <ufe/log.h>
#include <pxr/usd/usdGeom/xformCommonAPI.h>
Copy link
Collaborator

Choose a reason for hiding this comment

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

You sure we need this? The common API doesn't feel like it has much to do with visibility...

Copy link
Contributor Author

@HamedSabri-adsk HamedSabri-adsk Jan 11, 2021

Choose a reason for hiding this comment

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

@ppt-adsk yes it is needed for UsdGeomImageable. It usually brings other stuff which we may need.

But in this case, I don't think we need them. I will replace it with the below header if it is confusing.

#include <pxr/usd/usdGeom/imageable.h>

Addressed in :
88a3a5f
1a2008a

# This time, expect the visibility token to exists in the USD data model
self.assertTrue(bool(primSpecCapsule and UsdGeom.Tokens.visibility in primSpecCapsule.attributes))
self.assertTrue(bool(primSpecCylinder and UsdGeom.Tokens.visibility in primSpecCylinder.attributes))

Copy link
Collaborator

Choose a reason for hiding this comment

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

Would have been nice to undo / redo showHidden --- should be quick to add and we'd put this one to rest.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. Addressed in 585cca0

@HamedSabri-adsk HamedSabri-adsk added the ready-for-merge Development process is finished, PR is ready for merge label Jan 13, 2021
@kxl-adsk kxl-adsk merged commit 6180c3f into dev Jan 13, 2021
@kxl-adsk kxl-adsk deleted the sabrih/MAYA-108423/undo_correct_visibility branch January 13, 2021 18:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Related to core library ready-for-merge Development process is finished, PR is ready for merge workflows Related to in-context workflows
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants