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