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

LOOKDEVX-862- Rename ports #2644

Merged
merged 26 commits into from
Nov 9, 2022

Conversation

alicedegirolamo
Copy link
Collaborator

@alicedegirolamo alicedegirolamo commented Oct 11, 2022

Description

Added the command for renaming an attribute.
I modified UFE in this PR in order to add the new command to the interface.

Type of change

  • New feature (non-breaking change which adds functionality)

Checklist:

  • My code follows the style guidelines of this project

Copy link
Collaborator

@ppt-adsk ppt-adsk left a comment

Choose a reason for hiding this comment

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

I will let Jerry review the shading network part of this pull request. It does need an automated test.

@@ -62,6 +62,8 @@ class UsdAttributes : public Ufe::Attributes
Ufe::AddAttributeCommand::Ptr
addAttributeCmd(const std::string& name, const Ufe::Attribute::Type& type) override;
Ufe::UndoableCommand::Ptr removeAttributeCmd(const std::string& name) override;
Ufe::UndoableCommand::Ptr
Copy link
Collaborator

Choose a reason for hiding this comment

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

This will be available in UFE version 0.4.33; it isn't available in 0.4.24.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, I've updated the version.

const std::string& newName)
{
if (!sceneItem || !sceneItem->prim().IsActive()
|| !UsdAttributes(sceneItem).hasAttribute(targetName)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Don't understand this line. We can't rename if if don't have an attribute with the targetName?

Copy link
Collaborator

Choose a reason for hiding this comment

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

The name of the variable creates confusion. Maybe something like originalName would be less ambiguous and a better match to newName? When I see targetName I look for sourceName, which does not fit the logic of this code.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've renamed the variables everywhere (also in PR for UFE) so now should be more clear.

}

// Do not rename if an attribute already exists with the newName
if (UsdAttributes(sceneItem).hasAttribute(newName)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is the opposite condition of line 469.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I suspect we want to integrate the work you did in #2622 so a new name gets automatically generated on collision. This would most probably require updating the UFE API to return the renamed Ufe::Attribute instead of a boolean. Might not be too late to change that Ufe API.

Copy link
Collaborator Author

@alicedegirolamo alicedegirolamo Oct 13, 2022

Choose a reason for hiding this comment

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

Yes, right now if we want to create a unique name when there is a collision we need #2622.

}

// Do not rename if an attribute already exists with the newName
if (UsdAttributes(sceneItem).hasAttribute(newName)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I suspect we want to integrate the work you did in #2622 so a new name gets automatically generated on collision. This would most probably require updating the UFE API to return the renamed Ufe::Attribute instead of a boolean. Might not be too late to change that Ufe API.

const std::string& newName)
{
if (!sceneItem || !sceneItem->prim().IsActive()
|| !UsdAttributes(sceneItem).hasAttribute(targetName)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

The name of the variable creates confusion. Maybe something like originalName would be less ambiguous and a better match to newName? When I see targetName I look for sourceName, which does not fit the logic of this code.

auto prim = sceneItem->prim();
auto attribute = prim.GetAttribute(nameAsToken);

PXR_NS::UsdShadeNodeGraph ngPrim(prim);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Looks like some of this code could be replaced by a call to canRemoveAttribute(targetName) since the restrictions are exactly the same between removing and renaming.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes exactly, I delete that function

PXR_NS::TfToken nameAsToken(targetName);
auto prim = sceneItem->prim();
auto attribute = prim.GetAttribute(nameAsToken);
PXR_NS::UsdShadeNodeGraph ngPrim(prim);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This unused variable will most probably cause the preflight to fail on Linux and OS/X.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I removed it also in the new version since I don't use it.

if (propertyHandle) {
return propertyHandle->SetName(newName);
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

Almost there, but the hardest part goes here. If the attribute was connected, then it must stay connected. This means finding and updating all connection sources that used the old name and changing that to the new name. This is where ngPrim will come handy as you only have to do that if the attribute is a NodeGraph boundary. You do not have to traverse the whole stage, only the nodes in the enclosing NodeGraph, if any, and the nodes in ngPrim.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I should also have completed this part.

@@ -319,6 +319,12 @@ Ufe::UndoableCommand::Ptr UsdAttributes::removeAttributeCmd(const std::string& n
{
return UsdRemoveAttributeCommand::create(fItem, name);
}

Ufe::UndoableCommand::Ptr
Copy link
Collaborator

Choose a reason for hiding this comment

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

As Pierre mentioned somewhere else, this code is new to UFE 0.4.33; it isn't available in 0.4.24 where add/remove was added. You will have to move this new code into separate block that will be guarded with #if (UFE_PREVIEW_VERSION_NUM >= 4033) (see line 311).

Ufe::UndoableCommand::Ptr
UsdAttributes::renameAttributeCmd(const std::string& targetName, const std::string& newName)
#endif
//#if (UFE_PREVIEW_VERSION_NUM >= 4033)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Commented-out code.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yes I forgot to remove the comment.

Copy link
Collaborator

Choose a reason for hiding this comment

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

The #if condition is needed.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@JGamache-autodesk The code is not consistent in this file. Does it need the two conditions UFE_V4_FEATURES_AVAILABLE and UFE_PREVIEW_VERSION_NUM >= 4033 -- or -- only the latter?

@@ -96,14 +96,14 @@ class UsdRemoveAttributeCommand : public UsdUndoableCommand<Ufe::UndoableCommand
}; // UsdRemoveAttributeCommand

//! \brief Implementation of RenameAttributeCommand
class UsdRenameAttributeCommand : public UsdUndoableCommand<Ufe::UndoableCommand>
class UsdRenameAttributeCommand : public UsdUndoableCommand<Ufe::AttributeValuedUndoableCommand>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is AttributeValuedUndoableCommand in a checked-in version of UFE? I can't find it in UFE master.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Update, following this discussion for UFE, I've updated the names.

@alicedegirolamo
Copy link
Collaborator Author

I will let Jerry review the shading network part of this pull request. It does need an automated test.

I also added and tested the new test.

@seando-adsk seando-adsk added the ufe-usd Related to UFE-USD plugin in Maya-Usd label Oct 17, 2022
@hodoulp
Copy link
Collaborator

hodoulp commented Oct 18, 2022

@alicedegirolamo did you address all the reviewer's comments? if done, please ping reviewers to finalize & merge the pull request.

@alicedegirolamo
Copy link
Collaborator Author

@alicedegirolamo did you address all the reviewer's comments? if done, please ping reviewers to finalize & merge the pull request.

Yes, I did.

@ppt-adsk @JGamache-autodesk could you please check if my corrections are ok? Thank you.

Copy link
Collaborator

@hodoulp hodoulp left a comment

Choose a reason for hiding this comment

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

There are points:

  • The code is not consistent in the changed files and with the current changes. Does it need the two conditions UFE_V4_FEATURES_AVAILABLE and UFE_PREVIEW_VERSION_NUM >= 4033 -- or -- only the latter?
  • Being in maya-usd the pull request must have at least one unit test to demonstrate that the usd implementaion is working.

Ufe::UndoableCommand::Ptr
UsdAttributes::renameAttributeCmd(const std::string& targetName, const std::string& newName)
#endif
//#if (UFE_PREVIEW_VERSION_NUM >= 4033)
Copy link
Collaborator

Choose a reason for hiding this comment

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

The #if condition is needed.

Ufe::UndoableCommand::Ptr
UsdAttributes::renameAttributeCmd(const std::string& targetName, const std::string& newName)
#endif
//#if (UFE_PREVIEW_VERSION_NUM >= 4033)
Copy link
Collaborator

Choose a reason for hiding this comment

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

@JGamache-autodesk The code is not consistent in this file. Does it need the two conditions UFE_V4_FEATURES_AVAILABLE and UFE_PREVIEW_VERSION_NUM >= 4033 -- or -- only the latter?

@alicedegirolamo alicedegirolamo requested review from ppt-adsk and removed request for ppt-adsk November 2, 2022 07:50
@alicedegirolamo
Copy link
Collaborator Author

Hi @alicedegirolamo, you can take me off the reviewer's list for this pull request, I think others can fully take over. Cheers!

Hi @ppt-adsk , yes, sure. Thanks!

seando-adsk
seando-adsk previously approved these changes Nov 4, 2022
@alicedegirolamo alicedegirolamo added the ready-for-merge Development process is finished, PR is ready for merge label Nov 7, 2022
@seando-adsk seando-adsk removed the ready-for-merge Development process is finished, PR is ready for merge label Nov 7, 2022
Copy link
Collaborator

@JGamache-autodesk JGamache-autodesk left a comment

Choose a reason for hiding this comment

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

New code looks good, but is untested. Fastest way is to import test scene test\testSamples\MaterialX\MayaSurfaces.usda, and rename /pCube2/Looks/standardSurface2SG/MayaNG_standardSurface2SG.inputs:file2:varnameStr to inputs:file2:varname and make sure the connection from /pCube2/Looks/standardSurface2SG/MayaNG_standardSurface2SG/place2dTexture2.inputs:geomprop is fixed. Then you rename /pCube2/Looks/standardSurface2SG/MayaNG_standardSurface2SG.outputs:baseColor to outputs:MyColor and make sure the input connection from /pCube2/Looks/standardSurface2SG/standardSurface2.inputs:base_color stays connected.

@alicedegirolamo
Copy link
Collaborator Author

New code looks good, but is untested. Fastest way is to import test scene test\testSamples\MaterialX\MayaSurfaces.usda, and rename /pCube2/Looks/standardSurface2SG/MayaNG_standardSurface2SG.inputs:file2:varnameStr to inputs:file2:varname and make sure the connection from /pCube2/Looks/standardSurface2SG/MayaNG_standardSurface2SG/place2dTexture2.inputs:geomprop is fixed. Then you rename /pCube2/Looks/standardSurface2SG/MayaNG_standardSurface2SG.outputs:baseColor to outputs:MyColor and make sure the input connection from /pCube2/Looks/standardSurface2SG/standardSurface2.inputs:base_color stays connected.

I've updated the test and checked it's passing for the renaming in test/lib/ufe/testAttributes.py

@alicedegirolamo alicedegirolamo added the ready-for-merge Development process is finished, PR is ready for merge label Nov 9, 2022
@seando-adsk seando-adsk merged commit ed25078 into dev Nov 9, 2022
@seando-adsk seando-adsk deleted the degiroa/LOOKDEVX-862/rename-and-delete-ports branch November 9, 2022 15:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready-for-merge Development process is finished, PR is ready for merge ufe-usd Related to UFE-USD plugin in Maya-Usd
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants