Skip to content

Commit

Permalink
Merge pull request #3141 from Autodesk/bailp/MAYA-128907/drag-and-dro…
Browse files Browse the repository at this point in the history
…p-relative

MAYA-128907 fix layer parenting of relative layers
  • Loading branch information
seando-adsk authored Jun 7, 2023
2 parents 8aed586 + e6d85d4 commit cfe5053
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 14 deletions.
18 changes: 12 additions & 6 deletions lib/mayaUsd/utils/utilSerialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,10 @@ SdfLayerRefPtr saveAnonymousLayer(
LayerParent parent,
std::string formatArg)
{
// TODO: the code below is very similar to LayerTreeItem::saveAnonymousLayer().
// When fixing bug here or there, we need to fix it in the other. Refactor to have a
// single copy.

if (!anonLayer || !anonLayer->IsAnonymous()) {
return nullptr;
}
Expand Down Expand Up @@ -361,13 +365,15 @@ SdfLayerRefPtr saveAnonymousLayer(
}
}

// When the filePath was made relative, we need to help FindOrOpen to locate
// the sub-layers when using relative paths. We temporarily chande the
// current directory to the location the file path is relative to.
UsdMayaUtilFileSystem::TemporaryCurrentDir tempCurDir(relativePathAnchor);
SdfLayerRefPtr newLayer = SdfLayer::FindOrOpen(filePath);
tempCurDir.restore();
// Note: we need to open the layer with the absolute path. The relative path is only
// used by the parent layer to refer to the sub-layer relative to itself. When
// opening the layer in isolation, we need to use the absolute path. Failure to
// do so will make finding the layer by its own identifier fail! A symptom of
// this failure is that drag-and-drop in the Layer Manager UI fails immediately
// after saving a layer with a relative path.
SdfLayerRefPtr newLayer = SdfLayer::FindOrOpen(pathInfo.absolutePath);

// Now replace the layer in the parent, using a relative path if requested.
if (newLayer) {
if (isSubLayer) {
updateSubLayer(parent._layerParent, anonLayer, filePath);
Expand Down
22 changes: 14 additions & 8 deletions lib/usd/ui/layerEditor/layerTreeItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,10 @@ void LayerTreeItem::saveEditsNoPrompt()
// helper to save anon layers called by saveEdits()
void LayerTreeItem::saveAnonymousLayer()
{
// TODO: the code below is very similar to mayaUsd::utils::saveAnonymousLayer().
// When fixing bug here or there, we need to fix it in the other. Refactor to have a
// single copy.

auto sessionState = parentModel()->sessionState();

std::string fileName;
Expand All @@ -376,6 +380,8 @@ void LayerTreeItem::saveAnonymousLayer()
std::string formatTag = MayaUsd::utils::usdFormatArgOption();
if (saveSubLayer(dialogTitle, parentLayerItem(), layer(), fileName, formatTag)) {

const std::string absoluteFileName = fileName;

// now replace the layer in the parent
if (isRootLayer()) {
if (UsdMayaUtilFileSystem::requireUsdPathsRelativeToMayaSceneFile()) {
Expand All @@ -393,15 +399,15 @@ void LayerTreeItem::saveAnonymousLayer()
= UsdMayaUtilFileSystem::getLayerFileDir(parentItem->layer());
}

// Now replace the layer in the parent
//
// When the filePath was made relative, we need to help FindOrOpen to locate
// the sub-layers when using relative paths. We temporarily chande the
// current directory to the location the file path is relative to.
UsdMayaUtilFileSystem::TemporaryCurrentDir tempCurDir(relativePathAnchor);
auto newLayer = SdfLayer::FindOrOpen(fileName);
tempCurDir.restore();
// Note: we need to open the layer with the absolute path. The relative path is only
// used by the parent layer to refer to the sub-layer relative to itself. When
// opening the layer in isolation, we need to use the absolute path. Failure
// to do so will make finding the layer by its own identifier fail! A symptom
// of this failure is that drag-and-drop in the Layer Manager UI fails
// immediately after saving a layer with a relative path.
SdfLayerRefPtr newLayer = SdfLayer::FindOrOpen(absoluteFileName);

// Now replace the layer in the parent, using a relative path if requested.
if (newLayer) {
bool setTarget = _isTargetLayer;
auto model = parentModel();
Expand Down

0 comments on commit cfe5053

Please sign in to comment.