HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
layerStateDelegate.h
Go to the documentation of this file.
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_SDF_LAYER_STATE_DELEGATE_H
8 #define PXR_USD_SDF_LAYER_STATE_DELEGATE_H
9 
10 #include "pxr/pxr.h"
11 #include "pxr/usd/sdf/api.h"
13 #include "pxr/usd/sdf/types.h"
15 #include "pxr/base/tf/refBase.h"
16 #include "pxr/base/tf/weakBase.h"
17 
19 
21 
25 
27 class SdfPath;
28 class TfToken;
29 
30 /// \class SdfLayerStateDelegateBase
31 ///
32 /// Maintains authoring state information for an associated layer.
33 ///
34 /// For example, layers rely on a state delegate to determine whether or
35 /// not they have been dirtied by authoring operations.
36 ///
37 /// A layer's state delegate is invoked on every authoring operation on
38 /// that layer. The delegate may keep track of these operations for various
39 /// purposes.
40 ///
42  : public TfRefBase
43  , public TfWeakBase
44 {
45 public:
46  SDF_API
48 
49  SDF_API
50  bool IsDirty();
51 
52  SDF_API
53  void SetField(
54  const SdfPath& path,
55  const TfToken& field,
56  const VtValue& value,
57  VtValue *oldValue=NULL);
58 
59  SDF_API
60  void SetField(
61  const SdfPath& path,
62  const TfToken& field,
63  const SdfAbstractDataConstValue& value,
64  VtValue *oldValue=NULL);
65 
66  SDF_API
68  const SdfPath& path,
69  const TfToken& field,
70  const TfToken& keyPath,
71  const VtValue& value,
72  VtValue *oldValue=NULL);
73 
74  SDF_API
76  const SdfPath& path,
77  const TfToken& field,
78  const TfToken& keyPath,
79  const SdfAbstractDataConstValue& value,
80  VtValue *oldValue=NULL);
81 
82  SDF_API
83  void SetTimeSample(
84  const SdfPath& path,
85  double time,
86  const VtValue& value);
87 
88  SDF_API
89  void SetTimeSample(
90  const SdfPath& path,
91  double time,
92  const SdfAbstractDataConstValue& value);
93 
94  SDF_API
95  void CreateSpec(
96  const SdfPath& path,
97  SdfSpecType specType,
98  bool inert);
99 
100  SDF_API
101  void DeleteSpec(
102  const SdfPath& path,
103  bool inert);
104 
105  SDF_API
106  void MoveSpec(
107  const SdfPath& oldPath,
108  const SdfPath& newPath);
109 
110  SDF_API
111  void PushChild(
112  const SdfPath& parentPath,
113  const TfToken& field,
114  const TfToken& value);
115 
116  SDF_API
117  void PushChild(
118  const SdfPath& parentPath,
119  const TfToken& field,
120  const SdfPath& value);
121 
122  SDF_API
123  void PopChild(
124  const SdfPath& parentPath,
125  const TfToken& field,
126  const TfToken& oldValue);
127 
128  SDF_API
129  void PopChild(
130  const SdfPath& parentPath,
131  const TfToken& field,
132  const SdfPath& oldValue);
133 
134 protected:
135  SDF_API
137 
138  /// Returns the layer associated with this state delegate.
139  /// May be NULL if no layer is associated.
140  SDF_API
141  SdfLayerHandle _GetLayer() const;
142 
143  /// Returns the underlying data object for the layer associated with
144  /// this state delegate. May be NULL if no layer is associated.
145  SDF_API
146  SdfAbstractDataPtr _GetLayerData() const;
147 
148  /// Returns true if the associated layer has been authored to since
149  /// the last time the layer was marked clean, false otherwise.
150  virtual bool _IsDirty() = 0;
151 
152  /// Mark the current state of the layer as clean, i.e. unchanged from its
153  /// persistent representation.
154  virtual void _MarkCurrentStateAsClean() = 0;
155 
156  /// Mark the current state of the layer as dirty, i.e. modified from its
157  /// persistent representation.
158  virtual void _MarkCurrentStateAsDirty() = 0;
159 
160  /// Invoked when the state delegate is associated with layer \p layer.
161  /// \p layer may be NULL if the state delegate is being removed.
162  virtual void _OnSetLayer(
163  const SdfLayerHandle& layer) = 0;
164 
165  /// Invoked when a field is being changed on the associated layer.
166  virtual void _OnSetField(
167  const SdfPath& path,
168  const TfToken& fieldName,
169  const VtValue& value) = 0;
170  virtual void _OnSetField(
171  const SdfPath& path,
172  const TfToken& fieldName,
173  const SdfAbstractDataConstValue& value) = 0;
174 
175  /// Invoked when a field dict key is being changed on the associated layer.
176  virtual void _OnSetFieldDictValueByKey(
177  const SdfPath& path,
178  const TfToken& fieldName,
179  const TfToken& keyPath,
180  const VtValue& value) = 0;
181  virtual void _OnSetFieldDictValueByKey(
182  const SdfPath& path,
183  const TfToken& fieldName,
184  const TfToken& keyPath,
185  const SdfAbstractDataConstValue& value) = 0;
186 
187  /// Invoked when a time sample is being changed on the associated layer.
188  virtual void _OnSetTimeSample(
189  const SdfPath& path,
190  double time,
191  const VtValue& value) = 0;
192  virtual void _OnSetTimeSample(
193  const SdfPath& path,
194  double time,
195  const SdfAbstractDataConstValue& value) = 0;
196 
197  /// Invoked when a new spec is created on the associated layer.
198  virtual void _OnCreateSpec(
199  const SdfPath& path,
200  SdfSpecType specType,
201  bool inert) = 0;
202 
203  /// Invoked when a spec and its children are deleted from the associated
204  /// layer.
205  virtual void _OnDeleteSpec(
206  const SdfPath& path,
207  bool inert) = 0;
208 
209  /// Invoked when a spec and its children are moved.
210  virtual void _OnMoveSpec(
211  const SdfPath& oldPath,
212  const SdfPath& newPath) = 0;
213 
214  /// Invoked when a child spec is pushed onto a parent's list of children.
215  virtual void _OnPushChild(
216  const SdfPath& parentPath,
217  const TfToken& fieldName,
218  const TfToken& value) = 0;
219 
220  /// Invoked when a child spec is pushed onto a parent's list of children.
221  virtual void _OnPushChild(
222  const SdfPath& parentPath,
223  const TfToken& fieldName,
224  const SdfPath& value) = 0;
225 
226  /// Invoked when a child spec is popped off a parent's list of children.
227  virtual void _OnPopChild(
228  const SdfPath& parentPath,
229  const TfToken& fieldName,
230  const TfToken& oldValue) = 0;
231 
232  /// Invoked when a child spec is popped off a parent's list of children.
233  virtual void _OnPopChild(
234  const SdfPath& parentPath,
235  const TfToken& fieldName,
236  const SdfPath& oldValue) = 0;
237 
238 private:
239  friend class SdfLayer;
240  SDF_API void _SetLayer(const SdfLayerHandle& layer);
241 
242 private:
243  SdfLayerHandle _layer;
244 };
245 
246 /// \class SdfSimpleLayerStateDelegate
247 /// A layer state delegate that simply records whether any changes have
248 /// been made to a layer.
251 {
252 public:
253  SDF_API
254  static SdfSimpleLayerStateDelegateRefPtr New();
255 
256 protected:
257  SDF_API
259 
260  // SdfLayerStateDelegateBase overrides
261  SDF_API
262  virtual bool _IsDirty() override;
263 
264  SDF_API
265  virtual void _MarkCurrentStateAsClean() override;
266 
267  SDF_API
268  virtual void _MarkCurrentStateAsDirty() override;
269 
270  SDF_API
271  virtual void _OnSetLayer(
272  const SdfLayerHandle& layer) override;
273 
274  SDF_API
275  virtual void _OnSetField(
276  const SdfPath& path,
277  const TfToken& fieldName,
278  const VtValue& value) override;
279 
280  SDF_API
281  virtual void _OnSetField(
282  const SdfPath& path,
283  const TfToken& fieldName,
284  const SdfAbstractDataConstValue& value) override;
285 
286  SDF_API
287  virtual void _OnSetFieldDictValueByKey(
288  const SdfPath& path,
289  const TfToken& fieldName,
290  const TfToken& keyPath,
291  const VtValue& value) override;
292 
293  SDF_API
294  virtual void _OnSetFieldDictValueByKey(
295  const SdfPath& path,
296  const TfToken& fieldName,
297  const TfToken& keyPath,
298  const SdfAbstractDataConstValue& value) override;
299 
300  SDF_API
301  virtual void _OnSetTimeSample(
302  const SdfPath& path,
303  double time,
304  const VtValue& value) override;
305 
306  SDF_API
307  virtual void _OnSetTimeSample(
308  const SdfPath& path,
309  double time,
310  const SdfAbstractDataConstValue& value) override;
311 
312  SDF_API
313  virtual void _OnCreateSpec(
314  const SdfPath& path,
315  SdfSpecType specType,
316  bool inert) override;
317 
318  SDF_API
319  virtual void _OnDeleteSpec(
320  const SdfPath& path,
321  bool inert) override;
322 
323  SDF_API
324  virtual void _OnMoveSpec(
325  const SdfPath& oldPath,
326  const SdfPath& newPath) override;
327 
328  SDF_API
329  virtual void _OnPushChild(
330  const SdfPath& path,
331  const TfToken& fieldName,
332  const TfToken& value) override;
333 
334  SDF_API
335  virtual void _OnPushChild(
336  const SdfPath& path,
337  const TfToken& fieldName,
338  const SdfPath& value) override;
339 
340  SDF_API
341  virtual void _OnPopChild(
342  const SdfPath& path,
343  const TfToken& fieldName,
344  const TfToken& oldValue) override;
345 
346  SDF_API
347  virtual void _OnPopChild(
348  const SdfPath& path,
349  const TfToken& fieldName,
350  const SdfPath& oldValue) override;
351 
352 private:
353  bool _dirty;
354 };
355 
357 
358 #endif // PXR_USD_SDF_LAYER_STATE_DELEGATE_H
SDF_API void SetField(const SdfPath &path, const TfToken &field, const VtValue &value, VtValue *oldValue=NULL)
PXR_NAMESPACE_OPEN_SCOPE SDF_DECLARE_HANDLES(SdfLayer)
virtual SDF_API void _OnPushChild(const SdfPath &path, const TfToken &fieldName, const TfToken &value) override
Invoked when a child spec is pushed onto a parent's list of children.
virtual void _OnCreateSpec(const SdfPath &path, SdfSpecType specType, bool inert)=0
Invoked when a new spec is created on the associated layer.
SDF_API void SetFieldDictValueByKey(const SdfPath &path, const TfToken &field, const TfToken &keyPath, const VtValue &value, VtValue *oldValue=NULL)
Definition: layer.h:81
TF_DECLARE_WEAK_AND_REF_PTRS(SdfLayerStateDelegateBase)
virtual SDF_API void _OnSetTimeSample(const SdfPath &path, double time, const VtValue &value) override
Invoked when a time sample is being changed on the associated layer.
GT_API const UT_StringHolder time
virtual void _OnSetTimeSample(const SdfPath &path, double time, const VtValue &value)=0
Invoked when a time sample is being changed on the associated layer.
GLsizei const GLfloat * value
Definition: glcorearb.h:824
GLsizei const GLchar *const * path
Definition: glcorearb.h:3341
virtual SDF_API ~SdfLayerStateDelegateBase()
virtual SDF_API void _OnDeleteSpec(const SdfPath &path, bool inert) override
virtual SDF_API void _OnCreateSpec(const SdfPath &path, SdfSpecType specType, bool inert) override
Invoked when a new spec is created on the associated layer.
SDF_API void PopChild(const SdfPath &parentPath, const TfToken &field, const TfToken &oldValue)
GLenum GLuint GLint GLint layer
Definition: glcorearb.h:1299
virtual void _OnPopChild(const SdfPath &parentPath, const TfToken &fieldName, const TfToken &oldValue)=0
Invoked when a child spec is popped off a parent's list of children.
Definition: token.h:70
static SDF_API SdfSimpleLayerStateDelegateRefPtr New()
virtual SDF_API void _MarkCurrentStateAsDirty() override
virtual void _OnPushChild(const SdfPath &parentPath, const TfToken &fieldName, const TfToken &value)=0
Invoked when a child spec is pushed onto a parent's list of children.
SDF_API SdfAbstractDataPtr _GetLayerData() const
virtual void _OnSetLayer(const SdfLayerHandle &layer)=0
virtual SDF_API void _OnMoveSpec(const SdfPath &oldPath, const SdfPath &newPath) override
Invoked when a spec and its children are moved.
virtual void _OnMoveSpec(const SdfPath &oldPath, const SdfPath &newPath)=0
Invoked when a spec and its children are moved.
virtual SDF_API void _OnSetFieldDictValueByKey(const SdfPath &path, const TfToken &fieldName, const TfToken &keyPath, const VtValue &value) override
Invoked when a field dict key is being changed on the associated layer.
Definition: path.h:273
TF_DECLARE_WEAK_PTRS(SdfAbstractData)
virtual SDF_API void _MarkCurrentStateAsClean() override
virtual bool _IsDirty()=0
#define SDF_API
Definition: api.h:23
SDF_API void CreateSpec(const SdfPath &path, SdfSpecType specType, bool inert)
virtual void _OnSetFieldDictValueByKey(const SdfPath &path, const TfToken &fieldName, const TfToken &keyPath, const VtValue &value)=0
Invoked when a field dict key is being changed on the associated layer.
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
SDF_API void DeleteSpec(const SdfPath &path, bool inert)
virtual void _MarkCurrentStateAsClean()=0
SdfSpecType
Definition: types.h:68
virtual SDF_API bool _IsDirty() override
virtual void _OnSetField(const SdfPath &path, const TfToken &fieldName, const VtValue &value)=0
Invoked when a field is being changed on the associated layer.
virtual SDF_API void _OnPopChild(const SdfPath &path, const TfToken &fieldName, const TfToken &oldValue) override
Invoked when a child spec is popped off a parent's list of children.
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
SDF_API void PushChild(const SdfPath &parentPath, const TfToken &field, const TfToken &value)
virtual void _MarkCurrentStateAsDirty()=0
SDF_API void SetTimeSample(const SdfPath &path, double time, const VtValue &value)
SDF_API SdfLayerStateDelegateBase()
virtual SDF_API void _OnSetField(const SdfPath &path, const TfToken &fieldName, const VtValue &value) override
Invoked when a field is being changed on the associated layer.
virtual SDF_API void _OnSetLayer(const SdfLayerHandle &layer) override
SDF_API SdfLayerHandle _GetLayer() const
virtual void _OnDeleteSpec(const SdfPath &path, bool inert)=0
Definition: value.h:146
SDF_API void MoveSpec(const SdfPath &oldPath, const SdfPath &newPath)