Skip to content

Commit

Permalink
Fixes from code review and moved a class to flow viewport
Browse files Browse the repository at this point in the history
  • Loading branch information
lanierd-adsk committed Aug 30, 2024
1 parent f225b84 commit c4f8f5e
Show file tree
Hide file tree
Showing 12 changed files with 162 additions and 148 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@
//Std Headers
#include <mutex>

/// DataProducersNodeHashCodeToSdfPathRegistry does a mapping between DCC nodes hash code and Hydra
/// paths. The DCC nodes registered in this class are used by data producers scene indices as a
/// parent to all primitives. The registration/unregistration in this class is automatic when you
/// use the flow viewport API and provide a DCC node as a parent. This class is used when we select
/// one of these nodes to return the matching SdfPath so that all child prims of this node are
/// highlighted.
///
namespace
{
std::mutex dataProducerSceneIndicesThatApplyToAllViewports_mutex;
Expand Down Expand Up @@ -69,7 +76,7 @@ PXR_NS::FVP_NS_DEF::DataProducerSceneIndexDataBaseRefPtr DataProducerSceneIndexI
}

bool DataProducerSceneIndexInterfaceImp::addUsdStageDataProducerSceneIndexDataBaseToAllViewports(PXR_NS::FVP_NS_DEF::DataProducerSceneIndexDataBaseRefPtr& dataProducerSceneIndexData){
//Apply this maya usd scene index to all viewports
//Apply this usd scene index to all viewports
return _AddDataProducerSceneIndexToAllViewports(dataProducerSceneIndexData);
}

Expand Down
2 changes: 2 additions & 0 deletions lib/flowViewport/selection/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ target_sources(${TARGET_NAME}
fvpPathMapperFwd.cpp
fvpPathMapperRegistry.cpp
fvpPrefixPathMapper.cpp
fvpDataProducersNodeHashCodeToSdfPathRegistry.cpp
)

set(HEADERS
Expand All @@ -22,6 +23,7 @@ set(HEADERS
fvpPathMapperFwd.h
fvpPathMapperRegistry.h
fvpPrefixPathMapper.h
fvpDataProducersNodeHashCodeToSdfPathRegistry.h
)

# -----------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
//
// Copyright 2024 Autodesk
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

#include "fvpDataProducersNodeHashCodeToSdfPathRegistry.h"
#include <pxr/base/tf/instantiateSingleton.h>

PXR_NAMESPACE_USING_DIRECTIVE
TF_INSTANTIATE_SINGLETON(FVP_NS::DataProducersNodeHashCodeToSdfPathRegistry);

// DataProducersNodeHashCodeToSdfPathRegistry does a mapping between DCC nodes hash code and Hydra
// paths. The DCC nodes registered in this class are used by data producers scene indices as a
// parent to all their Hydra primitives. The registration/unregistration in this class is automatic
// when you use the flow viewport API and provide a DCC node as a parent. This class is used when
// we select one of these DCC nodes to return the matching SdfPath so that all prims child of this
// node are highlighted.

namespace FVP_NS_DEF {

/* static */
DataProducersNodeHashCodeToSdfPathRegistry& DataProducersNodeHashCodeToSdfPathRegistry::Instance()
{
return PXR_NS::TfSingleton<DataProducersNodeHashCodeToSdfPathRegistry>::GetInstance();
}

void DataProducersNodeHashCodeToSdfPathRegistry::Add(const unsigned long& dccNodeHashCode, const SdfPath& thePath)
{
if (thePath.IsEmpty() || 0 == dccNodeHashCode) {
TF_CODING_WARNING("Sending an empty SdfPath or an invalid dcc node hash code in DataProducersNodeHashCodeToSdfPathRegistry::Add, ignoring");
return;
}

_SdfPathByHashCode.insert({ dccNodeHashCode, thePath });
}

void DataProducersNodeHashCodeToSdfPathRegistry::Remove(const unsigned long& dccNodeHashCode)
{
if (0 == dccNodeHashCode) {
return;
}

auto it = _SdfPathByHashCode.find(dccNodeHashCode);
if (it != _SdfPathByHashCode.end()) {
_SdfPathByHashCode.erase(it);
}
}

SdfPath DataProducersNodeHashCodeToSdfPathRegistry::GetPath(const unsigned long& dccNodeHashCode) const
{
if (0 == dccNodeHashCode) {
TF_CODING_WARNING("Sending an invalid dccNodeHashCode in DataProducersNodeHashCodeToSdfPathRegistry::GetPath");
return {};
}
auto it = _SdfPathByHashCode.find(dccNodeHashCode);
if (it != _SdfPathByHashCode.end()) {
return (it->second);
}
return SdfPath();
}

} // namespace FVP_NS_DEF
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
//
// Copyright 2024 Autodesk
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#ifndef FLOW_VIEWPORT_SELECTION__DATA_PRODUCERS_NODE_HASH_CODE_TO_SDFPATH_REGISTRY_H
#define FLOW_VIEWPORT_SELECTION__DATA_PRODUCERS_NODE_HASH_CODE_TO_SDFPATH_REGISTRY_H

//local headers
#include "flowViewport/api.h"

//Usd headers
#include <pxr/base/tf/singleton.h>
#include <pxr/usd/sdf/path.h>

#include <unordered_map>

namespace FVP_NS_DEF {

/// DataProducersNodeHashCodeToSdfPathRegistry does a mapping between DCC nodes hash code and Hydra paths.
/// The DCC nodes registered in this class are used by data producers scene indices as a parent to all primitives.
/// The registration/unregistration in this class is automatic when you use the flow viewport API and provide a DCC node as a parent.
/// This class is used when we select one of these nodes to return the matching SdfPath so that all child prims of this node are highlighted.
class DataProducersNodeHashCodeToSdfPathRegistry
{
public:
// Access the singleton instance
FVP_API
static DataProducersNodeHashCodeToSdfPathRegistry& Instance();

FVP_API
void Add(const unsigned long& objectHandlehashCode, const PXR_NS::SdfPath& thePath);

FVP_API
void Remove(const unsigned long& objectHandleHashCode);

// Returns an empty SdfPath if the objectHandle is not registered or the matching SdfPath
// otherwise
FVP_API
PXR_NS::SdfPath GetPath(const unsigned long& objectHandleHashCode) const;

private:
// Singleton, no public creation or copy.
DataProducersNodeHashCodeToSdfPathRegistry() = default;
~DataProducersNodeHashCodeToSdfPathRegistry() = default;
DataProducersNodeHashCodeToSdfPathRegistry(const DataProducersNodeHashCodeToSdfPathRegistry& ) = delete;
DataProducersNodeHashCodeToSdfPathRegistry& operator=(const DataProducersNodeHashCodeToSdfPathRegistry& ) = delete;

friend class PXR_NS::TfSingleton<DataProducersNodeHashCodeToSdfPathRegistry>;

std::unordered_map<unsigned long, PXR_NS::SdfPath> _SdfPathByHashCode;

static std::unique_ptr<DataProducersNodeHashCodeToSdfPathRegistry> _instance;
};

} // namespace FVP_NS_DEF

#endif //FLOW_VIEWPORT_SELECTION__DATA_PRODUCERS_NODE_HASH_CODE_TO_SDFPATH_REGISTRY_H
2 changes: 0 additions & 2 deletions lib/mayaHydra/hydraExtensions/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ target_sources(${TARGET_NAME}
mhWireframeColorInterfaceImp.cpp
mhLeadObjectPathTracker.cpp
tokens.cpp
mhDataProducersMayaNodeToSdfPathRegistry.cpp
)

set(HEADERS
Expand All @@ -31,7 +30,6 @@ set(HEADERS
mhWireframeColorInterfaceImp.h
mhLeadObjectPathTracker.h
tokens.h
mhDataProducersMayaNodeToSdfPathRegistry.h
)

# -----------------------------------------------------------------------------
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,15 @@

//Local headers
#include "mayaHydraMayaDataProducerSceneIndexData.h"
#include "mayaHydraLib/mhDataProducersMayaNodeToSdfPathRegistry.h"
#include "mayaHydraLib/hydraUtils.h"
#include "mayaHydraLib/mayaUtils.h"

//Flow viewport
#include <flowViewport/selection/fvpDataProducersNodeHashCodeToSdfPathRegistry.h>

//maya headers
#include <maya/MObjectHandle.h>

PXR_NAMESPACE_USING_DIRECTIVE

class MayaDataProducerSceneIndexData::UfeSceneChangesHandler : public Ufe::Observer
Expand Down Expand Up @@ -70,7 +75,7 @@ MayaDataProducerSceneIndexData::~MayaDataProducerSceneIndexData()
}
if (0 != _dccNodeHashCode){
//Remove the node from the registry
MAYAHYDRA_NS::MhDataProducersMayaNodeToSdfPathRegistry::Instance().Remove(_dccNodeHashCode);
FVP_NS::DataProducersNodeHashCodeToSdfPathRegistry::Instance().Remove(_dccNodeHashCode);
}
}

Expand All @@ -89,7 +94,7 @@ void MayaDataProducerSceneIndexData::SetupDCCNode()
if (!dagPath.node().isNull()) {
MObjectHandle hdl(dagPath.node());
_dccNodeHashCode = hdl.hashCode();
MAYAHYDRA_NS::MhDataProducersMayaNodeToSdfPathRegistry::Instance().Add(
FVP_NS::DataProducersNodeHashCodeToSdfPathRegistry::Instance().Add(
_dccNodeHashCode, _prefix);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
#include <mayaHydraLib/sceneIndex/mayaHydraDataSource.h>
#include <mayaHydraLib/pick/mhPickHandler.h>
#include <mayaHydraLib/pick/mhPickHandlerRegistry.h>
#include <mayaHydraLib/mhDataProducersMayaNodeToSdfPathRegistry.h>
#include <flowViewport/selection/fvpDataProducersNodeHashCodeToSdfPathRegistry.h>

#include <ufeExtensions/Global.h>

Expand Down Expand Up @@ -771,7 +771,7 @@ Fvp::PrimSelections MayaHydraSceneIndex::UfePathToPrimSelections(const Ufe::Path
//highlighted.
MDagPath shapeDagPath(dagPath);
shapeDagPath.extendToShape();
const SdfPath matchingPath = MhDataProducersMayaNodeToSdfPathRegistry::Instance().GetPath(MObjectHandle(shapeDagPath.node()).hashCode());
const SdfPath matchingPath = FVP_NS::DataProducersNodeHashCodeToSdfPathRegistry::Instance().GetPath(MObjectHandle(shapeDagPath.node()).hashCode());
if (! matchingPath.IsEmpty()) {
primPath = matchingPath;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,4 @@ SdfPathVector MayaUsdProxyShapeSceneIndex::GetChildPrimPaths(const SdfPath& prim
return GetInputSceneIndex()->GetChildPrimPaths(primPath);
}

} // namespace MAYAUSD_NS_DEF
} // namespace MAYAHYDRA_NS_DEF
Loading

0 comments on commit c4f8f5e

Please sign in to comment.