-
Notifications
You must be signed in to change notification settings - Fork 221
EMSUSD-3762 - RenderSetup undo/redo #4654
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
32f93a0
Undo/redo support for the RenderSetup.
derlerk c70d9d1
SdfUndo block
derlerk 4a94862
Remove ambigious tests that did not actually cover the code paths.
derlerk a50ae43
Review changes :
derlerk e5db3c1
Fix header
derlerk 088dacb
Files first letter to lowercase.
derlerk b159855
Fix relative include path
derlerk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -128,6 +128,7 @@ endif() | |
| set(HEADERS | ||
| api.h | ||
| initStringResources.h | ||
| undoChunkUtils.h | ||
| ) | ||
|
|
||
| mayaUsd_promoteHeaderList( | ||
|
|
||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,73 @@ | ||
| // | ||
| // Copyright 2026 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 "mayaEditCommitter.h" | ||
|
|
||
| #include <mayaUsd/undo/MayaUsdUndoBlock.h> | ||
| #include <mayaUsdUI/ui/undoChunkUtils.h> | ||
|
|
||
| #include <usdUfe/undo/UsdUndoUtils.h> | ||
|
|
||
| #include <pxr/usd/sdf/changeBlock.h> | ||
|
|
||
| #include <QtCore/QTimer> | ||
|
|
||
| namespace MayaUsdRenderSetup { | ||
|
|
||
| MayaEditCommitter::MayaEditCommitter(QObject* parent) | ||
| : QObject(parent) | ||
| { | ||
| } | ||
|
|
||
| void MayaEditCommitter::setStages(const std::vector<Adsk::HostStage>& stages) | ||
| { | ||
| _stages.clear(); | ||
| _stages.reserve(stages.size()); | ||
| for (const auto& hostStage : stages) { | ||
| if (hostStage.stage) { | ||
| _stages.push_back(hostStage.stage); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| void MayaEditCommitter::commit(const std::string& undoLabel, std::function<void()> doEdit) | ||
| { | ||
| if (!doEdit || _stages.empty()) { | ||
| return; | ||
| } | ||
|
|
||
| ++_inFlightCount; | ||
| // Schedule the decrement before doEdit() so it fires even if doEdit() throws. | ||
| // The one-event-loop-cycle delay keeps isLocalEditInFlight() true through the | ||
| // USD-notice burst that follows the edit, so the notice bridge treats the | ||
| // resulting refresh as self-originated and skips re-entrancy. | ||
| QTimer::singleShot(0, this, [this]() { | ||
| if (_inFlightCount > 0) { | ||
| --_inFlightCount; | ||
| } | ||
| }); | ||
|
|
||
| UsdUfe::trackStagesEditTargets(_stages); | ||
|
|
||
| const MayaUsdUI::UndoChunkGuard undoChunkGuard(undoLabel); | ||
| MayaUsd::MayaUsdUndoBlock block; | ||
| { | ||
| PXR_NS::SdfChangeBlock changeBlock; | ||
| doEdit(); | ||
| } | ||
| } | ||
|
|
||
| } // namespace MayaUsdRenderSetup |
This file contains hidden or 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,55 @@ | ||
| // | ||
| // Copyright 2026 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 MAYAUSDUI_USD_RENDERSETUP_MAYAEDITCOMMITTER_H | ||
| #define MAYAUSDUI_USD_RENDERSETUP_MAYAEDITCOMMITTER_H | ||
|
|
||
| #include <pxr/usd/usd/stage.h> | ||
|
|
||
| #include <QtCore/QObject> | ||
| #include <RenderSetup/HostStage.h> | ||
| #include <RenderSetup/IEditCommitter.h> | ||
|
|
||
| #include <functional> | ||
| #include <string> | ||
| #include <vector> | ||
|
|
||
| namespace MayaUsdRenderSetup { | ||
|
|
||
| //! MayaUSD implementation of Adsk::IEditCommitter for the Render Setup UI. | ||
| //! Captures USD edits through UsdUfe and flushes them onto the Maya undo stack | ||
| //! via MayaUsdUndoBlock. | ||
| class MayaEditCommitter | ||
| : public QObject | ||
| , public Adsk::IEditCommitter | ||
| { | ||
| Q_OBJECT | ||
| public: | ||
| explicit MayaEditCommitter(QObject* parent = nullptr); | ||
|
|
||
| void setStages(const std::vector<Adsk::HostStage>& stages); | ||
|
|
||
| void commit(const std::string& undoLabel, std::function<void()> doEdit) override; | ||
| bool isLocalEditInFlight() const override { return _inFlightCount > 0; } | ||
|
|
||
| private: | ||
| std::vector<PXR_NS::UsdStageRefPtr> _stages; | ||
| int _inFlightCount { 0 }; | ||
| }; | ||
|
|
||
| } // namespace MayaUsdRenderSetup | ||
|
|
||
| #endif // MAYAUSDUI_USD_RENDERSETUP_MAYAEDITCOMMITTER_H |
This file contains hidden or 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 hidden or 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,66 @@ | ||
| // | ||
| // Copyright 2026 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 MAYAUSDUI_UNDO_CHUNK_UTILS_H | ||
| #define MAYAUSDUI_UNDO_CHUNK_UTILS_H | ||
|
|
||
| #include <maya/MGlobal.h> | ||
| #include <maya/MString.h> | ||
|
|
||
| #include <QtCore/QLatin1String> | ||
| #include <QtCore/QString> | ||
|
|
||
| #include <string> | ||
|
|
||
| namespace MayaUsdUI { | ||
|
|
||
| //! Sanitizes a user-facing undo label for use as a Maya undo chunk name. | ||
| //! Maya's -chunkName flag does not accept spaces; backslash and double-quote | ||
| //! are escaped so the result is safe to embed in a MEL double-quoted string. | ||
| inline MString cleanChunkName(const std::string& label) | ||
| { | ||
| QString name = QString::fromStdString(label); | ||
| name.replace(QLatin1Char('\\'), QLatin1String("\\\\")); | ||
| name.replace(QLatin1Char('"'), QLatin1String("\\\"")); | ||
| name.replace(QLatin1Char(' '), QLatin1Char('_')); | ||
| return MString(("\"" + name.toStdString() + "\"").c_str()); | ||
| } | ||
|
|
||
| //! RAII guard that opens a named Maya undo chunk on construction and closes it | ||
| //! on destruction, ensuring the chunk is always balanced even if an exception | ||
| //! is thrown inside the guarded scope. | ||
| struct UndoChunkGuard | ||
| { | ||
| //! Opens the undo chunk. If \p label is empty, no chunk name is set. | ||
| explicit UndoChunkGuard(const std::string& label) | ||
| { | ||
| if (label.empty()) { | ||
| MGlobal::executeCommand("undoInfo -openChunk", false, false); | ||
| } else { | ||
| MGlobal::executeCommand( | ||
| MString("undoInfo -openChunk -chunkName ") + cleanChunkName(label), false, false); | ||
| } | ||
| } | ||
|
|
||
| ~UndoChunkGuard() { MGlobal::executeCommand("undoInfo -closeChunk", false, false); } | ||
|
|
||
| UndoChunkGuard(const UndoChunkGuard&) = delete; | ||
| UndoChunkGuard& operator=(const UndoChunkGuard&) = delete; | ||
| }; | ||
|
|
||
| } // namespace MayaUsdUI | ||
|
|
||
| #endif // MAYAUSDUI_UNDO_CHUNK_UTILS_H |
This file contains hidden or 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 hidden or 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,36 @@ | ||
| // | ||
| // Copyright 2026 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 "UsdLabeledEditUndoableCommand.h" | ||
|
|
||
| namespace USDUFE_NS_DEF { | ||
|
|
||
| UsdLabeledEditUndoableCommand::UsdLabeledEditUndoableCommand( | ||
| std::string label, | ||
| std::function<void()> edit) | ||
| : _label(std::move(label)) | ||
| , _edit(std::move(edit)) | ||
| { | ||
| } | ||
|
|
||
| void UsdLabeledEditUndoableCommand::executeImplementation() | ||
| { | ||
| if (_edit) { | ||
| _edit(); | ||
| } | ||
| } | ||
|
|
||
| } // namespace USDUFE_NS_DEF |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.