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

MAYA-127428 - Missing metadata notification. #2846

Merged
merged 6 commits into from
Feb 16, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
25 changes: 22 additions & 3 deletions lib/mayaUsd/ufe/StagesSubject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@

#include <atomic>
#include <limits>
#include <regex>
#include <vector>

#ifdef UFE_V2_FEATURES_AVAILABLE
Expand Down Expand Up @@ -286,6 +287,25 @@ void attributeMetadataChanged(
}
#endif

std::vector<std::string> getMetadataKeys(const std::string& strMetadata)
{
std::vector<std::string> metadataKeys;
const std::regex rgx("(')([^ ]*)(':)");
Copy link
Collaborator

Choose a reason for hiding this comment

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

You are using the power of regular expressions, but not to their full extent. Please read more about capture groups. The function can be rewritten as:

std::vector<std::string> getMetadataKeys(const std::string& strMetadata)
{
    std::vector<std::string> metadataKeys;
    const std::regex         rgx("'([^ ]*)':");
    for (std::sregex_iterator it(strMetadata.begin(), strMetadata.end(), rgx), it_end; it != it_end;
         ++it) {
        metadataKeys.push_back(std::string((*it)[1]));
    }
    return metadataKeys;
}

And work exactly as requested by extracting the captured strings.

std::string metadataKey;

for (std::sregex_iterator it(strMetadata.begin(), strMetadata.end(), rgx), it_end; it != it_end;
++it) {
if (it->empty()) {
continue;
}
metadataKey = std::string((*it)[0]);
metadataKey = metadataKey.substr(metadataKey.find('\'') + 1, metadataKey.rfind('\'') - 1);
metadataKeys.push_back(metadataKey);
}

return metadataKeys;
}

void processAttributeChanges(
const Ufe::Path& ufePath,
const SdfPath& changedPath,
Expand Down Expand Up @@ -321,13 +341,12 @@ void processAttributeChanges(
sendMetadataChanged = true;
std::stringstream newMetadataStream;
newMetadataStream << infoChanged.second.second;
std::string newMetadataKeys = newMetadataStream.str();
const std::string newMetadataKeys = newMetadataStream.str();
Copy link
Collaborator

Choose a reason for hiding this comment

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

(minor) I'd probably rename this to strMetadata for consistency.

// e.g. newMetadataKeys string format:
// "'uifolder':,'uisoftmin':0.0, 'uihide':1, 'uiorder':0"
if (!newMetadataKeys.empty()) {
// Find the modified key which is between a pair of single quotes.
for (const auto& newMetadataKey :
MayaUsd::ufe::getSubStrings(newMetadataKeys, "'", "':")) {
for (const auto& newMetadataKey : getMetadataKeys(newMetadataKeys)) {
metadataKeys.insert(newMetadataKey);
}
}
Expand Down
24 changes: 0 additions & 24 deletions lib/mayaUsd/ufe/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1185,30 +1185,6 @@ std::vector<std::string> splitString(const std::string& str, const std::string&
return split;
}

std::vector<std::string> getSubStrings(
const std::string& str,
const std::string& startSeparator,
const std::string& endSeparator)
{
std::vector<std::string> subStrings;
const std::string rgxString = "(" + startSeparator + ")" + "([^ ]*)" + "(" + endSeparator + ")";
const std::regex rgx(rgxString);
std::string subString;

for (std::sregex_iterator it(str.begin(), str.end(), rgx), it_end; it != it_end; ++it) {
if (it->empty()) {
continue;
}
subString = std::string((*it)[0]);
// Remove the separators.
subString = subString.substr(
subString.find(startSeparator.back()) + 1, subString.rfind(endSeparator.front()) - 1);
subStrings.push_back(subString);
}

return subStrings;
}

#ifdef MAYA_HAS_DISPLAY_LAYER_API
template <typename PathType>
void handleDisplayLayer(
Expand Down
7 changes: 0 additions & 7 deletions lib/mayaUsd/ufe/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -216,13 +216,6 @@ Ufe::Selection recreateDescendants(const Ufe::Selection& src, const Ufe::Path& f
MAYAUSD_CORE_PUBLIC
std::vector<std::string> splitString(const std::string& str, const std::string& separators);

//! Gets the sub strings surrounded by separators.
MAYAUSD_CORE_PUBLIC
std::vector<std::string> getSubStrings(
const std::string& str,
const std::string& startSeparator,
const std::string& endSeparator);

std::string pathSegmentSeparator();

class ReplicateExtrasFromUSD
Expand Down