Loading...
Searching...
No Matches
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
113 public:
116 enum class PrimResyncType {
126 RenameDestination,
127 ReparentSource,
128 ReparentDestination,
129 RenameAndReparentSource,
130 RenameAndReparentDestination,
131
135 Delete,
136
144
150 Other,
151
153 Invalid
154 };
155
158 using RenamedProperties = std::vector<std::pair<SdfPath, TfToken>>;
159
160 private:
161 using _PathsToChangesMap =
162 std::map<SdfPath, std::vector<const SdfChangeList::Entry*>>;
163
164 struct _PrimResyncInfo {
165 PrimResyncType resyncType;
166 SdfPath associatePath;
167 };
168 using _PrimResyncInfoMap = std::map<SdfPath, _PrimResyncInfo>;
169
170 struct _NamespaceEditsInfo {
171 _PrimResyncInfoMap primResyncsInfo;
172 RenamedProperties renamedProperties;
173 };
174
175 static const _PathsToChangesMap& _GetEmptyChangesMap();
176 static const _NamespaceEditsInfo& _GetEmptyNamespaceEditsInfo();
177
178 friend class UsdStage;
179 ObjectsChanged(const UsdStageWeakPtr &stage,
180 const _PathsToChangesMap *resyncChanges,
181 const _PathsToChangesMap *infoChanges,
182 const _PathsToChangesMap *assetPathChanges,
183 const _NamespaceEditsInfo *namespaceEditsInfo)
184 : StageNotice(stage)
185 , _resyncChanges(resyncChanges)
186 , _infoChanges(infoChanges)
187 , _assetPathChanges(assetPathChanges)
188 , _namespaceEditsInfo(namespaceEditsInfo) {}
189
190 ObjectsChanged(const UsdStageWeakPtr &stage,
191 const _PathsToChangesMap *resyncChanges);
192
193 public:
194 USD_API ~ObjectsChanged() override;
195
202 bool AffectedObject(const UsdObject &obj) const {
203 return ResyncedObject(obj) || ResolvedAssetPathsResynced(obj)
204 || ChangedInfoOnly(obj);
205 }
206
210 USD_API bool ResyncedObject(const UsdObject &obj) const;
211
216 USD_API bool ResolvedAssetPathsResynced(const UsdObject &obj) const;
217
221 USD_API bool ChangedInfoOnly(const UsdObject &obj) const;
222
230 {
231 public:
233 class iterator {
234 using _UnderlyingIterator = _PathsToChangesMap::const_iterator;
235 public:
236 using iterator_category = std::forward_iterator_tag;
237 using value_type = const SdfPath&;
238 using reference = const SdfPath&;
239 using pointer = const SdfPath*;
240 using difference_type =
241 typename _UnderlyingIterator::difference_type;
242
243 iterator() = default;
244 reference operator*() const { return dereference(); }
245 pointer operator->() const { return &(dereference()); }
246
247 iterator& operator++() {
248 ++_underlyingIterator;
249 return *this;
250 }
251
252 iterator operator++(int) {
253 iterator result = *this;
254 ++_underlyingIterator;
255 return result;
256 }
257
258 bool operator==(const iterator& other) const{
259 return _underlyingIterator == other._underlyingIterator;
260 }
261
262 bool operator!=(const iterator& other) const{
263 return _underlyingIterator != other._underlyingIterator;
264 }
265
270 USD_API TfTokenVector GetChangedFields() const;
271
276 USD_API bool HasChangedFields() const;
277
279 _UnderlyingIterator GetBase() const {
280 return _underlyingIterator;
281 }
282
284 _UnderlyingIterator base() const {
285 return GetBase();
286 }
287
288 private:
289 friend class PathRange;
290
291 explicit iterator(_UnderlyingIterator baseIter)
292 : _underlyingIterator(baseIter) {}
293
294 inline reference dereference() const {
295 return _underlyingIterator->first;
296 }
297
298 _UnderlyingIterator _underlyingIterator;
299 };
300
301 using const_iterator = iterator;
302
303 PathRange() : _changes(nullptr) { }
304
306 explicit operator SdfPathVector() const {
307 return SdfPathVector(begin(), end());
308 }
309
311 bool empty() const {
312 return !_changes || _changes->empty();
313 }
314
316 size_t size() const {
317 return _changes ? _changes->size() : 0;
318 }
319
321 iterator begin() const {
322 return iterator(_changes->cbegin());
323 }
324
326 const_iterator cbegin() const {
327 return iterator(_changes->cbegin());
328 }
329
331 iterator end() const {
332 return iterator(_changes->cend());
333 }
334
336 const_iterator cend() const {
337 return iterator(_changes->cend());
338 }
339
343 const_iterator find(const SdfPath& path) const {
344 return const_iterator(_changes->find(path));
345 }
346
347 private:
348 friend class ObjectsChanged;
349 explicit PathRange(const _PathsToChangesMap* changes)
350 : _changes(changes)
351 { }
352
353 const _PathsToChangesMap* _changes;
354 };
355
371
387
404
416 USD_API TfTokenVector GetChangedFields(const UsdObject &obj) const;
417
419 USD_API TfTokenVector GetChangedFields(const SdfPath &path) const;
420
423 USD_API bool HasChangedFields(const UsdObject &obj) const;
424
426 USD_API bool HasChangedFields(const SdfPath &path) const;
427
449 const SdfPath &primPath,
450 SdfPath *associatedPrimPath = nullptr) const;
451
457 return _namespaceEditsInfo->renamedProperties;
458 }
459
460 private:
461 const _PathsToChangesMap *_resyncChanges;
462 const _PathsToChangesMap *_infoChanges;
463 const _PathsToChangesMap *_assetPathChanges;
464 const _NamespaceEditsInfo *_namespaceEditsInfo;
465 };
466
473 public:
474 explicit StageEditTargetChanged(const UsdStageWeakPtr &stage)
475 : StageNotice(stage) {}
476 USD_API ~StageEditTargetChanged() override;
477 };
478
494 public:
495 explicit LayerMutingChanged(const UsdStageWeakPtr &stage,
496 const std::vector<std::string>& mutedLayers,
497 const std::vector<std::string>& unmutedLayers)
498 : StageNotice(stage),
499 _mutedLayers(mutedLayers),
500 _unMutedLayers(unmutedLayers) {}
501
502 USD_API ~LayerMutingChanged() override;
503
509 const std::vector<std::string>& GetMutedLayers() const {
510 return _mutedLayers;
511 }
512
518 const std::vector<std::string>& GetUnmutedLayers() const {
519 return _unMutedLayers;
520 }
521
522 private:
523 const std::vector<std::string>& _mutedLayers;
524 const std::vector<std::string>& _unMutedLayers;
525 };
526
527};
528
529
530PXR_NAMESPACE_CLOSE_SCOPE
531
532#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:80
Notice sent after a set of layers have been newly muted or unmuted.
Definition: notice.h:493
const std::vector< std::string > & GetMutedLayers() const
Returns the identifier of the layers that were muted.
Definition: notice.h:509
const std::vector< std::string > & GetUnmutedLayers() const
Returns the identifier of the layers that were unmuted.
Definition: notice.h:518
An iterable range of paths to objects that have changed.
Definition: notice.h:230
iterator begin() const
Return iterator to the start of this range.
Definition: notice.h:321
size_t size() const
Return the number of paths in this range.
Definition: notice.h:316
const_iterator cbegin() const
Return iterator to the start of this range.
Definition: notice.h:326
bool empty() const
Return true if this range contains any paths, false otherwise.
Definition: notice.h:311
iterator end() const
Return the end iterator for this range.
Definition: notice.h:331
const_iterator cend() const
Return the end iterator for this range.
Definition: notice.h:336
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:343
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:202
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 PrimResyncType GetPrimResyncType(const SdfPath &primPath, SdfPath *associatedPrimPath=nullptr) const
Returns the type of resync that has occurred for the prim at primPath.
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.
std::vector< std::pair< SdfPath, TfToken > > RenamedProperties
Value type holding a list of property paths that have been renamed via the UsdNamespaceEditor paired ...
Definition: notice.h:158
const RenamedProperties & GetRenamedProperties() const
Return the list of property paths that have been renamed via a UsdNamespaceEditor ApplyEdits operatio...
Definition: notice.h:456
PrimResyncType
A type for further classifying objects that have may have been resynced because of namespace edits.
Definition: notice.h:116
@ UnchangedPrimStack
The UnchangedPrimStack type indicates that the resynced object still exists and is effectively unchan...
@ RenameSource
These six types indicate that a resynced object was moved to a new path, via a UsdNamespaceEditor,...
@ Invalid
Invalid indicates that the object has not been resynced.
@ Other
This type indicates all other resyncs that we cannot classify based on namespace edit information.
@ Delete
This Delete type indicates that an object has been removed from the stage without an indication that ...
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:472
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