Skip to content

Commit

Permalink
Isolate select scene index, with command-based implementation. (#164)
Browse files Browse the repository at this point in the history
* Isolate select scene index, with command-based implementation.

* Update to latest dev.
  • Loading branch information
ppt-adsk authored Sep 3, 2024
1 parent 7ee23a8 commit d13ba28
Show file tree
Hide file tree
Showing 24 changed files with 1,416 additions and 16 deletions.
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;
}

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

0 comments on commit d13ba28

Please sign in to comment.