-
Notifications
You must be signed in to change notification settings - Fork 202
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
EMSUSD-872 - Adds the ability to System-lock a layer
- Loading branch information
1 parent
574260d
commit 00346db
Showing
22 changed files
with
370 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
// | ||
// Copyright 2024 Autodesk | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
#include "layerLocking.h" | ||
|
||
#include <mayaUsd/listeners/notice.h> | ||
|
||
#include <pxr/base/tf/weakBase.h> | ||
|
||
namespace MAYAUSD_NS_DEF { | ||
|
||
namespace { | ||
|
||
// Automatic reset of recorded locked layers when the Maya scene is reset. | ||
struct SceneResetListener : public PXR_NS::TfWeakBase | ||
{ | ||
SceneResetListener() | ||
{ | ||
PXR_NS::TfWeakPtr<SceneResetListener> me(this); | ||
PXR_NS::TfNotice::Register(me, &SceneResetListener::OnSceneReset); | ||
} | ||
|
||
void OnSceneReset(const UsdMayaSceneResetNotice&) | ||
{ | ||
// Make sure we don't hold onto locked layers now that the | ||
// Maya scene is reset. | ||
forgetSystemLockedLayers(); | ||
} | ||
}; | ||
|
||
// The set of locked layers. | ||
// | ||
// Kept in a function to avoid problem with the order of construction | ||
// of global variables in C++. | ||
using LockedLayers = std::set<PXR_NS::SdfLayerRefPtr>; | ||
LockedLayers& getLockedLayers() | ||
{ | ||
// Note: C++ guarantees correct multi-thread protection for static | ||
// variables initialization in functions. | ||
static SceneResetListener onSceneResetListener; | ||
static LockedLayers layers; | ||
return layers; | ||
} | ||
} // namespace | ||
|
||
void addSystemLockedLayer(const PXR_NS::SdfLayerRefPtr& layer) | ||
{ | ||
if (!layer) | ||
return; | ||
|
||
LockedLayers& layers = getLockedLayers(); | ||
auto iter = layers.find(layer); | ||
if (iter != layers.end()) { | ||
return; | ||
} | ||
layers.insert(layer); | ||
} | ||
|
||
void removeSystemLockedLayer(const PXR_NS::SdfLayerRefPtr& layer) | ||
{ | ||
if (!layer) | ||
return; | ||
|
||
LockedLayers& layers = getLockedLayers(); | ||
layers.erase(layer); | ||
} | ||
|
||
bool isLayerSystemLocked(const PXR_NS::SdfLayerRefPtr& layer) | ||
{ | ||
if (!layer) | ||
return false; | ||
|
||
LockedLayers& layers = getLockedLayers(); | ||
auto iter = layers.find(layer); | ||
if (iter != layers.end()) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
void forgetSystemLockedLayers() | ||
{ | ||
LockedLayers& layers = getLockedLayers(); | ||
layers.clear(); | ||
} | ||
|
||
} // namespace MAYAUSD_NS_DEF |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
// | ||
// Copyright 2024 Autodesk | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
#ifndef MAYAUSD_LAYERLOCKING_H | ||
#define MAYAUSD_LAYERLOCKING_H | ||
|
||
#include <mayaUsd/base/api.h> | ||
#include <mayaUsd/nodes/proxyShapeBase.h> | ||
|
||
#include <pxr/usd/sdf/layer.h> | ||
#include <pxr/usd/usd/stage.h> | ||
|
||
namespace MAYAUSD_NS_DEF { | ||
|
||
// The lock state of a layer is stage-level data. As such, it is not saved | ||
// within the layer (i.e. in the USD files that have been staged.) The reason | ||
// behind this is that two stages could have different locked layers, a single | ||
// layer could be locked in one stage and not locked in another stage. So, the | ||
// locked state cannot be a layer-level data. | ||
// | ||
// Furthermore, stages in USD are not saved but are a pure run-time entity, | ||
// part of the hosting application. It is thus the host responsibility to save | ||
// 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 | ||
// and a layer's permission to save both to false. | ||
// | ||
// However, the USD API for checking permissions is a result of the following | ||
// conditions: | ||
// | ||
// For permission to save to be True (SdfLayer::PermissionToSave()): | ||
// | ||
// 1- The layer must not be anonymous | ||
// 2- The layer must not be muted | ||
// 3- The layer must have write access to disk | ||
// 4- The internal _permissionToSave must be True | ||
// | ||
// For permission to Edit (SdfLayer::PermissionToEdit()): | ||
// | ||
// 1- The layer must not be muted | ||
// 2- The internal _permissionToEdit must be True | ||
// | ||
// For this reason, the locked layer state needs to be managed inside Maya USD | ||
// to avoid receiving false positives for PermissionToSave and PermissionToEdit. | ||
// | ||
// We therefore save the lock state of layers. | ||
// OpenUSD forgets everything about layer permissions to save or edit as there are only applicable | ||
// to sessions | ||
// | ||
// 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. | ||
|
||
/*! \brief Adds a layer to the system lock list | ||
*/ | ||
MAYAUSD_CORE_PUBLIC | ||
void addSystemLockedLayer(const PXR_NS::SdfLayerRefPtr& layer); | ||
|
||
/*! \brief Removes a layer from the system lock list | ||
*/ | ||
MAYAUSD_CORE_PUBLIC | ||
void removeSystemLockedLayer(const PXR_NS::SdfLayerRefPtr& layer); | ||
|
||
/*! \brief Checks if a layer is in the lock list. | ||
*/ | ||
MAYAUSD_CORE_PUBLIC | ||
bool isLayerSystemLocked(const PXR_NS::SdfLayerRefPtr& layer); | ||
|
||
/*! \brief Clears the lock list | ||
*/ | ||
MAYAUSD_CORE_PUBLIC | ||
void forgetSystemLockedLayers(); | ||
|
||
} // namespace MAYAUSD_NS_DEF | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.