Skip to content

Commit 3ece341

Browse files
committed
Expose isRootChild as DCC function.
1 parent 9cdbf38 commit 3ece341

File tree

4 files changed

+41
-11
lines changed

4 files changed

+41
-11
lines changed

lib/usdUfe/ufe/Global.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ Ufe::Rtid initialize(
7575
UsdUfe::setIsAttributeLockedFn(dccFunctions.isAttributeLockedFn);
7676
if (dccFunctions.saveStageLoadRulesFn)
7777
UsdUfe::setSaveStageLoadRulesFn(dccFunctions.saveStageLoadRulesFn);
78+
if (dccFunctions.isRootChildFn)
79+
UsdUfe::setIsRootChildFn(dccFunctions.isRootChildFn);
7880

7981
// Create a default stages subject if none is provided.
8082
if (nullptr == ss) {

lib/usdUfe/ufe/Global.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ struct USDUFE_PUBLIC DCCFunctions
4646
// Optional: default values will be used if no function is supplied.
4747
IsAttributeLockedFn isAttributeLockedFn = nullptr;
4848
SaveStageLoadRulesFn saveStageLoadRulesFn = nullptr;
49+
IsRootChildFn isRootChildFn = nullptr;
4950
};
5051

5152
/*! Ufe runtime handlers used to initialize the plugin.

lib/usdUfe/ufe/Utils.cpp

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ UsdUfe::UfePathToPrimFn gUfePathToPrimFn = nullptr;
9090
UsdUfe::TimeAccessorFn gTimeAccessorFn = nullptr;
9191
UsdUfe::IsAttributeLockedFn gIsAttributeLockedFn = nullptr;
9292
UsdUfe::SaveStageLoadRulesFn gSaveStageLoadRulesFn = nullptr;
93+
UsdUfe::IsRootChildFn gIsRootChildFn = nullptr;
9394

9495
} // anonymous namespace
9596

@@ -231,6 +232,29 @@ void saveStageLoadRules(const PXR_NS::UsdStageRefPtr& stage)
231232
gSaveStageLoadRulesFn(stage);
232233
}
233234

235+
void setIsRootChildFn(IsRootChildFn fn)
236+
{
237+
// This function is allowed to be null in which case, the default implementation
238+
// is used (isRootChildDefault()).
239+
gIsRootChildFn = fn;
240+
}
241+
242+
bool isRootChild(const Ufe::Path& path)
243+
{
244+
return gIsRootChildFn ? gIsRootChildFn(path) : isRootChildDefault(path);
245+
}
246+
247+
bool isRootChildDefault(const Ufe::Path& path)
248+
{
249+
// When called we make the assumption that we are given a valid
250+
// path and we are only testing whether or not we are a root child.
251+
auto segments = path.getSegments();
252+
if (segments.size() != 2) {
253+
TF_RUNTIME_ERROR(kIllegalUFEPath, path.string().c_str());
254+
}
255+
return (segments[1].size() == 1);
256+
}
257+
234258
int ufePathToInstanceIndex(const Ufe::Path& path, UsdPrim* prim)
235259
{
236260
int instanceIndex = UsdImagingDelegate::ALL_INSTANCES;
@@ -254,17 +278,6 @@ int ufePathToInstanceIndex(const Ufe::Path& path, UsdPrim* prim)
254278
return instanceIndex;
255279
}
256280

257-
bool isRootChild(const Ufe::Path& path)
258-
{
259-
// When called we make the assumption that we are given a valid
260-
// path and we are only testing whether or not we are a root child.
261-
auto segments = path.getSegments();
262-
if (segments.size() != 2) {
263-
TF_RUNTIME_ERROR(kIllegalUFEPath, path.string().c_str());
264-
}
265-
return (segments[1].size() == 1);
266-
}
267-
268281
std::string uniqueName(const TfToken::HashSet& existingNames, std::string srcName)
269282
{
270283
// Compiled regular expression to find a numerical suffix to a path component.

lib/usdUfe/ufe/Utils.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ typedef PXR_NS::UsdPrim (*UfePathToPrimFn)(const Ufe::Path&);
4444
typedef PXR_NS::UsdTimeCode (*TimeAccessorFn)(const Ufe::Path&);
4545
typedef bool (*IsAttributeLockedFn)(const PXR_NS::UsdAttribute& attr, std::string* errMsg);
4646
typedef void (*SaveStageLoadRulesFn)(const PXR_NS::UsdStageRefPtr&);
47+
typedef bool (*IsRootChildFn)(const Ufe::Path& path);
4748

4849
//------------------------------------------------------------------------------
4950
// Helper functions
@@ -137,9 +138,22 @@ void saveStageLoadRules(const PXR_NS::UsdStageRefPtr& stage);
137138
USDUFE_PUBLIC
138139
int ufePathToInstanceIndex(const Ufe::Path& path, PXR_NS::UsdPrim* prim = nullptr);
139140

141+
//! Set the DCC specific "isRootChild" test function.
142+
//! Use of this function is optional, if one is not supplied then
143+
//! a default implementation of isRootChild is used..
144+
USDUFE_PUBLIC
145+
void setIsRootChildFn(IsRootChildFn fn);
146+
147+
//! Returns true if the path corresponds to an item at the root of a runtime.
148+
//! Implementation can be set by the DCC.
140149
USDUFE_PUBLIC
141150
bool isRootChild(const Ufe::Path& path);
142151

152+
//! Default isRootChild() implementation. Assumes 2 segments. Will report a root child
153+
//! if the second segment has a single component.
154+
USDUFE_PUBLIC
155+
bool isRootChildDefault(const Ufe::Path& path);
156+
143157
//! Split the source name into a base name and a numerical suffix (set to
144158
//! 1 if absent). Increment the numerical suffix until name is unique.
145159
USDUFE_PUBLIC

0 commit comments

Comments
 (0)