Skip to content
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

MAYA-125918 auto re-edit when merging a Maya Ref #2762

Merged
merged 6 commits into from
Dec 13, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/mayaUsd/fileio/primUpdaterContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
//
#include "primUpdaterContext.h"

#include <memory>

PXR_NAMESPACE_OPEN_SCOPE

UsdMayaPrimUpdaterContext::UsdMayaPrimUpdaterContext(
Expand All @@ -28,6 +30,7 @@ UsdMayaPrimUpdaterContext::UsdMayaPrimUpdaterContext(
, _pathMap(pathMap)
, _userArgs(userArgs)
, _args(UsdMayaPrimUpdaterArgs::createFromDictionary(userArgs))
, _additionalCommands(std::make_shared<Ufe::CompositeUndoableCommand>())
{
}

Expand All @@ -41,4 +44,9 @@ MDagPath UsdMayaPrimUpdaterContext::MapSdfPathToDagPath(const SdfPath& sdfPath)
return found == _pathMap->end() ? MDagPath() : found->second;
}

void UsdMayaPrimUpdaterContext::SetUsdPathToDagPathMap(const UsdPathToDagPathMapPtr& pathMap)
{
_pathMap = pathMap;
}

PXR_NAMESPACE_CLOSE_SCOPE
20 changes: 17 additions & 3 deletions lib/mayaUsd/fileio/primUpdaterContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <pxr/usd/usd/timeCode.h>

#include <maya/MDagPath.h>
#include <ufe/undoableCommand.h>

#include <memory> // shared_ptr

Expand Down Expand Up @@ -68,16 +69,29 @@ class UsdMayaPrimUpdaterContext
MAYAUSD_CORE_PUBLIC
MDagPath MapSdfPathToDagPath(const SdfPath& sdfPath) const;

/// \brief Sets the USD path to DAG path map.
MAYAUSD_CORE_PUBLIC
void SetUsdPathToDagPathMap(const UsdPathToDagPathMapPtr& pathMap);

/// \brief Returns the UFE composite command that can be extended and will be executed when
/// the pull or push have completed successfully.
const std::shared_ptr<Ufe::CompositeUndoableCommand>& GetAdditionalFinalCommands() const
{
return _additionalCommands;
}

const MayaUsd::ufe::ReplicateExtrasFromUSD _pullExtras;
const MayaUsd::ufe::ReplicateExtrasToUSD _pushExtras;

private:
const UsdTimeCode& _timeCode;
const UsdStageRefPtr _stage;
const UsdPathToDagPathMapPtr _pathMap;
const UsdTimeCode& _timeCode;
const UsdStageRefPtr _stage;
UsdPathToDagPathMapPtr _pathMap;

const VtDictionary& _userArgs;
const UsdMayaPrimUpdaterArgs _args;

std::shared_ptr<Ufe::CompositeUndoableCommand> _additionalCommands;
};

PXR_NAMESPACE_CLOSE_SCOPE
Expand Down
63 changes: 51 additions & 12 deletions lib/mayaUsd/fileio/primUpdaterManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,14 @@ class PushPullScope
}
}

void end()
{
if (_controllingFlag) {
*_controllingFlag = false;
_controllingFlag = nullptr;
}
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This allows resetting the "in-push-pull" flag early because otherwise it would interfere with the auto-edit mechanism that is triggered by the final additional command when merging to USD a Maya Ref with auto-edit on.

private:
bool* _controllingFlag { nullptr };
};
Expand Down Expand Up @@ -873,6 +881,12 @@ class RemovePullVariantInfoUndoItem : public MayaUsd::OpUndoItem
};
#endif

void executeAdditionalCommands(const UsdMayaPrimUpdaterContext& context)
{
std::shared_ptr<Ufe::CompositeUndoableCommand> cmds = context.GetAdditionalFinalCommands();
UfeCommandUndoItem::execute("Additional final commands", cmds);
}

} // namespace

PXR_NAMESPACE_OPEN_SCOPE
Expand Down Expand Up @@ -922,7 +936,7 @@ bool PrimUpdaterManager::mergeToUsd(
MString progStr(
VtDictionaryIsHolding<std::string>(userArgs, "rn_primName") ? "Caching to USD"
: "Merging to USD");
MayaUsd::ProgressBarScope progressBar(10, progStr);
MayaUsd::ProgressBarScope progressBar(11, progStr);
PushPullScope scopeIt(_inPushPull);

auto ctxArgs = VtDictionaryOver(userArgs, UsdMayaJobExportArgs::GetDefaultDictionary());
Expand Down Expand Up @@ -996,11 +1010,7 @@ bool PrimUpdaterManager::mergeToUsd(
// 2) Traverse the in-memory layer, creating a prim updater for each prim,
// and call Push for each updater. Build a new context with the USD path
// to Maya path mapping information.
UsdMayaPrimUpdaterContext customizeContext(
proxyShape->getTime(),
proxyStage,
ctxArgs,
std::get<UsdPathToDagPathMapPtr>(pushCustomizeSrc));
context.SetUsdPathToDagPathMap(std::get<UsdPathToDagPathMapPtr>(pushCustomizeSrc));

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid re-creating the context since it would interfere with having additional commands. The command would be added in the context, but a new one would be used afterward,,,,

if (!isCopy) {
if (!FunctionUndoItem::execute(
Expand All @@ -1016,7 +1026,7 @@ bool PrimUpdaterManager::mergeToUsd(
}
progressBar.advance();

if (!pushCustomize(pulledPath, pushCustomizeSrc, customizeContext)) {
if (!pushCustomize(pulledPath, pushCustomizeSrc, context)) {
return false;
}
progressBar.advance();
Expand Down Expand Up @@ -1073,6 +1083,10 @@ bool PrimUpdaterManager::mergeToUsd(
}
progressBar.advance();

scopeIt.end();
executeAdditionalCommands(context);
progressBar.advance();

return true;
}

Expand All @@ -1093,7 +1107,7 @@ bool PrimUpdaterManager::editAsMaya(const Ufe::Path& path, const VtDictionary& u
return false;
}

MayaUsd::ProgressBarScope progressBar(6, "Converting to Maya Data");
MayaUsd::ProgressBarScope progressBar(7, "Converting to Maya Data");

PushPullScope scopeIt(_inPushPull);

Expand Down Expand Up @@ -1158,6 +1172,10 @@ bool PrimUpdaterManager::editAsMaya(const Ufe::Path& path, const VtDictionary& u
scene.notify(Ufe::ObjectAdd(ufeItem));
progressBar.advance();

scopeIt.end();
executeAdditionalCommands(context);
progressBar.advance();

return true;
}

Expand Down Expand Up @@ -1218,7 +1236,7 @@ bool PrimUpdaterManager::discardPrimEdits(const Ufe::Path& pulledPath)
return false;
}

MayaUsd::ProgressBarScope progressBar(5);
MayaUsd::ProgressBarScope progressBar(6);
PushPullScope scopeIt(_inPushPull);

// Record all USD modifications in an undo block and item.
Expand Down Expand Up @@ -1310,12 +1328,17 @@ bool PrimUpdaterManager::discardPrimEdits(const Ufe::Path& pulledPath)
scene.notify(Ufe::SubtreeInvalidate(hier->defaultParent()));
}
progressBar.advance();

scopeIt.end();
executeAdditionalCommands(context);
progressBar.advance();

return true;
}

bool PrimUpdaterManager::discardOrphanedEdits(const MDagPath& dagPath, const Ufe::Path& pulledPath)
{
MayaUsd::ProgressBarScope progressBar(2);
MayaUsd::ProgressBarScope progressBar(3);
PushPullScope scopeIt(_inPushPull);

// Unlock the pulled hierarchy, clear the pull information, and remove the
Expand Down Expand Up @@ -1356,6 +1379,10 @@ bool PrimUpdaterManager::discardOrphanedEdits(const MDagPath& dagPath, const Ufe
}
progressBar.advance();

scopeIt.end();
executeAdditionalCommands(context);
progressBar.advance();

return true;
}

Expand Down Expand Up @@ -1401,7 +1428,7 @@ bool PrimUpdaterManager::duplicate(
return false;
}

MayaUsd::ProgressBarScope progressBar(2, "Duplicating to Maya Data");
MayaUsd::ProgressBarScope progressBar(3, "Duplicating to Maya Data");

auto ctxArgs = VtDictionaryOver(userArgs, UsdMayaJobImportArgs::GetDefaultDictionary());

Expand All @@ -1427,6 +1454,11 @@ bool PrimUpdaterManager::duplicate(

pullImport(srcPath, srcPrim, context);
progressBar.advance();

scopeIt.end();
executeAdditionalCommands(context);
progressBar.advance();

return true;
}
// Copy from DG to USD
Expand All @@ -1437,7 +1469,7 @@ bool PrimUpdaterManager::duplicate(
return false;
}

MayaUsd::ProgressBarScope progressBar(7, "Duplicating to USD");
MayaUsd::ProgressBarScope progressBar(8, "Duplicating to USD");

auto ctxArgs = VtDictionaryOver(userArgs, UsdMayaJobExportArgs::GetDefaultDictionary());

Expand Down Expand Up @@ -1494,6 +1526,11 @@ bool PrimUpdaterManager::duplicate(
Ufe::Scene::instance().notify(Ufe::SubtreeInvalidate(ufeItem));
}
progressBar.advance();

scopeIt.end();
executeAdditionalCommands(context);
progressBar.advance();

return true;
}

Expand Down Expand Up @@ -1573,6 +1610,8 @@ void PrimUpdaterManager::onProxyContentChanged(
}
}
}

executeAdditionalCommands(context);
}

PrimUpdaterManager& PrimUpdaterManager::getInstance()
Expand Down
5 changes: 5 additions & 0 deletions lib/mayaUsd/python/wrapPrimUpdater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,10 @@ void wrapPrimUpdaterContext()
"GetArgs",
&UsdMayaPrimUpdaterContext::GetArgs,
boost::python::return_internal_reference<>())
.def(
"GetAdditionalFinalCommands",
&UsdMayaPrimUpdaterContext::GetAdditionalFinalCommands,
boost::python::return_internal_reference<>())
.def("MapSdfPathToDagPath", &UsdMayaPrimUpdaterContext::MapSdfPathToDagPath);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, calling this currently fails in Python because UFE does not expose the UndoableCommand and CompositeUndoableCommand to Python. Not a blocker until someone wants to add additional commands from aprim updater in Python.

}

Expand Down Expand Up @@ -289,6 +293,7 @@ void wrapPrimUpdater()
boost::python::return_value_policy<boost::python::return_by_value>())
.def("getUfePath", &This::getUfePath, boost::python::return_internal_reference<>())
.def("getUsdPrim", &This::getUsdPrim)
.def("getContext", &This::getContext, boost::python::return_internal_reference<>())
.def("isAnimated", &This::isAnimated)
.staticmethod("isAnimated")
.def("Register", &PrimUpdaterWrapper::Register)
Expand Down
4 changes: 4 additions & 0 deletions lib/mayaUsd/ufe/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ target_sources(${PROJECT_NAME}
ProxyShapeHandler.cpp
ProxyShapeHierarchy.cpp
ProxyShapeHierarchyHandler.cpp
SetVariantSelectionCommand.cpp
StagesSubject.cpp
UsdHierarchy.cpp
UsdHierarchyHandler.cpp
Expand Down Expand Up @@ -74,6 +75,7 @@ if(CMAKE_UFE_V3_FEATURES_AVAILABLE)
target_sources(${PROJECT_NAME}
PRIVATE
# See MayaUIInfoHandler.h comments.
EditAsMayaCommand.cpp
MayaUIInfoHandler.cpp
PulledObjectHierarchy.cpp
PulledObjectHierarchyHandler.cpp
Expand Down Expand Up @@ -202,6 +204,7 @@ set(HEADERS
ProxyShapeHandler.h
ProxyShapeHierarchy.h
ProxyShapeHierarchyHandler.h
SetVariantSelectionCommand.h
StagesSubject.h
UsdHierarchy.h
UsdHierarchyHandler.h
Expand Down Expand Up @@ -270,6 +273,7 @@ if(CMAKE_UFE_V3_FEATURES_AVAILABLE)
list(APPEND HEADERS
# Not dependent on UFE v3, but used to draw orphaned pulled Maya nodes
# in the Outliner, which is a UFE v3 feature.
EditAsMayaCommand.h
MayaUIInfoHandler.h
PulledObjectHierarchy.h
PulledObjectHierarchyHandler.h
Expand Down
60 changes: 60 additions & 0 deletions lib/mayaUsd/ufe/EditAsMayaCommand.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
//
// Copyright 2022 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 "EditAsMayaCommand.h"

#include <mayaUsd/fileio/primUpdaterManager.h>
#include <mayaUsd/undo/OpUndoItemRecorder.h>

PXR_NAMESPACE_USING_DIRECTIVE

namespace MAYAUSD_NS_DEF {
namespace ufe {

EditAsMayaUfeCommand::Ptr EditAsMayaUfeCommand::create(const Ufe::Path& path)
{
return std::make_shared<ufe::EditAsMayaUfeCommand>(path);
}

EditAsMayaUfeCommand::EditAsMayaUfeCommand(const Ufe::Path& path)
: _path(path)
{
}

EditAsMayaUfeCommand::~EditAsMayaUfeCommand() { }

void EditAsMayaUfeCommand::execute()
{
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In case you're wondering: there was already a EditAsMayaCommand class... but it is a Maya Command (MPxCommand) not a UFE command (Ufe::UndoableCommand). So I had to use a more specific name to disambiguate.

bool status = false;

// Scope the undo item recording so we can undo on failure.
{
OpUndoItemRecorder undoRecorder(_undoItemList);

auto& manager = PXR_NS::PrimUpdaterManager::getInstance();
status = manager.editAsMaya(_path);
}

// Undo potentially partially-made edit-as-Maya on failure.
if (!status)
_undoItemList.undo();
}

void EditAsMayaUfeCommand::undo() { _undoItemList.redo(); }

void EditAsMayaUfeCommand::redo() { _undoItemList.redo(); }

} // namespace ufe
} // namespace MAYAUSD_NS_DEF
Loading