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

Improve rename logics #483

19 changes: 9 additions & 10 deletions lib/mayaUsd/ufe/UsdUndoRenameCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,17 @@ UsdUndoRenameCommand::UsdUndoRenameCommand(const UsdSceneItem::Ptr& srcItem, con
else
{
// account for internal vs external references
// internal references (references without a file path specified) from the same file
// should be renamable.
if (prim.HasAuthoredReferences()) {
auto primSpec = MayaUsdUtils::getPrimSpecAtEditTarget(_stage, prim);
for (const SdfReference& ref : primSpec->GetReferenceList().GetAddedOrExplicitItems()) {
// GetAssetPath returns the asset path to the root layer of the referenced layer
// this will be empty in the case of an internal reference.
if (ref.GetAssetPath().empty()) {
return;
}else{
std::string err = TfStringPrintf("Unable to rename referenced object [%s]",
prim.GetName().GetString().c_str());
throw std::runtime_error(err.c_str());
}

if(MayaUsdUtils::isInternalReference(primSpec)) {
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: could just be
if (!MayaUsdUtils::isInternalReference(primSpec)) {
throw blablabla;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

return;
}else {
std::string err = TfStringPrintf("Unable to rename referenced object [%s]",
prim.GetName().GetString().c_str());
throw std::runtime_error(err.c_str());
}
}

ppt-adsk marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
16 changes: 16 additions & 0 deletions lib/usd/utils/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,20 @@ getPrimSpecAtEditTarget(UsdStageWeakPtr stage, const UsdPrim& prim)
return stage->GetEditTarget().GetPrimSpecForScenePath(prim.GetPath());
}

bool
isInternalReference(const SdfPrimSpecHandle& primSpec)
{
bool isInternalRef{false};

for (const SdfReference& ref : primSpec->GetReferenceList().GetAddedOrExplicitItems()) {
// GetAssetPath returns the asset path to the root layer of the referenced layer
// this will be empty in the case of an internal reference.
if (ref.GetAssetPath().empty()) {
isInternalRef = true;
ppt-adsk marked this conversation as resolved.
Show resolved Hide resolved
}
}

return isInternalRef;
}

} // MayaUsdUtils
4 changes: 4 additions & 0 deletions lib/usd/utils/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ namespace MayaUsdUtils {
MAYA_USD_UTILS_PUBLIC
SdfPrimSpecHandle getPrimSpecAtEditTarget(UsdStageWeakPtr, const UsdPrim&);

//! Returns true if the prim spec has an internal reference.
MAYA_USD_UTILS_PUBLIC
bool isInternalReference(const SdfPrimSpecHandle&);

} // namespace MayaUsdUtils
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 a utility function for getting a PrimSpec from a prim path in the layer containing the stage's current edit target.


#endif // MAYAUSDUTILS_UTIL_H