Skip to content

Commit

Permalink
Updated according to the review feedback.
Browse files Browse the repository at this point in the history
  • Loading branch information
AramAzhari-adsk committed Feb 15, 2024
1 parent 62a9a4c commit 13619e9
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 24 deletions.
2 changes: 0 additions & 2 deletions lib/mayaUsd/commands/layerEditorCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ const char kMuteLayerFlag[] = "mt";
const char kMuteLayerFlagL[] = "muteLayer";
const char kLockLayerFlag[] = "lk";
const char kLockLayerFlagL[] = "lockLayer";
const char kSystemLockLayerFlag[] = "sk";
const char kSystemLockLayerFlagL[] = "SystemLockLayer";

} // namespace

Expand Down
4 changes: 2 additions & 2 deletions lib/mayaUsd/utils/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ target_sources(${PROJECT_NAME}
dynamicAttribute.cpp
editability.cpp
json.cpp
layerLocking.cpp
layerLocking.cpp
layerMuting.cpp
layers.cpp
loadRulesAttribute.cpp
Expand Down Expand Up @@ -46,7 +46,7 @@ set(HEADERS
editability.h
hash.h
json.h
layerLocking.h
layerLocking.h
layerMuting.h
layers.h
loadRules.h
Expand Down
4 changes: 0 additions & 4 deletions lib/mayaUsd/utils/layerLocking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,6 @@ void addSystemLockedLayer(const PXR_NS::SdfLayerRefPtr& layer)
return;

LockedLayers& layers = getLockedLayers();
auto iter = layers.find(layer);
if (iter != layers.end()) {
return;
}
layers.insert(layer);
}

Expand Down
11 changes: 9 additions & 2 deletions lib/mayaUsd/utils/layerLocking.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ namespace MAYAUSD_NS_DEF {
// stage-level state. So, we need to explicitly save the layer locked state.
//
// Additionally, there are multiple levels of locking defined for a layer
// 1- A layer is locked if layer's permission to edit is set to false
// 2- A layer is system locked by setting a layer's permission to edit
// 1- A layer is "Locked" if layer's permission to edit is set to false
// 2- A layer is "System-Locked" by setting a layer's permission to edit
// and a layer's permission to save both to false.
//
// However, the USD API for checking permissions is a result of the following
Expand Down Expand Up @@ -64,6 +64,13 @@ namespace MAYAUSD_NS_DEF {
// So we need to hold on to locked layers. We do this in a private global list
// of locked layers. That list gets cleared when a new Maya scene is created.

enum LayerLockType
{
LayerLock_Unlocked,
LayerLock_Locked,
LayerLock_SystemLocked
};

/*! \brief Adds a layer to the system lock list
*/
MAYAUSD_CORE_PUBLIC
Expand Down
6 changes: 4 additions & 2 deletions lib/usd/ui/layerEditor/abstractCommandHook.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

#include "pxr/usd/sdf/layer.h"

#include <mayaUsd/utils/layerLocking.h>

#include <pxr/usd/usd/stage.h>

#include <QtCore/QString>
Expand Down Expand Up @@ -79,8 +81,8 @@ class AbstractCommandHook
// mute or unmute the given layer
virtual void muteSubLayer(UsdLayer usdLayer, bool muteIt) = 0;

// lock or unlock the given layer
virtual void lockSubLayer(UsdLayer usdLayer, bool lockIt, bool systemLock) = 0;
// Sets the lock state on a layer
virtual void lockSubLayer(UsdLayer usdLayer, MayaUsd::LayerLockType lockState) = 0;

// starts a complex undo operation in the host app. Please use UndoContext class to safely
// open/close
Expand Down
4 changes: 2 additions & 2 deletions lib/usd/ui/layerEditor/layerEditorWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,10 +264,10 @@ void LayerEditorWidget::updateButtons()
if (layer->isSystemLocked()) {
count--;
}
// Neither does any anonymous layer whose parent is system locked.
// Neither does any anonymous layer whose parent is locked or system-locked.
// This is because saving an anonymous layer will cause
// the parent layer to re-path the sub layer with a file name.
if (layer->isAnonymous() && layer->appearsSystemLocked()) {
if (layer->isAnonymous() && (layer->appearsLocked() || layer->appearsSystemLocked())) {
count--;
}
}
Expand Down
4 changes: 4 additions & 0 deletions lib/usd/ui/layerEditor/layerTreeItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,8 @@ bool LayerTreeItem::isLocked() const { return _layer && _layer->PermissionToEdit

bool LayerTreeItem::appearsLocked() const
{
// Note: This is used to indicate that some of the actions
// cannot be performed on a layer whose parent is locked.
auto item = parentLayerItem();
if (item != nullptr) {
return item->isLocked();
Expand All @@ -293,6 +295,8 @@ bool LayerTreeItem::isSystemLocked() const { return MayaUsd::isLayerSystemLocked

bool LayerTreeItem::appearsSystemLocked() const
{
// Note: This is used to indicate that some of the actions cannot
// be performed on a layer whose parent is system-locked.
auto item = parentLayerItem();
if (item != nullptr) {
return item->isSystemLocked();
Expand Down
8 changes: 6 additions & 2 deletions lib/usd/ui/layerEditor/layerTreeItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,15 @@ class LayerTreeItem : public QStandardItem
bool isIncoming() const;
// is the layer locked?
bool isLocked() const;
// check if this layer is locked
// check if this layer appears locked. This means that the layer item itself
// may not be locked but by inference some of the action items of the layer
// can appear as locked if the parent is locked.
bool appearsLocked() const;
// is the layer system locked?
bool isSystemLocked() const;
// check if this layer is system locked
// check if this layer appears system locked. This means that the layer item itself
// may not be system locked but by inference some of the action items of the layer
// can appear as locked if the parent is system locked.
bool appearsSystemLocked() const;

// used by draw delegate: returns how deep in the hierarchy we are
Expand Down
5 changes: 4 additions & 1 deletion lib/usd/ui/layerEditor/layerTreeModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,10 @@ void LayerTreeModel::toggleLockLayer(LayerTreeItem* item, bool* forcedState /*=
return;
}

_sessionState->commandHook()->lockSubLayer(item->layer(), !item->isLocked(), false);
MayaUsd::LayerLockType toggledLockType = item->isLocked()
? MayaUsd::LayerLockType::LayerLock_Unlocked
: MayaUsd::LayerLockType::LayerLock_Locked;
_sessionState->commandHook()->lockSubLayer(item->layer(), toggledLockType);
}

} // namespace UsdLayerEditor
21 changes: 16 additions & 5 deletions lib/usd/ui/layerEditor/mayaCommandHook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,19 +210,30 @@ void MayaCommandHook::muteSubLayer(UsdLayer usdLayer, bool muteIt)
executeMel(cmd).asChar();
}

// lock or unlock the given layer
void MayaCommandHook::lockSubLayer(UsdLayer usdLayer, bool lockIt, bool systemLock)
// lock, system-lock or unlock the given layer
void MayaCommandHook::lockSubLayer(UsdLayer usdLayer, MayaUsd::LayerLockType lockState)
{
std::string cmd;
cmd = "mayaUsdLayerEditor -edit -lockLayer ";
// 0 = Unlocked
// 1 = Locked
// 2 = System Locked
if (systemLock) {
switch (lockState) {
default:
case MayaUsd::LayerLockType::LayerLock_Unlocked: {
cmd += "0";
break;
}
case MayaUsd::LayerLockType::LayerLock_Locked: {
cmd += "1";
break;
}
case MayaUsd::LayerLockType::LayerLock_SystemLocked: {
cmd += "2";
} else {
cmd += lockIt ? "1" : "0";
break;
}
}

cmd += quote(proxyShapePath());
cmd += quote(usdLayer->GetIdentifier());
executeMel(cmd).asChar();
Expand Down
4 changes: 2 additions & 2 deletions lib/usd/ui/layerEditor/mayaCommandHook.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ class MayaCommandHook : public AbstractCommandHook
// mute or unmute the given layer
void muteSubLayer(UsdLayer usdLayer, bool muteIt) override;

// lock or unlock the given layer
void lockSubLayer(UsdLayer usdLayer, bool lockIt, bool systemLock) override;
// lock, system-lock or unlock the given layer
void lockSubLayer(UsdLayer usdLayer, MayaUsd::LayerLockType lockState) override;

// starts a complex undo operation in the host app. Please use UndoContext class to safely
// open/close
Expand Down

0 comments on commit 13619e9

Please sign in to comment.