Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/mayaUsd/commands/abstractLayerEditorWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ class MAYAUSD_CORE_PUBLIC AbstractLayerEditorWindow
virtual bool layerIsSystemLocked() = 0;
virtual bool layerIsReadOnly() = 0;
virtual bool layerHasSubLayers() = 0;
virtual bool strongestLayerIsLocked() = 0;
virtual bool selectionHasSessionAndNonSessionLayers() = 0;
virtual std::string proxyShapeName(const bool fullPath = false) const = 0;

virtual void removeSubLayer() = 0;
Expand Down
6 changes: 6 additions & 0 deletions lib/mayaUsd/commands/layerEditorWindowCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ DEF_FLAG(lo, layerIsLocked)
DEF_FLAG(as, layerAppearsSystemLocked)
DEF_FLAG(ls, layerIsSystemLocked)
DEF_FLAG(ll, layerHasSubLayers)
DEF_FLAG(sk, strongestLayerIsLocked)
DEF_FLAG(ss, selectionHasSessionAndNonSessionLayers)

// edit flags
DEF_FLAG(rs, removeSubLayer)
Expand Down Expand Up @@ -145,6 +147,8 @@ MSyntax LayerEditorWindowCommand::createSyntax()
ADD_FLAG(layerAppearsSystemLocked);
ADD_FLAG(layerIsSystemLocked);
ADD_FLAG(layerHasSubLayers);
ADD_FLAG(strongestLayerIsLocked);
ADD_FLAG(selectionHasSessionAndNonSessionLayers);

ADD_FLAG(removeSubLayer);
ADD_FLAG(saveEdits);
Expand Down Expand Up @@ -338,6 +342,8 @@ MStatus LayerEditorWindowCommand::handleQueries(
HANDLE_Q_FLAG(layerAppearsSystemLocked)
HANDLE_Q_FLAG(layerIsSystemLocked)
HANDLE_Q_FLAG(layerHasSubLayers)
HANDLE_Q_FLAG(strongestLayerIsLocked)
HANDLE_Q_FLAG(selectionHasSessionAndNonSessionLayers)

// proxyShape flag is both create/query.
if (argParser.isFlagSet(FLAG(proxyShape)) && argParser.isQuery()) {
Expand Down
58 changes: 58 additions & 0 deletions lib/usd/ui/layerEditor/mayaLayerEditorWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@

#include <mayaUsd/utils/query.h>

#include <usdUfe/utils/layers.h>

#include <maya/MGlobal.h>
#include <maya/MQtUtil.h>

Expand Down Expand Up @@ -177,6 +179,62 @@ std::string MayaLayerEditorWindow::proxyShapeName(const bool fullPath) const
return fullPath ? stageEntry._proxyShapePath : stageEntry._displayName;
}

bool MayaLayerEditorWindow::strongestLayerIsLocked()
{
const LayerItemVector selectedItems = treeView()->getSelectedLayerItems();
if (selectedItems.size() < 2) {
return false;
}

const UsdStageRefPtr stage = _sessionState.stage();
if (!stage)
return false;

// Finds strongest layer from selectedItems by folding over the selection.
SdfLayerHandle strongestLayer;
const LayerTreeItem* strongestItem = nullptr;
for (const auto* item : selectedItems) {
SdfLayerHandle layer = item->layer();
if (!strongestLayer || UsdUfe::getStrongerLayer(stage, layer, strongestLayer) == layer) {
strongestLayer = layer;
strongestItem = item;
}
}

return strongestItem && strongestItem->isLocked();
}

bool MayaLayerEditorWindow::selectionHasSessionAndNonSessionLayers()
{
const LayerItemVector selectedItems = treeView()->getSelectedLayerItems();
if (selectedItems.size() < 2)
return false;

const UsdStageRefPtr stage = _sessionState.stage();
if (!stage)
return false;

const auto sessionLayers = UsdUfe::getAllSublayerRefs(stage->GetSessionLayer(), true);

bool hasSessionLayerItem = false;
bool hasNonSessionLayerItem = false;

for (const auto* item : selectedItems) {
if (!item)
continue;

if (UsdUfe::isSessionLayer(item->layer(), sessionLayers))
hasSessionLayerItem = true;
else
hasNonSessionLayerItem = true;

if (hasSessionLayerItem && hasNonSessionLayerItem)
return true;
}

return false;
}

void MayaLayerEditorWindow::removeSubLayer()
{
QString name = "Remove";
Expand Down
2 changes: 2 additions & 0 deletions lib/usd/ui/layerEditor/mayaLayerEditorWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ class MayaLayerEditorWindow
bool layerAppearsSystemLocked() override;
bool layerIsSystemLocked() override;
bool layerHasSubLayers() override;
bool strongestLayerIsLocked() override;
bool selectionHasSessionAndNonSessionLayers() override;

void removeSubLayer() override;
void saveEdits() override;
Expand Down
17 changes: 11 additions & 6 deletions plugin/adsk/scripts/mayaUsdMenu.mel
Original file line number Diff line number Diff line change
Expand Up @@ -1038,10 +1038,11 @@ global proc mayaUsdMenu_layerEditorContextMenu(string $panelName) {
return; // that's all we can support on invalid layers
}

// Single selection flags
int $singleSelect = `mayaUsdLayerEditorWindow -q -selectionLength $panelName` == 1;
int $isSessionLayer = `mayaUsdLayerEditorWindow -q -isSessionLayer $panelName`;
int $isAnonymousLayer = `mayaUsdLayerEditorWindow -q -isAnonymousLayer $panelName`;
int $needsSaving = `mayaUsdLayerEditorWindow -q -layerNeedsSaving $panelName`;
int $singleSelect = `mayaUsdLayerEditorWindow -q -selectionLength $panelName` == 1;
int $appearsMuted = `mayaUsdLayerEditorWindow -q -layerAppearsMuted $panelName`;
int $isSubLayer = `mayaUsdLayerEditorWindow -q -isSubLayer $panelName`;
int $isMuted = `mayaUsdLayerEditorWindow -q -layerIsMuted $panelName`;
Expand All @@ -1053,6 +1054,11 @@ global proc mayaUsdMenu_layerEditorContextMenu(string $panelName) {
int $isIncoming = `mayaUsdLayerEditorWindow -q -isIncomingLayer $panelName`;
int $hasSublayers = `mayaUsdLayerEditorWindow -q -layerHasSubLayers $panelName`;
string $proxyShape = `mayaUsdLayerEditorWindow -q -proxyShape $panelName`;

// Multi selection flags
int $multiSelect = `mayaUsdLayerEditorWindow -q -selectionLength $panelName` > 1;
int $strongestLayerIsLocked = `mayaUsdLayerEditorWindow -q -strongestLayerIsLocked $panelName`;
int $hasSessionAndNonSessionLayers = `mayaUsdLayerEditorWindow -q -selectionHasSessionAndNonSessionLayers $panelName`;

string $label;
int $enabled;
Expand Down Expand Up @@ -1096,12 +1102,11 @@ global proc mayaUsdMenu_layerEditorContextMenu(string $panelName) {
$enabled = $singleSelect && !$appearsMuted && !$isReadOnly && !$isLocked && !$isSystemLocked;
menuItem -label $label -enable $enabled -c $cmd;

int $multiSelect = `mayaUsdLayerEditorWindow -q -selectionLength $panelName` > 1;
if ($multiSelect && !$singleSelect) {
$label = getMayaUsdString("kMenuStitchLayers");
$cmd = makeCommand($panelName, "stitchLayers");
$enabled = !$isReadOnly && !$appearsLocked && !$appearsSystemLocked && !$appearsMuted;
menuItem -label $label -enable $enabled -c $cmd;
$label = getMayaUsdString("kMenuStitchLayers");
$cmd = makeCommand($panelName, "stitchLayers");
$enabled = !$isReadOnly && !$appearsLocked && !$appearsSystemLocked && !$appearsMuted && !$strongestLayerIsLocked && !$hasSessionAndNonSessionLayers;
menuItem -label $label -enable $enabled -c $cmd;
}

if ($hasSublayers) {
Expand Down