From ca1ebb730cdb0d5b4ad6baf2aa019825165e0103 Mon Sep 17 00:00:00 2001 From: Julien Frantz Date: Tue, 24 Sep 2024 11:13:06 +0200 Subject: [PATCH] SetSceneItemMetadata command enforces edit restrictions --- .../UsdUndoSetSceneItemMetadataCommand.cpp | 24 ++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/lib/usdUfe/ufe/UsdUndoSetSceneItemMetadataCommand.cpp b/lib/usdUfe/ufe/UsdUndoSetSceneItemMetadataCommand.cpp index 625e3adabb..80788473de 100644 --- a/lib/usdUfe/ufe/UsdUndoSetSceneItemMetadataCommand.cpp +++ b/lib/usdUfe/ufe/UsdUndoSetSceneItemMetadataCommand.cpp @@ -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, SetSceneItemMetadataCommand); @@ -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() @@ -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); } }