All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
changes.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 PCP_CHANGES_H
25 #define PCP_CHANGES_H
26 
28 
29 #include "pxr/pxr.h"
30 #include "pxr/usd/pcp/api.h"
31 #include "pxr/usd/sdf/declareHandles.h"
32 #include "pxr/usd/sdf/path.h"
33 #include "pxr/usd/sdf/types.h"
34 #include "pxr/base/tf/declarePtrs.h"
35 
36 #include <map>
37 #include <set>
38 
39 PXR_NAMESPACE_OPEN_SCOPE
40 
41 SDF_DECLARE_HANDLES(SdfLayer);
43 
44 class PcpCache;
45 class PcpSite;
46 class SdfChangeList;
47 typedef std::map<SdfLayerHandle, SdfChangeList> SdfLayerChangeListMap;
48 
54 public:
57 
60 
63 
70 
77  SdfRelocatesMap newRelocatesSourceToTarget;
78  SdfRelocatesMap newIncrementalRelocatesSourceToTarget;
79  SdfRelocatesMap newIncrementalRelocatesTargetToSource;
80  SdfPathVector newRelocatesPrimPaths;
81 
84 
86  didChangeLayers(false),
87  didChangeLayerOffsets(false),
88  didChangeRelocates(false),
90  {}
91 };
92 
98 public:
99  enum TargetType {
100  TargetTypeConnection = 1 << 0,
101  TargetTypeRelationshipTarget = 1 << 1
102  };
103 
108 
110  SdfPathSet didChangeSpecs;
111 
114  SdfPathSet didChangePrims;
115 
117  std::map<SdfPath, int, SdfPath::FastLessThan> didChangeTargets;
118 
119  typedef std::map<SdfPath, SdfPath> PathEditMap;
120 
124  PathEditMap didChangePath;
125 
126 private:
127  friend class PcpCache;
128  friend class PcpChanges;
129 
130  // Must rebuild the prim/property stacks at each path due to a change
131  // that only affects the internal representation of the stack and
132  // not its contents. Because this causes no externally-observable
133  // changes in state, clients do not need to be aware of these changes.
134  SdfPathSet _didChangeSpecsInternal;
135 };
136 
139 class PcpLifeboat {
140 public:
141  PcpLifeboat();
142  ~PcpLifeboat();
143 
145  void Retain(const SdfLayerRefPtr& layer);
146 
148  void Retain(const PcpLayerStackRefPtr& layerStack);
149 
152  const std::set<PcpLayerStackRefPtr>& GetLayerStacks() const;
153 
155  void Swap(PcpLifeboat& other);
156 
157 private:
158  std::set<SdfLayerRefPtr> _layers;
159  std::set<PcpLayerStackRefPtr> _layerStacks;
160 };
161 
171 class PcpChanges {
172 public:
173  PCP_API PcpChanges();
174  PCP_API ~PcpChanges();
175 
183  PCP_API
184  void DidChange(const std::vector<PcpCache*>& caches,
185  const SdfLayerChangeListMap& changes);
186 
191  PCP_API
192  void DidMaybeFixSublayer(PcpCache* cache,
193  const SdfLayerHandle& layer,
194  const std::string& assetPath);
195 
198  PCP_API
199  void DidMaybeFixAsset(PcpCache* cache,
200  const PcpSite& site,
201  const SdfLayerHandle& srcLayer,
202  const std::string& assetPath);
203 
205  PCP_API
206  void DidMuteLayer(PcpCache* cache, const std::string& layerId);
207 
209  PCP_API
210  void DidUnmuteLayer(PcpCache* cache, const std::string& layerId);
211 
216  PCP_API
217  void DidChangeLayers(PcpCache* cache);
218 
220  PCP_API
221  void DidChangeLayerOffsets(PcpCache* cache);
222 
227  PCP_API
228  void DidChangeSignificantly(PcpCache* cache, const SdfPath& path);
229 
235  PCP_API
236  void DidChangeSpecs(PcpCache* cache, const SdfPath& path,
237  const SdfLayerHandle& changedLayer,
238  const SdfPath& changedPath);
239 
242  PCP_API
243  void DidChangeSpecStack(PcpCache* cache, const SdfPath& path);
244 
247  PCP_API
248  void DidChangeTargets(PcpCache* cache, const SdfPath& path,
249  PcpCacheChanges::TargetType targetType);
250 
253  PCP_API
254  void DidChangeRelocates(PcpCache* cache, const SdfPath& path);
255 
261  PCP_API
262  void DidChangePaths(PcpCache* cache,
263  const SdfPath& oldPath, const SdfPath& newPath);
264 
266  PCP_API
267  void DidDestroyCache(PcpCache* cache);
268 
270  PCP_API
271  void Swap(PcpChanges& other);
272 
274  PCP_API
275  bool IsEmpty() const;
276 
277  typedef std::map<PcpLayerStackPtr, PcpLayerStackChanges> LayerStackChanges;
278  typedef std::map<PcpCache*, PcpCacheChanges> CacheChanges;
279 
282  PCP_API
283  const LayerStackChanges& GetLayerStackChanges() const;
284 
286  PCP_API
287  const CacheChanges& GetCacheChanges() const;
288 
293  PCP_API
294  const PcpLifeboat& GetLifeboat() const;
295 
297  PCP_API
298  void Apply() const;
299 
300 private:
301  // Internal data type for namespace edits from Sd.
302  typedef std::map<PcpCache*, PcpCacheChanges::PathEditMap> _RenameChanges;
303 
304  // Returns the PcpLayerStackChanges for the given cache's layer stack.
305  PcpLayerStackChanges& _GetLayerStackChanges(PcpCache* cache);
306 
307  // Returns the PcpLayerStackChanges for the given layer stack.
308  PcpLayerStackChanges& _GetLayerStackChanges(const PcpLayerStackPtr&);
309 
310  // Returns the PcpCacheChanges for the given cache.
311  PcpCacheChanges& _GetCacheChanges(PcpCache* cache);
312 
313  // Returns the PcpCacheChanges::PathEditMap for the given cache.
314  PcpCacheChanges::PathEditMap& _GetRenameChanges(PcpCache* cache);
315 
316 
317  // Optimize the changes.
318  void _Optimize() const;
319 
320  // Optimize the changes.
321  void _Optimize();
322 
323  // Optimize the changes for a given cache.
324  void _Optimize(PcpCacheChanges*);
325 
326  // Optimize path changes.
327  void _OptimizePathChanges(const PcpCache* cache, PcpCacheChanges* changes,
328  PcpCacheChanges::PathEditMap* pathChanges);
329 
330  // Sublayer change type for _DidChangeSublayer.
331  enum _SublayerChangeType {
332  _SublayerAdded,
333  _SublayerRemoved
334  };
335 
336  // Helper function for loading a sublayer of \p layer at \p sublayerPath
337  // for processing changes described by \p sublayerChange.
338  SdfLayerRefPtr _LoadSublayerForChange(PcpCache* cache,
339  const SdfLayerHandle& layer,
340  const std::string& sublayerPath,
341  _SublayerChangeType changeType) const;
342 
343  // Helper function for loading a sublayer at \p sublayerPath
344  // for processing changes described by \p sublayerChange.
345  SdfLayerRefPtr _LoadSublayerForChange(PcpCache* cache,
346  const std::string& sublayerPath,
347  _SublayerChangeType changeType) const;
348 
349  // Propagates changes to \p sublayer specified by \p sublayerChange to
350  // the dependents of that sublayer. This includes all layer stacks
351  // that include the sublayer.
352  void _DidChangeSublayerAndLayerStacks(PcpCache* cache,
353  const PcpLayerStackPtrVector& stacks,
354  const std::string& sublayerPath,
355  const SdfLayerHandle& sublayer,
356  _SublayerChangeType sublayerChange,
357  std::string* debugSummary);
358 
359  // Propagates changes to \p sublayer specified by \p sublayerChange to
360  // the dependents of that sublayer.
361  void _DidChangeSublayer(PcpCache* cache,
362  const PcpLayerStackPtrVector& layerStacks,
363  const std::string& sublayerPath,
364  const SdfLayerHandle& sublayer,
365  _SublayerChangeType sublayerChange,
366  std::string* debugSummary,
367  bool *significant);
368 
369  // Mark the layer stack as having changed.
370  void _DidChangeLayerStack(const PcpLayerStackPtr& layerStack,
371  bool requiresLayerStackChange,
372  bool requiresLayerStackOffsetsChange,
373  bool requiresSignificantChange);
374 
375  // Mark the layer stack's relocations as having changed.
376  // Recompute the new relocations, storing the result in the Changes,
377  // so that change-processing can determine which other caches it
378  // needs to invalidate.
379  void _DidChangeLayerStackRelocations( const std::vector<PcpCache*>& caches,
380  const PcpLayerStackPtr & layerStack,
381  std::string* debugSummary );
382 
383  // Register changes to any prim indexes in \p caches that are affected
384  // by a change to a layer's resolved path used by \p layerStack.
385  void _DidChangeLayerStackResolvedPath(const std::vector<PcpCache*>& caches,
386  const PcpLayerStackPtr& layerStack,
387  std::string* debugSummary);
388 
389  // The spec stack for the prim or property index at \p path must be
390  // recomputed due to a change that affects only the internal representation
391  // of the stack and not its contents.
392  void _DidChangeSpecStackInternal(PcpCache* cache, const SdfPath& path);
393 
394 private:
395  LayerStackChanges _layerStackChanges;
396  CacheChanges _cacheChanges;
397  _RenameChanges _renameChanges;
398  mutable PcpLifeboat _lifeboat;
399 };
400 
401 PXR_NAMESPACE_CLOSE_SCOPE
402 
403 #endif // PCP_CHANGES_H
A unit of scene description that you combine with other units of scene description to form a shot...
Definition: layer.h:93
bool didChangeSignificantly
A significant layer stack change means the composed opinions of the layer stack may have changed in a...
Definition: changes.h:69
PCP_API void DidChangeSpecStack(PcpCache *cache, const SdfPath &path)
The spec stack for the prim or property at path in cache has changed.
Represents a stack of layers that contribute opinions to composition.
Definition: layerStack.h:65
PCP_API const LayerStackChanges & GetLayerStackChanges() const
Returns a map of all of the layer stack changes.
Describes Pcp changes.
Definition: changes.h:171
bool didChangeLayers
Must rebuild the layer tree. Implies didChangeLayerOffsets.
Definition: changes.h:56
bool didChangeLayerOffsets
Must rebuild the layer offsets.
Definition: changes.h:59
PcpCache is the context required to make requests of the Pcp composition algorithm and cache the resu...
Definition: cache.h:91
A site specifies a path in a layer stack of scene description.
Definition: site.h:46
PCP_API void Swap(PcpChanges &other)
Swap the contents of this and other.
PCP_API void DidUnmuteLayer(PcpCache *cache, const std::string &layerId)
The layer identified by layerId was unmuted in cache.
#define TF_DECLARE_WEAK_AND_REF_PTRS(type)
Define standard weak, ref, and vector pointer types.
Definition: declarePtrs.h:89
SdfPathSet didChangeSpecs
Must rebuild the prim/property stacks at each path.
Definition: changes.h:110
PCP_API void DidChangeRelocates(PcpCache *cache, const SdfPath &path)
The relocates that affect prims and properties at and below the given cache path have changed...
PCP_API void DidChangeTargets(PcpCache *cache, const SdfPath &path, PcpCacheChanges::TargetType targetType)
The connections on the attribute or targets on the relationship have changed.
SdfPathSet didChangeSignificantly
Must rebuild the indexes at and below each path.
Definition: changes.h:107
SdfPathSet pathsAffectedByRelocationChanges
Paths that are affected by the above relocation changes.
Definition: changes.h:83
PathEditMap didChangePath
Must update the path on every namespace object at and below each given path.
Definition: changes.h:124
PCP_API void DidChangeLayers(PcpCache *cache)
The sublayer tree changed.
PCP_API void DidDestroyCache(PcpCache *cache)
Remove any changes for cache.
PCP_API void DidChangeSpecs(PcpCache *cache, const SdfPath &path, const SdfLayerHandle &changedLayer, const SdfPath &changedPath)
The spec stack for the prim or property has changed, due to the addition or removal of the spec in ch...
Types of changes per layer stack.
Definition: changes.h:53
std::map< SdfPath, int, SdfPath::FastLessThan > didChangeTargets
Must rebuild the connections/targets at each path.
Definition: changes.h:117
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:287
Types of changes per cache.
Definition: changes.h:97
void Swap(PcpLifeboat &other)
Swap the contents of this and other.
PCP_API void DidChange(const std::vector< PcpCache * > &caches, const SdfLayerChangeListMap &changes)
Breaks down changes into individual changes on the caches in caches.
A list of scene description modifications, organized by the namespace paths where the changes occur...
Definition: changeList.h:49
PCP_API void Apply() const
Applies the changes to the layer stacks and caches.
PCP_API void DidMaybeFixAsset(PcpCache *cache, const PcpSite &site, const SdfLayerHandle &srcLayer, const std::string &assetPath)
Tries to load the asset at assetPath.
bool didChangeRelocates
Must rebuild the relocation tables.
Definition: changes.h:62
PCP_API void DidChangeLayerOffsets(PcpCache *cache)
The sublayer offsets changed.
SdfRelocatesMap newRelocatesTargetToSource
New relocation maps for this layer stack.
Definition: changes.h:76
void Retain(const SdfLayerRefPtr &layer)
Ensure that layer exists until this object is destroyed.
PCP_API bool IsEmpty() const
Returns true iff there are no changes.
PCP_API void DidChangePaths(PcpCache *cache, const SdfPath &oldPath, const SdfPath &newPath)
The composed object at oldPath was moved to newPath.
PCP_API void DidMuteLayer(PcpCache *cache, const std::string &layerId)
The layer identified by layerId was muted in cache.
std::map< SdfPath, SdfPath > SdfRelocatesMap
A map of source SdfPaths to target SdfPaths for relocation.
Definition: types.h:277
const std::set< PcpLayerStackRefPtr > & GetLayerStacks() const
Returns reference to the set of layer stacks currently being held in the lifeboat.
Structure used to temporarily retain layers and layerStacks within a code block.
Definition: changes.h:139
PCP_API const PcpLifeboat & GetLifeboat() const
Returns the lifeboat responsible for maintaining the lifetime of layers and layer stacks during chang...
PCP_API void DidChangeSignificantly(PcpCache *cache, const SdfPath &path)
The object at path changed significantly enough to require recomputing the entire prim or property in...
PCP_API void DidMaybeFixSublayer(PcpCache *cache, const SdfLayerHandle &layer, const std::string &assetPath)
Tries to load the sublayer of layer at sublayerPath.
PCP_API const CacheChanges & GetCacheChanges() const
Returns a map of all of the cache changes.
SdfPathSet didChangePrims
Must rebuild the prim indexes at each path.
Definition: changes.h:114