HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
notice.h
Go to the documentation of this file.
1 //
2 // Copyright 2016 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_USD_NOTICE_H
25 #define PXR_USD_USD_NOTICE_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/usd/usd/api.h"
29 #include "pxr/usd/usd/common.h"
30 #include "pxr/usd/usd/object.h"
31 
32 #include "pxr/usd/sdf/changeList.h"
33 #include "pxr/usd/sdf/path.h"
34 #include "pxr/base/tf/notice.h"
35 
37 
38 
39 /// \class UsdNotice
40 ///
41 /// Container class for Usd notices
42 ///
43 class UsdNotice {
44 public:
45 
46  /// Base class for UsdStage notices.
47  class StageNotice : public TfNotice {
48  public:
49  USD_API
50  StageNotice(const UsdStageWeakPtr &stage);
51  USD_API
52  virtual ~StageNotice();
53 
54  /// Return the stage associated with this notice.
55  const UsdStageWeakPtr &GetStage() const { return _stage; }
56 
57  private:
58  UsdStageWeakPtr _stage;
59  };
60 
61  /// \class StageContentsChanged
62  ///
63  /// Ultra-conservative notice sent when the given UsdStage's contents
64  /// have changed in any way. This notice is sent when \em any authoring
65  /// is performed in any of the stage's participatory layers, in the
66  /// thread performing the authoring, \em after the affected UsdStage
67  /// has reconfigured itself in response to the authored changes.
68  ///
69  /// Receipt of this notice should cause clients to disregard any cached
70  /// values for properties or metadata. It does not \em necessarily imply
71  /// invalidation of UsdPrim s.
72  ///
74  public:
75  explicit StageContentsChanged(const UsdStageWeakPtr& stage)
76  : StageNotice(stage) {}
78  };
79 
80  /// \class ObjectsChanged
81  ///
82  /// Notice sent in response to authored changes that affect UsdObjects.
83  ///
84  /// The kinds of object changes are divided into two categories: "resync"
85  /// and "changed-info". "Resyncs" are potentially structural changes that
86  /// invalidate entire subtrees of UsdObjects (including prims and
87  /// properties). For example, if the path "/foo" is resynced, then all
88  /// subpaths like "/foo/bar" and "/foo/bar.baz" may be arbitrarily changed.
89  /// In contrast, "changed-info" means that a nonstructural change has
90  /// occurred, like an attribute value change or a value change to a metadata
91  /// field not related to composition.
92  ///
93  /// When a prim is resynced, say "/foo/bar", it might have been created or
94  /// destroyed. Indication of possible changes flows down the resynced prim
95  /// namespace, implicitly via prim resync notices. We *do not* consider the
96  /// parent "/foo" to be resynced, as this would incorrectly imply that
97  /// some or all of "/foo/bar"'s siblings (and their descendants) have
98  /// also changed. Additionally, we do not propagate change indication to
99  /// objects associated with the changed object through relationships or
100  /// connections.
101  ///
102  /// This notice provides API for two client use-cases. Clients interested
103  /// in testing whether specific objects are affected by the changes should
104  /// use the AffectedObject() method (and the ResyncedObject() and
105  /// ChangedInfoOnly() methods). Clients that wish to reason about all
106  /// changes as a whole should use the GetResyncedPaths() and
107  /// GetChangedInfoOnlyPaths() methods.
108  ///
109  class ObjectsChanged : public StageNotice {
110  using _PathsToChangesMap =
111  std::map<SdfPath, std::vector<const SdfChangeList::Entry*>>;
112 
113  friend class UsdStage;
114  ObjectsChanged(const UsdStageWeakPtr &stage,
115  const _PathsToChangesMap *resyncChanges,
116  const _PathsToChangesMap *infoChanges)
117  : StageNotice(stage)
118  , _resyncChanges(resyncChanges)
119  , _infoChanges(infoChanges) {}
120  public:
121  USD_API virtual ~ObjectsChanged();
122 
123  /// Return true if \p obj was possibly affected by the layer changes
124  /// that generated this notice. This is the case if either the object
125  /// is subject to a resync or has changed info. Equivalent to:
126  /// \code
127  /// ResyncedObject(obj) or ChangedInfoOnly(obj)
128  /// \endcode
129  bool AffectedObject(const UsdObject &obj) const {
130  return ResyncedObject(obj) || ChangedInfoOnly(obj);
131  }
132 
133  /// Return true if \p obj was resynced by the layer changes that
134  /// generated this notice. This is the case if the object's path or an
135  /// ancestor path is present in GetResyncedPrimPaths().
136  USD_API bool ResyncedObject(const UsdObject &obj) const;
137 
138  /// Return true if \p obj was changed but not resynced by the layer
139  /// changes that generated this notice.
140  USD_API bool ChangedInfoOnly(const UsdObject &obj) const;
141 
142  /// \class PathRange
143  /// An iterable range of paths to objects that have changed.
144  ///
145  /// Users may use this object in range-based for loops, or use the
146  /// iterators to access additional information about each changed
147  /// object.
148  class PathRange
149  {
150  public:
151  /// \class iterator
152  class iterator : public hboost::iterator_adaptor<
153  iterator, // crtp base,
154  _PathsToChangesMap::const_iterator, // base iterator
155  const SdfPath& // value type
156  >
157  {
158  public:
160  : iterator_adaptor_(base_type()) {}
161 
162  /// Return the set of changed fields in layers that affected
163  /// the object at the path specified by this iterator. See
164  /// UsdNotice::ObjectsChanged::GetChangedFields for more
165  /// details.
167 
168  /// Return true if the object at the path specified by this
169  /// iterator has any changed fields, false otherwise. See
170  /// UsdNotice::ObjectsChanged::HasChangedFields for more
171  /// details.
172  USD_API bool HasChangedFields() const;
173 
174  private:
175  friend class PathRange;
177 
178  iterator(base_type baseIter)
179  : iterator_adaptor_(baseIter) {}
180  inline reference dereference() const {
181  return base()->first;
182  }
183  };
184 
186 
187  PathRange() : _changes(nullptr) { }
188 
189  /// Explicit conversion to SdfPathVector for convenience
190  explicit operator SdfPathVector() const {
191  return SdfPathVector(begin(), end());
192  }
193 
194  /// Return true if this range contains any paths, false otherwise.
195  bool empty() const {
196  return !_changes || _changes->empty();
197  }
198 
199  /// Return the number of paths in this range.
200  size_t size() const {
201  return _changes ? _changes->size() : 0;
202  }
203 
204  /// Return iterator to the start of this range.
205  iterator begin() const {
206  return iterator(_changes->cbegin());
207  }
208 
209  /// Return iterator to the start of this range.
211  return iterator(_changes->cbegin());
212  }
213 
214  /// Return the end iterator for this range.
215  iterator end() const {
216  return iterator(_changes->cend());
217  }
218 
219  /// Return the end iterator for this range.
220  const_iterator cend() const {
221  return iterator(_changes->cend());
222  }
223 
224  /// Return an iterator to the specified \p path in this range if
225  /// it exists, or end() if it does not. This is potentially more
226  /// efficient than std::find(begin(), end()).
227  const_iterator find(const SdfPath& path) const {
228  return const_iterator(_changes->find(path));
229  }
230 
231  private:
232  friend class ObjectsChanged;
233  explicit PathRange(const _PathsToChangesMap* changes)
234  : _changes(changes)
235  { }
236 
237  const _PathsToChangesMap* _changes;
238  };
239 
240  /// Return the set of paths that are resynced in lexicographical order.
241  /// Resyncs imply entire subtree invalidation of all descendant prims
242  /// and properties, so this set is minimal regarding ancestors and
243  /// descendants. For example, if the path '/foo' appears in this set,
244  /// the entire subtree at '/foo' is resynced so the path '/foo/bar' will
245  /// not appear, but it should be considered resynced.
246  USD_API PathRange GetResyncedPaths() const;
247 
248  /// Return the set of paths that have only info changes (those that do
249  /// not affect the structure of cached UsdPrims on a UsdStage) in
250  /// lexicographical order. Info changes do not imply entire subtree
251  /// invalidation, so this set is not minimal regarding ancestors and
252  /// descendants, as opposed to GetResyncedPaths(). For example, both
253  /// the paths '/foo' and '/foo/bar' may appear in this set.
254  USD_API PathRange GetChangedInfoOnlyPaths() const;
255 
256  /// Return the set of changed fields in layers that affected \p obj.
257  ///
258  /// This set will be empty for objects whose paths are not in
259  /// GetResyncedPaths() or GetChangedInfoOnlyPaths().
260  ///
261  /// If a field is present in this set, it does not necessarily mean the
262  /// composed value of that field on \p obj has changed. For example, if
263  /// a metadata value on \p obj is overridden in a stronger layer and
264  /// is changed in a weaker layer, that field will appear in this set.
265  /// However, since the value in the stronger layer did not change,
266  /// the composed value returned by GetMetadata() will not have changed.
268 
269  /// \overload
271 
272  /// Return true if there are any changed fields that affected \p obj,
273  /// false otherwise. See GetChangedFields for more details.
274  USD_API bool HasChangedFields(const UsdObject &obj) const;
275 
276  /// \overload
277  USD_API bool HasChangedFields(const SdfPath &path) const;
278 
279  private:
280  const _PathsToChangesMap *_resyncChanges;
281  const _PathsToChangesMap *_infoChanges;
282  };
283 
284  /// \class StageEditTargetChanged
285  ///
286  /// Notice sent when a stage's EditTarget has changed. Sent in the
287  /// thread that changed the target.
288  ///
290  public:
292  : StageNotice(stage) {}
294  };
295 
296  /// \class LayerMutingChanged
297  ///
298  /// Notice sent after a set of layers have been newly muted or unmuted.
299  /// Note this does not necessarily mean the specified layers are currently
300  /// loaded.
301  ///
302  /// LayerMutingChanged notice is sent before any UsdNotice::ObjectsChanged
303  /// or UsdNotice::StageContentsChanged notices are sent resulting from
304  /// muting or unmuting of layers.
305  ///
306  /// Note that LayerMutingChanged notice is sent even if the
307  /// muting/unmuting layer does not belong to the current stage, or is a
308  /// layer that does belong to the current stage but is not yet loaded
309  /// because it is behind an unloaded payload or unselected variant.
311  public:
312  explicit LayerMutingChanged(const UsdStageWeakPtr &stage,
313  const std::vector<std::string>& mutedLayers,
314  const std::vector<std::string>& unmutedLayers)
315  : StageNotice(stage),
316  _mutedLayers(mutedLayers),
317  _unMutedLayers(unmutedLayers) {}
318 
319  USD_API virtual ~LayerMutingChanged();
320 
321  /// Returns the identifier of the layers that were muted.
322  ///
323  /// The stage's resolver context must be bound when looking up
324  /// layers using the returned identifiers to ensure the same layers
325  /// that would be used by the stage are found.
326  const std::vector<std::string>& GetMutedLayers() const {
327  return _mutedLayers;
328  }
329 
330  /// Returns the identifier of the layers that were unmuted.
331  ///
332  /// The stage's resolver context must be bound when looking up
333  /// layers using the returned identifiers to ensure the same layers
334  /// that would be used by the stage are found.
335  const std::vector<std::string>& GetUnmutedLayers() const {
336  return _unMutedLayers;
337  }
338 
339  private:
340  const std::vector<std::string>& _mutedLayers;
341  const std::vector<std::string>& _unMutedLayers;
342  };
343 
344 };
345 
346 
348 
349 #endif // PXR_USD_USD_NOTICE_H
StageContentsChanged(const UsdStageWeakPtr &stage)
Definition: notice.h:75
size_t size() const
Return the number of paths in this range.
Definition: notice.h:200
const_iterator cend() const
Return the end iterator for this range.
Definition: notice.h:220
#define USD_API
Definition: api.h:40
bool AffectedObject(const UsdObject &obj) const
Definition: notice.h:129
GLsizei const GLchar *const * path
Definition: glcorearb.h:3341
bool empty() const
Return true if this range contains any paths, false otherwise.
Definition: notice.h:195
USD_API StageNotice(const UsdStageWeakPtr &stage)
const UsdStageWeakPtr & GetStage() const
Return the stage associated with this notice.
Definition: notice.h:55
const std::vector< std::string > & GetMutedLayers() const
Definition: notice.h:326
UsdStagePtr UsdStageWeakPtr
Definition: common.h:55
USD_API TfTokenVector GetChangedFields() const
const std::vector< std::string > & GetUnmutedLayers() const
Definition: notice.h:335
const_iterator cbegin() const
Return iterator to the start of this range.
Definition: notice.h:210
StageEditTargetChanged(const UsdStageWeakPtr &stage)
Definition: notice.h:291
virtual USD_API ~LayerMutingChanged()
Base class for UsdStage notices.
Definition: notice.h:47
USD_API bool HasChangedFields(const UsdObject &obj) const
virtual USD_API ~StageContentsChanged()
USD_API bool ChangedInfoOnly(const UsdObject &obj) const
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:442
Definition: path.h:291
iterator begin() const
Return iterator to the start of this range.
Definition: notice.h:205
std::vector< class SdfPath > SdfPathVector
A vector of SdfPaths.
Definition: path.h:212
virtual USD_API ~StageNotice()
virtual USD_API ~ObjectsChanged()
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1441
USD_API PathRange GetChangedInfoOnlyPaths() const
USD_API PathRange GetResyncedPaths() const
USD_API TfTokenVector GetChangedFields(const UsdObject &obj) const
LayerMutingChanged(const UsdStageWeakPtr &stage, const std::vector< std::string > &mutedLayers, const std::vector< std::string > &unmutedLayers)
Definition: notice.h:312
const_iterator find(const SdfPath &path) const
Definition: notice.h:227
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
iterator end() const
Return the end iterator for this range.
Definition: notice.h:215
USD_API bool ResyncedObject(const UsdObject &obj) const
virtual USD_API ~StageEditTargetChanged()