Skip to content

Commit

Permalink
Connect isolate select to Maya UI, and empty isolate selection
Browse files Browse the repository at this point in the history
correctness.
  • Loading branch information
ppt-adsk committed Sep 24, 2024
1 parent 009535a commit 1ce914b
Show file tree
Hide file tree
Showing 18 changed files with 603 additions and 276 deletions.
10 changes: 10 additions & 0 deletions cmake/modules/FindMaya.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
# MAYA_HAS_DISPLAY_LAYER_API Presence of MFnDisplayLayer
# MAYA_HAS_NEW_DISPLAY_LAYER_MESSAGING_API Presence of MDisplayLayerMemberChangedFunction
# MAYA_HAS_RENDER_ITEM_HIDE_ON_PLAYBACK_API Presence of MRenderItem has HideOnPlayback API
# MAYA_HAS_VIEW_SELECTED_OBJECT_API Presence of M3dView::viewSelectedObject
# MAYA_LINUX_BUILT_WITH_CXX11_ABI Maya Linux was built with new cxx11 ABI.
# MAYA_MACOSX_BUILT_WITH_UB2 Maya OSX was built with Universal Binary 2.

Expand Down Expand Up @@ -403,6 +404,15 @@ if(MAYA_INCLUDE_DIRS AND EXISTS "${MAYA_INCLUDE_DIR}/maya/MHWGeometry.h")
endif()
endif()

set(MAYA_HAS_VIEW_SELECTED_OBJECT_API FALSE CACHE INTERNAL "hasViewSelectedObject")
if(MAYA_INCLUDE_DIRS AND EXISTS "${MAYA_INCLUDE_DIR}/maya/M3dView.h")
file(STRINGS ${MAYA_INCLUDE_DIR}/maya/M3dView.h MAYA_HAS_API REGEX "numViewSelectedObjects")
if(MAYA_HAS_API)
set(MAYA_HAS_VIEW_SELECTED_OBJECT_API TRUE CACHE INTERNAL "hasViewSelectedObject")
message(STATUS "M3dView has viewSelectedObject API")
endif()
endif()

set(MAYA_LINUX_BUILT_WITH_CXX11_ABI FALSE CACHE INTERNAL "MayaLinuxBuiltWithCxx11ABI")
if(IS_LINUX AND MAYA_Foundation_LIBRARY)
# Determine if Maya (on Linux) was built using the new CXX11 ABI.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,9 @@ SelectionPtr ViewportInformationAndSceneIndicesPerViewportDataManager::GetOrCrea
if (found != _isolateSelection.end()) {
return found->second;
}
auto selection = std::make_shared<Selection>();
_isolateSelection[viewportId] = selection;
return selection;
// Initially isolate selection is disabled.
_isolateSelection[viewportId] = nullptr;
return nullptr;
}

SelectionPtr ViewportInformationAndSceneIndicesPerViewportDataManager::GetIsolateSelection(const std::string& viewportId) const
Expand All @@ -169,6 +169,29 @@ SelectionPtr ViewportInformationAndSceneIndicesPerViewportDataManager::GetIsolat
return (found != _isolateSelection.end()) ? found->second : nullptr;
}

void ViewportInformationAndSceneIndicesPerViewportDataManager::DisableIsolateSelection(
const std::string& viewportId
)
{
_isolateSelection[viewportId] = nullptr;
}

SelectionPtr
ViewportInformationAndSceneIndicesPerViewportDataManager::_EnableIsolateSelection(
const std::string& viewportId
)
{
auto& is = _isolateSelection.at(viewportId);

// If the viewport didn't have an isolate selection because it was
// disabled, create it now.
if (!is) {
is = std::make_shared<Selection>();
_isolateSelection[viewportId] = is;
}
return is;
}

void ViewportInformationAndSceneIndicesPerViewportDataManager::AddIsolateSelection(
const std::string& viewportId,
const PrimSelections& primSelections
Expand All @@ -177,7 +200,8 @@ void ViewportInformationAndSceneIndicesPerViewportDataManager::AddIsolateSelecti
if (!TF_VERIFY(_isolateSelectSceneIndex, "No isolate select scene index set.")) {
return;
}
_CheckAndSetViewport(viewportId);

_EnableIsolateSelectAndSetViewport(viewportId);
_isolateSelectSceneIndex->AddIsolateSelection(primSelections);
}

Expand All @@ -189,36 +213,40 @@ void ViewportInformationAndSceneIndicesPerViewportDataManager::RemoveIsolateSele
if (!TF_VERIFY(_isolateSelectSceneIndex, "No isolate select scene index set.")) {
return;
}
_CheckAndSetViewport(viewportId);
_EnableIsolateSelectAndSetViewport(viewportId);
_isolateSelectSceneIndex->RemoveIsolateSelection(primSelections);
}

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

_isolateSelection[viewportId] = isolateSelection;
_isolateSelectSceneIndex->SetViewport(viewportId, isolateSelection);
}

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

void ViewportInformationAndSceneIndicesPerViewportDataManager::SetIsolateSelectSceneIndex(
const IsolateSelectSceneIndexRefPtr& sceneIndex
)
{
_isolateSelectSceneIndex = sceneIndex;
_isolateSelectSceneIndex = sceneIndex;
// If we're resetting the isolate select scene index, we're starting anew,
// so clear out existing isolate selections.
_isolateSelection.clear();
}

IsolateSelectSceneIndexRefPtr
Expand All @@ -228,12 +256,22 @@ ViewportInformationAndSceneIndicesPerViewportDataManager::GetIsolateSelectSceneI
}

void
ViewportInformationAndSceneIndicesPerViewportDataManager::_CheckAndSetViewport(
ViewportInformationAndSceneIndicesPerViewportDataManager::_EnableIsolateSelectAndSetViewport(
const std::string& viewportId
)
{
const bool enabled{_isolateSelectSceneIndex->GetIsolateSelection()};
auto isolateSelection = _EnableIsolateSelection(viewportId);

// If the isolate select scene index is not set to the right viewport,
// do a viewport switch.
if (_isolateSelectSceneIndex->GetViewportId() != viewportId) {
_isolateSelectSceneIndex->SetViewport(viewportId, _isolateSelection.at(viewportId));
_isolateSelectSceneIndex->SetViewport(viewportId, isolateSelection);
}
else if (!enabled) {
// Same viewport, so no viewport switch, but must move from disabled to
// enabled for that viewport.
_isolateSelectSceneIndex->SetIsolateSelection(isolateSelection);
}
}

Expand Down Expand Up @@ -288,6 +326,9 @@ void ViewportInformationAndSceneIndicesPerViewportDataManager::RemoveAllViewport
#endif

_viewportsInformationAndSceneIndicesPerViewportData.clear();//Delete all of them

_isolateSelection.clear();
_isolateSelectSceneIndex = nullptr;
}

} //End of namespace FVP_NS_DEF {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class FVP_API ViewportInformationAndSceneIndicesPerViewportDataManager

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

void AddIsolateSelection(
const std::string& viewportId,
Expand All @@ -73,8 +74,8 @@ class FVP_API ViewportInformationAndSceneIndicesPerViewportDataManager
const PrimSelections& primSelections
);
void ReplaceIsolateSelection(
const std::string& viewportId,
const SelectionConstPtr& selection
const std::string& viewportId,
const SelectionPtr& selection
);
void ClearIsolateSelection(const std::string& viewportId);

Expand All @@ -98,20 +99,24 @@ class FVP_API ViewportInformationAndSceneIndicesPerViewportDataManager
const ViewportInformationAndSceneIndicesPerViewportDataManager&
) = delete;

void _CheckAndSetViewport(const std::string& viewportId);
SelectionPtr _EnableIsolateSelection(const std::string& viewportId);
void _EnableIsolateSelectAndSetViewport(const std::string& viewportId);

///Hydra viewport information
ViewportInformationAndSceneIndicesPerViewportDataVector _viewportsInformationAndSceneIndicesPerViewportData;

// Isolate selection, keyed by viewportId.
// Isolate selection, keyed by viewportId. A null selection pointer means
// isolate select for that viewport is disabled. Disabling isolate select
// on a viewport clears its isolate selection, so that at next isolate
// select enable for that viewport its isolate selection is empty.
std::map<std::string, SelectionPtr> _isolateSelection;

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

// Convenience shorthand declaration.
using PerViewportDataManager = ViewportInformationAndSceneIndicesPerViewportDataManager;
using ViewportDataMgr = ViewportInformationAndSceneIndicesPerViewportDataManager;

} //End of namespace FVP_NS_DEF

Expand Down
Loading

0 comments on commit 1ce914b

Please sign in to comment.