Skip to content

Commit

Permalink
Merge pull request #3343 from Autodesk/donnels/EMSUSD-287/usd_prefere…
Browse files Browse the repository at this point in the history
…nce_section

EMSUSD-287 - Setup preference section
  • Loading branch information
seando-adsk authored Sep 25, 2023
2 parents 3b26c42 + 0456c30 commit ce7fc17
Show file tree
Hide file tree
Showing 12 changed files with 529 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def filenameBrowser(self, callback):

@staticmethod
def wantRelativeFileName():
opVarName = "mayaUsd_MakePathRelativeToEditTargetLayer"
opVarName = "mayaUsd_MakePathRelativeToImageEditTargetLayer"
return cmds.optionVar(exists=opVarName) and cmds.optionVar(query=opVarName)

@staticmethod
Expand Down
53 changes: 0 additions & 53 deletions lib/usd/ui/layerEditor/layerEditorWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,59 +79,6 @@ void setupDefaultMenu(SessionState* in_sessionState, QMainWindow* in_parent)
action->setCheckable(true);
action->setChecked(in_sessionState->autoHideSessionLayer());

auto usdSaveMenu = optionMenu->addMenu(
StringResources::getAsQString(StringResources::kUsdSaveFileFormat));

// Add the save confirm existing file save checkbox
static const MString kConfirmExistingFileSave
= MayaUsdOptionVars->ConfirmExistingFileSave.GetText();
auto confirmExistingFileSaveAct = optionMenu->addAction(
StringResources::getAsQString(StringResources::kConfirmExistFileSave));

confirmExistingFileSaveAct->setCheckable(true);

QObject::connect(confirmExistingFileSaveAct, &QAction::toggled, in_parent, [](bool enable) {
MGlobal::setOptionVarValue(kConfirmExistingFileSave, enable);
});

if (MGlobal::optionVarExists(kConfirmExistingFileSave)) {
confirmExistingFileSaveAct->setChecked(
MGlobal::optionVarIntValue(kConfirmExistingFileSave) != 0);
} else {
confirmExistingFileSaveAct->setChecked(true);
}

auto formatGroup = new QActionGroup(usdSaveMenu);
formatGroup->setExclusive(true);
auto formatBinary
= formatGroup->addAction(StringResources::getAsQString(StringResources::kBinary));
auto formatAscii
= formatGroup->addAction(StringResources::getAsQString(StringResources::kAscii));
auto grpAnn = StringResources::getAsQString(StringResources::kSaveLayerUsdFileFormatAnn);
auto grpSbm = StringResources::getAsQString(StringResources::kSaveLayerUsdFileFormatSbm);
formatBinary->setCheckable(true);
formatBinary->setData(1);
formatBinary->setToolTip(grpAnn);
formatBinary->setStatusTip(grpSbm);
formatAscii->setCheckable(true);
formatAscii->setData(0);
formatAscii->setToolTip(grpAnn);
formatAscii->setStatusTip(grpSbm);
usdSaveMenu->addAction(formatBinary);
usdSaveMenu->addAction(formatAscii);
bool isBinary = true;

static const MString kSaveLayerFormatBinaryOption(
MayaUsdOptionVars->SaveLayerFormatArgBinaryOption.GetText());
if (MGlobal::optionVarExists(kSaveLayerFormatBinaryOption)) {
isBinary = MGlobal::optionVarIntValue(kSaveLayerFormatBinaryOption) != 0;
}
isBinary ? formatBinary->setChecked(true) : formatAscii->setChecked(true);
auto onFileFormatChanged = [=](QAction* action) {
MGlobal::setOptionVarValue(kSaveLayerFormatBinaryOption, action->data().toInt());
};
QObject::connect(formatGroup, &QActionGroup::triggered, in_parent, onFileFormatChanged);

auto helpMenu = menuBar->addMenu(StringResources::getAsQString(StringResources::kHelp));
helpMenu->addAction(
StringResources::getAsQString(StringResources::kHelpOnUSDLayerEditor),
Expand Down
75 changes: 59 additions & 16 deletions lib/usd/ui/layerEditor/saveLayersDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,14 @@ SaveLayerPathRow::SaveLayerPathRow(
QString pathToSaveAs
= MayaUsd::utils::generateUniqueLayerFileName(stageName, _layerInfo.layer).c_str();
_pathEdit->setText(QFileInfo(pathToSaveAs).absoluteFilePath());

// Set default state of checkbox and proper setting of path (must come after the initial
// setting above).
bool shouldCheck = _layerInfo.parent._layerParent
? UsdMayaUtilFileSystem::requireUsdPathsRelativeToParentLayer()
: UsdMayaUtilFileSystem::requireUsdPathsRelativeToMayaSceneFile();
_relative->setChecked(shouldCheck);
onRelativeChanged();
}

QString SaveLayerPathRow::layerDisplayName() const { return _label->text(); }
Expand Down Expand Up @@ -359,27 +367,55 @@ class SaveLayerPathRowArea : public QScrollArea

QSize sizeHint() const override
{
QSize hint;

if (widget() && widget()->layout()) {
auto l = widget()->layout();
for (int i = 0; i < l->count(); ++i) {
QWidget* w = l->itemAt(i)->widget();

QSize rowHint = w->sizeHint();
if (hint.width() < rowHint.width()) {
hint.setWidth(rowHint.width());
QGridLayout* gridLayout = qobject_cast<QGridLayout*>(widget()->layout());
if (nullptr != gridLayout) {
QSize hint { 0, 0 };
const int nbCols = gridLayout->columnCount();
const int nbRows = gridLayout->rowCount();
for (int r = 0; r < nbRows; ++r) {
int rowWidth { 0 };
int rowHeight { 0 };
for (int c = 0; c < nbCols; ++c) {
QWidget* w = gridLayout->itemAtPosition(r, c)->widget();
QSize rowHint = w->sizeHint();
rowWidth += rowHint.width();
rowHeight = std::max(rowHeight, rowHint.height());
}
if (hint.width() < rowWidth) {
hint.setWidth(rowWidth);
}
hint.rheight() += rowHeight;
}
if (0 < rowHint.height())
hint.rheight() += rowHint.height();

// Extra padding (enough for 3.5 lines).
if (hint.height() < DPIScale(120))
hint.setHeight(DPIScale(120));
return hint;
}

// Extra padding (enough for 3.5 lines).
hint.rwidth() += 100;
if (hint.height() < DPIScale(120))
hint.setHeight(DPIScale(120));
QVBoxLayout* vLayout = qobject_cast<QVBoxLayout*>(widget()->layout());
if (nullptr != vLayout) {
QSize hint { 0, 0 };
for (int i = 0; i < vLayout->count(); ++i) {
QWidget* w = vLayout->itemAt(i)->widget();

QSize rowHint = w->sizeHint();
if (hint.width() < rowHint.width()) {
hint.setWidth(rowHint.width());
}
if (0 < rowHint.height())
hint.rheight() += rowHint.height();
}

// Extra padding (enough for 3.5 lines).
hint.rwidth() += 100;
if (hint.height() < DPIScale(120))
hint.setHeight(DPIScale(120));
return hint;
}
}
return hint;
return {};
}
};

Expand Down Expand Up @@ -567,6 +603,13 @@ void SaveLayersDialog::buildDialog(const QString& msg1, const QString& msg2)
&QCheckBox::stateChanged,
this,
&SaveLayersDialog::onAllAsRelativeChanged);

// Default state for all relative checkbox. If both relative to SceneFile and
// ParentLayer optionvars are on, then this should be on.
bool shouldCheck = UsdMayaUtilFileSystem::requireUsdPathsRelativeToParentLayer()
&& UsdMayaUtilFileSystem::requireUsdPathsRelativeToMayaSceneFile();
_allAsRelative->setChecked(shouldCheck);

topLayout->addWidget(_allAsRelative);

// Then add the first scroll area (containing the anonymous layers)
Expand Down
7 changes: 0 additions & 7 deletions lib/usd/ui/layerEditor/stringResources.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,7 @@ MStringResourceId create(const char* key, const char* value);

const auto kAddNewLayer { create("kAddNewLayer", "Add a New Layer") };
const auto kAddSublayer { create("kAddSublayer", "Add sublayer") };
const auto kAscii { create("kAscii", "ASCII") };
const auto kAutoHideSessionLayer { create("kAutoHideSessionLayer", "Auto-Hide Session Layer") };
const auto kBinary { create("kBinary", "Binary") };
const auto kConfirmExistFileSave { create("kConfirmExistFileSave", "Confirm Save of Existing Files") };
const auto kConvertToRelativePath { create("kConvertToRelativePath", "Convert to Relative Path") };
const auto kCancel { create("kCancel", "Cancel") };
const auto kCreate { create("kCreate", "Create") };
Expand Down Expand Up @@ -90,7 +87,6 @@ const auto kToSaveTheStageSaveFiles { create("kToSaveTheStageSaveFiles", "T
const auto kUsedInStagesTooltip { create("kUsedInStagesTooltip", "<b>Used in Stages</b>: ") };

const auto kSetLayerAsTargetLayerTooltip { create("kSetLayerAsTargetLayerTooltip", "Set layer as target layer. Edits are added to the target layer.") };
const auto kUsdSaveFileFormat { create("kUsdSaveFileFormat", "Save .usd File Format") };
const auto kUsdLayerIdentifier { create("kUsdLayerIdentifier", "USD Layer identifier: ^1s") };
const auto kUsdStage { create("kUsdStage", "USD Stage:") };
const auto kPinUsdStageTooltip { create("kPinUsdStage", "When unpinned, follow the USD stage selected in the outliner.") };
Expand All @@ -103,9 +99,6 @@ const auto kSaveAnonymousConfirmOverwrite { create("kSaveAnonymousConfirmOverwri
const auto kSaveAnonymousIdenticalFilesTitle { create("kSaveAnonymousIdenticalFilesTitle", "Identical Names Error")};
const auto kSaveAnonymousIdenticalFiles { create("kSaveAnonymousIdenticalFiles", "^1s files have identical file names and prevent correct saving. Please select different file names for each layer. Here is the list of identical file names:<br>")};

const auto kSaveLayerUsdFileFormatAnn { create("kSaveLayerUsdFileFormatAnn", "Select whether the .usd file is written out in binary or ASCII. You can save a file in .usdc (binary) or .usda (ASCII) format. Manually entering a file name with an extension overrides the selection in this drop-down menu.") };
const auto kSaveLayerUsdFileFormatSbm { create("kSaveLayerUsdFileFormatSbm", "Select whether the .usd file is written out in binary or ASCII") };

const auto kBatchSaveAllRelative { create("kBatchSaveAllRelative", "Convert All to Relative Paths")};
const auto kBatchSaveRelativeToScene { create("kBatchSaveRelativeToScene", "Relative to Scene File")};
const auto kBatchSaveRelativeToParent { create("kBatchSaveRelativeToParent", "Relative to Parent Layer")};
Expand Down
1 change: 1 addition & 0 deletions plugin/adsk/scripts/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ list(APPEND scripts_src
mayaUsd_pluginUIDeletion.mel
mayaUsd_pluginBatchLoad.mel
mayaUsd_pluginBatchUnload.mel
mayaUsd_preferenceTab.mel
mayaUsd_selectionUtils.py
mayaUsd_USDRootFileRelative.py
usdFileSaveOptions.mel
Expand Down
22 changes: 22 additions & 0 deletions plugin/adsk/scripts/mayaUSDRegisterStrings.mel
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,28 @@ global proc mayaUSDRegisterStrings()
register("kMayaRefDuplicateAsUsdDataDiv", "Stages");
register("kMayaRefDuplicateAsUsdDataOptions", "Options...");

// All strings for the USD Global Preferences:
register("kUSDPreferences", "USD: USD Preferences");
register("KSavingUSDFiles", "Save USD Files");
register("kdotusdFileFormat", ".usd File Format:");
register("kAscii", "ASCII");
register("kBinary", "Binary");
register("kSaveLayerUsdFileFormatAnn", "Select whether the .usd file is written out in binary or ASCII. You can save a file in .usdc (binary) or .usda (ASCII) format. Manually entering a file name with an extension overrides the selection in this preference.");
register("kSaveLayerUsdFileFormatSbm", "Select whether the .usd file is written out in binary or ASCII");
register("kConfirmExistFileSave", "Confirm Save of Existing Files");
register("kSavingMayaSceneFiles", "Save Maya Scene Files");
register("kSaveFileRelatively", "Save Files Relatively");
register("kAllRelativeToggle", "All files");
register("kAllRelativeToggleAnn", "When on, all of your files will be saved as relative paths.");
register("kRootLayersRelativeToSceneFile", "USD root layers");
register("kRootLayersRelativeToSceneFileAnn", "When on, your USD root layer file will be saved relatively to your Maya scene file.");
register("kSubLayersRelativeToParentLayer", "Sublayers");
register("kSubLayersRelativeToParentLayerAnn", "When on, all sublayers will be saved relatively to their parent layers.");
register("kReferencesRelativeToEditTargetLayer", "References/Payloads");
register("kReferencesRelativeToEditTargetLayerAnn", "When on, any references or payloads will be saved relatively to their respective edit target layer.");
register("kFileDependenciesRelativeToEditTargetLayer", "File dependencies");
register("kFileDependenciesRelativeToEditTargetLayerAnn", "When on, any file dependencies, such as textures or Maya references will be saved relatively to their respective edit target layer.");

// Register the strings from the python equivalent register function.
// Note: the strings from both the MEL and python register can be loaded
// by either MEL or python. They all get registered together under
Expand Down
2 changes: 2 additions & 0 deletions plugin/adsk/scripts/mayaUSDRegisterStrings.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ def mayaUSDRegisterStrings():
register("kMakePathRelativeToSceneFileAnn", "Path will be relative to your Maya scene file.")
register("kMakePathRelativeToEditTargetLayer", "Make Path Relative to Edit Target Layer Directory")
register("kMakePathRelativeToEditTargetLayerAnn", "Enable to activate relative pathing to your current edit target layer's directory.\nIf this option is disabled, verify that your target layer is not anonymous and save it to disk.")
register("kMakePathRelativeToImageEditTargetLayer", "Make Path Relative to Edit Target Layer Directory")
register("kMakePathRelativeToImageEditTargetLayerAnn", "Enable to activate relative pathing to your current edit target layer's directory.\nIf this option is disabled, verify that your target layer is not anonymous and save it to disk.")
register("kMakePathRelativeToParentLayer", "Make Path Relative to Parent Layer Directory")
register("kMakePathRelativeToParentLayerAnn", "Enable to activate relative pathing to your current parent layer's directory.\nIf this option is disabled, verify that your parent layer is not anonymous and save it to disk.")
register("kUnresolvedPath", "Path Preview:")
Expand Down
3 changes: 3 additions & 0 deletions plugin/adsk/scripts/mayaUsd_USDRootFileRelative.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,9 @@ class usdImageRelativeToEditTargetLayer(usdFileRelativeToEditTargetLayer):
'''
Helper class to create the UI for image optionally relative to a layer file.
'''

kRelativeToWhat = 'ImageEditTargetLayer'

@classmethod
def uiInit(cls, parentLayout, filterType):
'''
Expand Down
10 changes: 10 additions & 0 deletions plugin/adsk/scripts/mayaUsd_pluginUICreation.mel
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ global proc mayaUsd_pluginUICreation()
source "mayaUsdMenu.mel";
mayaUsdMenu_loadui;

source "mayaUsd_preferenceTab.mel";
addCustomPrefsTab("mayaUsd_PrefCreateTab",
"mayaUsd_PrefCreateFrameLayout",
"mayaUsd_PrefUpdate",
"mayaUsd_PrefHoldState",
"mayaUsd_PrefSetOptVarsToDefault",
`getMayaUsdString("kUSDPreferences")`,
"USD");
mayaUsd_PrefInitOptionVars(false);

source "mayaUsd_fileOptions.mel";

// Set the default USD attributes we want to display
Expand Down
4 changes: 4 additions & 0 deletions plugin/adsk/scripts/mayaUsd_pluginUIDeletion.mel
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,9 @@ global proc mayaUsd_pluginUIDeletion()
// we do attempt to load it when this plugin gets loaded. It is a utility
// plugin that we depend on, but so could others so we will leave it alone.


// Unregister the Preferences tab.
deleteCustomPrefsTab("mayaUsd_PrefCreateTab");

mayaUsdMenu_unloadui();
}
Loading

0 comments on commit ce7fc17

Please sign in to comment.