Skip to content

Commit

Permalink
SetSceneItemMetadata command enforces edit restrictions
Browse files Browse the repository at this point in the history
  • Loading branch information
jufrantz committed Sep 24, 2024
1 parent b317f57 commit ca1ebb7
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions lib/usdUfe/ufe/UsdUndoSetSceneItemMetadataCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,24 @@

namespace USDUFE_NS_DEF {

namespace {

void setSceneItemCustomDataByKey(
const PXR_NS::UsdPrim& prim,
const PXR_NS::TfToken& key,
const Ufe::Value& value)
{
std::string errMsg;
if (!UsdUfe::isPrimMetadataEditAllowed(prim, PXR_NS::SdfFieldKeys->CustomData, key, &errMsg)) {
// Note: we don't throw an exception because this would break bulk actions.
TF_RUNTIME_ERROR(errMsg);
} else {
prim.SetCustomDataByKey(key, ufeValueToVtValue(value));
}
}

} // namespace

USDUFE_VERIFY_CLASS_SETUP(
UsdUfe::UsdUndoableCommand<Ufe::UndoableCommand>,
SetSceneItemMetadataCommand);
Expand Down Expand Up @@ -69,7 +87,7 @@ void SetSceneItemMetadataCommand::setKeyMetadata()

// If this is not a grouped metadata, set the _value directly on the _key
PrimMetadataEditRouterContext ctx(prim, PXR_NS::SdfFieldKeys->CustomData, key);
prim.SetCustomDataByKey(key, ufeValueToVtValue(_value));
setSceneItemCustomDataByKey(prim, key, _value);
}

void SetSceneItemMetadataCommand::setGroupMetadata()
Expand All @@ -88,11 +106,11 @@ void SetSceneItemMetadataCommand::setGroupMetadata()
fullKey,
/*fallbackLayer=*/_stage->GetSessionLayer());

prim.SetCustomDataByKey(fullKey, ufeValueToVtValue(_value));
setSceneItemCustomDataByKey(prim, fullKey, _value);
} else {
PXR_NS::TfToken fullKey(_group + std::string(":") + _key);
PrimMetadataEditRouterContext ctx(prim, PXR_NS::SdfFieldKeys->CustomData, fullKey);
prim.SetCustomDataByKey(fullKey, ufeValueToVtValue(_value));
setSceneItemCustomDataByKey(prim, fullKey, _value);
}
}

Expand Down

0 comments on commit ca1ebb7

Please sign in to comment.