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

MAYA-103547 Use the common utility function to check error conditions #905

Merged
merged 5 commits into from
Nov 12, 2020

Conversation

fowlertADSK
Copy link
Contributor

There is a utility function in Utils that can be shared between some of the commands (e.g. duplicate and rename). Using it to get the correct logic and proper error message.

There is still a question about what the exact logic/message should be for the commands, but if we want to change it then that will happen in a separate PR.

@@ -59,6 +60,8 @@ void UsdUndoDuplicateCommand::primInfo(
SdfPath& usdDstPath,
SdfLayerHandle& srcLayer)
{
ufe::applyCommandRestriction(srcPrim, "duplicate");
Copy link
Contributor

Choose a reason for hiding this comment

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

1- both static flavors of primInfo() can go away. All the logics in primInfo can be moved directly to the constructor.

static void primInfo();

static void primInfo(const UsdPrim& srcPrim, SdfPath& usdDstPath, SdfLayerHandle& srcLayer);

2- fStage can go away. We don't need to save it . It can be obtained from fUfeSrcPath.

3- I believe there is a bug around the layer. You should get layer from the srcPrim and store in

fLayer = GetStage()->GetEditTarget().GetLayer()

Copy link
Contributor

Choose a reason for hiding this comment

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

Nit-pick: these includes can go away.

#include <mayaUsd/ufe/UsdSceneItem.h>
#include <pxr/usd/usd/stage.h>

all the fxxx member variables should follow the coding standard.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. primInfo() doesn't even have an implementation as far as I can tell, so I'll just get rid of it. The other primInfo static is used by Scene Item Ops so can't be moved to the constructor.

  2. Yes, we can get the stage when needed. I think I'd have to use _srcPrim.GetStage() though, fUfeSrcPath doesn't know anything about Usd.

  3. Hmm. fLayer is currently set by passing it to primInfo where it's set to the whatever layer the def primspec is on. What you're suggesting is to change this to always grab the current edit target layer? With the new restriction we want to enforce, I think those two should always be the same, but there is a comment in the next function down that says we chose to not just grab the edit target layer.

  4. I removed one include that didn't look like it was needed. I only see stage.h in the .cpp though, which is needed.

  5. Yes, I can switch to the new naming convention for variables while I'm here.

Comment on lines 73 to 74
auto dstName = uniqueName(childrenNames, srcPrim.GetName());
usdDstPath = parent.GetPath().AppendChild(TfToken(dstName));
Copy link
Contributor

Choose a reason for hiding this comment

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

line 66-73 can be factored out. See uniqueChildName utility function:

std::string uniqueChildName(const UsdPrim& usdParent, const std::string& name)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Copy link
Contributor

@HamedSabri-adsk HamedSabri-adsk left a comment

Choose a reason for hiding this comment

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

It would be nice to clean up this class and also back this new change with a test case.

Also putting back in the original error message, which will now only run when the def can't be found.  Most of the error conditions will still now be caught by using the new common function though and provide proper error messages.
@fowlertADSK
Copy link
Contributor Author

It would be nice to clean up this class and also back this new change with a test case.
The existing test cases in testDuplicateCmd.py should cover the cases we're checking right now. The only real difference at the moment is that the error message itself should give more details.

The requested changes in MAYA-107582 would be where we will probably want to add some new coverage. At least that's what I think, unless you have a specific case that isn't covered right now?

std::string err
= TfStringPrintf("No prim found at %s", srcPrim.GetPath().GetString().c_str());
throw std::runtime_error(err.c_str());
}
}
Copy link
Contributor

@HamedSabri-adsk HamedSabri-adsk Nov 9, 2020

Choose a reason for hiding this comment

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

Hey @fowlertADSK There is no need to call MayaUsdUtils::defPrimSpecLayer . This routine can be removed all together later. It is currently called in some Ufe1.0 but I believe this can be cleaned up as well.

SdfLayerHandle layer = MayaUsdUtils::defPrimSpecLayer(childPrim);

What you're suggesting is to change this to always grab the current edit target layer? With the new restriction we want to enforce, I think those two should always be the same, but there is a comment in the next function down that says we chose to not just grab the edit target layer.

By calling applyCommandRestriction(), you are guaranteed to be in the correct layer. That's the whole idea, this restrict function puts you in a correct layer to perform your change. This layer can be retrieved from the edit target:

_layer = srcPrim.GetStage()->GetEditTarget().GetLayer();

The other primInfo static is used by Scene Item Ops so can't be moved to the constructor.

The name primInfo is confusing and can be simplified. This is how I would imagine the constructor to be

{
    ufe::applyCommandRestriction(srcPrim, "duplicate");

    _layer = _srcPrim.GetStage()->GetEditTarget().GetLayer();

    auto parentPrim = srcPrim.GetParent();
    auto dstName = uniqueChildName(parentPrim, srcPrim.GetName());
    _usdDstPath = parentPrim.GetPath().AppendChild(TfToken(dstName));
}

Similar to UsdUndoRenameCommand, UsdUndoDuplicateCommand can return the duplicate Scene item which can be returned by UsdSceneItemOps::duplicateItem()

UsdSceneItem::Ptr duplicatedItem() const;  { return _ufeDuplicateItem; }

Ufe::SceneItem::Ptr UsdSceneItemOps::duplicateItem()
{
    auto duplicateCmd = UsdUndoDuplicateCommand::create(prim(), fItem->path());
    duplicateCmd->execute();
    return duplicateCmd->duplicatedItem();
}

Ufe::Duplicate UsdSceneItemOps::duplicateItemCmd()
{
    auto duplicateCmd = UsdUndoDuplicateCommand::create(prim(), fItem->path());
    duplicateCmd->execute();
    return Ufe::Duplicate(duplicateCmd->duplicatedItem(), duplicateCmd);
}

I hope it makes sense.

@HamedSabri-adsk HamedSabri-adsk added ufe-usd Related to UFE-USD plugin in Maya-Usd workflows Related to in-context workflows labels Nov 9, 2020
Comment on lines 114 to 115
// MAYA-92264: Pixar bug prevents redo from working. Try again with USD
// version 0.8.5 or later. PPT, 28-May-2018.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Well clearly redo() is working, so the comment is obsolete!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@HamedSabri-adsk This is not the comment I was talking about, I meant the comment on lines 82-84:
// We use the source layer as the destination. An alternate workflow
// would be the edit target layer be the destination:
// layer = self._stage.GetEditTarget().GetLayer()
The static duplicate function assumes that they should be on the same layer, but the constructor of the command assumes that it's the edit target.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

And for the redo comment... I originally missed this comment, but I did see a similar comment in the test. I removed that comment and reenabled the test for redo.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, that comment can also be clean up.

I believe both srcLayer and dstLayer that are being passed to SdfCopySpec should be the same. This is the _layer that is populated in the constructor.

My thinking is that the duplicate always happen in one single layer. Kind of similar to how rename works.

- Changed the input to be a single UsdSceneItem instead of Prim + Path.
- Changed it to keep around a Ufe::Path and a SdfPath for src/dst objects instead of the various objects it had before (prim/stage/layer/two paths).
- Create the new UsdSceneItem on-demand instead of keeping it around through undo/redo.
Copy link
Contributor

@HamedSabri-adsk HamedSabri-adsk left a comment

Choose a reason for hiding this comment

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

LGTM! Thank you for the extra clean up. It certainly makes it easier to follow the logics.

#include <ufe/scene.h>
#include <ufe/sceneNotification.h>

#include <iostream>
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit-pick: this include can be removed.

@fowlertADSK fowlertADSK added the ready-for-merge Development process is finished, PR is ready for merge label Nov 12, 2020
@kxl-adsk kxl-adsk merged commit 7bc35c3 into dev Nov 12, 2020
@kxl-adsk kxl-adsk deleted the fowlert/MAYA-103547/provide_better_error_messages branch November 12, 2020 16:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready-for-merge Development process is finished, PR is ready for merge ufe-usd Related to UFE-USD plugin in Maya-Usd workflows Related to in-context workflows
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants