All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
changes.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_PCP_CHANGES_H
8#define PXR_USD_PCP_CHANGES_H
9
11
12#include "pxr/pxr.h"
13#include "pxr/usd/pcp/api.h"
14#include "pxr/usd/pcp/errors.h"
18#include "pxr/usd/sdf/path.h"
19#include "pxr/usd/sdf/types.h"
21
22#include <map>
23#include <set>
24#include <unordered_set>
25
26PXR_NAMESPACE_OPEN_SCOPE
27
28SDF_DECLARE_HANDLES(SdfLayer);
30
31class PcpCache;
32class PcpSite;
33
39public:
42
45
48
51
58
65 SdfRelocatesMap newRelocatesSourceToTarget;
66 SdfRelocatesMap newIncrementalRelocatesSourceToTarget;
67 SdfRelocatesMap newIncrementalRelocatesTargetToSource;
68 SdfPathVector newRelocatesPrimPaths;
69 PcpErrorVector newRelocatesErrors;
70
73
76
78 : didChangeLayers(false)
80 , didChangeRelocates(false)
83 , _didChangeExpressionVariablesSource(false)
84 {}
85
86private:
87 friend class PcpChanges;
88 friend class PcpLayerStack;
89
90 // Expression variables source has changed.
91 bool _didChangeExpressionVariablesSource;
92
93 // New source for expression variables for this layer stack.
94 PcpExpressionVariablesSource _newExpressionVariablesSource;
95};
96
102public:
103 enum TargetType {
104 TargetTypeConnection = 1 << 0,
105 TargetTypeRelationshipTarget = 1 << 1
106 };
107
112
114 SdfPathSet didChangeSpecs;
115
118 SdfPathSet didChangePrims;
119
121 std::map<SdfPath, int, SdfPath::FastLessThan> didChangeTargets;
122
127 std::vector<std::pair<SdfPath, SdfPath>> didChangePath;
128
131
134
137
140 std::unordered_set<SdfLayerHandle, TfHash> layersAffectedByMutingOrRemoval;
141
142 // Holds all the diff changelists that were computed when adding/removing
143 // sublayers or muting/unmuting layers.
144 SdfLayerChangeListVec layerChangeListVec;
145
146private:
147 friend class PcpCache;
148 friend class PcpChanges;
149
150 // Must rebuild the prim/property stacks at each path due to a change
151 // that only affects the internal representation of the stack and
152 // not its contents. Because this causes no externally-observable
153 // changes in state, clients do not need to be aware of these changes.
154 SdfPathSet _didChangeSpecsInternal;
155
156 // This set serves a similar purpose to _didChangeSpecsInternal above,
157 // however, during processing descendants of the specs in this set will also
158 // be marked as changed. A performance gain is accomplished by placing the
159 // ancestor specs in this set and marking children iteratively when applying
160 // changes to the cache.
161 SdfPathSet _didChangeSpecsAndChildrenInternal;
162};
163
167public:
168 PcpLifeboat();
169 ~PcpLifeboat();
170
172 void Retain(const SdfLayerRefPtr& layer);
173
175 void Retain(const PcpLayerStackRefPtr& layerStack);
176
179 const std::set<PcpLayerStackRefPtr>& GetLayerStacks() const;
180
182 void Swap(PcpLifeboat& other);
183
184private:
185 std::set<SdfLayerRefPtr> _layers;
186 std::set<PcpLayerStackRefPtr> _layerStacks;
187};
188
199public:
200 PCP_API PcpChanges();
201 PCP_API ~PcpChanges();
202
210 PCP_API
211 void DidChange(const PcpCache* cache,
212 const SdfLayerChangeListVec& changes);
213
218 PCP_API
219 void DidMaybeFixSublayer(const PcpCache* cache,
220 const SdfLayerHandle& layer,
221 const std::string& assetPath);
222
225 PCP_API
226 void DidMaybeFixAsset(const PcpCache* cache,
227 const PcpSite& site,
228 const SdfLayerHandle& srcLayer,
229 const std::string& assetPath);
230
232 PCP_API
233 void _DidMuteLayer(const PcpCache* cache, const std::string& layerId);
234
236 PCP_API
237 void _DidUnmuteLayer(const PcpCache* cache, const std::string& layerId);
238
245 const std::vector<std::string>& layersToMute,
246 const std::vector<std::string>& layersToUnmute);
247
252 PCP_API
253 void DidChangeSignificantly(const PcpCache* cache, const SdfPath& path);
254
255 enum ChangeSpecsType {
256 ChangeSpecsTypeRemoved,
257 ChangeSpecsTypeAdded
258 };
259
265 PCP_API
266 void DidChangeSpecs(const PcpCache* cache, const SdfPath& path,
267 const SdfLayerHandle& changedLayer,
268 const SdfPath& changedPath, ChangeSpecsType changeType);
269
272 PCP_API
273 void DidChangeSpecStack(const PcpCache* cache, const SdfPath& path);
274
277 PCP_API
278 void DidChangeTargets(const PcpCache* cache, const SdfPath& path,
279 PcpCacheChanges::TargetType targetType);
280
286 PCP_API
287 void DidChangePaths(const PcpCache* cache,
288 const SdfPath& oldPath, const SdfPath& newPath);
289
291 PCP_API
292 void DidDestroyCache(const PcpCache* cache);
293
298 PCP_API
300
302 PCP_API
303 void Swap(PcpChanges& other);
304
306 PCP_API
307 bool IsEmpty() const;
308
309 typedef std::map<PcpLayerStackPtr, PcpLayerStackChanges> LayerStackChanges;
310 typedef std::map<PcpCache*, PcpCacheChanges> CacheChanges;
311
314 PCP_API
315 const LayerStackChanges& GetLayerStackChanges() const;
316
318 PCP_API
319 const CacheChanges& GetCacheChanges() const;
320
325 PCP_API
326 const PcpLifeboat& GetLifeboat() const;
327
329 PCP_API
330 void Apply() const;
331
332private:
333 // Internal data types for namespace edits from Sd.
334 typedef std::map<SdfPath, SdfPath> _PathEditMap;
335 typedef std::map<PcpCache*, _PathEditMap> _RenameChanges;
336
337 // Returns the PcpLayerStackChanges for the given layer stack.
338 PcpLayerStackChanges& _GetLayerStackChanges(const PcpLayerStackPtr&);
339
340 // Returns the PcpCacheChanges for the given cache.
341 PcpCacheChanges& _GetCacheChanges(const PcpCache* cache);
342
343 // Returns the _PathEditMap for the given cache.
344 _PathEditMap& _GetRenameChanges(const PcpCache* cache);
345
346
347 // Optimize the changes.
348 void _Optimize() const;
349
350 // Optimize the changes.
351 void _Optimize();
352
353 // Optimize the changes for a given cache.
354 void _Optimize(PcpCacheChanges*);
355
356 // Optimize path changes.
357 void _OptimizePathChanges(const PcpCache* cache, PcpCacheChanges* changes,
358 const _PathEditMap* pathChanges);
359
360 // Sublayer change type for _DidChangeSublayer.
361 enum _SublayerChangeType {
362 _SublayerAdded,
363 _SublayerRemoved
364 };
365
366 // Helper function for loading a sublayer of \p layer at \p sublayerPath
367 // for processing changes described by \p sublayerChange.
368 SdfLayerRefPtr _LoadSublayerForChange(const PcpCache* cache,
369 const SdfLayerHandle& layer,
370 const std::string& sublayerPath,
371 _SublayerChangeType changeType) const;
372
373 // Helper function for loading a sublayer at \p sublayerPath
374 // for processing changes described by \p sublayerChange.
375 SdfLayerRefPtr _LoadSublayerForChange(const PcpCache* cache,
376 const std::string& sublayerPath,
377 _SublayerChangeType changeType) const;
378
379 // Propagates changes to \p sublayer specified by \p sublayerChange to
380 // the dependents of that sublayer. This includes all layer stacks
381 // that include the sublayer.
382 void _DidChangeSublayerAndLayerStacks(const PcpCache* cache,
383 const PcpLayerStackPtrVector& stacks,
384 const std::string& sublayerPath,
385 const SdfLayerHandle& sublayer,
386 _SublayerChangeType sublayerChange,
387 std::string* debugSummary);
388
389 // Propagates changes to \p sublayer specified by \p sublayerChange to
390 // the dependents of that sublayer.
391 void _DidChangeSublayer(const PcpCache* cache,
392 const PcpLayerStackPtrVector& layerStacks,
393 const std::string& sublayerPath,
394 const SdfLayerHandle& sublayer,
395 _SublayerChangeType sublayerChange,
396 std::string* debugSummary,
397 bool *significant);
398
399 // Propagates changes due to the addition/removal of the sublayer
400 // at the given \p sublayerPath to/from the parent \p layer.
401 void _DidAddOrRemoveSublayer(const PcpCache* cache,
402 const PcpLayerStackPtrVector& layerStacks,
403 const SdfLayerHandle& layer,
404 const std::string& sublayerPath,
405 _SublayerChangeType sublayerChange,
406 std::string* debugSummary,
407 std::vector<bool> *significant);
408
409 // Mark the layer stack as having changed.
410 void _DidChangeLayerStack(
411 const PcpCache* cache,
412 const PcpLayerStackPtr& layerStack,
413 bool requiresLayerStackChange,
414 bool requiresLayerStackOffsetsChange,
415 bool requiresSignificantChange);
416
417 // Mark the layer stack's relocations as having changed.
418 // Recompute the new relocations, storing the result in the Changes,
419 // so that change-processing can determine which other caches it
420 // needs to invalidate.
421 void _DidChangeLayerStackRelocations(
422 const PcpCache* cache,
423 const PcpLayerStackPtr& layerStack,
424 std::string* debugSummary);
425
426 // Register changes to any prim indexes in \p caches that are affected
427 // by a change to a layer's resolved path used by \p layerStack.
428 void _DidChangeLayerStackResolvedPath(
429 const PcpCache* cache,
430 const PcpLayerStackPtr& layerStack,
431 bool requiresLayerStackChange,
432 std::string* debugSummary);
433
434 // Register changes to layer stacks and prim indexes in \p cache that are
435 // affected by a change to a layer's expression variables used by
436 // \p layerStack.
437 void _DidChangeLayerStackExpressionVariables(
438 const PcpCache* cache,
439 const PcpLayerStackPtr& layerStack,
440 std::string* debugSummary);
441
442 // The spec stack for the prim or property index at \p path must be
443 // recomputed due to a change that affects only the internal representation
444 // of the stack and not its contents.
445 void _DidChangeSpecStackInternal(
446 const PcpCache* cache, const SdfPath& path);
447
448 void _DidChangeSpecStackAndChildrenInternal(
449 const PcpCache* cache, const SdfPath& path);
450
451 // This method is used when processing layer operations. It ensures that
452 // affected layer stacks and their dependent spec stacks are marked as
453 // changed.
454 void _ProcessLayerStackAndDependencyChanges(
455 const PcpCache* cache,
456 const PcpLayerStackPtrVector& layerStacks);
457
458 // When muting or unmuting a layer that is being referenced or payloaded,
459 // we need to ensure that all the relevant sites are recomposed. This
460 // function searches site dependencies of the provided layer stacks and
461 // marks those that are introduced via reference or payload arcs as
462 // significantly changed.
463 void _MarkReferencingSitesAsSignificantlyChanged(
464 const PcpCache* cache,
465 const PcpLayerStackPtrVector& layerStacks);
466
467private:
468 LayerStackChanges _layerStackChanges;
469 CacheChanges _cacheChanges;
470 _RenameChanges _renameChanges;
471 mutable PcpLifeboat _lifeboat;
472};
473
474PXR_NAMESPACE_CLOSE_SCOPE
475
476#endif // PXR_USD_PCP_CHANGES_H
Types of changes per cache.
Definition: changes.h:101
std::vector< std::pair< SdfPath, SdfPath > > didChangePath
Must update the path on every namespace object at and below each given path.
Definition: changes.h:127
bool didMuteOrUnmuteNonEmptyLayer
Will be true if a muting operation took place on a non empty layer.
Definition: changes.h:133
SdfPathSet didChangePrims
Must rebuild the prim indexes at each path.
Definition: changes.h:118
bool didAddOrRemoveNonEmptySublayer
Will be true if a non empty sublayer was added or removed.
Definition: changes.h:136
SdfPathSet didChangeSpecs
Must rebuild the prim/property stacks at each path.
Definition: changes.h:114
std::unordered_set< SdfLayerHandle, TfHash > layersAffectedByMutingOrRemoval
Set of layers that were explicitly muted or removed from a sublayer list and all sublayers of those l...
Definition: changes.h:140
SdfPathSet didChangeSignificantly
Must rebuild the indexes at and below each path.
Definition: changes.h:111
bool didMaybeChangeLayers
Layers used in the composition may have changed.
Definition: changes.h:130
std::map< SdfPath, int, SdfPath::FastLessThan > didChangeTargets
Must rebuild the connections/targets at each path.
Definition: changes.h:121
PcpCache is the context required to make requests of the Pcp composition algorithm and cache the resu...
Definition: cache.h:77
Describes Pcp changes.
Definition: changes.h:198
PCP_API void DidChangeSignificantly(const PcpCache *cache, const SdfPath &path)
The object at path changed significantly enough to require recomputing the entire prim or property in...
PCP_API void DidChangeSpecs(const PcpCache *cache, const SdfPath &path, const SdfLayerHandle &changedLayer, const SdfPath &changedPath, ChangeSpecsType changeType)
The spec stack for the prim or property has changed, due to the addition or removal of the spec in ch...
PCP_API void DidChangeAssetResolver(const PcpCache *cache)
The asset resolver has changed, invalidating previously-resolved asset paths.
PCP_API bool IsEmpty() const
Returns true iff there are no changes.
PCP_API void _DidMuteLayer(const PcpCache *cache, const std::string &layerId)
The layer identified by layerId was muted in cache.
PCP_API void DidMaybeFixSublayer(const PcpCache *cache, const SdfLayerHandle &layer, const std::string &assetPath)
Tries to load the sublayer of layer at sublayerPath.
PCP_API void DidChangePaths(const PcpCache *cache, const SdfPath &oldPath, const SdfPath &newPath)
The composed object at oldPath was moved to newPath.
PCP_API void DidChangeSpecStack(const PcpCache *cache, const SdfPath &path)
The spec stack for the prim or property at path in cache has changed.
PCP_API void Apply() const
Applies the changes to the layer stacks and caches.
PCP_API const CacheChanges & GetCacheChanges() const
Returns a map of all of the cache changes.
PCP_API void DidMaybeFixAsset(const PcpCache *cache, const PcpSite &site, const SdfLayerHandle &srcLayer, const std::string &assetPath)
Tries to load the asset at assetPath.
PCP_API void DidChangeTargets(const PcpCache *cache, const SdfPath &path, PcpCacheChanges::TargetType targetType)
The connections on the attribute or targets on the relationship have changed.
PCP_API void _DidUnmuteLayer(const PcpCache *cache, const std::string &layerId)
The layer identified by layerId was unmuted in cache.
PCP_API const LayerStackChanges & GetLayerStackChanges() const
Returns a map of all of the layer stack changes.
PCP_API void Swap(PcpChanges &other)
Swap the contents of this and other.
PCP_API const PcpLifeboat & GetLifeboat() const
Returns the lifeboat responsible for maintaining the lifetime of layers and layer stacks during chang...
PCP_API void DidChange(const PcpCache *cache, const SdfLayerChangeListVec &changes)
Breaks down changes into individual changes on cache.
void DidMuteAndUnmuteLayers(const PcpCache *cache, const std::vector< std::string > &layersToMute, const std::vector< std::string > &layersToUnmute)
Sets the list of layers that will ultimately be muted and unmuted for this round of changes.
PCP_API void DidDestroyCache(const PcpCache *cache)
Remove any changes for cache.
Represents the layer stack associated with a set of expression variables.
Types of changes per layer stack.
Definition: changes.h:38
SdfRelocatesMap newRelocatesTargetToSource
New relocation maps for this layer stack.
Definition: changes.h:64
bool didChangeLayers
Must rebuild the layer tree. Implies didChangeLayerOffsets.
Definition: changes.h:41
bool didChangeExpressionVariables
Must rebuild expression variables.
Definition: changes.h:50
VtDictionary newExpressionVariables
New expression variables for this layer stack.
Definition: changes.h:75
bool didChangeLayerOffsets
Must rebuild the layer offsets.
Definition: changes.h:44
bool didChangeSignificantly
A significant layer stack change means the composed opinions of the layer stack may have changed in a...
Definition: changes.h:57
SdfPathSet pathsAffectedByRelocationChanges
Paths that are affected by the above relocation changes.
Definition: changes.h:72
bool didChangeRelocates
Must rebuild the relocation tables.
Definition: changes.h:47
Represents a stack of layers that contribute opinions to composition.
Definition: layerStack.h:50
Structure used to temporarily retain layers and layerStacks within a code block.
Definition: changes.h:166
void Retain(const PcpLayerStackRefPtr &layerStack)
Ensure that layerStack exists until this object is destroyed.
void Swap(PcpLifeboat &other)
Swap the contents of this and other.
void Retain(const SdfLayerRefPtr &layer)
Ensure that layer exists until this object is destroyed.
const std::set< PcpLayerStackRefPtr > & GetLayerStacks() const
Returns reference to the set of layer stacks currently being held in the lifeboat.
A site specifies a path in a layer stack of scene description.
Definition: site.h:29
A scene description container that can combine with other such containers to form simple component as...
Definition: layer.h:84
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:274
A map with string keys and VtValue values.
Definition: dictionary.h:43
Standard pointer typedefs.
#define TF_DECLARE_WEAK_AND_REF_PTRS(type)
Define standard weak, ref, and vector pointer types.
Definition: declarePtrs.h:72
Basic Sdf data types.
std::map< SdfPath, SdfPath > SdfRelocatesMap
A map of source SdfPaths to target SdfPaths for relocation.
Definition: types.h:267