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

Isolate select scene index, with command-based implementation. #164

Merged
merged 3 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "flowViewport/API/interfacesImp/fvpDataProducerSceneIndexInterfaceImp.h"
#include "flowViewport/API/interfacesImp/fvpInformationInterfaceImp.h"
#include "flowViewport/sceneIndex/fvpRenderIndexProxy.h"
#include "flowViewport/selection/fvpSelection.h"
#include "flowViewport/API/perViewportSceneIndicesData/fvpFilteringSceneIndicesChainManager.h"

//Hydra headers
Expand Down Expand Up @@ -151,6 +152,91 @@ ViewportInformationAndSceneIndicesPerViewportData* ViewportInformationAndSceneIn
return nullptr;
}

SelectionPtr ViewportInformationAndSceneIndicesPerViewportDataManager::GetOrCreateIsolateSelection(const std::string& viewportId)
{
auto found = _isolateSelection.find(viewportId);
if (found != _isolateSelection.end()) {
return found->second;
}
auto selection = std::make_shared<Selection>();
_isolateSelection[viewportId] = selection;
return selection;
}

SelectionPtr ViewportInformationAndSceneIndicesPerViewportDataManager::GetIsolateSelection(const std::string& viewportId) const
{
auto found = _isolateSelection.find(viewportId);
return (found != _isolateSelection.end()) ? found->second : nullptr;
}

void ViewportInformationAndSceneIndicesPerViewportDataManager::AddIsolateSelection(
const std::string& viewportId,
const PrimSelections& primSelections
)
{
if (!TF_VERIFY(_isolateSelectSceneIndex, "No isolate select scene index set.")) {
return;
}
_CheckAndSetViewport(viewportId);
_isolateSelectSceneIndex->AddIsolateSelection(primSelections);
}

void ViewportInformationAndSceneIndicesPerViewportDataManager::RemoveIsolateSelection(
const std::string& viewportId,
const PrimSelections& primSelections
)
{
if (!TF_VERIFY(_isolateSelectSceneIndex, "No isolate select scene index set.")) {
return;
}
_CheckAndSetViewport(viewportId);
_isolateSelectSceneIndex->RemoveIsolateSelection(primSelections);
}

void ViewportInformationAndSceneIndicesPerViewportDataManager::ReplaceIsolateSelection(
const std::string& viewportId,
const SelectionConstPtr& selection
)
{
if (!TF_VERIFY(_isolateSelectSceneIndex, "No isolate select scene index set.")) {
return;
}
_CheckAndSetViewport(viewportId);
_isolateSelectSceneIndex->ReplaceIsolateSelection(selection);
}

void ViewportInformationAndSceneIndicesPerViewportDataManager::ClearIsolateSelection(const std::string& viewportId)
{
if (!TF_VERIFY(_isolateSelectSceneIndex, "No isolate select scene index set.")) {
return;
}
_CheckAndSetViewport(viewportId);
_isolateSelectSceneIndex->ClearIsolateSelection();
}

void ViewportInformationAndSceneIndicesPerViewportDataManager::SetIsolateSelectSceneIndex(
const IsolateSelectSceneIndexRefPtr& sceneIndex
)
{
_isolateSelectSceneIndex = sceneIndex;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there anything you need to clean up if there was a previous sceneIndex ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't believe so. The isolate selections exist independently of the isolate scene index.

}

IsolateSelectSceneIndexRefPtr
ViewportInformationAndSceneIndicesPerViewportDataManager::GetIsolateSelectSceneIndex() const
{
return _isolateSelectSceneIndex;
}

void
ViewportInformationAndSceneIndicesPerViewportDataManager::_CheckAndSetViewport(
const std::string& viewportId
)
{
if (_isolateSelectSceneIndex->GetViewportId() != viewportId) {
_isolateSelectSceneIndex->SetViewport(viewportId, _isolateSelection.at(viewportId));
}
}

const std::set<PXR_NS::FVP_NS_DEF::DataProducerSceneIndexDataBaseRefPtr>&
ViewportInformationAndSceneIndicesPerViewportDataManager::GetDataProducerSceneIndicesDataFromViewportId(const std::string& viewportId)const
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
//Local headers
#include "fvpViewportInformationAndSceneIndicesPerViewportData.h"
#include "flowViewport/sceneIndex/fvpRenderIndexProxyFwd.h"
#include "flowViewport/sceneIndex/fvpPathInterface.h"
#include "flowViewport/sceneIndex/fvpIsolateSelectSceneIndex.h"
#include "flowViewport/selection/fvpSelectionFwd.h"

//Hydra headers
#include <pxr/imaging/hd/sceneIndex.h>
Expand All @@ -31,11 +34,16 @@ namespace FVP_NS_DEF {
*
* To get an instance of this class, please use
* ViewportInformationAndSceneIndicesPerViewportDataManager& manager = ViewportInformationAndSceneIndicesPerViewportDataManager:Get();
*
* The PerViewportDataManager also manages the per-viewport isolate selection,
* as well as providing access to the single isolate select scene index.
*/
class FVP_API ViewportInformationAndSceneIndicesPerViewportDataManager
{
public:

using ViewportIds = std::vector<std::string>;

/// Manager accessor
static ViewportInformationAndSceneIndicesPerViewportDataManager& Get();

Expand All @@ -53,18 +61,58 @@ class FVP_API ViewportInformationAndSceneIndicesPerViewportDataManager
const ViewportInformationAndSceneIndicesPerViewportData* GetViewportInfoAndDataFromViewportId(const std::string& viewportId)const;
ViewportInformationAndSceneIndicesPerViewportData* GetViewportInfoAndDataFromViewportId(const std::string& viewportId);

SelectionPtr GetOrCreateIsolateSelection(const std::string& viewportId);
SelectionPtr GetIsolateSelection(const std::string& viewportId) const;

void AddIsolateSelection(
const std::string& viewportId,
const PrimSelections& primSelections
);
void RemoveIsolateSelection(
const std::string& viewportId,
const PrimSelections& primSelections
);
void ReplaceIsolateSelection(
const std::string& viewportId,
const SelectionConstPtr& selection
);
void ClearIsolateSelection(const std::string& viewportId);

// Get and set the isolate select scene index. This scene index provides
// isolate select services for all viewports.
void SetIsolateSelectSceneIndex(
const IsolateSelectSceneIndexRefPtr& sceneIndex
);
IsolateSelectSceneIndexRefPtr GetIsolateSelectSceneIndex() const;

const std::set<PXR_NS::FVP_NS_DEF::DataProducerSceneIndexDataBaseRefPtr>& GetDataProducerSceneIndicesDataFromViewportId(const std::string& viewportId)const;

bool ModelPanelIsAlreadyRegistered(const std::string& modelPanel)const;
void RemoveAllViewportsInformation();

private:

// Singleton, no public creation or copy.
ViewportInformationAndSceneIndicesPerViewportDataManager() = default;
ViewportInformationAndSceneIndicesPerViewportDataManager(
const ViewportInformationAndSceneIndicesPerViewportDataManager&
) = delete;

void _CheckAndSetViewport(const std::string& viewportId);

///Hydra viewport information
ViewportInformationAndSceneIndicesPerViewportDataVector _viewportsInformationAndSceneIndicesPerViewportData;

ViewportInformationAndSceneIndicesPerViewportDataManager() = default;
// Isolate selection, keyed by viewportId.
std::map<std::string, SelectionPtr> _isolateSelection;

// Isolate select scene index.
IsolateSelectSceneIndexRefPtr _isolateSelectSceneIndex;
};

// Convenience shorthand declaration.
using PerViewportDataManager = ViewportInformationAndSceneIndicesPerViewportDataManager;

} //End of namespace FVP_NS_DEF

#endif // FLOW_VIEWPORT_API_PERVIEWPORTSCENEINDICESDATA_VIEWPORT_INFORMATION_AND_SCENE_INDICES_DATA_PER_VIEWPORT_DATA_MANAGER
#endif // FLOW_VIEWPORT_API_PERVIEWPORTSCENEINDICESDATA_VIEWPORT_INFORMATION_AND_SCENE_INDICES_DATA_PER_VIEWPORT_DATA_MANAGER
4 changes: 4 additions & 0 deletions lib/flowViewport/debugCodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ TF_REGISTRY_FUNCTION(TfDebug)
TF_DEBUG_ENVIRONMENT_SYMBOL(
PXR_NS::FVP_WIREFRAME_SELECTION_HIGHLIGHT_SCENE_INDEX,
"Print information about the Flow Viewport wireframe selection highlight scene index.");

TF_DEBUG_ENVIRONMENT_SYMBOL(
PXR_NS::FVP_ISOLATE_SELECT_SCENE_INDEX,
"Print information about the Flow Viewport isolate select scene index.");
}

PXR_NAMESPACE_CLOSE_SCOPE
1 change: 1 addition & 0 deletions lib/flowViewport/debugCodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ TF_DEBUG_CODES(
, FVP_APP_SELECTION_CHANGE
, FVP_MERGING_SCENE_INDEX
, FVP_WIREFRAME_SELECTION_HIGHLIGHT_SCENE_INDEX
, FVP_ISOLATE_SELECT_SCENE_INDEX
);
// clang-format on

Expand Down
2 changes: 2 additions & 0 deletions lib/flowViewport/sceneIndex/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# -----------------------------------------------------------------------------
target_sources(${TARGET_NAME}
PRIVATE
fvpIsolateSelectSceneIndex.cpp
fvpMergingSceneIndex.cpp
fvpPathInterface.cpp
fvpPathInterfaceSceneIndex.cpp
Expand All @@ -19,6 +20,7 @@ target_sources(${TARGET_NAME}
)

set(HEADERS
fvpIsolateSelectSceneIndex.h
fvpMergingSceneIndex.h
fvpPathInterface.h
fvpPathInterfaceSceneIndex.h
Expand Down
Loading