Skip to content

Commit

Permalink
Merge pull request #3102 from Autodesk/bailp/MAYA-128513/composite-co…
Browse files Browse the repository at this point in the history
…mmand-handler

MAYA-128513 implement code wrapper handler
  • Loading branch information
seando-adsk authored Jun 1, 2023
2 parents 52fd3e8 + 6795467 commit 4994a90
Show file tree
Hide file tree
Showing 15 changed files with 441 additions and 108 deletions.
5 changes: 5 additions & 0 deletions cmake/modules/FindUFE.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ if (UFE_INCLUDE_DIR AND EXISTS "${UFE_INCLUDE_DIR}/ufe/batchOpsHandler.h")
list(APPEND UFE_PREVIEW_FEATURES v4_BatchOps)
endif()

if(UFE_INCLUDE_DIR AND EXISTS "${UFE_INCLUDE_DIR}/ufe/codeWrapperHandler.h")
list(APPEND UFE_PREVIEW_FEATURES CodeWrapperHandler)
message(STATUS "Maya has UFE code wrapper API")
endif()

# Handle the QUIETLY and REQUIRED arguments and set UFE_FOUND to TRUE if
# all listed variables are TRUE.
include(FindPackageHandleStandardArgs)
Expand Down
19 changes: 19 additions & 0 deletions lib/mayaUsd/ufe/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,19 @@ if (v4_BatchOps IN_LIST UFE_PREVIEW_FEATURES)
)
endif()

if(CodeWrapperHandler IN_LIST UFE_PREVIEW_FEATURES)
message(STATUS "UFE_PREVIEW has composite command handler support")
target_sources(${PROJECT_NAME}
PRIVATE
UsdCodeWrapperHandler.cpp
)

target_compile_definitions(${PROJECT_NAME}
PRIVATE
UFE_PREVIEW_CODE_WRAPPER_HANDLER_SUPPORT=1
)
endif()

if(CMAKE_UFE_V4_FEATURES_AVAILABLE)
target_sources(${PROJECT_NAME}
PRIVATE
Expand Down Expand Up @@ -270,6 +283,12 @@ if (v4_BatchOps IN_LIST UFE_PREVIEW_FEATURES)
)
endif()

if(CodeWrapperHandler IN_LIST UFE_PREVIEW_FEATURES)
list(APPEND HEADERS
UsdCodeWrapperHandler.h
)
endif()

if(CMAKE_UFE_V4_FEATURES_AVAILABLE)
list(APPEND HEADERS
UsdShaderNodeDef.h
Expand Down
36 changes: 30 additions & 6 deletions lib/mayaUsd/ufe/Global.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <mayaUsd/ufe/UsdSceneItemOpsHandler.h>
#include <mayaUsd/ufe/UsdTransform3dHandler.h>
#include <mayaUsd/ufe/Utils.h>

#ifdef UFE_V2_FEATURES_AVAILABLE
#include <mayaUsd/ufe/ProxyShapeContextOpsHandler.h>
#include <mayaUsd/ufe/UsdAttributesHandler.h>
Expand All @@ -37,29 +38,40 @@
#include <mayaUsd/ufe/UsdUIInfoHandler.h>
#include <mayaUsd/ufe/UsdUIUfeObserver.h>
#endif

#ifdef UFE_V3_FEATURES_AVAILABLE
#define HAVE_PATH_MAPPING
#include <mayaUsd/ufe/MayaUIInfoHandler.h>
#include <mayaUsd/ufe/MayaUsdHierarchyHandler.h>
#include <mayaUsd/ufe/PulledObjectHierarchyHandler.h>
#include <mayaUsd/ufe/UsdPathMappingHandler.h>
#endif

#if UFE_LIGHTS_SUPPORT
#include <mayaUsd/ufe/UsdLightHandler.h>
#endif

#if UFE_MATERIALS_SUPPORT
#include <mayaUsd/ufe/UsdMaterialHandler.h>
#endif

#ifdef UFE_V4_FEATURES_AVAILABLE
#include <mayaUsd/ufe/ProxyShapeCameraHandler.h>
#include <mayaUsd/ufe/UsdConnectionHandler.h>
#include <mayaUsd/ufe/UsdShaderNodeDefHandler.h>
#include <mayaUsd/ufe/UsdTransform3dRead.h>
#include <mayaUsd/ufe/UsdUINodeGraphNodeHandler.h>

#if UFE_PREVIEW_BATCHOPS_SUPPORT
#include <mayaUsd/ufe/UsdBatchOpsHandler.h>
#endif
#include <mayaUsd/ufe/ProxyShapeCameraHandler.h>
#include <mayaUsd/ufe/UsdShaderNodeDefHandler.h>

#endif

#ifdef UFE_PREVIEW_CODE_WRAPPER_HANDLER_SUPPORT
#include <mayaUsd/ufe/UsdCodeWrapperHandler.h>
#endif

#if UFE_SCENE_SEGMENT_SUPPORT
#include <mayaUsd/ufe/ProxyShapeSceneSegmentHandler.h>
#endif
Expand All @@ -72,6 +84,7 @@
#include <maya/MSceneMessage.h>
#include <ufe/hierarchyHandler.h>
#include <ufe/runTimeMgr.h>

#ifdef UFE_V2_FEATURES_AVAILABLE
#include <ufe/pathString.h>
#endif
Expand Down Expand Up @@ -187,20 +200,28 @@ MStatus initialize()
handlers.contextOpsHandler = UsdContextOpsHandler::create();
handlers.uiInfoHandler = UsdUIInfoHandler::create();
handlers.cameraHandler = UsdCameraHandler::create();

#ifdef UFE_V4_FEATURES_AVAILABLE

#if UFE_LIGHTS_SUPPORT
handlers.lightHandler = UsdLightHandler::create();
#endif

#if UFE_MATERIALS_SUPPORT
handlers.materialHandler = UsdMaterialHandler::create();
#endif
handlers.connectionHandler = UsdConnectionHandler::create();
handlers.uiNodeGraphNodeHandler = UsdUINodeGraphNodeHandler::create();
#if UFE_PREVIEW_BATCHOPS_SUPPORT

#ifdef UFE_PREVIEW_CODE_WRAPPER_HANDLER_SUPPORT
handlers.batchOpsHandler = UsdCodeWrapperHandler::create();
#elif UFE_PREVIEW_BATCHOPS_SUPPORT
handlers.batchOpsHandler = UsdBatchOpsHandler::create();
#endif

handlers.nodeDefHandler = UsdShaderNodeDefHandler::create();
#endif

#endif /* UFE_V4_FEATURES_AVAILABLE */

#if UFE_SCENE_SEGMENT_SUPPORT
// set up the SceneSegmentHandler
Expand All @@ -209,6 +230,7 @@ MStatus initialize()
= ProxyShapeSceneSegmentHandler::create(g_MayaSceneSegmentHandler);
runTimeMgr.setSceneSegmentHandler(g_MayaRtid, proxyShapeSceneSegmentHandler);
#endif

#ifdef UFE_V4_FEATURES_AVAILABLE
// set up the ProxyShapeCameraHandler
g_MayaCameraHandler = runTimeMgr.cameraHandler(g_MayaRtid);
Expand Down Expand Up @@ -281,13 +303,15 @@ MStatus initialize()
MayaUsd::ufe::UsdUIUfeObserver::create();

#ifndef UFE_V4_FEATURES_AVAILABLE

#if UFE_LIGHTS_SUPPORT
runTimeMgr.setLightHandler(usdRtid, UsdLightHandler::create());
#endif
#if UFE_MATERIALS_SUPPORT
runTimeMgr.setMaterialHandler(usdRtid, UsdMaterialHandler::create());
#endif
#endif

#endif /* UFE_V4_FEATURES_AVAILABLE */

#ifdef HAVE_PATH_MAPPING
g_MayaPathMappingHandler = runTimeMgr.pathMappingHandler(g_MayaRtid);
Expand All @@ -300,7 +324,7 @@ MStatus initialize()
runTimeMgr.setUIInfoHandler(g_MayaRtid, uiInfoHandler);
#endif

#endif
#endif /* UFE_V2_FEATURES_AVAILABLE */

#if !defined(NDEBUG)
assert(usdRtid != 0);
Expand Down
5 changes: 1 addition & 4 deletions lib/mayaUsd/ufe/UsdBatchOpsHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@
namespace MAYAUSD_NS_DEF {
namespace ufe {

UsdBatchOpsHandler::UsdBatchOpsHandler()
: Ufe::BatchOpsHandler()
{
}
UsdBatchOpsHandler::UsdBatchOpsHandler() { }

UsdBatchOpsHandler::~UsdBatchOpsHandler() { }

Expand Down
8 changes: 8 additions & 0 deletions lib/mayaUsd/ufe/UsdBatchOpsHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,21 @@
#include <pxr/usd/sdf/types.h>
#include <pxr/usd/usd/stage.h>

#ifdef UFE_PREVIEW_CODE_WRAPPER_HANDLER_SUPPORT
#include <ufe/codeWrapperHandler.h>
#else
#include <ufe/batchOpsHandler.h>
#endif

namespace MAYAUSD_NS_DEF {
namespace ufe {

//! \brief Interface to create a UsdBatchOpsHandler interface object.
#ifdef UFE_PREVIEW_CODE_WRAPPER_HANDLER_SUPPORT
class MAYAUSD_CORE_PUBLIC UsdBatchOpsHandler : public Ufe::CodeWrapperHandler
#else
class MAYAUSD_CORE_PUBLIC UsdBatchOpsHandler : public Ufe::BatchOpsHandler
#endif
{
public:
typedef std::shared_ptr<UsdBatchOpsHandler> Ptr;
Expand Down
96 changes: 96 additions & 0 deletions lib/mayaUsd/ufe/UsdCodeWrapperHandler.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
//
// Copyright 2023 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 "UsdCodeWrapperHandler.h"

#include <UsdUfe/ufe/UsdSceneItem.h>
#include <UsdUfe/utils/editRouterContext.h>

#include <ufe/selection.h>

namespace {

// A code wrapper that does edit routing for a command name by its operation.
// The edit routing decision is cached after the first sub-operation and is
// reused in subsequent sub-operations. This ensures the same edit routing is
// used during a command execution and during undo and redo.
//
// Note: the code wrapper is the same for the command execute, undo and redo,
// so we don't need the sub-operation name.
class UsdEditRoutingCodeWrapper : public Ufe::CodeWrapper
{
public:
UsdEditRoutingCodeWrapper(const Ufe::Selection& selection, const std::string& operationName)
: _prim(findPrimInSelection(selection))
, _operationName(PXR_NS::TfToken(operationName))
{
}

void prelude(const std::string& /* subOperation */) override
{
if (_alreadyRouted) {
_editRouterContext = std::make_unique<OperationEditRouterContext>(_stage, _layer);
} else {
_editRouterContext
= std::make_unique<OperationEditRouterContext>(_operationName, _prim);
_stage = _editRouterContext->getStage();
_layer = _editRouterContext->getLayer();
_alreadyRouted = true;
}
}

void cleanup(const std::string& /* subOperation */) override { _editRouterContext.reset(); }

private:
static PXR_NS::UsdPrim findPrimInSelection(const Ufe::Selection& selection)
{
for (const Ufe::SceneItem::Ptr& item : selection) {
const auto usdItem = std::dynamic_pointer_cast<UsdSceneItem>(item);
if (!usdItem)
continue;
return usdItem->prim();
}

return {};
}

PXR_NS::UsdPrim _prim;
PXR_NS::TfToken _operationName;
bool _alreadyRouted = false;
PXR_NS::UsdStagePtr _stage;
PXR_NS::SdfLayerHandle _layer;
std::unique_ptr<OperationEditRouterContext> _editRouterContext;
};

} // namespace

namespace MAYAUSD_NS_DEF {
namespace ufe {

/*static*/
std::shared_ptr<UsdCodeWrapperHandler> UsdCodeWrapperHandler::create()
{
return std::make_shared<UsdCodeWrapperHandler>();
}

Ufe::CodeWrapper::Ptr UsdCodeWrapperHandler::createCodeWrapper(
const Ufe::Selection& selection,
const std::string& operationName)
{
return std::make_unique<UsdEditRoutingCodeWrapper>(selection, operationName);
}

} // namespace ufe
} // namespace MAYAUSD_NS_DEF
42 changes: 42 additions & 0 deletions lib/mayaUsd/ufe/UsdCodeWrapperHandler.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//
// Copyright 2023 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 MAYA_USD_CODE_WRAPPER_HANDLER_H
#define MAYA_USD_CODE_WRAPPER_HANDLER_H

#include <mayaUsd/ufe/UsdBatchOpsHandler.h>

#include <ufe/codeWrapperHandler.h>

namespace MAYAUSD_NS_DEF {
namespace ufe {

//! \brief Interface to create a UsdCodeWrapperHandler interface object.
class MAYAUSD_CORE_PUBLIC UsdCodeWrapperHandler : public UsdBatchOpsHandler
{
public:
//! Create a UsdCodeWrapperHandler.
static std::shared_ptr<UsdCodeWrapperHandler> create();

protected:
// Ufe::CodeWrapperHandler overrides.
Ufe::CodeWrapper::Ptr
createCodeWrapper(const Ufe::Selection& selection, const std::string& operationName) override;
}; // UsdCodeWrapperHandler

} // namespace ufe
} // namespace MAYAUSD_NS_DEF

#endif /* MAYA_USD_CODE_WRAPPER_HANDLER_H */
Loading

0 comments on commit 4994a90

Please sign in to comment.