Usd Notice Framework 0.8.1
Loading...
Searching...
No Matches
notice.h
Go to the documentation of this file.
1#ifndef USD_NOTICE_FRAMEWORK_NOTICE_H
2#define USD_NOTICE_FRAMEWORK_NOTICE_H
3
5
6#include "unf/api.h"
7
8#include <pxr/base/arch/demangle.h>
9#include <pxr/base/tf/notice.h>
10#include <pxr/base/tf/refBase.h>
11#include <pxr/base/tf/refPtr.h>
12#include <pxr/pxr.h>
13#include <pxr/usd/sdf/path.h>
14#include <pxr/usd/usd/notice.h>
15
16#include <string>
17#include <unordered_map>
18#include <unordered_set>
19#include <vector>
20
21namespace unf {
22
25 std::unordered_set<PXR_NS::TfToken, PXR_NS::TfToken::HashFunctor>;
26
28using SdfPathSet = std::unordered_set<PXR_NS::SdfPath, PXR_NS::SdfPath::Hash>;
29
32 std::unordered_map<PXR_NS::SdfPath, TfTokenSet, PXR_NS::SdfPath::Hash>;
33
34namespace UnfNotice {
35
48 public:
49 UNF_API virtual ~StageNotice() = default;
50
59 UNF_API virtual bool IsMergeable() const { return true; }
60
66 virtual void Merge(StageNotice&&)
67 {
68 PXR_NAMESPACE_USING_DIRECTIVE
69 TF_FATAL_ERROR("Abstract class 'StageNotice' cannot be merged.");
70 }
71
77 virtual void PostProcess() {}
78
84 UNF_API virtual std::string GetTypeId() const
85 {
86 PXR_NAMESPACE_USING_DIRECTIVE
87 TF_FATAL_ERROR(
88 "Abstract class 'StageNotice' does not have a unique identifier.");
89 return "";
90 }
91
98 {
99 return PXR_NS::TfCreateRefPtr(_Clone());
100 }
101
102 protected:
103 UNF_API StageNotice() = default;
104
105 private:
115 virtual StageNotice* _Clone() const
116 {
117 PXR_NAMESPACE_USING_DIRECTIVE
118 TF_FATAL_ERROR("Abstract class 'StageNotice' cannot be cloned.");
119 return nullptr;
120 }
121};
122
125
128
145template <class Self>
147 public:
148 virtual ~StageNoticeImpl() = default;
149
151 template <class... Args>
152 static PXR_NS::TfRefPtr<Self> Create(Args&&... args)
153 {
154 return PXR_NS::TfCreateRefPtr(new Self(std::forward<Args>(args)...));
155 }
156
159 {
160 return PXR_NS::TfCreateRefPtr(static_cast<Self*>(_Clone()));
161 }
162
163 virtual void Merge(StageNotice&& notice) override
164 {
165 Merge(dynamic_cast<Self&&>(notice));
166 }
167
172 virtual void Merge(Self&&) {}
173
178 virtual std::string GetTypeId() const override
179 {
180 return PXR_NS::ArchGetDemangled(typeid(Self).name());
181 }
182
183 private:
190 virtual StageNotice* _Clone() const override
191 {
192 return new Self(static_cast<const Self&>(*this));
193 }
194};
195
204class StageContentsChanged : public StageNoticeImpl<StageContentsChanged> {
205 public:
206 UNF_API virtual ~StageContentsChanged() = default;
207
208 protected:
214
217};
218
227class ObjectsChanged : public StageNoticeImpl<ObjectsChanged> {
228 public:
229 UNF_API virtual ~ObjectsChanged() = default;
230
233
236
237 // Bring all Merge declarations from base class to prevent
238 // overloaded-virtual warning.
240
246 UNF_API virtual void Merge(ObjectsChanged&&) override;
247 UNF_API virtual void PostProcess() override;
248
255 UNF_API bool AffectedObject(const PXR_NS::UsdObject& object) const
256 {
257 return ResyncedObject(object) || ChangedInfoOnly(object);
258 }
259
266 UNF_API bool ResyncedObject(const PXR_NS::UsdObject&) const;
267
274 UNF_API bool ChangedInfoOnly(const PXR_NS::UsdObject&) const;
275
281 UNF_API const PXR_NS::SdfPathVector& GetResyncedPaths() const
282 {
283 return _resyncChanges;
284 }
285
293 UNF_API const PXR_NS::SdfPathVector& GetChangedInfoOnlyPaths() const
294 {
295 return _infoChanges;
296 }
297
306
315
323 UNF_API bool HasChangedFields(const PXR_NS::UsdObject&) const;
324
332 UNF_API bool HasChangedFields(const PXR_NS::SdfPath&) const;
333
336 const ChangedFieldMap& GetChangedFieldMap() const { return _changedFields; }
337
338 protected:
341
344
345 private:
347 PXR_NS::SdfPathVector _resyncChanges;
348
350 PXR_NS::SdfPathVector _infoChanges;
351
353 ChangedFieldMap _changedFields;
354};
355
363class StageEditTargetChanged : public StageNoticeImpl<StageEditTargetChanged> {
364 public:
365 UNF_API virtual ~StageEditTargetChanged() = default;
366
367 protected:
373
376};
377
385class LayerMutingChanged : public StageNoticeImpl<LayerMutingChanged> {
386 public:
387 UNF_API virtual ~LayerMutingChanged() = default;
388
391
394
395 // Bring all Merge declarations from base class to prevent
396 // overloaded-virtual warning.
398
404 UNF_API virtual void Merge(LayerMutingChanged&&) override;
405
412 UNF_API const std::vector<std::string>& GetMutedLayers() const
413 {
414 return _mutedLayers;
415 }
416
423 UNF_API const std::vector<std::string>& GetUnmutedLayers() const
424 {
425 return _unmutedLayers;
426 }
427
428 protected:
431
434
435 private:
437 std::vector<std::string> _mutedLayers;
438
440 std::vector<std::string> _unmutedLayers;
441};
442
443} // namespace UnfNotice
444
445} // namespace unf
446
447#endif // USD_NOTICE_FRAMEWORK_NOTICE_H
Notice sent after a set of layers have been newly muted or unmuted.
Definition notice.h:385
LayerMutingChanged(const PXR_NS::UsdNotice::LayerMutingChanged &)
Create notice from PXR_NS::UsdNotice::LayerMutingChanged instance.
UNF_API LayerMutingChanged & operator=(const LayerMutingChanged &)
Assignment operator.
virtual UNF_API void Merge(LayerMutingChanged &&) override
Merge notice with another LayerMutingChanged notice.
UNF_API const std::vector< std::string > & GetMutedLayers() const
Returns identifiers of the layers that were muted.
Definition notice.h:412
UNF_API const std::vector< std::string > & GetUnmutedLayers() const
Returns identifiers of the layers that were unmuted.
Definition notice.h:423
UNF_API LayerMutingChanged(const LayerMutingChanged &)
Copy constructor.
Notice sent in response to authored changes that affect any PXR_NS::UsdObject.
Definition notice.h:227
UNF_API bool HasChangedFields(const PXR_NS::SdfPath &) const
Indicate whether any changed fields affected the path.
UNF_API ObjectsChanged & operator=(const ObjectsChanged &)
Assignment operator.
UNF_API bool ChangedInfoOnly(const PXR_NS::UsdObject &) const
Indicate whether object was modified but not resynced by the change that generated this notice.
UNF_API TfTokenSet GetChangedFields(const PXR_NS::SdfPath &) const
Return the set of changed fields in layers that affected the path.
const ChangedFieldMap & GetChangedFieldMap() const
Return map of affected token sets organized per path.
Definition notice.h:336
UNF_API ObjectsChanged(const ObjectsChanged &)
Copy constructor.
virtual UNF_API void PostProcess() override
Base method for adding post process after merging data within a transaction.
UNF_API const PXR_NS::SdfPathVector & GetResyncedPaths() const
Return vector of paths that are resynced in lexicographical order.
Definition notice.h:281
ObjectsChanged(const PXR_NS::UsdNotice::ObjectsChanged &)
Create notice from PXR_NS::UsdNotice::ObjectsChanged instance.
virtual UNF_API void Merge(ObjectsChanged &&) override
Merge notice with another ObjectsChanged notice.
UNF_API TfTokenSet GetChangedFields(const PXR_NS::UsdObject &) const
Return the set of changed fields in layers that affected the object.
UNF_API bool ResyncedObject(const PXR_NS::UsdObject &) const
Indicate whether object was resynced by the change that generated this notice.
UNF_API bool HasChangedFields(const PXR_NS::UsdObject &) const
Indicate whether any changed fields affected the object.
UNF_API bool AffectedObject(const PXR_NS::UsdObject &object) const
Indicate whether object was affected by the change that generated this notice.
Definition notice.h:255
UNF_API const PXR_NS::SdfPathVector & GetChangedInfoOnlyPaths() const
Return vector of paths that are modified but not resynced in lexicographical order.
Definition notice.h:293
Notice sent when the given PXR_NS::UsdStage's contents have changed in any way.
Definition notice.h:204
StageContentsChanged(const PXR_NS::UsdNotice::StageContentsChanged &)
Create notice from PXR_NS::UsdNotice::StageContentsChanged instance.
Definition notice.h:210
Notice sent when a stage's EditTarget has changed.
Definition notice.h:363
StageEditTargetChanged(const PXR_NS::UsdNotice::StageEditTargetChanged &)
Create notice from PXR_NS::UsdNotice::StageEditTargetChanged instance.
Definition notice.h:369
Intermediate interface using the CRTP idiom to provide factory and default merging logic.
Definition notice.h:146
PXR_NS::TfRefPtr< Self > Clone() const
Return a copy of the notice.
Definition notice.h:158
virtual void Merge(StageNotice &&notice) override
Interface method for merging StageNotice.
Definition notice.h:163
static PXR_NS::TfRefPtr< Self > Create(Args &&... args)
Create a notice with variadic arguments.
Definition notice.h:152
virtual std::string GetTypeId() const override
Base method for returing unique type identifier.
Definition notice.h:178
virtual void Merge(Self &&)
Base method for merging notice with similar type.
Definition notice.h:172
Base class for standalone PXR_NS::UsdStage notices.
Definition notice.h:47
virtual UNF_API bool IsMergeable() const
Indicate whether notice from the same type can be consolidated during a transaction.
Definition notice.h:59
virtual void PostProcess()
Base method for adding post process after merging data within a transaction.
Definition notice.h:77
PXR_NS::TfRefPtr< StageNotice > Clone() const
Interface method to return a copy of the notice.
Definition notice.h:97
virtual UNF_API std::string GetTypeId() const
Interface method for returing unique type identifier.
Definition notice.h:84
virtual void Merge(StageNotice &&)
Interface method for merging StageNotice.
Definition notice.h:66
std::unordered_set< PXR_NS::TfToken, PXR_NS::TfToken::HashFunctor > TfTokenSet
Convenient alias for set of tokens.
Definition notice.h:25
std::unordered_set< PXR_NS::SdfPath, PXR_NS::SdfPath::Hash > SdfPathSet
Convenient alias for set of paths.
Definition notice.h:28
std::unordered_map< PXR_NS::SdfPath, TfTokenSet, PXR_NS::SdfPath::Hash > ChangedFieldMap
Convenient alias for map of token sets organized per path.
Definition notice.h:32