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-129061 - Refactor material commands. #3056

Merged
merged 5 commits into from
May 15, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 1 addition & 3 deletions lib/mayaUsd/ufe/UsdShaderNodeDef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -361,9 +361,7 @@ Ufe::InsertChildCommand::Ptr UsdShaderNodeDef::createNodeCmd(
TF_AXIOM(fShaderNodeDef);
UsdSceneItem::Ptr parentItem = std::dynamic_pointer_cast<UsdSceneItem>(parent);
if (parentItem) {
if (parentItem->nodeType() == "Scope"
&& parentItem->nodeName()
== UsdUndoAssignNewMaterialCommand::resolvedMaterialScopeName()) {
if (UsdUndoAddNewMaterialCommand::CompatiblePrim(parentItem)) {
return UsdUndoAddNewMaterialCommand::create(
parentItem, fShaderNodeDef->GetIdentifier());
}
Expand Down
10 changes: 10 additions & 0 deletions lib/mayaUsd/ufe/UsdUndoAddNewPrimCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <mayaUsd/ufe/Utils.h>
#include <mayaUsd/undo/UsdUndoBlock.h>

#include <ufe/hierarchy.h>
#include <ufe/pathString.h>

namespace {
Expand All @@ -47,7 +48,11 @@ UsdUndoAddNewPrimCommand::UsdUndoAddNewPrimCommand(
const UsdSceneItem::Ptr& usdSceneItem,
const std::string& name,
const std::string& type)
#ifdef UFE_V4_FEATURES_AVAILABLE
: Ufe::SceneItemResultUndoableCommand()
#else
: Ufe::UndoableCommand()
#endif
{
// First get the stage from the proxy shape.
auto ufePath = usdSceneItem->path();
Expand Down Expand Up @@ -115,6 +120,11 @@ std::string UsdUndoAddNewPrimCommand::commandString() const
return std::string("CreatePrim ") + _primToken.GetText() + " "
+ Ufe::PathString::string(_newUfePath);
}

Ufe::SceneItem::Ptr UsdUndoAddNewPrimCommand::sceneItem() const
{
return Ufe::Hierarchy::createItem(newUfePath());
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This method is currently not used or tested. However, I'm not sure if it can easily be tested right now, since UsdUndoAddNewPrimCommand is tested though Ufe::ContextOps::doOpCmd() (see here), which returns a UndoableCommand::Ptr, not a Ufe::SceneItemResultUndoableCommand().

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I made the material commands call UsdUndoAddNewPrimCommand::sceneItem() instead of manually calling Ufe::Hierarchy::createItem() on UsdUndoAddNewPrimCommand::newUfePath(). This makes the code a little more tidy and ensures that UsdUndoAddNewPrimCommand::sceneItem() is covered by existing tests. See 088f54ab81ccfb4ddc941d5c120888d34dee9fea.

}
#endif

const Ufe::Path& UsdUndoAddNewPrimCommand::newUfePath() const { return _newUfePath; }
Expand Down
5 changes: 5 additions & 0 deletions lib/mayaUsd/ufe/UsdUndoAddNewPrimCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ namespace ufe {
// This command is not restricted: it is always possible to create a new
// prim even in weaker layer since the new prim, by the fact that it is new
// cannot have an already-existing opinon that would shadow it.
#ifdef UFE_V4_FEATURES_AVAILABLE
class MAYAUSD_CORE_PUBLIC UsdUndoAddNewPrimCommand : public Ufe::SceneItemResultUndoableCommand
#else
class MAYAUSD_CORE_PUBLIC UsdUndoAddNewPrimCommand : public Ufe::UndoableCommand
#endif
{
public:
typedef std::shared_ptr<UsdUndoAddNewPrimCommand> Ptr;
Expand All @@ -50,6 +54,7 @@ class MAYAUSD_CORE_PUBLIC UsdUndoAddNewPrimCommand : public Ufe::UndoableCommand
PXR_NS::UsdPrim newPrim() const;

UFE_V4(std::string commandString() const override;)
UFE_V4(Ufe::SceneItem::Ptr sceneItem() const override;)

static UsdUndoAddNewPrimCommand::Ptr
create(const UsdSceneItem::Ptr& usdSceneItem, const std::string& name, const std::string& type);
Expand Down
Loading