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

EMSUSD-1000 - Implement new Hierarchy Cmd. #3597

Draft
wants to merge 1 commit into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
12 changes: 12 additions & 0 deletions lib/mayaUsd/ufe/ProxyShapeHierarchy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,18 @@ ProxyShapeHierarchy::insertChild(const Ufe::SceneItem::Ptr& child, const Ufe::Sc
return insertChildCommand->insertedChild();
}

Ufe::InsertChildCommand::Ptr
ProxyShapeHierarchy::appendChildVerifyRestrictionsCmd(const Ufe::SceneItem::Ptr& child)
{
const auto childCmd = appendChildCmd(child);

if (childCmd && isConnected(downcast(child))) {
throw std::runtime_error("The node you're trying to move has connections.");
}
Comment on lines +259 to +261
Copy link
Collaborator

Choose a reason for hiding this comment

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

In your Ufe PR it states "Returns a null pointer if the restrictions are not observed." - but here you are throwing. It should be one of the. Either return nullptr here or in Ufe change the doc to state that it will throw runtime_error if the restrictions are not observed.


return childCmd;
}

#ifdef UFE_V3_FEATURES_AVAILABLE
Ufe::SceneItem::Ptr ProxyShapeHierarchy::createGroup(const Ufe::PathComponent& name) const
{
Expand Down
2 changes: 2 additions & 0 deletions lib/mayaUsd/ufe/ProxyShapeHierarchy.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ class MAYAUSD_CORE_PUBLIC ProxyShapeHierarchy : public Ufe::Hierarchy
insertChild(const Ufe::SceneItem::Ptr& child, const Ufe::SceneItem::Ptr& pos) override;
Ufe::InsertChildCommand::Ptr
insertChildCmd(const Ufe::SceneItem::Ptr& child, const Ufe::SceneItem::Ptr& pos) override;
Ufe::InsertChildCommand::Ptr
appendChildVerifyRestrictionsCmd(const Ufe::SceneItem::Ptr& child) override;

Ufe::UndoableCommand::Ptr reorderCmd(const Ufe::SceneItemList& orderedList) const override;

Expand Down
7 changes: 7 additions & 0 deletions lib/mayaUsd/ufe/PulledObjectHierarchy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@ Ufe::InsertChildCommand::Ptr PulledObjectHierarchy::insertChildCmd(
return nullptr;
}

Ufe::InsertChildCommand::Ptr
PulledObjectHierarchy::appendChildVerifyRestrictionsCmd(const Ufe::SceneItem::Ptr& child)
{
TF_CODING_ERROR("Illegal call to unimplemented %s", __func__);
return nullptr;
}

Ufe::SceneItem::Ptr
PulledObjectHierarchy::insertChild(const Ufe::SceneItem::Ptr& child, const Ufe::SceneItem::Ptr& pos)
{
Expand Down
2 changes: 2 additions & 0 deletions lib/mayaUsd/ufe/PulledObjectHierarchy.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ class MAYAUSD_CORE_PUBLIC PulledObjectHierarchy : public Ufe::Hierarchy
insertChild(const Ufe::SceneItem::Ptr& child, const Ufe::SceneItem::Ptr& pos) override;
Ufe::InsertChildCommand::Ptr
insertChildCmd(const Ufe::SceneItem::Ptr& child, const Ufe::SceneItem::Ptr& pos) override;
Ufe::InsertChildCommand::Ptr
appendChildVerifyRestrictionsCmd(const Ufe::SceneItem::Ptr& child) override;

Ufe::UndoableCommand::Ptr reorderCmd(const Ufe::SceneItemList& orderedList) const override;

Expand Down
2 changes: 1 addition & 1 deletion lib/mayaUsd/ufe/UsdAttributes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ static void removeSrcAttrConnections(PXR_NS::UsdPrim& prim, const PXR_NS::UsdAtt
for (const auto& attribute : prim.GetAttributes()) {
PXR_NS::UsdAttribute dstUsdAttr = attribute.As<PXR_NS::UsdAttribute>();

if (MayaUsd::ufe::isConnected(srcUsdAttr, dstUsdAttr)) {
if (isConnected(srcUsdAttr, dstUsdAttr)) {
UsdShadeConnectableAPI::DisconnectSource(dstUsdAttr, srcUsdAttr);
// Check if we can remove the property.
if (MayaUsd::ufe::canRemoveDstProperty(dstUsdAttr)) {
Expand Down
5 changes: 3 additions & 2 deletions lib/mayaUsd/ufe/UsdUndoConnectionCommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <mayaUsd/ufe/UsdConnections.h>
#include <mayaUsd/ufe/Utils.h>

#include <usdUfe/ufe/Utils.h>
#include <usdUfe/ufe/UsdSceneItem.h>
#include <usdUfe/undo/UsdUndoBlock.h>
#include <usdUfe/utils/usdUtils.h>
Expand Down Expand Up @@ -155,7 +156,7 @@ void UsdUndoCreateConnectionCommand::execute()
return;
}

if (MayaUsd::ufe::isConnected(srcUsdAttr->usdAttribute(), dstUsdAttr->usdAttribute())) {
if (isConnected(srcUsdAttr->usdAttribute(), dstUsdAttr->usdAttribute())) {
return;
}

Expand Down Expand Up @@ -287,7 +288,7 @@ void UsdUndoDeleteConnectionCommand::execute()
UsdAttribute* dstUsdAttr = usdAttrFromUfeAttr(dstAttr);

if (!srcUsdAttr || !dstUsdAttr
|| !MayaUsd::ufe::isConnected(srcUsdAttr->usdAttribute(), dstUsdAttr->usdAttribute())) {
|| !isConnected(srcUsdAttr->usdAttribute(), dstUsdAttr->usdAttribute())) {
return;
}
#if PXR_VERSION < 2302
Expand Down
14 changes: 0 additions & 14 deletions lib/mayaUsd/ufe/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,20 +347,6 @@ TfTokenVector getProxyShapePurposes(const Ufe::Path& path)
return purposes;
}

bool isConnected(const PXR_NS::UsdAttribute& srcUsdAttr, const PXR_NS::UsdAttribute& dstUsdAttr)
{
PXR_NS::SdfPathVector connectedAttrs;
dstUsdAttr.GetConnections(&connectedAttrs);

for (PXR_NS::SdfPath path : connectedAttrs) {
if (path == srcUsdAttr.GetPath()) {
return true;
}
}

return false;
}

bool canRemoveSrcProperty(const PXR_NS::UsdAttribute& srcAttr)
{

Expand Down
5 changes: 0 additions & 5 deletions lib/mayaUsd/ufe/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,6 @@ PXR_NS::UsdTimeCode getTime(const Ufe::Path& path);
MAYAUSD_CORE_PUBLIC
PXR_NS::TfTokenVector getProxyShapePurposes(const Ufe::Path& path);

//! Check if the src and dst attributes are connected.
//! \return True, if they are connected.
MAYAUSD_CORE_PUBLIC
bool isConnected(const PXR_NS::UsdAttribute& srcUsdAttr, const PXR_NS::UsdAttribute& dstUsdAttr);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Moving it to usdUfe/ufe as I see this function doesn't need the maya and mayaUsd .h included in lib/mayaUsd/ufe/Utils.h


//! Check if a source connection property is allowed to be removed.
//! \return True, if the property can be removed.
MAYAUSD_CORE_PUBLIC
Expand Down
13 changes: 13 additions & 0 deletions lib/usdUfe/ufe/UsdHierarchy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,19 @@ UsdHierarchy::insertChildCmd(const Ufe::SceneItem::Ptr& child, const Ufe::SceneI
return UsdUndoInsertChildCommand::create(fItem, downcast(child), downcast(pos));
}

Ufe::InsertChildCommand::Ptr
UsdHierarchy::appendChildVerifyRestrictionsCmd(const Ufe::SceneItem::Ptr& child)
{
const auto childCmd = appendChildCmd(child);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

A better and cleaner solution would be to create a new cmd that inherits from UsdUndoInsertChildCommand and in the new constructor check the restrictions and throw the exception.


if (childCmd && isConnected(downcast(child))) {
throw std::runtime_error("The node you're trying to move has connections.");
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We should update this message according to the updated and approved UI linked in the related story

}

return childCmd;
}


Ufe::SceneItem::Ptr
UsdHierarchy::insertChild(const Ufe::SceneItem::Ptr& child, const Ufe::SceneItem::Ptr& pos)
{
Expand Down
2 changes: 2 additions & 0 deletions lib/usdUfe/ufe/UsdHierarchy.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ class USDUFE_PUBLIC UsdHierarchy : public Ufe::Hierarchy
insertChild(const Ufe::SceneItem::Ptr& child, const Ufe::SceneItem::Ptr& pos) override;
Ufe::InsertChildCommand::Ptr
insertChildCmd(const Ufe::SceneItem::Ptr& child, const Ufe::SceneItem::Ptr& pos) override;
Ufe::InsertChildCommand::Ptr
appendChildVerifyRestrictionsCmd(const Ufe::SceneItem::Ptr& child) override;

Ufe::UndoableCommand::Ptr reorderCmd(const Ufe::SceneItemList& orderedList) const override;

Expand Down
89 changes: 89 additions & 0 deletions lib/usdUfe/ufe/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,95 @@ Ufe::BBox3d combineUfeBBox(const Ufe::BBox3d& ufeBBox1, const Ufe::BBox3d& ufeBB
return combinedBBox;
}

bool isConnected(const PXR_NS::UsdAttribute& srcUsdAttr, const PXR_NS::UsdAttribute& dstUsdAttr)
{
PXR_NS::SdfPathVector connectedAttrs;
dstUsdAttr.GetConnections(&connectedAttrs);

for (PXR_NS::SdfPath path : connectedAttrs) {
if (path == srcUsdAttr.GetPath()) {
return true;
}
}

return false;
}

bool isConnected(const UsdSceneItem::Ptr& usdItem)
{

if (!usdItem) {
return false;
}

const auto prim = usdItem->prim();

if (!prim) {
return false;
}

const auto primAttrs = prim.GetAuthoredAttributes();

for (const auto& attr : primAttrs) {
const auto kBaseNameAndType
= PXR_NS::UsdShadeUtils::GetBaseNameAndType(PXR_NS::TfToken(attr.GetName()));

if (kBaseNameAndType.second != PXR_NS::UsdShadeAttributeType::Output
&& kBaseNameAndType.second != PXR_NS::UsdShadeAttributeType::Input) {
continue;
}

if (kBaseNameAndType.second == PXR_NS::UsdShadeAttributeType::Input) {
// The attribute could be a destination for connected sources, so check for its
// connections.
PXR_NS::UsdShadeSourceInfoVector sourcesInfo
= pxr::UsdShadeConnectableAPI::GetConnectedSources(attr);

if (!sourcesInfo.empty()) {
return true;
}
}

if (kBaseNameAndType.second == PXR_NS::UsdShadeAttributeType::Output) {
const auto primParent = prim.GetParent();

if (!primParent) {
continue;
}

// The attribute could be a source connection, we have to explore the siblings.
for (auto&& child : primParent.GetChildren()) {
if (child == prim) {
continue;
}

for (const auto& otherAttr : child.GetAttributes()) {
const auto childAttrBaseNameAndType = PXR_NS::UsdShadeUtils::GetBaseNameAndType(
PXR_NS::TfToken(otherAttr.GetName()));

if (childAttrBaseNameAndType.second == PXR_NS::UsdShadeAttributeType::Input
&& isConnected(attr, otherAttr)) {
return true;
}
}
}

// Check also if there are connections to the parent.
for (const auto& otherAttr : primParent.GetAttributes()) {
const auto parentAttrBaseNameAndType = PXR_NS::UsdShadeUtils::GetBaseNameAndType(
PXR_NS::TfToken(otherAttr.GetName()));

if (parentAttrBaseNameAndType.second == PXR_NS::UsdShadeAttributeType::Output
&& isConnected(attr, otherAttr)) {
return true;
}
}
}
}

return false;
}

void applyRootLayerMetadataRestriction(const UsdPrim& prim, const std::string& commandName)
{
// return early if prim is the pseudo-root.
Expand Down
10 changes: 10 additions & 0 deletions lib/usdUfe/ufe/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,16 @@ bool isEditTargetLayerModifiable(
USDUFE_PUBLIC
Ufe::BBox3d combineUfeBBox(const Ufe::BBox3d& ufeBBox1, const Ufe::BBox3d& ufeBBox2);

//! Check if the src and dst attributes are connected.
//! \return True, if they are connected.
USDUFE_PUBLIC
bool isConnected(const PXR_NS::UsdAttribute& srcUsdAttr, const PXR_NS::UsdAttribute& dstUsdAttr);

//! Check if the usdItem is connected (i.e. if there are in or out connections).
//! \return True, if it is connected.
USDUFE_PUBLIC
bool isConnected(const UsdSceneItem::Ptr& usdItem);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Moving out this function from LookdevXUsd


//! Set both the start and stop wait cursor functions.
USDUFE_PUBLIC
void setWaitCursorFns(WaitCursorFn startFn, WaitCursorFn stopFn);
Expand Down
Loading