Files
UnrealEngineUWP/Engine/Source/Runtime/Experimental/InteractiveToolsFramework/Public/MultiSelectionTool.h
Marc Audy a7f9391231 Merge UE5/Release-Engine-Staging @ 14811410 to UE5/Main
This represents UE4/Main @ 14768117

For ReleaseObjectVersion.h
#lockdown Marcus.Wassmer

[CL 14811440 by Marc Audy in ue5-main branch]
2020-11-24 18:42:39 -04:00

79 lines
2.0 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#pragma once
#include "InteractiveTool.h"
#include "ComponentSourceInterfaces.h"
#include "MultiSelectionTool.generated.h"
UCLASS(Transient)
class INTERACTIVETOOLSFRAMEWORK_API UMultiSelectionTool : public UInteractiveTool
{
GENERATED_BODY()
public:
void SetSelection(TArray<TUniquePtr<FPrimitiveComponentTarget>> ComponentTargetsIn)
{
ComponentTargets = MoveTemp(ComponentTargetsIn);
}
/**
* @return true if all ComponentTargets of this tool are still valid
*/
virtual bool AreAllTargetsValid() const
{
for (const TUniquePtr<FPrimitiveComponentTarget>& Target : ComponentTargets)
{
if (Target->IsValid() == false)
{
return false;
}
}
return true;
}
public:
virtual bool CanAccept() const override
{
return AreAllTargetsValid();
}
protected:
TArray<TUniquePtr<FPrimitiveComponentTarget>> ComponentTargets{};
/**
* Helper to find which component targets share source data
*
* @return Array of indices, 1:1 with ComponentTargets, indicating the first index where a component target sharing the same source data appeared.
*/
bool GetMapToFirstComponentsSharingSourceData(TArray<int32>& MapToFirstOccurrences)
{
bool bSharesSources = false;
MapToFirstOccurrences.SetNumUninitialized(ComponentTargets.Num());
for (int32 ComponentIdx = 0; ComponentIdx < ComponentTargets.Num(); ComponentIdx++)
{
MapToFirstOccurrences[ComponentIdx] = -1;
}
for (int32 ComponentIdx = 0; ComponentIdx < ComponentTargets.Num(); ComponentIdx++)
{
if (MapToFirstOccurrences[ComponentIdx] >= 0) // already mapped
{
continue;
}
MapToFirstOccurrences[ComponentIdx] = ComponentIdx;
FPrimitiveComponentTarget* ComponentTarget = ComponentTargets[ComponentIdx].Get();
for (int32 VsIdx = ComponentIdx + 1; VsIdx < ComponentTargets.Num(); VsIdx++)
{
if (ComponentTarget->HasSameSourceData(*ComponentTargets[VsIdx]))
{
bSharesSources = true;
MapToFirstOccurrences[VsIdx] = ComponentIdx;
}
}
}
return bSharesSources;
}
};