Files
UnrealEngineUWP/Engine/Plugins/Runtime/MeshModelingToolset/Source/ModelingComponents/Public/Selection/PersistentMeshSelectionManager.h

126 lines
3.7 KiB
C
Raw Normal View History

ModelingTools: replace StorableSelection mechanism with new UPersistentMeshSelection and UPersistentMeshSelectionManager context object. - UPersistentMeshSelection is largely a port of UGroupTopologyStorableSelection, with the actual selection data moved to FGenericMeshSelection - UPersistentMeshSelectionManager is meant to be used as a ContextObject in a ToolsContext, also contains utility functions to register/unregister/find context object - Selection is no longer passed as part of FToolBuilderState. Instead Tools access the selection via ContextObject - UPersistentMeshSelectionManager currently supports a single active selection. Selection changes are transacted via an FChange. - When not inside a Tool, Selection is visualized with a pink border outline. Currently vertex selection is not visualized. - Usage model is that on Tool Accept/Complete, prior to Tool Shutdown, any existing selection is cleared, and Tool may set a new Output selection which becomes the active selection - StoredMeshSelectionUtil.h has utility functions to get current selection, set output selection, and clear it - SingleSelectionMeshEditingTool already made input selection available to subclasses, port that capability to new architecture - convert EditMeshPolygonsTool to be a SingleSelectionMeshEditingTool, use provided Input selection and set Output selection as appropriate - ModelingToolsEditorMode clears active selection where appropriate, eg if selected object changes. However the behavior here will need further improvement, currently relies on questionable event handling from the TypedElement system #rb semion.piskarev #rnx #jira none #preflight 6136cbbfd9c85a0001fc3b56 #ROBOMERGE-AUTHOR: ryan.schmidt #ROBOMERGE-SOURCE: CL 17441056 in //UE5/Main/... #ROBOMERGE-BOT: STARSHIP (Main -> Release-Engine-Test) (v870-17433530) [CL 17441061 by ryan schmidt in ue5-release-engine-test branch]
2021-09-06 23:05:07 -04:00
// Copyright Epic Games, Inc. All Rights Reserved.
#pragma once
#include "CoreMinimal.h"
#include "Selection/PersistentMeshSelection.h"
#include "InteractiveToolChange.h"
#include "PersistentMeshSelectionManager.generated.h"
class UInteractiveToolsContext;
class UInteractiveToolManager;
class UPrimitiveComponent;
class UInteractiveTool;
class UPreviewGeometry;
/**
* UPersistentMeshSelectionManager manages an active Mesh Selection.
* The assumption is that this class will be registered with the ContextStore of an InteractiveToolsContext,
* and the various Tool implementations will get/set the selection.
*
*
*
* StoredMeshSelectionUtil.h contains various utility functions to simplify usage of this class,
* those functions are preferable to directly using the Manager.
*
*/
UCLASS()
class MODELINGCOMPONENTS_API UPersistentMeshSelectionManager : public UObject
{
GENERATED_BODY()
public:
virtual void Initialize(TObjectPtr<UInteractiveToolsContext> ToolsContext);
virtual void Shutdown();
/** @return true if there is an active selection */
virtual bool HasActiveSelection();
/** @return the active selection */
virtual UPersistentMeshSelection* GetActiveSelection();
/** Set a new active selection. This is undoable, ie a FPersistentMeshSelectionChange will be emitted */
virtual void SetNewActiveSelection(UPersistentMeshSelection* Selection);
/** Clear the active selection. This is undoable, ie a FPersistentMeshSelectionChange will be emitted */
virtual void ClearActiveSelection();
protected:
UPROPERTY()
TObjectPtr<UInteractiveToolsContext> ParentContext;
UPROPERTY()
TObjectPtr<UPersistentMeshSelection> ActiveSelection;
UPROPERTY()
TObjectPtr<UPreviewGeometry> SelectionDisplay;
virtual void OnSelectionModified();
virtual void SetNewActiveSelectionInternal(UPersistentMeshSelection* Selection);
friend class FPersistentMeshSelectionChange;
};
/**
* FPersistentMeshSelectionChange stores a selection change, ie before-and-after states.
* UPersistentMeshSelectionManager emits these changes on selection modifications.
*/
class MODELINGCOMPONENTS_API FPersistentMeshSelectionChange : public FToolCommandChange
{
public:
FGenericMeshSelection From;
FGenericMeshSelection To;
virtual void Apply(UObject* Object) override;
virtual void Revert(UObject* Object) override;
virtual bool HasExpired(UObject* Object) const override;
virtual FString ToString() const override;
};
namespace UE
{
namespace Geometry
{
//
// The functions below are helper functions that simplify usage of a UPersistentMeshSelectionManager
// that is registered as a ContextStoreObject in an InteractiveToolsContext
//
/**
* If one does not already exist, create a new instance of UPersistentMeshSelectionManager and add it to the
* ToolsContext's ContextObjectStore
* @return true if the ContextObjectStore now has a UPersistentMeshSelectionManager (whether it already existed, or was created)
*/
MODELINGCOMPONENTS_API bool RegisterPersistentMeshSelectionManager(UInteractiveToolsContext* ToolsContext);
/**
* Remove any existing UPersistentMeshSelectionManager from the ToolsContext's ContextObjectStore
* @return true if the ContextObjectStore no longer has a UPersistentMeshSelectionManager (whether it was removed, or did not exist)
*/
MODELINGCOMPONENTS_API bool DeregisterPersistentMeshSelectionManager(UInteractiveToolsContext* ToolsContext);
/**
* Find an existing UPersistentMeshSelectionManager in the ToolsContext's ContextObjectStore
* @return SelectionManager pointer or nullptr if not found
*/
MODELINGCOMPONENTS_API UPersistentMeshSelectionManager* FindPersistentMeshSelectionManager(UInteractiveToolManager* ToolManager);
}
}