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-105175: Rewrote the rename restriction algorithm from scratch to cover more edge cases. #786

Merged
merged 11 commits into from
Sep 24, 2020
23 changes: 7 additions & 16 deletions lib/mayaUsd/ufe/private/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,12 @@ void applyCommandRestriction(const UsdPrim& prim, const std::string& commandName
std::string layerDisplayName;

// check to see if there is a spec at the edit target layer.
if (primSpec)
for (const auto& spec : primStack)
{
for (const auto& spec : primStack)
if (primSpec != spec) {
layerDisplayName.append("[" + spec->GetLayer()->GetDisplayName() + "]" + ",");
}
else
{
// skip if the spec already exist
if (primSpec == spec && spec->GetSpecifier() == SdfSpecifierDef && primSpec->GetLayer() == spec->GetLayer()) {
Expand All @@ -159,22 +162,10 @@ void applyCommandRestriction(const UsdPrim& prim, const std::string& commandName
break;
}
}

if(!layerDisplayName.empty())
{
layerDisplayName.pop_back();
std::string err = TfStringPrintf("Cannot %s [%s]. It is defined on another layer. Please set %s as the target layer to proceed.",
commandName.c_str(),
prim.GetName().GetString().c_str(),
layerDisplayName.c_str());
throw std::runtime_error(err.c_str());
}
}
else

if(!layerDisplayName.empty())
Copy link
Contributor Author

@HamedSabri-adsk HamedSabri-adsk Sep 21, 2020

Choose a reason for hiding this comment

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

Simplified the logic by removing the redundant primSpec check and loop in primStack.

{
for (const auto& spec : primStack) {
layerDisplayName.append("[" + spec->GetLayer()->GetDisplayName() + "]" + ",");
}
layerDisplayName.pop_back();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why the pop_back()?

Copy link
Contributor Author

@HamedSabri-adsk HamedSabri-adsk Sep 22, 2020

Choose a reason for hiding this comment

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

the pop_back is just for make up purposes in the error message. It just removes the last "," in the case where there are multiple layers:

[bob],[foo],

I pop back the last "," so it looks

[bob],[foo]

Copy link
Collaborator

Choose a reason for hiding this comment

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

Right, you've explained this to me once before... A shortened version of your explanation would make a great code comment.

std::string err = TfStringPrintf("Cannot %s [%s]. It is defined on another layer. Please set %s as the target layer to proceed.",
commandName.c_str(),
Expand Down