PropertyPanel Update

This commit is contained in:
2026-06-13 08:45:16 +08:00
parent 2a8534eda7
commit 43c70be574
4 changed files with 93 additions and 17 deletions
+87 -16
View File
@@ -1,5 +1,7 @@
#include "PropertyManager.h"
#include "LayerManager.h"
#include "CommandHistory.h"
#include "commands/AttributeSetCommand.h"
#include "../utils/Logger.h"
#include <pxr/usd/usd/prim.h>
#include <pxr/usd/usd/primRange.h>
@@ -123,17 +125,51 @@ bool PropertyManager::SetPropertyValue(const std::string& primPath,
return false;
}
// If a current layer is set, create an edit context to target it
try {
if (m_currentLayer) {
UsdEditContext editCtx(m_stage, m_currentLayer);
return ApplyValue(attr, value);
} else {
return ApplyValue(attr, value);
// Capture old value for undo
PropertyValue oldValue = ExtractValue(attr);
SdfLayerHandle targetLayer = m_currentLayer ? m_currentLayer : m_stage->GetEditTarget().GetLayer();
// Create command with closures that capture old/new values and layer context
if (m_commandHistory) {
auto executeFunc = [this, primPath, propName, value, targetLayer]() {
UsdPrim p = GetPrim(primPath);
if (!p.IsValid()) return;
UsdAttribute a = p.GetAttribute(TfToken(propName));
if (!a.IsValid()) return;
UsdEditContext editCtx(m_stage, targetLayer);
ApplyValue(a, value);
};
auto undoFunc = [this, primPath, propName, oldValue, targetLayer]() {
UsdPrim p = GetPrim(primPath);
if (!p.IsValid()) return;
UsdAttribute a = p.GetAttribute(TfToken(propName));
if (!a.IsValid()) return;
UsdEditContext editCtx(m_stage, targetLayer);
ApplyValue(a, oldValue);
};
std::string description = "Set " + propName + " on " + primPath;
m_commandHistory->Push(std::make_unique<AttributeSetCommand>(
description, executeFunc, undoFunc
));
return true;
} else {
// Fallback: apply directly without undo support
try {
if (m_currentLayer) {
UsdEditContext editCtx(m_stage, m_currentLayer);
return ApplyValue(attr, value);
} else {
return ApplyValue(attr, value);
}
} catch (const std::exception& e) {
LOG_ERROR(std::string("Failed to set property: ") + e.what());
return false;
}
} catch (const std::exception& e) {
LOG_ERROR(std::string("Failed to set property: ") + e.what());
return false;
}
}
@@ -147,12 +183,47 @@ bool PropertyManager::SetPropertyValueInLayer(const std::string& primPath,
UsdAttribute attr = prim.GetAttribute(TfToken(propName));
if (!attr.IsValid()) return false;
try {
UsdEditContext editCtx(m_stage, layer);
return ApplyValue(attr, value);
} catch (const std::exception& e) {
LOG_ERROR(std::string("Failed to set property: ") + e.what());
return false;
// Capture old value for undo
PropertyValue oldValue = ExtractValue(attr);
// Create command with closures that capture old/new values and layer context
if (m_commandHistory) {
auto executeFunc = [this, primPath, propName, value, layer]() {
UsdPrim p = GetPrim(primPath);
if (!p.IsValid()) return;
UsdAttribute a = p.GetAttribute(TfToken(propName));
if (!a.IsValid()) return;
UsdEditContext editCtx(m_stage, layer);
ApplyValue(a, value);
};
auto undoFunc = [this, primPath, propName, oldValue, layer]() {
UsdPrim p = GetPrim(primPath);
if (!p.IsValid()) return;
UsdAttribute a = p.GetAttribute(TfToken(propName));
if (!a.IsValid()) return;
UsdEditContext editCtx(m_stage, layer);
ApplyValue(a, oldValue);
};
std::string layerName = layer ? LayerManager::ExtractDisplayName(layer->GetIdentifier()) : "default";
std::string description = "Set " + propName + " on " + primPath + " in " + layerName;
m_commandHistory->Push(std::make_unique<AttributeSetCommand>(
description, executeFunc, undoFunc
));
return true;
} else {
// Fallback: apply directly without undo support
try {
UsdEditContext editCtx(m_stage, layer);
return ApplyValue(attr, value);
} catch (const std::exception& e) {
LOG_ERROR(std::string("Failed to set property: ") + e.what());
return false;
}
}
}
+4
View File
@@ -13,6 +13,8 @@ PXR_NAMESPACE_USING_DIRECTIVE
namespace UsdLayerManager {
class CommandHistory;
using PropertyValue = std::variant<
bool, int, float, double, std::string,
pxr::GfVec3f, pxr::GfVec3d
@@ -35,6 +37,7 @@ public:
void SetStage(UsdStageRefPtr stage);
void SetCurrentLayer(const SdfLayerHandle& layer);
void SetCommandHistory(CommandHistory* history) { m_commandHistory = history; }
SdfLayerHandle GetCurrentLayer() const { return m_currentLayer; }
// Prim properties
@@ -61,6 +64,7 @@ private:
UsdStageRefPtr m_stage;
SdfLayerHandle m_currentLayer;
CommandHistory* m_commandHistory = nullptr;
};
} // namespace UsdLayerManager