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
Changes from 4 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
32 changes: 27 additions & 5 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,12 +341,14 @@ void processAttributeChanges(
sendMetadataChanged = true;
std::stringstream newMetadataStream;
newMetadataStream << infoChanged.second.second;
std::string newMetadataKey = newMetadataStream.str();
if (!newMetadataKey.empty()) {
const std::string strMetadata = newMetadataStream.str();
// e.g. strMetadata string format:
// "'uifolder':,'uisoftmin':0.0, 'uihide':1, 'uiorder':0"
if (!strMetadata.empty()) {
// Find the modified key which is between a pair of single quotes.
newMetadataKey = newMetadataKey.substr(
newMetadataKey.find('\'') + 1, newMetadataKey.rfind('\'') - 2);
metadataKeys.insert(newMetadataKey);
for (const auto& newMetadataKey : getMetadataKeys(strMetadata)) {
metadataKeys.insert(newMetadataKey);
}
}
}
}
Expand Down