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 Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 // names, trademarks, service marks, or product names of the Licensor
11 // and its affiliates, except as required to comply with Section 4(c) of
12 // the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 // http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
24 #ifndef PXR_USD_IMAGING_USDVIEWQ_HYDRA_OBSERVER_H
25 #define PXR_USD_IMAGING_USDVIEWQ_HYDRA_OBSERVER_H
26 
29 
30 
32 
33 /// \class UsdviewqHydraObserver
34 ///
35 /// Abstracts pieces necessary for implementing a Hydra Scene Browser in a
36 /// manner convenient for exposing to python.
37 ///
38 /// For C++ code, this offers no benefits over directly implementing an
39 /// HdSceneIndexObserver. It exists solely in service of the python
40 /// implementation of Hydra Scene Browser present in usdview.
41 ///
42 /// See extras/imaging/examples/hdui for an example of a C++ direct
43 /// implementation.
44 ///
46 {
47 public:
48 
50  UsdviewqHydraObserver() = default;
51 
54 
55  /// Returns the names of scene indices previously registered with
56  /// HdSceneIndexNameRegistry. It allows a browser to retrieve available
57  /// instances without direct interaction with the application.
59  static
60  std::vector<std::string> GetRegisteredSceneIndexNames();
61 
62 
63  /// Target this observer to a scene index with the given name previously
64  /// registered via HdSceneIndexNameRegistry
67 
68  using IndexList = std::vector<size_t> ;
69 
70  /// Starting from the currently targeted HdSceneIndex, each value in the
71  /// \p inputIndices is treated as an index into the result of
72  /// HdFilteringSceneIndexBase::GetInputScenes.
73  ///
74  /// Returns true if each followed index maps to a valid index into the
75  /// input scenes of the previous.
77  bool TargetToInputSceneIndex(const IndexList &inputIndices);
78 
79 
80  /// Returns the display name of the actively targeted scene index.
81  /// This display name is currently derived from the C++ typename.
84 
85  /// Starting from the currently targeted HdSceneIndex, each value in the
86  /// \p inputIndices is treated as an index into the result of
87  /// HdFilteringSceneIndexBase::GetInputScenes.
88  ///
89  /// If the scene index reached is a subclass of HdFilteringSceneIndexBase,
90  /// the display names of the return value of GetInputScenes is returned.
91  /// Otherwise, the return value is empty.
93  std::vector<std::string> GetInputDisplayNames(
94  const IndexList &inputIndices);
95 
96  /// Returns the paths of the immediate children of the specified
97  /// \p primPath for the actively observer scene index.
99  SdfPathVector GetChildPrimPaths(const SdfPath &primPath);
100 
101  /// Returns the prim type and data source for the specified \p primPath for
102  /// the actively observer scene index.
104  HdSceneIndexPrim GetPrim(const SdfPath &primPath);
105 
106  /// Aggregate of HdSceneIndexObserver entry types for easier binding to
107  /// python.
108  struct NoticeEntry
109  {
111  : added(entries)
112  {}
113 
115  : removed(entries)
116  {}
117 
119  : dirtied(entries)
120  {}
121 
122  NoticeEntry(const NoticeEntry &other) = default;
123 
127  };
128 
129  using NoticeEntryVector = std::vector<NoticeEntry>;
130 
131  /// Returns true if there are pending scene change notices. Consumers
132  /// of this follow a polling rather than callback pattern.
134  bool HasPendingNotices();
135 
136  /// Returns (and clears) any accumulated scene change notices. Consumers
137  /// of this follow a polling rather than callback pattern.
140 
141  /// Clears any accumulated scene change notices
143  void ClearPendingNotices();
144 
145 private:
146 
147  bool _Target(const HdSceneIndexBaseRefPtr &sceneIndex);
148 
149  class _Observer : public HdSceneIndexObserver
150  {
151  public:
153  void PrimsAdded(
154  const HdSceneIndexBase &sender,
155  const AddedPrimEntries &entries) override;
156 
158  void PrimsRemoved(
159  const HdSceneIndexBase &sender,
160  const RemovedPrimEntries &entries) override;
161 
163  void PrimsDirtied(
164  const HdSceneIndexBase &sender,
165  const DirtiedPrimEntries &entries) override;
166 
168  void PrimsRenamed(
169  const HdSceneIndexBase &sender,
170  const RenamedPrimEntries &entries) override;
171 
172 
173  NoticeEntryVector notices;
174  };
175 
176  HdSceneIndexBaseRefPtr _sceneIndex;
177  _Observer _observer;
178 };
179 
181 
182 #endif
USDVIEWQ_API bool TargetToInputSceneIndex(const IndexList &inputIndices)
NoticeEntry(const HdSceneIndexObserver::RemovedPrimEntries &entries)
USDVIEWQ_API bool HasPendingNotices()
std::vector< size_t > IndexList
Definition: hydraObserver.h:68
USDVIEWQ_API UsdviewqHydraObserver()=default
GLsizei const GLchar *const * string
Definition: glcorearb.h:814
NoticeEntry(const HdSceneIndexObserver::AddedPrimEntries &entries)
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:40
HdSceneIndexObserver::RemovedPrimEntries removed
static USDVIEWQ_API std::vector< std::string > GetRegisteredSceneIndexNames()
std::vector< NoticeEntry > NoticeEntryVector
GLuint const GLchar * name
Definition: glcorearb.h:786
Definition: path.h:290
USDVIEWQ_API SdfPathVector GetChildPrimPaths(const SdfPath &primPath)
std::vector< class SdfPath > SdfPathVector
A vector of SdfPaths.
Definition: path.h:211
USDVIEWQ_API bool TargetToNamedSceneIndex(const std::string &name)
HdSceneIndexObserver::DirtiedPrimEntries dirtied
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1432
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
USDVIEWQ_API void ClearPendingNotices()
Clears any accumulated scene change notices.
USDVIEWQ_API std::string GetDisplayName()
HdSceneIndexObserver::AddedPrimEntries added