All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
notice.h
1//
2// Copyright 2016 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_USD_NOTICE_H
8#define PXR_USD_USD_NOTICE_H
9
10#include "pxr/pxr.h"
11#include "pxr/usd/usd/api.h"
12#include "pxr/usd/usd/common.h"
13#include "pxr/usd/usd/object.h"
14
16#include "pxr/usd/sdf/path.h"
17#include "pxr/base/tf/notice.h"
18
19PXR_NAMESPACE_OPEN_SCOPE
20
21
26class UsdNotice {
27public:
28
30 class StageNotice : public TfNotice {
31 public:
32 USD_API
33 StageNotice(const UsdStageWeakPtr &stage);
34 USD_API
35 ~StageNotice() override;
36
38 const UsdStageWeakPtr &GetStage() const { return _stage; }
39
40 private:
41 UsdStageWeakPtr _stage;
42 };
43
57 public:
58 explicit StageContentsChanged(const UsdStageWeakPtr& stage)
59 : StageNotice(stage) {}
60 USD_API ~StageContentsChanged() override;
61 };
62
112 using _PathsToChangesMap =
113 std::map<SdfPath, std::vector<const SdfChangeList::Entry*>>;
114
115 static const _PathsToChangesMap& _GetEmptyChangesMap();
116
117 friend class UsdStage;
118 ObjectsChanged(const UsdStageWeakPtr &stage,
119 const _PathsToChangesMap *resyncChanges,
120 const _PathsToChangesMap *infoChanges,
121 const _PathsToChangesMap *assetPathChanges)
122 : StageNotice(stage)
123 , _resyncChanges(resyncChanges)
124 , _infoChanges(infoChanges)
125 , _assetPathChanges(assetPathChanges) {}
126
127 ObjectsChanged(const UsdStageWeakPtr &stage,
128 const _PathsToChangesMap *resyncChanges);
129
130 public:
131 USD_API ~ObjectsChanged() override;
132
139 bool AffectedObject(const UsdObject &obj) const {
140 return ResyncedObject(obj) || ResolvedAssetPathsResynced(obj)
141 || ChangedInfoOnly(obj);
142 }
143
147 USD_API bool ResyncedObject(const UsdObject &obj) const;
148
153 USD_API bool ResolvedAssetPathsResynced(const UsdObject &obj) const;
154
158 USD_API bool ChangedInfoOnly(const UsdObject &obj) const;
159
167 {
168 public:
170 class iterator {
171 using _UnderlyingIterator = _PathsToChangesMap::const_iterator;
172 public:
173 using iterator_category = std::forward_iterator_tag;
174 using value_type = const SdfPath&;
175 using reference = const SdfPath&;
176 using pointer = const SdfPath*;
177 using difference_type =
178 typename _UnderlyingIterator::difference_type;
179
180 iterator() = default;
181 reference operator*() const { return dereference(); }
182 pointer operator->() const { return &(dereference()); }
183
184 iterator& operator++() {
185 ++_underlyingIterator;
186 return *this;
187 }
188
189 iterator operator++(int) {
190 iterator result = *this;
191 ++_underlyingIterator;
192 return result;
193 }
194
195 bool operator==(const iterator& other) const{
196 return _underlyingIterator == other._underlyingIterator;
197 }
198
199 bool operator!=(const iterator& other) const{
200 return _underlyingIterator != other._underlyingIterator;
201 }
202
207 USD_API TfTokenVector GetChangedFields() const;
208
213 USD_API bool HasChangedFields() const;
214
216 _UnderlyingIterator GetBase() const {
217 return _underlyingIterator;
218 }
219
221 _UnderlyingIterator base() const {
222 return GetBase();
223 }
224
225 private:
226 friend class PathRange;
227
228 explicit iterator(_UnderlyingIterator baseIter)
229 : _underlyingIterator(baseIter) {}
230
231 inline reference dereference() const {
232 return _underlyingIterator->first;
233 }
234
235 _UnderlyingIterator _underlyingIterator;
236 };
237
238 using const_iterator = iterator;
239
240 PathRange() : _changes(nullptr) { }
241
243 explicit operator SdfPathVector() const {
244 return SdfPathVector(begin(), end());
245 }
246
248 bool empty() const {
249 return !_changes || _changes->empty();
250 }
251
253 size_t size() const {
254 return _changes ? _changes->size() : 0;
255 }
256
258 iterator begin() const {
259 return iterator(_changes->cbegin());
260 }
261
263 const_iterator cbegin() const {
264 return iterator(_changes->cbegin());
265 }
266
268 iterator end() const {
269 return iterator(_changes->cend());
270 }
271
273 const_iterator cend() const {
274 return iterator(_changes->cend());
275 }
276
280 const_iterator find(const SdfPath& path) const {
281 return const_iterator(_changes->find(path));
282 }
283
284 private:
285 friend class ObjectsChanged;
286 explicit PathRange(const _PathsToChangesMap* changes)
287 : _changes(changes)
288 { }
289
290 const _PathsToChangesMap* _changes;
291 };
292
308
324
341
353 USD_API TfTokenVector GetChangedFields(const UsdObject &obj) const;
354
356 USD_API TfTokenVector GetChangedFields(const SdfPath &path) const;
357
360 USD_API bool HasChangedFields(const UsdObject &obj) const;
361
363 USD_API bool HasChangedFields(const SdfPath &path) const;
364
365 private:
366 const _PathsToChangesMap *_resyncChanges;
367 const _PathsToChangesMap *_infoChanges;
368 const _PathsToChangesMap *_assetPathChanges;
369 };
370
377 public:
378 explicit StageEditTargetChanged(const UsdStageWeakPtr &stage)
379 : StageNotice(stage) {}
380 USD_API ~StageEditTargetChanged() override;
381 };
382
398 public:
399 explicit LayerMutingChanged(const UsdStageWeakPtr &stage,
400 const std::vector<std::string>& mutedLayers,
401 const std::vector<std::string>& unmutedLayers)
402 : StageNotice(stage),
403 _mutedLayers(mutedLayers),
404 _unMutedLayers(unmutedLayers) {}
405
406 USD_API ~LayerMutingChanged() override;
407
413 const std::vector<std::string>& GetMutedLayers() const {
414 return _mutedLayers;
415 }
416
422 const std::vector<std::string>& GetUnmutedLayers() const {
423 return _unMutedLayers;
424 }
425
426 private:
427 const std::vector<std::string>& _mutedLayers;
428 const std::vector<std::string>& _unMutedLayers;
429 };
430
431};
432
433
434PXR_NAMESPACE_CLOSE_SCOPE
435
436#endif // PXR_USD_USD_NOTICE_H
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:274
The base class for objects used to notify interested parties (listeners) when events have occurred.
Definition: notice.h:76
Notice sent after a set of layers have been newly muted or unmuted.
Definition: notice.h:397
const std::vector< std::string > & GetMutedLayers() const
Returns the identifier of the layers that were muted.
Definition: notice.h:413
const std::vector< std::string > & GetUnmutedLayers() const
Returns the identifier of the layers that were unmuted.
Definition: notice.h:422
An iterable range of paths to objects that have changed.
Definition: notice.h:167
iterator begin() const
Return iterator to the start of this range.
Definition: notice.h:258
size_t size() const
Return the number of paths in this range.
Definition: notice.h:253
const_iterator cbegin() const
Return iterator to the start of this range.
Definition: notice.h:263
bool empty() const
Return true if this range contains any paths, false otherwise.
Definition: notice.h:248
iterator end() const
Return the end iterator for this range.
Definition: notice.h:268
const_iterator cend() const
Return the end iterator for this range.
Definition: notice.h:273
const_iterator find(const SdfPath &path) const
Return an iterator to the specified path in this range if it exists, or end() if it does not.
Definition: notice.h:280
Notice sent in response to authored changes that affect UsdObjects.
Definition: notice.h:111
USD_API PathRange GetChangedInfoOnlyPaths() const
Return the set of paths that have only info changes (those that do not affect the structure of cached...
bool AffectedObject(const UsdObject &obj) const
Return true if obj was possibly affected by the layer changes that generated this notice.
Definition: notice.h:139
USD_API TfTokenVector GetChangedFields(const UsdObject &obj) const
Return the set of changed fields in layers that affected obj.
USD_API TfTokenVector GetChangedFields(const SdfPath &path) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
USD_API bool ResolvedAssetPathsResynced(const UsdObject &obj) const
Return true if asset path values in obj were resynced by the layer changes that generated this notice...
USD_API PathRange GetResyncedPaths() const
Return the set of paths that are resynced in lexicographical order.
USD_API bool HasChangedFields(const UsdObject &obj) const
Return true if there are any changed fields that affected obj, false otherwise.
USD_API bool HasChangedFields(const SdfPath &path) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
USD_API PathRange GetResolvedAssetPathsResyncedPaths() const
Return the set of paths affected by changes that may cause asset path values to resolve to different ...
USD_API bool ChangedInfoOnly(const UsdObject &obj) const
Return true if obj was changed but not resynced by the layer changes that generated this notice.
USD_API bool ResyncedObject(const UsdObject &obj) const
Return true if obj was resynced by the layer changes that generated this notice.
Ultra-conservative notice sent when the given UsdStage's contents have changed in any way.
Definition: notice.h:56
Notice sent when a stage's EditTarget has changed.
Definition: notice.h:376
Base class for UsdStage notices.
Definition: notice.h:30
const UsdStageWeakPtr & GetStage() const
Return the stage associated with this notice.
Definition: notice.h:38
Container class for Usd notices.
Definition: notice.h:26
Base class for Usd scenegraph objects, providing common API.
Definition: object.h:115
The outermost container for scene description, which owns and presents composed prims as a scenegraph...
Definition: stage.h:136
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:440