Skip to content

Commit 20e1c11

Browse files
authored
Merge pull request #4416 from Autodesk/deboisj/cc_save_fix
2 parents 8e6ebcc + 49d5b12 commit 20e1c11

File tree

6 files changed

+54
-34
lines changed

6 files changed

+54
-34
lines changed

lib/mayaUsd/utils/utilComponentCreator.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,20 @@
1414
// limitations under the License.
1515
//
1616

17+
#include "util.h"
18+
#include "utilFileSystem.h"
19+
1720
#include <mayaUsd/utils/utilComponentCreator.h>
1821

1922
#include <pxr/base/tf/diagnostic.h>
2023
#include <pxr/pxr.h>
24+
#include <pxr/usd/usd/stage.h>
2125

2226
#include <maya/MGlobal.h>
2327
#include <maya/MString.h>
2428

29+
#include <ghc/filesystem.hpp>
30+
2531
#include <vector>
2632

2733
PXR_NAMESPACE_USING_DIRECTIVE
@@ -203,5 +209,19 @@ std::string moveAdskUsdComponent(
203209
return {};
204210
}
205211

212+
bool shouldDisplayComponentInitialSaveDialog(
213+
const pxr::UsdStageRefPtr stage,
214+
const std::string& proxyShapePath)
215+
{
216+
if (!MayaUsd::ComponentUtils::isAdskUsdComponent(proxyShapePath)) {
217+
return false;
218+
}
219+
220+
MString tempDir;
221+
MGlobal::executeCommand("internalVar -userTmpDir", tempDir);
222+
return UsdMayaUtilFileSystem::isPathInside(
223+
UsdMayaUtil::convert(tempDir), stage->GetRootLayer()->GetRealPath());
224+
}
225+
206226
} // namespace ComponentUtils
207227
} // namespace MAYAUSD_NS_DEF

lib/mayaUsd/utils/utilComponentCreator.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,14 @@ std::string moveAdskUsdComponent(
6565
const std::string& componentName,
6666
const std::string& proxyPath);
6767

68+
/*! \brief Checks if the initial save dialog for components should be opened.
69+
* \return Returns true if the initial save dialog for components should be opened.
70+
*/
71+
MAYAUSD_CORE_PUBLIC
72+
bool shouldDisplayComponentInitialSaveDialog(
73+
const pxr::UsdStageRefPtr stage,
74+
const std::string& proxyShapePath);
75+
6876
} // namespace ComponentUtils
6977
} // namespace MAYAUSD_NS_DEF
7078

lib/mayaUsd/utils/utilFileSystem.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -803,3 +803,20 @@ void UsdMayaUtilFileSystem::FileBackup::restore()
803803
const std::string backupFileName = getBackupFilename();
804804
rename(backupFileName.c_str(), _filename.c_str());
805805
}
806+
807+
bool UsdMayaUtilFileSystem::isPathInside(const std::string& parentDir, const std::string& childPath)
808+
{
809+
ghc::filesystem::path parent = ghc::filesystem::weakly_canonical(parentDir);
810+
ghc::filesystem::path child = ghc::filesystem::weakly_canonical(childPath);
811+
812+
// Iterate up from child to root
813+
for (ghc::filesystem::path p = child; !p.empty(); p = p.parent_path()) {
814+
if (p == parent)
815+
return true;
816+
817+
ghc::filesystem::path next = p.parent_path();
818+
if (next == p) // reached root (ex "C:\")
819+
break;
820+
}
821+
return false;
822+
}

lib/mayaUsd/utils/utilFileSystem.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,11 @@ void pathRemoveExtension(std::string& filePath);
308308
MAYAUSD_CORE_PUBLIC
309309
std::string pathFindExtension(std::string& filePath);
310310

311+
/*! \brief returns true if the given child path is inside the given parent directory.
312+
*/
313+
MAYAUSD_CORE_PUBLIC
314+
bool isPathInside(const std::string& parentDir, const std::string& childPath);
315+
311316
// Backup a file and restore it if not committed.
312317
class FileBackup
313318
{

lib/usd/ui/layerEditor/layerTreeModel.cpp

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -50,37 +50,6 @@ namespace {
5050
const QString LAYER_EDITOR_MIME_TYPE = QStringLiteral("text/plain");
5151
const QString LAYED_EDITOR_MIME_SEP = QStringLiteral(";");
5252

53-
bool isPathInside(const std::string& parentDir, const std::string& childPath)
54-
{
55-
ghc::filesystem::path parent = ghc::filesystem::weakly_canonical(parentDir);
56-
ghc::filesystem::path child = ghc::filesystem::weakly_canonical(childPath);
57-
58-
// Iterate up from child to root
59-
for (ghc::filesystem::path p = child; !p.empty(); p = p.parent_path()) {
60-
if (p == parent)
61-
return true;
62-
63-
ghc::filesystem::path next = p.parent_path();
64-
if (next == p) // reached root (ex "C:\")
65-
break;
66-
}
67-
return false;
68-
}
69-
70-
bool shouldDisplayComponentInitialSaveDialog(
71-
const UsdStageRefPtr stage,
72-
const std::string& proxyShapePath)
73-
{
74-
if (!MayaUsd::ComponentUtils::isAdskUsdComponent(proxyShapePath)) {
75-
return false;
76-
}
77-
78-
MString tempDir;
79-
MGlobal::executeCommand("internalVar -userTmpDir", tempDir);
80-
81-
return isPathInside(UsdMayaUtil::convert(tempDir), stage->GetRootLayer()->GetRealPath());
82-
}
83-
8453
} // namespace
8554

8655
namespace UsdLayerEditor {
@@ -575,7 +544,7 @@ void LayerTreeModel::saveStage(QWidget* in_parent)
575544
}
576545

577546
// Show the save dialog for component stages (initial save) or if confirmation is needed
578-
if (shouldDisplayComponentInitialSaveDialog(
547+
if (MayaUsd::ComponentUtils::shouldDisplayComponentInitialSaveDialog(
579548
_sessionState->stageEntry()._stage, _sessionState->stageEntry()._proxyShapePath)
580549
|| showConfirmDgl) {
581550
bool isExporting = false;

lib/usd/ui/layerEditor/saveLayersDialog.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -502,8 +502,9 @@ SaveLayersDialog::SaveLayersDialog(
502502
msg.format(StringResources::getAsMString(StringResources::kSaveName), stageName.c_str());
503503
dialogTitle = MQtUtil::toQString(msg);
504504

505-
// Check if this stage is a component stage
506-
if (MayaUsd::ComponentUtils::isAdskUsdComponent(stageEntry._proxyShapePath)) {
505+
// Check if this stage is an unsaved component stage.
506+
if (MayaUsd::ComponentUtils::shouldDisplayComponentInitialSaveDialog(
507+
_sessionState->stageEntry()._stage, _sessionState->stageEntry()._proxyShapePath)) {
507508
MayaUsd::StageSavingInfo info;
508509
MObject proxyObj;
509510
UsdMayaUtil::GetMObjectByName(stageEntry._proxyShapePath, proxyObj);

0 commit comments

Comments
 (0)