Skip to content

Commit

Permalink
EMSUSD-533 - Incremental naming doesn't take zero into consideration
Browse files Browse the repository at this point in the history
* Fix Linux/Mac build issues and broken unit tests.
  • Loading branch information
seando-adsk committed Sep 6, 2023
1 parent 2dad1ff commit b424e54
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
4 changes: 2 additions & 2 deletions lib/mayaUsd/ufe/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,13 @@ std::string uniqueChildNameMayaStandard(const PXR_NS::UsdPrim& usdParent, const

std::string childBaseName;
std::pair<TfToken, int> largestMatching("", -1);
for (const auto child : allChildrenNames) {
for (const auto& child : allChildrenNames) {
// While iterating thru all the children look for ones that match
// the base name of the input. When we find one check its numerical
// suffix and store the greatest one.
splitNumericalSuffix(child.GetString(), childBaseName, suffix);
if (baseName == childBaseName) {
int suffixValue = std::stoi(suffix);
int suffixValue = !suffix.empty() ? std::stoi(suffix) : 0;
if (suffixValue > largestMatching.second) {
largestMatching = std::make_pair(child, suffixValue);
}
Expand Down
12 changes: 10 additions & 2 deletions lib/usdUfe/python/wrapUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ std::string _usdPathToUfePathSegment(

std::string _uniqueName(const std::vector<std::string>& existingNames, std::string srcName)
{
PXR_NS::TfToken::HashSet existingNamesSet(existingNames.begin(), existingNames.end());
PXR_NS::TfToken::HashSet existingNamesSet;
for (const auto& n : existingNames) {
existingNamesSet.insert(PXR_NS::TfToken(n));
}
return UsdUfe::uniqueName(existingNamesSet, srcName);
}

Expand All @@ -77,6 +80,11 @@ int _ufePathToInstanceIndex(const std::string& ufePathString)
return UsdUfe::ufePathToInstanceIndex(Ufe::PathString::path(ufePathString));
}

bool _isEditTargetLayerModifiable(const PXR_NS::UsdStageWeakPtr stage)
{
return UsdUfe::isEditTargetLayerModifiable(stage);
}

PXR_NS::UsdTimeCode _getTime(const std::string& pathStr)
{
const Ufe::Path path = Ufe::PathString::path(pathStr);
Expand Down Expand Up @@ -106,7 +114,7 @@ void wrapUtils()
def("stripInstanceIndexFromUfePath", _stripInstanceIndexFromUfePath, (arg("ufePathString")));
def("ufePathToPrim", _ufePathToPrim);
def("ufePathToInstanceIndex", _ufePathToInstanceIndex);
def("isEditTargetLayerModifiable", UsdUfe::isEditTargetLayerModifiable);
def("isEditTargetLayerModifiable", _isEditTargetLayerModifiable);
def("getTime", _getTime);
def("isAttributeEditAllowed", _isAttributeEditAllowed);
}
13 changes: 9 additions & 4 deletions test/lib/ufe/testContextOps.py
Original file line number Diff line number Diff line change
Expand Up @@ -919,13 +919,15 @@ def createMaterial(proxyShape):
assert ufe.Hierarchy.createItem(ufe.PathString.path(expectedPath))

# Case 6: A non-scope object named "mtl" exists and a scope named "mtl2" exists.
# The new material should get created in a new scope named "mtl1".
# The new material should get created in a new scope named "mtl3".
# This follows normal Maya naming standard where it increments the largest numerical
# suffix (even if there are gaps).
proxyShape = createProxyShape()
proxyShapePath = ufe.PathString.string(proxyShape.path())
addNewPrim(proxyShape, "Def", materialsScopeName)
addNewPrim(proxyShape, "Scope", materialsScopeName + "2")
createMaterial(proxyShape)
expectedPath = proxyShapePath + ",/" + materialsScopeName + "1/" + materialName
expectedPath = proxyShapePath + ",/" + materialsScopeName + "3/" + materialName
assert ufe.Hierarchy.createItem(ufe.PathString.path(expectedPath))

# Case 7: A non-scope object named "mtl" exists and a scope named "mtlBingBong" exists.
Expand All @@ -948,8 +950,11 @@ def createMaterial(proxyShape):
for scopeNamePostfix in scopeNamePostfixes:
addNewPrim(proxyShape, "Scope", materialsScopeName + scopeNamePostfix)

# Again here follow the normal Maya naming standard which increments the largest
# numerical suffix (1337).
createMaterial(proxyShape)
expectedPath = proxyShapePath + ",/" + materialsScopeName + "1/" + materialName
expectedPath = proxyShapePath + ",/" + materialsScopeName + "1338/" + materialName
print(expectedPath)
assert ufe.Hierarchy.createItem(ufe.PathString.path(expectedPath))

# Case 9: Multiple non-scope object named "mtl", "mtl1", ..., "mtl3" exists and multiple
Expand All @@ -967,7 +972,7 @@ def createMaterial(proxyShape):
addNewPrim(proxyShape, "Scope", materialsScopeName + scopeNamePostfix)

createMaterial(proxyShape)
expectedPath = proxyShapePath + ",/" + materialsScopeName + "4/" + materialName
expectedPath = proxyShapePath + ",/" + materialsScopeName + "1338/" + materialName
assert ufe.Hierarchy.createItem(ufe.PathString.path(expectedPath))

# Case 10: Multiple non-scope object named "mtl", "mtl1", ..., "mtl3" exists and multiple
Expand Down

0 comments on commit b424e54

Please sign in to comment.