Skip to content

Commit

Permalink
#5643: Cleanup and docs
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Jun 22, 2021
1 parent aca1f96 commit 6d18eb9
Showing 1 changed file with 30 additions and 22 deletions.
52 changes: 30 additions & 22 deletions libs/scene/merge/ThreeWaySelectionGroupMerger.h
Expand Up @@ -8,6 +8,13 @@ namespace scene
namespace merge
{

/**
* Three-way merger class to detect the changes that have been made
* to selection groups in the source map, replaying them onto the target scene.
*
* It will try to keep all added grouping information intact, while it will
* only remove group links if they haven't been altered in the target map.
*/
class ThreeWaySelectionGroupMerger :
public SelectionGroupMergerBase
{
Expand All @@ -17,7 +24,6 @@ class ThreeWaySelectionGroupMerger :
enum class Type
{
NodeAddedToGroup,
NodeRemovedFromGroup,
TargetGroupAdded,
TargetGroupRemoved,
NodeGroupsReordered,
Expand All @@ -37,18 +43,15 @@ class ThreeWaySelectionGroupMerger :
selection::ISelectionGroupManager& _sourceManager;
selection::ISelectionGroupManager& _targetManager;

NodeFingerprints _baseNodes;
NodeFingerprints _sourceNodes;
private:
// Temporary data only needed during analysis/processing
NodeFingerprints _targetNodes;

std::map<std::size_t, std::string> _sourceGroupFingerprints;
std::set<std::string> _targetGroupFingerprints;

std::set<std::size_t> _addedSourceGroupIds; // groups that have been added to source
std::set<std::size_t> _addedTargetGroupIds; // groups that have been added to target

std::set<std::size_t> _removedSourceGroupIds; // base groups that have been removed in source
std::set<std::size_t> _removedTargetGroupIds; // base groups that have been removed in target

std::set<std::size_t> _modifiedSourceGroupIds; // groups that have been modified in source
std::set<std::size_t> _modifiedTargetGroupIds; // groups that have been modified in target
Expand Down Expand Up @@ -87,16 +90,14 @@ class ThreeWaySelectionGroupMerger :

void adjustTargetGroups()
{
// Collect all node fingerprints for easier lookup
_sourceNodes = collectNodeFingerprints(_sourceRoot);
_log << "Got " << _sourceNodes.size() << " groups in the source map" << std::endl;
cleanupWorkingData();
_changes.clear();
_log.str(std::string());

// Collect all node fingerprints for easier lookup
_targetNodes = collectNodeFingerprints(_targetRoot);
_log << "Got " << _targetNodes.size() << " in the target map" << std::endl;

_baseNodes = collectNodeFingerprints(_baseRoot);
_log << "Got " << _baseNodes.size() << " in the base map" << std::endl;

_baseManager.foreachSelectionGroup(
std::bind(&ThreeWaySelectionGroupMerger::processBaseGroup, this, std::placeholders::_1));

Expand Down Expand Up @@ -126,9 +127,26 @@ class ThreeWaySelectionGroupMerger :
Change::Type::NodeGroupsReordered
});
});

cleanupWorkingData();
}

private:
void cleanupWorkingData()
{
_targetNodes.clear();

_sourceGroupFingerprints.clear();
_targetGroupFingerprints.clear();

_addedSourceGroupIds.clear();

_removedSourceGroupIds.clear();

_modifiedSourceGroupIds.clear();
_modifiedTargetGroupIds.clear();
}

void adjustGroupMemberships()
{
for (auto id : _modifiedSourceGroupIds)
Expand Down Expand Up @@ -237,15 +255,6 @@ class ThreeWaySelectionGroupMerger :
_log << "Base group is not present in source: " << group.getId() << std::endl;
_removedSourceGroupIds.insert(group.getId());
}

// Check if this group exists in target
auto targetGroup = _targetManager.getSelectionGroup(group.getId());

if (!targetGroup)
{
_log << "Base group is not present in target: " << group.getId() << std::endl;
_removedTargetGroupIds.insert(group.getId());
}
}

void processSourceGroup(selection::ISelectionGroup& group)
Expand Down Expand Up @@ -285,7 +294,6 @@ class ThreeWaySelectionGroupMerger :
if (!baseGroup)
{
_log << "Target group is not present in base: " << group.getId() << std::endl;
_addedTargetGroupIds.insert(group.getId());
return;
}

Expand Down

0 comments on commit 6d18eb9

Please sign in to comment.