Skip to content

Commit

Permalink
First attempt to handle following scenario:
Browse files Browse the repository at this point in the history
Error if object to rename has ANY definitions or overs on ANY stronger or weaker layers. This is the most restrictive we can be. We will revisit how much we loosen this up later.

Cannot rename a prim with definitions or opinions on other layers. Opinions exist in [layer name 1], [layer name 2], [layer name 3], [layer name 4],etc...”
  • Loading branch information
Hamed Sabri committed May 1, 2020
1 parent 54166d2 commit 8f8295f
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 6 deletions.
21 changes: 18 additions & 3 deletions lib/mayaUsd/ufe/UsdUndoRenameCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ UsdUndoRenameCommand::UsdUndoRenameCommand(const UsdSceneItem::Ptr& srcItem, con
_stage = prim.GetStage();
_ufeSrcItem = srcItem;
_usdSrcPath = prim.GetPath();

// Every call to rename() (through execute(), undo() or redo()) removes
// a prim, which becomes expired. Since USD UFE scene items contain a
// prim, we must recreate them after every call to rename.
Expand All @@ -58,15 +58,30 @@ UsdUndoRenameCommand::UsdUndoRenameCommand(const UsdSceneItem::Ptr& srcItem, con
throw std::runtime_error(err.c_str());
}

// check if a layer has any opinions that affects selected prim
// if the current layer doesn't have any opinions that affects selected prim
if (!MayaUsdUtils::doesLayerHavePrimSpec(prim)) {
auto possibleTargetLayer = MayaUsdUtils::strongestLayerWithPrimSpec(prim);
std::string err = TfStringPrintf("Unable to rename [%s] on current target layer, "
std::string err = TfStringPrintf("Cannot rename [%s] defined on another layer. "
"Please set [%s] as the target layer to proceed",
prim.GetName().GetString(),
possibleTargetLayer->GetDisplayName());
throw std::runtime_error(err.c_str());
}
else
{
auto layers = MayaUsdUtils::layersWithOpinion(prim);

if (layers.size() > 1) {
std::string layerNames;
for (auto layer : layers) {
layerNames.append("[" + layer->GetDisplayName() + "]" + ",");
}
layerNames.pop_back();
std::string err = TfStringPrintf("Cannot rename [%s] with definitions or opinions on other layers. "
"Opinions exist in %s", prim.GetName().GetString(), layerNames);
throw std::runtime_error(err.c_str());
}
}
}

UsdUndoRenameCommand::~UsdUndoRenameCommand()
Expand Down
23 changes: 20 additions & 3 deletions lib/usd/utils/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#include <pxr/usd/usd/prim.h>
#include <pxr/usd/usd/stage.h>

#include <vector>

PXR_NAMESPACE_USING_DIRECTIVE

namespace MayaUsdUtils {
Expand All @@ -44,8 +46,23 @@ defPrimSpecLayer(const UsdPrim& prim)
return defLayer;
}

std::vector<SdfLayerHandle>
layersWithOpinion(const UsdPrim& prim)
{
// get the list of PrimSpecs that provide opinions for this prim
// ordered from strongest to weakest opinion.
const auto& primStack = prim.GetPrimStack();

std::vector<SdfLayerHandle> layersWithOpion;
for (auto primSpec : primStack) {
layersWithOpion.emplace_back(primSpec->GetLayer());
}

return layersWithOpion;
}

bool
MayaUsdUtils::doesLayerHavePrimSpec(const UsdPrim& prim)
doesLayerHavePrimSpec(const UsdPrim& prim)
{
auto editTarget = prim.GetStage()->GetEditTarget();
auto layer = editTarget.GetLayer();
Expand All @@ -61,7 +78,7 @@ MayaUsdUtils::doesLayerHavePrimSpec(const UsdPrim& prim)
}

SdfLayerHandle
MayaUsdUtils::strongestLayerWithPrimSpec(const UsdPrim& prim)
strongestLayerWithPrimSpec(const UsdPrim& prim)
{
SdfLayerHandle targetLayer;
auto layerStack = prim.GetStage()->GetLayerStack();
Expand All @@ -78,4 +95,4 @@ MayaUsdUtils::strongestLayerWithPrimSpec(const UsdPrim& prim)
return targetLayer;
}

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

//! Return a list of layers in strength order that have opinions on a prim
MAYA_USD_UTILS_PUBLIC
std::vector<SdfLayerHandle> layersWithOpinion(const UsdPrim&);

//! Check if a layer has any opinions that affects a particular prim
MAYA_USD_UTILS_PUBLIC
bool doesLayerHavePrimSpec(const UsdPrim&);
Expand Down

0 comments on commit 8f8295f

Please sign in to comment.