-
Notifications
You must be signed in to change notification settings - Fork 202
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
MAYA-103547 Use the common utility function to check error conditions #905
Conversation
… for the duplicate command
@@ -59,6 +60,8 @@ void UsdUndoDuplicateCommand::primInfo( | |||
SdfPath& usdDstPath, | |||
SdfLayerHandle& srcLayer) | |||
{ | |||
ufe::applyCommandRestriction(srcPrim, "duplicate"); |
There was a problem hiding this comment.
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()
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-
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.
-
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.
-
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.
-
I removed one include that didn't look like it was needed. I only see stage.h in the .cpp though, which is needed.
-
Yes, I can switch to the new naming convention for variables while I'm here.
auto dstName = uniqueName(childrenNames, srcPrim.GetName()); | ||
usdDstPath = parent.GetPath().AppendChild(TfToken(dstName)); |
There was a problem hiding this comment.
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:
maya-usd/lib/mayaUsd/ufe/Utils.cpp
Line 123 in 91994c0
std::string uniqueChildName(const UsdPrim& usdParent, const std::string& name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this 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.
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()); | ||
} | ||
} |
There was a problem hiding this comment.
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.
maya-usd/lib/mayaUsd/ufe/UsdHierarchy.cpp
Line 149 in 91994c0
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.
// MAYA-92264: Pixar bug prevents redo from working. Try again with USD | ||
// version 0.8.5 or later. PPT, 28-May-2018. |
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this 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> |
There was a problem hiding this comment.
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.
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.