Skip to content

Commit 7bf26f2

Browse files
authored
Merge pull request #4321 from Autodesk/kheloua/dev/EMSUSD-2789_port_expr_var_support_LE
EMSUSD-2789: Add Variable Expression Support to Layer editor
2 parents 1215f14 + 18d52fd commit 7bf26f2

4 files changed

Lines changed: 53 additions & 13 deletions

File tree

lib/usd/ui/layerEditor/layerTreeItem.cpp

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121
#include <maya/MGlobal.h>
2222
#include <maya/MQtUtil.h>
2323

24+
#if PXR_VERSION >= 2308
25+
#include <pxr/usd/sdf/variableExpression.h>
26+
#endif
27+
2428
#include <algorithm>
2529

2630
PXR_NAMESPACE_USING_DIRECTIVE
@@ -81,13 +85,15 @@ const LayerActionDefinitions& LayerTreeItem::actionButtonsDefinition()
8185

8286
LayerTreeItem::LayerTreeItem(
8387
SdfLayerRefPtr in_usdLayer,
88+
UsdStageRefPtr in_stage,
8489
LayerType in_layerType,
8590
std::string in_subLayerPath,
8691
std::set<std::string>* in_incomingLayers,
8792
bool in_sharedStage,
8893
std::set<std::string>* in_sharedLayers,
8994
RecursionDetector* in_recursionDetector)
9095
: _layer(std::move(in_usdLayer))
96+
, _stage(std::move(in_stage))
9197
, _isTargetLayer(false)
9298
, _layerType(in_layerType)
9399
, _subLayerPath(in_subLayerPath)
@@ -138,11 +144,44 @@ void LayerTreeItem::populateChildren(RecursionDetector* recursionDetector)
138144
recursionDetector->push(_layer->GetRealPath());
139145

140146
for (auto const path : subPaths) {
147+
#if PXR_VERSION >= 2308
148+
// Resolve any variable expressions in the path using the stage's expression variables
149+
std::string resolvedPath = path;
150+
if (_stage && SdfVariableExpression::IsExpression(path)) {
151+
auto resolveExprVarsFromLayer =
152+
[](SdfVariableExpression& varExpr, SdfLayerRefPtr fromLayer, std::string& outPath) {
153+
if (fromLayer && fromLayer->HasExpressionVariables()) {
154+
auto expressionVars = fromLayer->GetExpressionVariables();
155+
auto result = varExpr.Evaluate(expressionVars);
156+
if (result.errors.empty() && !result.value.IsEmpty()) {
157+
outPath = result.value.UncheckedGet<std::string>();
158+
}
159+
}
160+
};
161+
162+
SdfVariableExpression varExpr(path);
163+
// Get the root layer's expression variables for resolution context
164+
auto rootLayer = _stage->GetRootLayer();
165+
resolveExprVarsFromLayer(varExpr, rootLayer, resolvedPath);
166+
167+
// Expression variables are composed across session layer and root
168+
// layer of a stage. So we do another pass with the session layer
169+
// to override/set the resolvedPath in case it is present in the
170+
// session layer
171+
auto sessionLayer = _stage->GetSessionLayer();
172+
resolveExprVarsFromLayer(varExpr, sessionLayer, resolvedPath);
173+
}
174+
175+
std::string actualPath = SdfComputeAssetPathRelativeToLayer(_layer, resolvedPath);
176+
auto subLayer = SdfLayer::FindOrOpen(actualPath);
177+
#else
141178
std::string actualPath = SdfComputeAssetPathRelativeToLayer(_layer, path);
142179
auto subLayer = SdfLayer::FindOrOpen(actualPath);
180+
#endif
143181
if (!subLayer || !recursionDetector->contains(subLayer->GetRealPath())) {
144182
auto item = new LayerTreeItem(
145183
subLayer,
184+
_stage,
146185
LayerType::SubLayer,
147186
path,
148187
&_incomingLayers,
@@ -230,14 +269,9 @@ AbstractCommandHook* LayerTreeItem::commandHook() const
230269
return parentModel()->sessionState()->commandHook();
231270
}
232271

233-
PXR_NS::UsdStageRefPtr const& LayerTreeItem::stage() const
234-
{
235-
return parentModel()->sessionState()->stage();
236-
}
237-
238272
bool LayerTreeItem::isMuted() const
239273
{
240-
return isInvalidLayer() || !stage() ? false : stage()->IsLayerMuted(_layer->GetIdentifier());
274+
return isInvalidLayer() || !_stage ? false : _stage->IsLayerMuted(_layer->GetIdentifier());
241275
}
242276

243277
bool LayerTreeItem::appearsMuted() const

lib/usd/ui/layerEditor/layerTreeItem.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ class LayerTreeItem : public QStandardItem
9898
public:
9999
LayerTreeItem(
100100
PXR_NS::SdfLayerRefPtr in_usdLayer,
101+
PXR_NS::UsdStageRefPtr in_stage,
101102
LayerType in_layerType = LayerType::SubLayer,
102103
std::string in_subLayerPath = "",
103104
std::set<std::string>* in_incomingLayers = nullptr,
@@ -127,8 +128,6 @@ class LayerTreeItem : public QStandardItem
127128
const std::string& displayName() const { return _displayName; }
128129
// if a sublayer, get the path we were saved with in the parent
129130
const std::string& subLayerPath() const { return _subLayerPath; }
130-
// shortcut to get stage from model
131-
PXR_NS::UsdStageRefPtr const& stage() const;
132131

133132
// is the layer muted at the stage level?
134133
bool isMuted() const;
@@ -202,6 +201,7 @@ class LayerTreeItem : public QStandardItem
202201

203202
protected:
204203
PXR_NS::SdfLayerRefPtr _layer;
204+
PXR_NS::UsdStageRefPtr _stage;
205205
std::string _displayName;
206206
bool _isTargetLayer = false;
207207
LayerType _layerType = LayerType::SubLayer;

lib/usd/ui/layerEditor/layerTreeModel.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,7 @@ void LayerTreeModel::rebuildModel(bool refreshLockState /*= false*/)
343343
if (showSessionLayer) {
344344
appendRow(new LayerTreeItem(
345345
sessionLayer,
346+
_sessionState->stage(),
346347
LayerType::SessionLayer,
347348
"",
348349
&incomingLayers,
@@ -351,7 +352,13 @@ void LayerTreeModel::rebuildModel(bool refreshLockState /*= false*/)
351352
}
352353

353354
appendRow(new LayerTreeItem(
354-
rootLayer, LayerType::RootLayer, "", &incomingLayers, sharedStage, &sharedLayers));
355+
rootLayer,
356+
_sessionState->stage(),
357+
LayerType::RootLayer,
358+
"",
359+
&incomingLayers,
360+
sharedStage,
361+
&sharedLayers));
355362

356363
updateTargetLayer(InRebuildModel::Yes);
357364

lib/usd/ui/layerEditor/warningDialogs.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,18 +72,17 @@ bool confirmDialog_internal(
7272

7373
if (okCancel) {
7474
msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
75-
msgBox.setDefaultButton(QMessageBox::Cancel);
75+
msgBox.setDefaultButton(QMessageBox::Ok);
76+
msgBox.button(QMessageBox::Ok)->setFocus();
7677
} else {
7778
msgBox.setStandardButtons(QMessageBox::Ok);
7879
}
7980

8081
if (!showIcon)
8182
msgBox.setStyleSheet(QString("QLabel{min-width: %1px;}").arg(DPIScale(400)));
8283

83-
if (okButtonText != nullptr) {
84+
if (okButtonText != nullptr)
8485
msgBox.button(QMessageBox::Ok)->setText(*okButtonText);
85-
msgBox.button(QMessageBox::Ok)->setFocus();
86-
}
8786

8887
return msgBox.exec() == QMessageBox::Ok;
8988
}

0 commit comments

Comments
 (0)