HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
hydraObserver.h
Go to the documentation of this file.
1 //
2 // Copyright 2022 Pixar
3 //
4 // Licensed under the terms set forth in the LICENSE.txt file available at
5 // https://openusd.org/license.
6 //
7 #ifndef PXR_USD_IMAGING_USDVIEWQ_HYDRA_OBSERVER_H
8 #define PXR_USD_IMAGING_USDVIEWQ_HYDRA_OBSERVER_H
9 
12 
13 #include <optional>
14 
16 
17 /// \class UsdviewqHydraObserver
18 ///
19 /// Abstracts pieces necessary for implementing a Hydra Scene Browser in a
20 /// manner convenient for exposing to python.
21 ///
22 /// For C++ code, this offers no benefits over directly implementing an
23 /// HdSceneIndexObserver. It exists solely in service of the python
24 /// implementation of Hydra Scene Browser present in usdview.
25 ///
26 /// See extras/imaging/examples/hdui for an example of a C++ direct
27 /// implementation.
28 ///
30 {
31 public:
32 
34  UsdviewqHydraObserver() = default;
35 
38 
39  /// Returns the names of scene indices previously registered with
40  /// HdSceneIndexNameRegistry. It allows a browser to retrieve available
41  /// instances without direct interaction with the application.
43  static
44  std::vector<std::string> GetRegisteredSceneIndexNames();
45 
46 
47  /// Target this observer to a scene index with the given name previously
48  /// registered via HdSceneIndexNameRegistry
50  bool TargetToNamedSceneIndex(const std::string &name);
51 
52  using IndexList = std::vector<size_t> ;
53 
54  /// Starting from the currently targeted HdSceneIndex, each value in the
55  /// \p inputIndices is treated as an index into the result of
56  /// HdFilteringSceneIndexBase::GetInputScenes.
57  ///
58  /// Returns true if each followed index maps to a valid index into the
59  /// input scenes of the previous.
61  bool TargetToInputSceneIndex(const IndexList &inputIndices);
62 
63 
64  /// Returns the display name of the actively targeted scene index.
65  /// This display name is currently derived from the C++ typename.
67  std::string GetDisplayName();
68 
69  /// Starting from the currently targeted HdSceneIndex, each value in the
70  /// \p inputIndices is treated as an index into the result of
71  /// HdFilteringSceneIndexBase::GetInputScenes.
72  ///
73  /// If the scene index reached is a subclass of HdFilteringSceneIndexBase,
74  /// the display names of the return value of GetInputScenes is returned.
75  /// Otherwise, the return value is empty.
77  std::vector<std::string> GetInputDisplayNames(
78  const IndexList &inputIndices);
79 
80  /// Recurses through all input scene indices and lists them all by
81  /// display name. Includes targeted scene index itself.
83  std::vector<std::string> GetNestedInputDisplayNames();
84 
85  /// Given an index into GetNestedInputDisplayNames(), sets the
86  /// corresponding scene index as targeted HdSceneIndex.
87  ///
88  /// Returns false, if index was out of bounds.
90  bool TargetToNestedInputSceneIndex(size_t nestedInputIndex);
91 
92  /// Returns the paths of the immediate children of the specified
93  /// \p primPath for the actively observer scene index.
95  SdfPathVector GetChildPrimPaths(const SdfPath &primPath);
96 
97  /// Returns the prim type and data source for the specified \p primPath for
98  /// the actively observer scene index.
100  HdSceneIndexPrim GetPrim(const SdfPath &primPath);
101 
102  /// Aggregate of HdSceneIndexObserver entry types for easier binding to
103  /// python.
104  struct NoticeEntry
105  {
107  : added(entries)
108  {}
109 
111  : removed(entries)
112  {}
113 
115  : dirtied(entries)
116  {}
117 
118  NoticeEntry(const NoticeEntry &other) = default;
119 
123  };
124 
125  using NoticeEntryVector = std::vector<NoticeEntry>;
126 
127  /// Returns true if there are pending scene change notices. Consumers
128  /// of this follow a polling rather than callback pattern.
130  bool HasPendingNotices();
131 
132  /// Returns (and clears) any accumulated scene change notices. Consumers
133  /// of this follow a polling rather than callback pattern.
136 
137  /// Clears any accumulated scene change notices
139  void ClearPendingNotices();
140 
141 private:
142 
143  bool _Target(const HdSceneIndexBaseRefPtr &sceneIndex);
144 
145  // Fill _nestedInputSceneIndices.
146  void _ComputeNestedInputSceneIndices();
147 
148  class _Observer : public HdSceneIndexObserver
149  {
150  public:
152  void PrimsAdded(
153  const HdSceneIndexBase &sender,
154  const AddedPrimEntries &entries) override;
155 
157  void PrimsRemoved(
158  const HdSceneIndexBase &sender,
159  const RemovedPrimEntries &entries) override;
160 
162  void PrimsDirtied(
163  const HdSceneIndexBase &sender,
164  const DirtiedPrimEntries &entries) override;
165 
167  void PrimsRenamed(
168  const HdSceneIndexBase &sender,
169  const RenamedPrimEntries &entries) override;
170 
171 
172  NoticeEntryVector notices;
173  };
174 
175  // Cached result for GetNestedInputDisplayNames and
176  // TargetToNestedInputSceneIndex.
177  std::optional<HdSceneIndexBaseRefPtrVector> _nestedInputSceneIndices;
178 
179  HdSceneIndexBaseRefPtr _sceneIndex;
180  _Observer _observer;
181 };
182 
184 
185 #endif
USDVIEWQ_API bool TargetToInputSceneIndex(const IndexList &inputIndices)
NoticeEntry(const HdSceneIndexObserver::RemovedPrimEntries &entries)
USDVIEWQ_API bool HasPendingNotices()
USDVIEWQ_API std::vector< std::string > GetNestedInputDisplayNames()
std::vector< size_t > IndexList
Definition: hydraObserver.h:52
USDVIEWQ_API UsdviewqHydraObserver()=default
NoticeEntry(const HdSceneIndexObserver::AddedPrimEntries &entries)
USDVIEWQ_API bool TargetToNestedInputSceneIndex(size_t nestedInputIndex)
USDVIEWQ_API NoticeEntryVector GetPendingNotices()
USDVIEWQ_API std::vector< std::string > GetInputDisplayNames(const IndexList &inputIndices)
USDVIEWQ_API ~UsdviewqHydraObserver()
NoticeEntry(const HdSceneIndexObserver::DirtiedPrimEntries &entries)
USDVIEWQ_API HdSceneIndexPrim GetPrim(const SdfPath &primPath)
#define USDVIEWQ_API
Definition: api.h:23
HdSceneIndexObserver::RemovedPrimEntries removed
static USDVIEWQ_API std::vector< std::string > GetRegisteredSceneIndexNames()
std::vector< NoticeEntry > NoticeEntryVector
std::vector< class SdfPath > SdfPathVector
GLuint const GLchar * name
Definition: glcorearb.h:786
Definition: path.h:273
USDVIEWQ_API SdfPathVector GetChildPrimPaths(const SdfPath &primPath)
USDVIEWQ_API bool TargetToNamedSceneIndex(const std::string &name)
HdSceneIndexObserver::DirtiedPrimEntries dirtied
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
USDVIEWQ_API void ClearPendingNotices()
Clears any accumulated scene change notices.
USDVIEWQ_API std::string GetDisplayName()
HdSceneIndexObserver::AddedPrimEntries added