Loading...
Searching...
No Matches
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
25PXR_NAMESPACE_OPEN_SCOPE
26
27SDF_DECLARE_HANDLES(SdfLayer);
29
30class PcpCache;
31class PcpSite;
32
38public:
41
44
47
50
57
64 SdfRelocatesMap newRelocatesSourceToTarget;
65 SdfRelocatesMap newIncrementalRelocatesSourceToTarget;
66 SdfRelocatesMap newIncrementalRelocatesTargetToSource;
67 SdfPathVector newRelocatesPrimPaths;
68 PcpErrorVector newRelocatesErrors;
69
72
75
77 : didChangeLayers(false)
79 , didChangeRelocates(false)
82 , _didChangeExpressionVariablesSource(false)
83 {}
84
85private:
86 friend class PcpChanges;
87 friend class PcpLayerStack;
88
89 // Expression variables source has changed.
90 bool _didChangeExpressionVariablesSource;
91
92 // New source for expression variables for this layer stack.
93 PcpExpressionVariablesSource _newExpressionVariablesSource;
94};
95
101public:
102 enum TargetType {
103 TargetTypeConnection = 1 << 0,
104 TargetTypeRelationshipTarget = 1 << 1
105 };
106
111
113 SdfPathSet didChangeSpecs;
114
117 SdfPathSet didChangePrims;
118
120 std::map<SdfPath, int, SdfPath::FastLessThan> didChangeTargets;
121
126 std::vector<std::pair<SdfPath, SdfPath>> didChangePath;
127
130
131private:
132 friend class PcpCache;
133 friend class PcpChanges;
134
135 // Must rebuild the prim/property stacks at each path due to a change
136 // that only affects the internal representation of the stack and
137 // not its contents. Because this causes no externally-observable
138 // changes in state, clients do not need to be aware of these changes.
139 SdfPathSet _didChangeSpecsInternal;
140};
141
145public:
146 PcpLifeboat();
147 ~PcpLifeboat();
148
150 void Retain(const SdfLayerRefPtr& layer);
151
153 void Retain(const PcpLayerStackRefPtr& layerStack);
154
157 const std::set<PcpLayerStackRefPtr>& GetLayerStacks() const;
158
160 void Swap(PcpLifeboat& other);
161
162private:
163 std::set<SdfLayerRefPtr> _layers;
164 std::set<PcpLayerStackRefPtr> _layerStacks;
165};
166
177public:
178 PCP_API PcpChanges();
179 PCP_API ~PcpChanges();
180
188 PCP_API
189 void DidChange(const PcpCache* cache,
190 const SdfLayerChangeListVec& changes);
191
196 PCP_API
197 void DidMaybeFixSublayer(const PcpCache* cache,
198 const SdfLayerHandle& layer,
199 const std::string& assetPath);
200
203 PCP_API
204 void DidMaybeFixAsset(const PcpCache* cache,
205 const PcpSite& site,
206 const SdfLayerHandle& srcLayer,
207 const std::string& assetPath);
208
210 PCP_API
211 void DidMuteLayer(const PcpCache* cache, const std::string& layerId);
212
214 PCP_API
215 void DidUnmuteLayer(const PcpCache* cache, const std::string& layerId);
216
221 PCP_API
222 void DidChangeSignificantly(const PcpCache* cache, const SdfPath& path);
223
229 PCP_API
230 void DidChangeSpecs(const PcpCache* cache, const SdfPath& path,
231 const SdfLayerHandle& changedLayer,
232 const SdfPath& changedPath);
233
236 PCP_API
237 void DidChangeSpecStack(const PcpCache* cache, const SdfPath& path);
238
241 PCP_API
242 void DidChangeTargets(const PcpCache* cache, const SdfPath& path,
243 PcpCacheChanges::TargetType targetType);
244
250 PCP_API
251 void DidChangePaths(const PcpCache* cache,
252 const SdfPath& oldPath, const SdfPath& newPath);
253
255 PCP_API
256 void DidDestroyCache(const PcpCache* cache);
257
262 PCP_API
264
266 PCP_API
267 void Swap(PcpChanges& other);
268
270 PCP_API
271 bool IsEmpty() const;
272
273 typedef std::map<PcpLayerStackPtr, PcpLayerStackChanges> LayerStackChanges;
274 typedef std::map<PcpCache*, PcpCacheChanges> CacheChanges;
275
278 PCP_API
279 const LayerStackChanges& GetLayerStackChanges() const;
280
282 PCP_API
283 const CacheChanges& GetCacheChanges() const;
284
289 PCP_API
290 const PcpLifeboat& GetLifeboat() const;
291
293 PCP_API
294 void Apply() const;
295
296private:
297 // Internal data types for namespace edits from Sd.
298 typedef std::map<SdfPath, SdfPath> _PathEditMap;
299 typedef std::map<PcpCache*, _PathEditMap> _RenameChanges;
300
301 // Returns the PcpLayerStackChanges for the given layer stack.
302 PcpLayerStackChanges& _GetLayerStackChanges(const PcpLayerStackPtr&);
303
304 // Returns the PcpCacheChanges for the given cache.
305 PcpCacheChanges& _GetCacheChanges(const PcpCache* cache);
306
307 // Returns the _PathEditMap for the given cache.
308 _PathEditMap& _GetRenameChanges(const PcpCache* cache);
309
310
311 // Optimize the changes.
312 void _Optimize() const;
313
314 // Optimize the changes.
315 void _Optimize();
316
317 // Optimize the changes for a given cache.
318 void _Optimize(PcpCacheChanges*);
319
320 // Optimize path changes.
321 void _OptimizePathChanges(const PcpCache* cache, PcpCacheChanges* changes,
322 const _PathEditMap* pathChanges);
323
324 // Sublayer change type for _DidChangeSublayer.
325 enum _SublayerChangeType {
326 _SublayerAdded,
327 _SublayerRemoved
328 };
329
330 // Helper function for loading a sublayer of \p layer at \p sublayerPath
331 // for processing changes described by \p sublayerChange.
332 SdfLayerRefPtr _LoadSublayerForChange(const PcpCache* cache,
333 const SdfLayerHandle& layer,
334 const std::string& sublayerPath,
335 _SublayerChangeType changeType) const;
336
337 // Helper function for loading a sublayer at \p sublayerPath
338 // for processing changes described by \p sublayerChange.
339 SdfLayerRefPtr _LoadSublayerForChange(const PcpCache* cache,
340 const std::string& sublayerPath,
341 _SublayerChangeType changeType) const;
342
343 // Propagates changes to \p sublayer specified by \p sublayerChange to
344 // the dependents of that sublayer. This includes all layer stacks
345 // that include the sublayer.
346 void _DidChangeSublayerAndLayerStacks(const PcpCache* cache,
347 const PcpLayerStackPtrVector& stacks,
348 const std::string& sublayerPath,
349 const SdfLayerHandle& sublayer,
350 _SublayerChangeType sublayerChange,
351 std::string* debugSummary);
352
353 // Propagates changes to \p sublayer specified by \p sublayerChange to
354 // the dependents of that sublayer.
355 void _DidChangeSublayer(const PcpCache* cache,
356 const PcpLayerStackPtrVector& layerStacks,
357 const std::string& sublayerPath,
358 const SdfLayerHandle& sublayer,
359 _SublayerChangeType sublayerChange,
360 std::string* debugSummary,
361 bool *significant);
362
363 // Propagates changes due to the addition/removal of the sublayer
364 // at the given \p sublayerPath to/from the parent \p layer.
365 void _DidAddOrRemoveSublayer(const PcpCache* cache,
366 const PcpLayerStackPtrVector& layerStacks,
367 const SdfLayerHandle& layer,
368 const std::string& sublayerPath,
369 _SublayerChangeType sublayerChange,
370 std::string* debugSummary,
371 std::vector<bool> *significant);
372
373 // Mark the layer stack as having changed.
374 void _DidChangeLayerStack(
375 const PcpCache* cache,
376 const PcpLayerStackPtr& layerStack,
377 bool requiresLayerStackChange,
378 bool requiresLayerStackOffsetsChange,
379 bool requiresSignificantChange);
380
381 // Mark the layer stack's relocations as having changed.
382 // Recompute the new relocations, storing the result in the Changes,
383 // so that change-processing can determine which other caches it
384 // needs to invalidate.
385 void _DidChangeLayerStackRelocations(
386 const PcpCache* cache,
387 const PcpLayerStackPtr& layerStack,
388 std::string* debugSummary);
389
390 // Register changes to any prim indexes in \p caches that are affected
391 // by a change to a layer's resolved path used by \p layerStack.
392 void _DidChangeLayerStackResolvedPath(
393 const PcpCache* cache,
394 const PcpLayerStackPtr& layerStack,
395 bool requiresLayerStackChange,
396 std::string* debugSummary);
397
398 // Register changes to layer stacks and prim indexes in \p cache that are
399 // affected by a change to a layer's expression variables used by
400 // \p layerStack.
401 void _DidChangeLayerStackExpressionVariables(
402 const PcpCache* cache,
403 const PcpLayerStackPtr& layerStack,
404 std::string* debugSummary);
405
406 // The spec stack for the prim or property index at \p path must be
407 // recomputed due to a change that affects only the internal representation
408 // of the stack and not its contents.
409 void _DidChangeSpecStackInternal(
410 const PcpCache* cache, const SdfPath& path);
411
412private:
413 LayerStackChanges _layerStackChanges;
414 CacheChanges _cacheChanges;
415 _RenameChanges _renameChanges;
416 mutable PcpLifeboat _lifeboat;
417};
418
419PXR_NAMESPACE_CLOSE_SCOPE
420
421#endif // PXR_USD_PCP_CHANGES_H
Types of changes per cache.
Definition: changes.h:100
std::vector< std::pair< SdfPath, SdfPath > > didChangePath
Must update the path on every namespace object at and below each given path.
Definition: changes.h:126
SdfPathSet didChangePrims
Must rebuild the prim indexes at each path.
Definition: changes.h:117
SdfPathSet didChangeSpecs
Must rebuild the prim/property stacks at each path.
Definition: changes.h:113
SdfPathSet didChangeSignificantly
Must rebuild the indexes at and below each path.
Definition: changes.h:110
bool didMaybeChangeLayers
Layers used in the composition may have changed.
Definition: changes.h:129
std::map< SdfPath, int, SdfPath::FastLessThan > didChangeTargets
Must rebuild the connections/targets at each path.
Definition: changes.h:120
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:176
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 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 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 DidUnmuteLayer(const PcpCache *cache, const std::string &layerId)
The layer identified by layerId was unmuted in cache.
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 DidChangeSpecs(const 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...
PCP_API void DidMuteLayer(const PcpCache *cache, const std::string &layerId)
The layer identified by layerId was muted 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.
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:37
SdfRelocatesMap newRelocatesTargetToSource
New relocation maps for this layer stack.
Definition: changes.h:63
bool didChangeLayers
Must rebuild the layer tree. Implies didChangeLayerOffsets.
Definition: changes.h:40
bool didChangeExpressionVariables
Must rebuild expression variables.
Definition: changes.h:49
VtDictionary newExpressionVariables
New expression variables for this layer stack.
Definition: changes.h:74
bool didChangeLayerOffsets
Must rebuild the layer offsets.
Definition: changes.h:43
bool didChangeSignificantly
A significant layer stack change means the composed opinions of the layer stack may have changed in a...
Definition: changes.h:56
SdfPathSet pathsAffectedByRelocationChanges
Paths that are affected by the above relocation changes.
Definition: changes.h:71
bool didChangeRelocates
Must rebuild the relocation tables.
Definition: changes.h:46
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:144
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:83
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