From 0de74df934381f7b3f6844e88d21d28c210ecdb1 Mon Sep 17 00:00:00 2001 From: Jonathan Feldstein Date: Thu, 28 Jul 2022 14:00:33 -0400 Subject: [PATCH 1/6] LOOKDEVX-683 | UsdUINodeGraphNode implementation. --- lib/mayaUsd/ufe/CMakeLists.txt | 15 +++ lib/mayaUsd/ufe/Global.cpp | 6 ++ lib/mayaUsd/ufe/UsdUINodeGraphNode.cpp | 102 ++++++++++++++++++ lib/mayaUsd/ufe/UsdUINodeGraphNode.h | 53 +++++++++ lib/mayaUsd/ufe/UsdUINodeGraphNodeHandler.cpp | 30 ++++++ lib/mayaUsd/ufe/UsdUINodeGraphNodeHandler.h | 46 ++++++++ 6 files changed, 252 insertions(+) create mode 100644 lib/mayaUsd/ufe/UsdUINodeGraphNode.cpp create mode 100644 lib/mayaUsd/ufe/UsdUINodeGraphNode.h create mode 100644 lib/mayaUsd/ufe/UsdUINodeGraphNodeHandler.cpp create mode 100644 lib/mayaUsd/ufe/UsdUINodeGraphNodeHandler.h diff --git a/lib/mayaUsd/ufe/CMakeLists.txt b/lib/mayaUsd/ufe/CMakeLists.txt index 148455bc2a..4f6a462e38 100644 --- a/lib/mayaUsd/ufe/CMakeLists.txt +++ b/lib/mayaUsd/ufe/CMakeLists.txt @@ -138,6 +138,14 @@ if(CMAKE_UFE_V4_FEATURES_AVAILABLE) UsdConnectionHandler.cpp ) endif() + + if (${UFE_PREVIEW_VERSION_NUM} GREATER_EQUAL 4023) + target_sources(${PROJECT_NAME} + PRIVATE + UsdUINodeGraphNode.cpp + UsdUINodeGraphNodeHandler.cpp + ) + endif() endif() if(PXR_VERSION GREATER_EQUAL 2108) @@ -266,6 +274,13 @@ if(CMAKE_UFE_V4_FEATURES_AVAILABLE) UsdConnectionHandler.h ) endif() + + if (${UFE_PREVIEW_VERSION_NUM} GREATER_EQUAL 4023) + list(APPEND HEADERS + UsdUINodeGraphNode.h + UsdUINodeGraphNodeHandler.h + ) + endif() endif() if(PXR_VERSION GREATER_EQUAL 2108) diff --git a/lib/mayaUsd/ufe/Global.cpp b/lib/mayaUsd/ufe/Global.cpp index a5ed633682..1b524732f7 100644 --- a/lib/mayaUsd/ufe/Global.cpp +++ b/lib/mayaUsd/ufe/Global.cpp @@ -51,6 +51,9 @@ #if (UFE_PREVIEW_VERSION_NUM >= 4020) #include #endif +#if (UFE_PREVIEW_VERSION_NUM >= 4023) +#include +#endif #if (UFE_PREVIEW_VERSION_NUM >= 4001) #include #endif @@ -190,6 +193,9 @@ MStatus initialize() #if (UFE_PREVIEW_VERSION_NUM >= 4020) handlers.connectionHandler = UsdConnectionHandler::create(); #endif +#if (UFE_PREVIEW_VERSION_NUM >= 4023) + handlers.uiNodeGraphNodeHandler = UsdUINodeGraphNodeHandler::create(); +#endif #if (UFE_PREVIEW_VERSION_NUM >= 4001) handlers.nodeDefHandler = UsdShaderNodeDefHandler::create(); #endif diff --git a/lib/mayaUsd/ufe/UsdUINodeGraphNode.cpp b/lib/mayaUsd/ufe/UsdUINodeGraphNode.cpp new file mode 100644 index 0000000000..920e4ae139 --- /dev/null +++ b/lib/mayaUsd/ufe/UsdUINodeGraphNode.cpp @@ -0,0 +1,102 @@ +// ======================================================================= +// Copyright 2022 Autodesk, Inc. All rights reserved. +// +// This computer source code and related instructions and comments are the +// unpublished confidential and proprietary information of Autodesk, Inc. +// and are protected under applicable copyright and trade secret law. They +// may not be disclosed to, copied or used by any third party without the +// prior written consent of Autodesk, Inc. +// ======================================================================= + +#include "UsdUINodeGraphNode.h" + +#include + +namespace MAYAUSD_NS_DEF { +namespace ufe { + +class SetPositionCommand : public Ufe::UndoableCommand +{ +public: + SetPositionCommand( + UsdSceneItem::Ptr& sceneItem, + const Ufe::Vector2f& newPos) + : _sceneItem(sceneItem) + , _newPos(PXR_NS::GfVec2f(newPos.x(), newPos.y())) + { + } + + void execute() override { + const PXR_NS::UsdPrim prim = _sceneItem->prim(); + if (!prim.HasAPI() + && PXR_NS::UsdUINodeGraphNodeAPI::CanApply(prim)) { + PXR_NS::UsdUINodeGraphNodeAPI::Apply(prim); + } + if (prim.HasAPI()) { + PXR_NS::UsdUINodeGraphNodeAPI posApi(prim); + PXR_NS::UsdAttribute attr = posApi.GetPosAttr(); + if (!attr) { + attr = posApi.CreatePosAttr(); + } + attr.Set(_newPos); + } + } + + void undo() override {} + void redo() override {} + +private: + UsdSceneItem::Ptr _sceneItem; + const PXR_NS::VtValue _newPos; +}; + +UsdUINodeGraphNode::UsdUINodeGraphNode(const UsdSceneItem::Ptr& item) + : Ufe::UINodeGraphNode() + , fItem(item) +{ +} + +UsdUINodeGraphNode::Ptr UsdUINodeGraphNode::create(const UsdSceneItem::Ptr& item) +{ + return std::make_shared(item); +} + +Ufe::SceneItem::Ptr UsdUINodeGraphNode::sceneItem() const +{ + return fItem; +} + +bool UsdUINodeGraphNode::hasPosition() const +{ + const PXR_NS::UsdPrim prim = fItem->prim(); + if (prim.HasAPI()) + { + PXR_NS::UsdUINodeGraphNodeAPI posApi(prim); + PXR_NS::UsdAttribute attr = posApi.GetPosAttr(); + return attr.IsValid(); + } + return false; +} + +Ufe::Vector2f UsdUINodeGraphNode::getPosition() const +{ + if (hasPosition()) { + const PXR_NS::UsdPrim prim = fItem->prim(); + const PXR_NS::UsdUINodeGraphNodeAPI posApi(prim); + const PXR_NS::UsdAttribute attr = posApi.GetPosAttr(); + PXR_NS::VtValue v; + attr.Get(&v); + const PXR_NS::GfVec2f pos = v.Get(); + return Ufe::Vector2f(pos[0], pos[1]); + } else { + return Ufe::Vector2f(0.0f, 0.0f); + } +} + +Ufe::UndoableCommand::Ptr UsdUINodeGraphNode::setPositionCmd(const Ufe::Vector2f& pos) +{ + return std::make_shared(fItem, pos); +} + +} // namespace ufe +} // namespace MAYAUSD_NS_DEF diff --git a/lib/mayaUsd/ufe/UsdUINodeGraphNode.h b/lib/mayaUsd/ufe/UsdUINodeGraphNode.h new file mode 100644 index 0000000000..1b853f45ce --- /dev/null +++ b/lib/mayaUsd/ufe/UsdUINodeGraphNode.h @@ -0,0 +1,53 @@ +#ifndef USDUINODEGRAPHNODE_H +#define USDUINODEGRAPHNODE_H + +// ======================================================================= +// Copyright 2022 Autodesk, Inc. All rights reserved. +// +// This computer source code and related instructions and comments are the +// unpublished confidential and proprietary information of Autodesk, Inc. +// and are protected under applicable copyright and trade secret law. They +// may not be disclosed to, copied or used by any third party without the +// prior written consent of Autodesk, Inc. +// ======================================================================= + +#include + +#include + +#include "UsdSceneItem.h" + +namespace MAYAUSD_NS_DEF { +namespace ufe { + +//! \brief Implementation of Ufe::UINodeGraphNode interface for USD objects. +class MAYAUSD_CORE_PUBLIC UsdUINodeGraphNode : public Ufe::UINodeGraphNode +{ +public: + typedef std::shared_ptr Ptr; + + UsdUINodeGraphNode(const UsdSceneItem::Ptr& item); + ~UsdUINodeGraphNode() override = default; + + UsdUINodeGraphNode(const UsdUINodeGraphNode&) = delete; + UsdUINodeGraphNode& operator=(const UsdUINodeGraphNode&) = delete; + UsdUINodeGraphNode(UsdUINodeGraphNode&&) = delete; + UsdUINodeGraphNode& operator=(UsdUINodeGraphNode&&) = delete; + + //! Create a UsdUINodeGraphNode. + static UsdUINodeGraphNode::Ptr create(const UsdSceneItem::Ptr& item); + + // Ufe::UsdUINodeGraphNode overrides + Ufe::SceneItem::Ptr sceneItem() const override; + bool hasPosition() const override; + Ufe::Vector2f getPosition() const override; + Ufe::UndoableCommand::Ptr setPositionCmd(const Ufe::Vector2f& pos) override; + +private: + UsdSceneItem::Ptr fItem; +}; + +} // namespace ufe +} // namespace MAYAUSD_NS_DEF + +#endif // USDUINODEGRAPHNODE_H diff --git a/lib/mayaUsd/ufe/UsdUINodeGraphNodeHandler.cpp b/lib/mayaUsd/ufe/UsdUINodeGraphNodeHandler.cpp new file mode 100644 index 0000000000..0b0a3feaf1 --- /dev/null +++ b/lib/mayaUsd/ufe/UsdUINodeGraphNodeHandler.cpp @@ -0,0 +1,30 @@ +// =========================================================================== +// Copyright 2022 Autodesk, Inc. All rights reserved. +// +// Use of this software is subject to the terms of the Autodesk license +// agreement provided at the time of installation or download, or which +// otherwise accompanies this software in either electronic or hard copy form. +// =========================================================================== + +#include "UsdUINodeGraphNodeHandler.h" + +#include "UsdUINodeGraphNode.h" + +namespace MAYAUSD_NS_DEF { +namespace ufe { + +UsdUINodeGraphNodeHandler::Ptr UsdUINodeGraphNodeHandler::create() +{ + return std::make_shared(); +} + +Ufe::UINodeGraphNode::Ptr UsdUINodeGraphNodeHandler::uiNodeGraphNode(const Ufe::SceneItem::Ptr& item) const +{ + PXR_NAMESPACE_USING_DIRECTIVE + UsdSceneItem::Ptr usdItem = std::dynamic_pointer_cast(item); + TF_VERIFY(usdItem); + + return UsdUINodeGraphNode::create(usdItem);} + +} // namespace ufe +} // namespace MAYAUSD_NS_DEF diff --git a/lib/mayaUsd/ufe/UsdUINodeGraphNodeHandler.h b/lib/mayaUsd/ufe/UsdUINodeGraphNodeHandler.h new file mode 100644 index 0000000000..f85087dea1 --- /dev/null +++ b/lib/mayaUsd/ufe/UsdUINodeGraphNodeHandler.h @@ -0,0 +1,46 @@ +#ifndef USDUINODEGRAPHNODEHANDLER_H +#define USDUINODEGRAPHNODEHANDLER_H + +// =========================================================================== +// Copyright 2022 Autodesk, Inc. All rights reserved. +// +// Use of this software is subject to the terms of the Autodesk license +// agreement provided at the time of installation or download, or which +// otherwise accompanies this software in either electronic or hard copy form. +// =========================================================================== + +#include + +#include + +#include "UsdSceneItem.h" + +namespace MAYAUSD_NS_DEF { +namespace ufe { + +//! \brief Implementation of Ufe::UINodeGraphNodeHandler interface for USD objects. +class MAYAUSD_CORE_PUBLIC UsdUINodeGraphNodeHandler : public Ufe::UINodeGraphNodeHandler +{ +public: + typedef std::shared_ptr Ptr; + + UsdUINodeGraphNodeHandler() = default; + ~UsdUINodeGraphNodeHandler() override = default; + + // Delete the copy/move constructors assignment operators. + UsdUINodeGraphNodeHandler(const UsdUINodeGraphNodeHandler&) = delete; + UsdUINodeGraphNodeHandler& operator=(const UsdUINodeGraphNodeHandler&) = delete; + UsdUINodeGraphNodeHandler(UsdUINodeGraphNodeHandler&&) = delete; + UsdUINodeGraphNodeHandler& operator=(UsdUINodeGraphNodeHandler&&) = delete; + + //! Create a UsdUINodeGraphNodeHandler. + static UsdUINodeGraphNodeHandler::Ptr create(); + + // Ufe::UINodeGraphNodeHandler overrides + Ufe::UINodeGraphNode::Ptr uiNodeGraphNode(const Ufe::SceneItem::Ptr& item) const override; +}; + +} // namespace ufe +} // namespace MAYAUSD_NS_DEF + +#endif /* USDUINODEGRAPHNODEHANDLER_H */ From 290b7531deca358368df8dfd65c11e02c94eb9c7 Mon Sep 17 00:00:00 2001 From: Jonathan Feldstein Date: Thu, 28 Jul 2022 15:19:44 -0400 Subject: [PATCH 2/6] LOOKDEVX-683 | Fixed formatting and applied code review feedback. --- lib/mayaUsd/ufe/UsdUINodeGraphNode.cpp | 62 +++++++++---------- lib/mayaUsd/ufe/UsdUINodeGraphNode.h | 10 +-- lib/mayaUsd/ufe/UsdUINodeGraphNodeHandler.cpp | 6 +- lib/mayaUsd/ufe/UsdUINodeGraphNodeHandler.h | 4 +- 4 files changed, 42 insertions(+), 40 deletions(-) diff --git a/lib/mayaUsd/ufe/UsdUINodeGraphNode.cpp b/lib/mayaUsd/ufe/UsdUINodeGraphNode.cpp index 920e4ae139..d24accb88b 100644 --- a/lib/mayaUsd/ufe/UsdUINodeGraphNode.cpp +++ b/lib/mayaUsd/ufe/UsdUINodeGraphNode.cpp @@ -3,8 +3,8 @@ // // This computer source code and related instructions and comments are the // unpublished confidential and proprietary information of Autodesk, Inc. -// and are protected under applicable copyright and trade secret law. They -// may not be disclosed to, copied or used by any third party without the +// and are protected under applicable copyright and trade secret law. They +// may not be disclosed to, copied or used by any third party without the // prior written consent of Autodesk, Inc. // ======================================================================= @@ -18,36 +18,40 @@ namespace ufe { class SetPositionCommand : public Ufe::UndoableCommand { public: - SetPositionCommand( - UsdSceneItem::Ptr& sceneItem, - const Ufe::Vector2f& newPos) - : _sceneItem(sceneItem) + SetPositionCommand(const PXR_NS::UsdPrim& prim, const Ufe::Vector2f& newPos) + : Ufe::UndoableCommand() , _newPos(PXR_NS::GfVec2f(newPos.x(), newPos.y())) { + _stage = prim.GetStage(); + _primPath = prim.GetPath(); } - void execute() override { - const PXR_NS::UsdPrim prim = _sceneItem->prim(); - if (!prim.HasAPI() - && PXR_NS::UsdUINodeGraphNodeAPI::CanApply(prim)) { - PXR_NS::UsdUINodeGraphNodeAPI::Apply(prim); - } - if (prim.HasAPI()) { - PXR_NS::UsdUINodeGraphNodeAPI posApi(prim); - PXR_NS::UsdAttribute attr = posApi.GetPosAttr(); - if (!attr) { - attr = posApi.CreatePosAttr(); + void execute() override + { + if (_stage) { + const PXR_NS::UsdPrim prim = _stage->GetPrimAtPath(_primPath); + if (!prim.HasAPI() + && PXR_NS::UsdUINodeGraphNodeAPI::CanApply(prim)) { + PXR_NS::UsdUINodeGraphNodeAPI::Apply(prim); + } + if (prim.HasAPI()) { + PXR_NS::UsdUINodeGraphNodeAPI posApi(prim); + PXR_NS::UsdAttribute attr = posApi.GetPosAttr(); + if (!attr) { + attr = posApi.CreatePosAttr(); + } + attr.Set(_newPos); } - attr.Set(_newPos); } } - void undo() override {} - void redo() override {} + void undo() override { } + void redo() override { } private: - UsdSceneItem::Ptr _sceneItem; - const PXR_NS::VtValue _newPos; + PXR_NS::UsdStageWeakPtr _stage; + PXR_NS::SdfPath _primPath; + const PXR_NS::VtValue _newPos; }; UsdUINodeGraphNode::UsdUINodeGraphNode(const UsdSceneItem::Ptr& item) @@ -61,16 +65,12 @@ UsdUINodeGraphNode::Ptr UsdUINodeGraphNode::create(const UsdSceneItem::Ptr& item return std::make_shared(item); } -Ufe::SceneItem::Ptr UsdUINodeGraphNode::sceneItem() const -{ - return fItem; -} +Ufe::SceneItem::Ptr UsdUINodeGraphNode::sceneItem() const { return fItem; } bool UsdUINodeGraphNode::hasPosition() const { const PXR_NS::UsdPrim prim = fItem->prim(); - if (prim.HasAPI()) - { + if (prim.HasAPI()) { PXR_NS::UsdUINodeGraphNodeAPI posApi(prim); PXR_NS::UsdAttribute attr = posApi.GetPosAttr(); return attr.IsValid(); @@ -81,10 +81,10 @@ bool UsdUINodeGraphNode::hasPosition() const Ufe::Vector2f UsdUINodeGraphNode::getPosition() const { if (hasPosition()) { - const PXR_NS::UsdPrim prim = fItem->prim(); + const PXR_NS::UsdPrim prim = fItem->prim(); const PXR_NS::UsdUINodeGraphNodeAPI posApi(prim); const PXR_NS::UsdAttribute attr = posApi.GetPosAttr(); - PXR_NS::VtValue v; + PXR_NS::VtValue v; attr.Get(&v); const PXR_NS::GfVec2f pos = v.Get(); return Ufe::Vector2f(pos[0], pos[1]); @@ -95,7 +95,7 @@ Ufe::Vector2f UsdUINodeGraphNode::getPosition() const Ufe::UndoableCommand::Ptr UsdUINodeGraphNode::setPositionCmd(const Ufe::Vector2f& pos) { - return std::make_shared(fItem, pos); + return std::make_shared(fItem ? fItem->prim() : PXR_NS::UsdPrim(), pos); } } // namespace ufe diff --git a/lib/mayaUsd/ufe/UsdUINodeGraphNode.h b/lib/mayaUsd/ufe/UsdUINodeGraphNode.h index 1b853f45ce..14798b4519 100644 --- a/lib/mayaUsd/ufe/UsdUINodeGraphNode.h +++ b/lib/mayaUsd/ufe/UsdUINodeGraphNode.h @@ -11,12 +11,12 @@ // prior written consent of Autodesk, Inc. // ======================================================================= +#include "UsdSceneItem.h" + #include #include -#include "UsdSceneItem.h" - namespace MAYAUSD_NS_DEF { namespace ufe { @@ -38,9 +38,9 @@ class MAYAUSD_CORE_PUBLIC UsdUINodeGraphNode : public Ufe::UINodeGraphNode static UsdUINodeGraphNode::Ptr create(const UsdSceneItem::Ptr& item); // Ufe::UsdUINodeGraphNode overrides - Ufe::SceneItem::Ptr sceneItem() const override; - bool hasPosition() const override; - Ufe::Vector2f getPosition() const override; + Ufe::SceneItem::Ptr sceneItem() const override; + bool hasPosition() const override; + Ufe::Vector2f getPosition() const override; Ufe::UndoableCommand::Ptr setPositionCmd(const Ufe::Vector2f& pos) override; private: diff --git a/lib/mayaUsd/ufe/UsdUINodeGraphNodeHandler.cpp b/lib/mayaUsd/ufe/UsdUINodeGraphNodeHandler.cpp index 0b0a3feaf1..e26e594ce4 100644 --- a/lib/mayaUsd/ufe/UsdUINodeGraphNodeHandler.cpp +++ b/lib/mayaUsd/ufe/UsdUINodeGraphNodeHandler.cpp @@ -18,13 +18,15 @@ UsdUINodeGraphNodeHandler::Ptr UsdUINodeGraphNodeHandler::create() return std::make_shared(); } -Ufe::UINodeGraphNode::Ptr UsdUINodeGraphNodeHandler::uiNodeGraphNode(const Ufe::SceneItem::Ptr& item) const +Ufe::UINodeGraphNode::Ptr +UsdUINodeGraphNodeHandler::uiNodeGraphNode(const Ufe::SceneItem::Ptr& item) const { PXR_NAMESPACE_USING_DIRECTIVE UsdSceneItem::Ptr usdItem = std::dynamic_pointer_cast(item); TF_VERIFY(usdItem); - return UsdUINodeGraphNode::create(usdItem);} + return UsdUINodeGraphNode::create(usdItem); +} } // namespace ufe } // namespace MAYAUSD_NS_DEF diff --git a/lib/mayaUsd/ufe/UsdUINodeGraphNodeHandler.h b/lib/mayaUsd/ufe/UsdUINodeGraphNodeHandler.h index f85087dea1..acd80c2ea1 100644 --- a/lib/mayaUsd/ufe/UsdUINodeGraphNodeHandler.h +++ b/lib/mayaUsd/ufe/UsdUINodeGraphNodeHandler.h @@ -9,12 +9,12 @@ // otherwise accompanies this software in either electronic or hard copy form. // =========================================================================== +#include "UsdSceneItem.h" + #include #include -#include "UsdSceneItem.h" - namespace MAYAUSD_NS_DEF { namespace ufe { From 6c8504ce23dff2d7ec4ae46d92b01f8db99a4be6 Mon Sep 17 00:00:00 2001 From: Jonathan Feldstein Date: Fri, 29 Jul 2022 13:56:46 -0400 Subject: [PATCH 3/6] LOOKDEVX-683 | Added test case. --- test/lib/ufe/CMakeLists.txt | 6 ++ test/lib/ufe/testUINodeGraphNode.py | 90 +++++++++++++++++++++++++++++ 2 files changed, 96 insertions(+) create mode 100644 test/lib/ufe/testUINodeGraphNode.py diff --git a/test/lib/ufe/CMakeLists.txt b/test/lib/ufe/CMakeLists.txt index ebfb5b3cbb..7c607a5894 100644 --- a/test/lib/ufe/CMakeLists.txt +++ b/test/lib/ufe/CMakeLists.txt @@ -68,6 +68,12 @@ if(CMAKE_UFE_V4_FEATURES_AVAILABLE) ) endif() + if (${UFE_PREVIEW_VERSION_NUM} GREATER_EQUAL 4023) + list(APPEND TEST_SCRIPT_FILES + testUINodeGraphNode.py + ) + endif() + if(CMAKE_WANT_MATERIALX_BUILD) list(APPEND TEST_SCRIPT_FILES testShaderNodeDef.py diff --git a/test/lib/ufe/testUINodeGraphNode.py b/test/lib/ufe/testUINodeGraphNode.py new file mode 100644 index 0000000000..5556e23867 --- /dev/null +++ b/test/lib/ufe/testUINodeGraphNode.py @@ -0,0 +1,90 @@ +#!/usr/bin/env python + +# +# 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. +# + +import fixturesUtils +import mayaUtils + +from maya import cmds +from maya import standalone + +import ufe +import mayaUsd.ufe + +import os +import unittest + + +class UINodeGraphNodeTestCase(unittest.TestCase): + '''Verify the UINodeGraphNode USD implementation. + ''' + + pluginsLoaded = False + + @classmethod + def setUpClass(cls): + fixturesUtils.readOnlySetUpClass(__file__, loadPlugin=False) + + if not cls.pluginsLoaded: + cls.pluginsLoaded = mayaUtils.isMayaUsdPluginLoaded() + + @classmethod + def tearDownClass(cls): + standalone.uninitialize() + + def setUp(self): + ''' Called initially to set up the Maya test environment ''' + # Load plugins + self.assertTrue(self.pluginsLoaded) + + # Open ballset.ma scene in testSamples + mayaUtils.openGroupBallsScene() + + # Clear selection to start off + cmds.select(clear=True) + + def testUIInfo(self): + ball3Path = ufe.PathString.path('|transform1|proxyShape1,/Ball_set/Props/Ball_3') + ball3SceneItem = ufe.Hierarchy.createItem(ball3Path) + + uiNodeGraphNode = ufe.UINodeGraphNode.uiNodeGraphNode(ball3SceneItem) + + self.assertFalse(uiNodeGraphNode.hasPosition()) + pos0 = uiNodeGraphNode.getPosition() + self.assertEqual(pos0.x(), 0) + self.assertEqual(pos0.y(), 0) + pos1 = ufe.Vector2f(10, 20) + uiNodeGraphNode.setPosition(pos1) + self.assertTrue(uiNodeGraphNode.hasPosition()) + pos2 = uiNodeGraphNode.getPosition() + self.assertEqual(pos1.x(), pos2.x()) + self.assertEqual(pos1.y(), pos2.y()) + uiNodeGraphNode.setPosition(13, 41) + self.assertTrue(uiNodeGraphNode.hasPosition()) + pos3 = uiNodeGraphNode.getPosition() + self.assertEqual(pos3.x(), 13) + self.assertEqual(pos3.y(), 41) + pos4 = ufe.Vector2f(21, 20) + cmd = uiNodeGraphNode.setPositionCmd(pos4) + cmd.execute() + self.assertTrue(uiNodeGraphNode.hasPosition()) + pos5 = uiNodeGraphNode.getPosition() + self.assertEqual(pos4.x(), pos5.x()) + self.assertEqual(pos4.y(), pos5.y()) + +if __name__ == '__main__': + unittest.main(verbosity=2) From 17c9d55f380c2e107002feff178f38ea6ba1745d Mon Sep 17 00:00:00 2001 From: Jonathan Feldstein Date: Fri, 29 Jul 2022 14:01:47 -0400 Subject: [PATCH 4/6] LOOKDEVX-683 | Applied code review feedback. --- lib/mayaUsd/ufe/UsdUINodeGraphNode.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/mayaUsd/ufe/UsdUINodeGraphNode.cpp b/lib/mayaUsd/ufe/UsdUINodeGraphNode.cpp index d24accb88b..dfd5ae7ff8 100644 --- a/lib/mayaUsd/ufe/UsdUINodeGraphNode.cpp +++ b/lib/mayaUsd/ufe/UsdUINodeGraphNode.cpp @@ -20,10 +20,10 @@ class SetPositionCommand : public Ufe::UndoableCommand public: SetPositionCommand(const PXR_NS::UsdPrim& prim, const Ufe::Vector2f& newPos) : Ufe::UndoableCommand() + , _stage(prim.GetStage()) + , _primPath(prim.GetPath()) , _newPos(PXR_NS::GfVec2f(newPos.x(), newPos.y())) { - _stage = prim.GetStage(); - _primPath = prim.GetPath(); } void execute() override @@ -49,9 +49,9 @@ class SetPositionCommand : public Ufe::UndoableCommand void redo() override { } private: - PXR_NS::UsdStageWeakPtr _stage; - PXR_NS::SdfPath _primPath; - const PXR_NS::VtValue _newPos; + const PXR_NS::UsdStageWeakPtr _stage; + const PXR_NS::SdfPath _primPath; + const PXR_NS::VtValue _newPos; }; UsdUINodeGraphNode::UsdUINodeGraphNode(const UsdSceneItem::Ptr& item) From 455e9df479ccb46bdba87d1c8ccf8a8745934cff Mon Sep 17 00:00:00 2001 From: Jonathan Feldstein Date: Fri, 29 Jul 2022 14:45:47 -0400 Subject: [PATCH 5/6] LOOKDEVX-683 | Applied code review feedback. --- lib/mayaUsd/ufe/UsdUINodeGraphNode.cpp | 20 +++++++++---------- lib/mayaUsd/ufe/UsdUINodeGraphNodeHandler.cpp | 8 +++++++- test/lib/ufe/testUINodeGraphNode.py | 1 - 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/lib/mayaUsd/ufe/UsdUINodeGraphNode.cpp b/lib/mayaUsd/ufe/UsdUINodeGraphNode.cpp index dfd5ae7ff8..4ab03553bf 100644 --- a/lib/mayaUsd/ufe/UsdUINodeGraphNode.cpp +++ b/lib/mayaUsd/ufe/UsdUINodeGraphNode.cpp @@ -28,15 +28,16 @@ class SetPositionCommand : public Ufe::UndoableCommand void execute() override { + PXR_NAMESPACE_USING_DIRECTIVE if (_stage) { const PXR_NS::UsdPrim prim = _stage->GetPrimAtPath(_primPath); - if (!prim.HasAPI() - && PXR_NS::UsdUINodeGraphNodeAPI::CanApply(prim)) { + if (!prim.HasAPI()) { PXR_NS::UsdUINodeGraphNodeAPI::Apply(prim); } if (prim.HasAPI()) { PXR_NS::UsdUINodeGraphNodeAPI posApi(prim); - PXR_NS::UsdAttribute attr = posApi.GetPosAttr(); + TF_VERIFY(posApi); + PXR_NS::UsdAttribute attr = posApi.GetPosAttr(); if (!attr) { attr = posApi.CreatePosAttr(); } @@ -69,13 +70,12 @@ Ufe::SceneItem::Ptr UsdUINodeGraphNode::sceneItem() const { return fItem; } bool UsdUINodeGraphNode::hasPosition() const { - const PXR_NS::UsdPrim prim = fItem->prim(); - if (prim.HasAPI()) { - PXR_NS::UsdUINodeGraphNodeAPI posApi(prim); - PXR_NS::UsdAttribute attr = posApi.GetPosAttr(); - return attr.IsValid(); - } - return false; + PXR_NAMESPACE_USING_DIRECTIVE + const PXR_NS::UsdPrim prim = fItem->prim(); + PXR_NS::UsdUINodeGraphNodeAPI posApi(prim); + TF_VERIFY(posApi); + PXR_NS::UsdAttribute attr = posApi.GetPosAttr(); + return attr.IsValid(); } Ufe::Vector2f UsdUINodeGraphNode::getPosition() const diff --git a/lib/mayaUsd/ufe/UsdUINodeGraphNodeHandler.cpp b/lib/mayaUsd/ufe/UsdUINodeGraphNodeHandler.cpp index e26e594ce4..4eeccbe24f 100644 --- a/lib/mayaUsd/ufe/UsdUINodeGraphNodeHandler.cpp +++ b/lib/mayaUsd/ufe/UsdUINodeGraphNodeHandler.cpp @@ -10,6 +10,8 @@ #include "UsdUINodeGraphNode.h" +#include + namespace MAYAUSD_NS_DEF { namespace ufe { @@ -25,7 +27,11 @@ UsdUINodeGraphNodeHandler::uiNodeGraphNode(const Ufe::SceneItem::Ptr& item) cons UsdSceneItem::Ptr usdItem = std::dynamic_pointer_cast(item); TF_VERIFY(usdItem); - return UsdUINodeGraphNode::create(usdItem); + const PXR_NS::UsdPrim prim = usdItem->prim(); + if (prim.IsValid() && PXR_NS::UsdUINodeGraphNodeAPI::CanApply(prim)) { + return UsdUINodeGraphNode::create(usdItem); + } + return nullptr; } } // namespace ufe diff --git a/test/lib/ufe/testUINodeGraphNode.py b/test/lib/ufe/testUINodeGraphNode.py index 5556e23867..addaae3355 100644 --- a/test/lib/ufe/testUINodeGraphNode.py +++ b/test/lib/ufe/testUINodeGraphNode.py @@ -23,7 +23,6 @@ from maya import standalone import ufe -import mayaUsd.ufe import os import unittest From 6aab6d214b709b1f9a5978157ba6dbae4ae58c46 Mon Sep 17 00:00:00 2001 From: Jonathan Feldstein Date: Fri, 29 Jul 2022 15:05:53 -0400 Subject: [PATCH 6/6] LOOKDEVX-683 | Removed unneeded namespaces. --- lib/mayaUsd/ufe/UsdUINodeGraphNode.cpp | 18 +++++++++--------- lib/mayaUsd/ufe/UsdUINodeGraphNodeHandler.cpp | 4 ++-- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/mayaUsd/ufe/UsdUINodeGraphNode.cpp b/lib/mayaUsd/ufe/UsdUINodeGraphNode.cpp index 4ab03553bf..b4c093ad26 100644 --- a/lib/mayaUsd/ufe/UsdUINodeGraphNode.cpp +++ b/lib/mayaUsd/ufe/UsdUINodeGraphNode.cpp @@ -30,14 +30,14 @@ class SetPositionCommand : public Ufe::UndoableCommand { PXR_NAMESPACE_USING_DIRECTIVE if (_stage) { - const PXR_NS::UsdPrim prim = _stage->GetPrimAtPath(_primPath); - if (!prim.HasAPI()) { - PXR_NS::UsdUINodeGraphNodeAPI::Apply(prim); + const UsdPrim prim = _stage->GetPrimAtPath(_primPath); + if (!prim.HasAPI()) { + UsdUINodeGraphNodeAPI::Apply(prim); } - if (prim.HasAPI()) { - PXR_NS::UsdUINodeGraphNodeAPI posApi(prim); + if (prim.HasAPI()) { + UsdUINodeGraphNodeAPI posApi(prim); TF_VERIFY(posApi); - PXR_NS::UsdAttribute attr = posApi.GetPosAttr(); + UsdAttribute attr = posApi.GetPosAttr(); if (!attr) { attr = posApi.CreatePosAttr(); } @@ -71,10 +71,10 @@ Ufe::SceneItem::Ptr UsdUINodeGraphNode::sceneItem() const { return fItem; } bool UsdUINodeGraphNode::hasPosition() const { PXR_NAMESPACE_USING_DIRECTIVE - const PXR_NS::UsdPrim prim = fItem->prim(); - PXR_NS::UsdUINodeGraphNodeAPI posApi(prim); + const UsdPrim prim = fItem->prim(); + UsdUINodeGraphNodeAPI posApi(prim); TF_VERIFY(posApi); - PXR_NS::UsdAttribute attr = posApi.GetPosAttr(); + UsdAttribute attr = posApi.GetPosAttr(); return attr.IsValid(); } diff --git a/lib/mayaUsd/ufe/UsdUINodeGraphNodeHandler.cpp b/lib/mayaUsd/ufe/UsdUINodeGraphNodeHandler.cpp index 4eeccbe24f..6010840419 100644 --- a/lib/mayaUsd/ufe/UsdUINodeGraphNodeHandler.cpp +++ b/lib/mayaUsd/ufe/UsdUINodeGraphNodeHandler.cpp @@ -27,8 +27,8 @@ UsdUINodeGraphNodeHandler::uiNodeGraphNode(const Ufe::SceneItem::Ptr& item) cons UsdSceneItem::Ptr usdItem = std::dynamic_pointer_cast(item); TF_VERIFY(usdItem); - const PXR_NS::UsdPrim prim = usdItem->prim(); - if (prim.IsValid() && PXR_NS::UsdUINodeGraphNodeAPI::CanApply(prim)) { + const UsdPrim prim = usdItem->prim(); + if (prim.IsValid() && UsdUINodeGraphNodeAPI::CanApply(prim)) { return UsdUINodeGraphNode::create(usdItem); } return nullptr;