All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
notice.h
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 USD_NOTICE_H
25 #define USD_NOTICE_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/usd/usd/api.h"
29 #include "pxr/usd/usd/common.h"
30 #include "pxr/usd/usd/object.h"
31 
32 #include "pxr/usd/sdf/changeList.h"
33 #include "pxr/usd/sdf/path.h"
34 #include "pxr/base/tf/notice.h"
35 
36 PXR_NAMESPACE_OPEN_SCOPE
37 
38 
43 class UsdNotice {
44 public:
45 
47  class StageNotice : public TfNotice {
48  public:
49  USD_API
50  StageNotice(const UsdStageWeakPtr &stage);
51  USD_API
52  virtual ~StageNotice();
53 
55  const UsdStageWeakPtr &GetStage() const { return _stage; }
56 
57  private:
58  UsdStageWeakPtr _stage;
59  };
60 
74  public:
75  explicit StageContentsChanged(const UsdStageWeakPtr& stage)
76  : StageNotice(stage) {}
77  USD_API virtual ~StageContentsChanged();
78  };
79 
107  class ObjectsChanged : public StageNotice {
108  using _PathsToChangesMap =
109  std::map<SdfPath, std::vector<const SdfChangeList::Entry*>>;
110 
111  friend class UsdStage;
112  ObjectsChanged(const UsdStageWeakPtr &stage,
113  const _PathsToChangesMap *resyncChanges,
114  const _PathsToChangesMap *infoChanges)
115  : StageNotice(stage)
116  , _resyncChanges(resyncChanges)
117  , _infoChanges(infoChanges) {}
118  public:
119  USD_API virtual ~ObjectsChanged();
120 
127  bool AffectedObject(const UsdObject &obj) const {
128  return ResyncedObject(obj) || ChangedInfoOnly(obj);
129  }
130 
134  USD_API bool ResyncedObject(const UsdObject &obj) const;
135 
138  USD_API bool ChangedInfoOnly(const UsdObject &obj) const;
139 
146  class PathRange
147  {
148  public:
150  class iterator : public boost::iterator_adaptor<
151  iterator, // crtp base,
152  _PathsToChangesMap::const_iterator, // base iterator
153  const SdfPath& // value type
154  >
155  {
156  public:
157  iterator()
158  : iterator_adaptor_(base_type()) {}
159 
164  USD_API TfTokenVector GetChangedFields() const;
165 
170  USD_API bool HasChangedFields() const;
171 
172  private:
173  friend class PathRange;
174  friend class boost::iterator_core_access;
175 
176  iterator(base_type baseIter)
177  : iterator_adaptor_(baseIter) {}
178  inline reference dereference() const {
179  return base()->first;
180  }
181  };
182 
183  using const_iterator = iterator;
184 
185  PathRange() : _changes(nullptr) { }
186 
188  explicit operator SdfPathVector() const {
189  return SdfPathVector(begin(), end());
190  }
191 
193  bool empty() const {
194  return !_changes || _changes->empty();
195  }
196 
198  size_t size() const {
199  return _changes ? _changes->size() : 0;
200  }
201 
203  iterator begin() const {
204  return iterator(_changes->cbegin());
205  }
206 
208  const_iterator cbegin() const {
209  return iterator(_changes->cbegin());
210  }
211 
213  iterator end() const {
214  return iterator(_changes->cend());
215  }
216 
218  const_iterator cend() const {
219  return iterator(_changes->cend());
220  }
221 
225  const_iterator find(const SdfPath& path) const {
226  return const_iterator(_changes->find(path));
227  }
228 
229  private:
230  friend class ObjectsChanged;
231  explicit PathRange(const _PathsToChangesMap* changes)
232  : _changes(changes)
233  { }
234 
235  const _PathsToChangesMap* _changes;
236  };
237 
244  USD_API PathRange GetResyncedPaths() const;
245 
252  USD_API PathRange GetChangedInfoOnlyPaths() const;
253 
265  USD_API TfTokenVector GetChangedFields(const UsdObject &obj) const;
266 
268  USD_API TfTokenVector GetChangedFields(const SdfPath &path) const;
269 
272  USD_API bool HasChangedFields(const UsdObject &obj) const;
273 
275  USD_API bool HasChangedFields(const SdfPath &path) const;
276 
277  private:
278  const _PathsToChangesMap *_resyncChanges;
279  const _PathsToChangesMap *_infoChanges;
280  };
281 
288  public:
289  explicit StageEditTargetChanged(const UsdStageWeakPtr &stage)
290  : StageNotice(stage) {}
291  USD_API virtual ~StageEditTargetChanged();
292  };
293 
294 };
295 
296 
297 PXR_NAMESPACE_CLOSE_SCOPE
298 
299 #endif // USD_NOTICE_H
Container class for Usd notices.
Definition: notice.h:43
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 TfTokenVector GetChangedFields(const UsdObject &obj) const
Return the set of changed fields in layers that affected obj.
An iterable range of paths to objects that have changed.
Definition: notice.h:146
iterator begin() const
Return iterator to the start of this range.
Definition: notice.h:203
The base class for objects used to notify interested parties (listeners) when events have occurred...
Definition: notice.h:93
USD_API PathRange GetResyncedPaths() const
Return the set of paths that are resynced in lexicographical order.
The outermost container for scene description, which owns and presents composed prims as a scenegraph...
Definition: stage.h:142
Notice sent when a stage&#39;s EditTarget has changed.
Definition: notice.h:287
bool AffectedObject(const UsdObject &obj) const
Return true if obj was possibly affected by the layer changes that generated this notice...
Definition: notice.h:127
USD_API bool HasChangedFields(const UsdObject &obj) const
Return true if there are any changed fields that affected obj, false otherwise.
Base class for UsdStage notices.
Definition: notice.h:47
size_t size() const
Return the number of paths in this range.
Definition: notice.h:198
Ultra-conservative notice sent when the given UsdStage&#39;s contents have changed in any way...
Definition: notice.h:73
Notice sent in response to authored changes that affect UsdObjects.
Definition: notice.h:107
Base class for Usd scenegraph objects, providing common API.
Definition: object.h:129
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:438
const_iterator cbegin() const
Return iterator to the start of this range.
Definition: notice.h:208
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:287
bool empty() const
Return true if this range contains any paths, false otherwise.
Definition: notice.h:193
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:225
iterator end() const
Return the end iterator for this range.
Definition: notice.h:213
const UsdStageWeakPtr & GetStage() const
Return the stage associated with this notice.
Definition: notice.h:55
USD_API PathRange GetChangedInfoOnlyPaths() const
Return the set of paths that have only info changes (those that do not affect the structure of cached...
const_iterator cend() const
Return the end iterator for this range.
Definition: notice.h:218
USD_API bool ResyncedObject(const UsdObject &obj) const
Return true if obj was resynced by the layer changes that generated this notice.