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

Update to newer UFE interface for Create Group #593

Merged
merged 2 commits into from
Jun 30, 2020

Conversation

fowlertADSK
Copy link
Contributor

No description provided.

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.

Looking really good! I'm hopeful that deriving from CompositeUndoableCommand will help out in UsdUndoCreateGroupCommand, but otherwise the functionality and implementation look sound.

@@ -17,6 +17,7 @@

#include <ufe/hierarchy.h>
#include <ufe/path.h>
#include <ufe/selection.h>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not needed, fwd decl sufficient.


UsdUndoCreateGroupCommand::Ptr cmd = UsdUndoCreateGroupCommand::create(fItem, selection, name.string());
if (cmd) {
cmd->redo();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not that it makes much difference in your case, because the base class UndoableCommand::execute() calls redo(), but in case we ever implement UsdUndoCreateGroupCommand::execute() it would be future-proof to call cmd->execute() here.

Comment on lines 40 to 45
void undo() override;
void redo() override;

const Ufe::Path& newUfePath() const;

static UsdUndoAddNewPrimCommand::Ptr create(const UsdSceneItem::Ptr& usdSceneItem,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit-pick: funky indent.


const Ufe::Path& newUfePath() const;

static UsdUndoAddNewPrimCommand::Ptr create(const UsdSceneItem::Ptr& usdSceneItem,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit-pick: just Ptr

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually I'm voting to leave as-is. All the other command classes have the full namespace listed here (so this one would look a bit odd if it was the only one that didn't), and I actually like it because there are multiple "Ptr" typedefs being used (e.g. this class has a Ptr and there's also the scene item Ptr's being used in the same functions).

Copy link
Collaborator

Choose a reason for hiding this comment

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

O.K.

@@ -0,0 +1,100 @@
//
// Copyright 2019 Autodesk
Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess we have to update the copyright year?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, this is the new file and I should have 2020 here (it's there in the .h). We don't update these dates in all files though.

auto stage = prim.GetStage();
auto usdPath = prim.GetPath();
stage->RemovePrim(usdPath);

fGroup.reset();
_group.reset();
#else
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think you should really consider deriving from Ufe::CompositeUndoableCommand, also in undoableCommand.h. It does this for you; in fact, you would not even need to implement undo() or redo().


_group = std::dynamic_pointer_cast<UsdSceneItem>(newParentSceneItem);
}
else {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same comment as for undo(): if you derived from CompositeUndoableCommand, you would not need to implement redo().

Ufe::SceneItem::Ptr group = hierarchy->createGroup(_name);
_group = std::dynamic_pointer_cast<UsdSceneItem>(group);
#else
if (_ufeUndoCommands.empty()) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think you should implement this "first time" behavior by overriding UndoableCommand::execute() rather than redo(); that's what it's for.

_ufeUndoCommands.push_back(addPrimCmd);
addPrimCmd->redo();

auto newParentSceneItem = Ufe::Hierarchy::createItem(addPrimCmd->newUfePath());
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is nice, but since we're all in USD-land here, if we could just get the UsdPrim out of the addPrimCmd (and we know it's there), we could just call UsdSceneItem::create() directly, get a derived class UsdSceneItem out of it, and assign directly into _group, saving the dynamic_pointer_cast at line 122. What do you think? All you need is a prim accessor in UsdUndoAddNewPrimCommand, which sounds reasonable to me.

UsdUndoCreateGroupCommand(const UsdSceneItem::Ptr& parentItem, const Ufe::PathComponent& name);
#else
typedef std::list<std::shared_ptr<Ufe::UndoableCommand>> UfeUndoCommands;
Copy link
Collaborator

Choose a reason for hiding this comment

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

As per other comments, if you derived from CompositeUndoableCommand, you wouldn't need this.

Comment on lines 44 to 48
// First get the stage from the proxy shape.
auto ufePath = usdSceneItem->path();
auto segments = ufePath.getSegments();
auto dagSegment = segments[0];
_stage = MayaUsd::ufe::getStage(Ufe::Path(dagSegment));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since you have a UsdSceneItem, to get the stage you can just use: usdSceneItem->prim().GetStage()


Ufe::SceneItem::Ptr ProxyShapeHierarchy::createGroup(const Ufe::Selection& selection, const Ufe::PathComponent& name) const
{
Ufe::SceneItem::Ptr createdItem = nullptr;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since these are shared_ptr, you don't really need '= nullptr'

Copy link
Contributor Author

Choose a reason for hiding this comment

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

true

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.

Excellent, great changes, clean code.

@kxl-adsk kxl-adsk merged commit bb145da into dev Jun 30, 2020
@kxl-adsk kxl-adsk deleted the update_create_group_interface branch June 30, 2020 17:28
@kxl-adsk kxl-adsk added the ufe-usd Related to UFE-USD plugin in Maya-Usd label Jul 19, 2020
@kxl-adsk kxl-adsk mentioned this pull request Jul 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ufe-usd Related to UFE-USD plugin in Maya-Usd
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants