Loading...
Searching...
No Matches
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 PXR_USD_PCP_CHANGES_H
25#define PXR_USD_PCP_CHANGES_H
26
28
29#include "pxr/pxr.h"
30#include "pxr/usd/pcp/api.h"
31#include "pxr/usd/pcp/errors.h"
35#include "pxr/usd/sdf/path.h"
36#include "pxr/usd/sdf/types.h"
38
39#include <map>
40#include <set>
41
42PXR_NAMESPACE_OPEN_SCOPE
43
44SDF_DECLARE_HANDLES(SdfLayer);
46
47class PcpCache;
48class PcpSite;
49
55public:
58
61
64
67
74
81 SdfRelocatesMap newRelocatesSourceToTarget;
82 SdfRelocatesMap newIncrementalRelocatesSourceToTarget;
83 SdfRelocatesMap newIncrementalRelocatesTargetToSource;
84 SdfPathVector newRelocatesPrimPaths;
85 PcpErrorVector newRelocatesErrors;
86
89
92
94 : didChangeLayers(false)
96 , didChangeRelocates(false)
99 , _didChangeExpressionVariablesSource(false)
100 {}
101
102private:
103 friend class PcpChanges;
104 friend class PcpLayerStack;
105
106 // Expression variables source has changed.
107 bool _didChangeExpressionVariablesSource;
108
109 // New source for expression variables for this layer stack.
110 PcpExpressionVariablesSource _newExpressionVariablesSource;
111};
112
118public:
119 enum TargetType {
120 TargetTypeConnection = 1 << 0,
121 TargetTypeRelationshipTarget = 1 << 1
122 };
123
128
130 SdfPathSet didChangeSpecs;
131
134 SdfPathSet didChangePrims;
135
137 std::map<SdfPath, int, SdfPath::FastLessThan> didChangeTargets;
138
143 std::vector<std::pair<SdfPath, SdfPath>> didChangePath;
144
147
148private:
149 friend class PcpCache;
150 friend class PcpChanges;
151
152 // Must rebuild the prim/property stacks at each path due to a change
153 // that only affects the internal representation of the stack and
154 // not its contents. Because this causes no externally-observable
155 // changes in state, clients do not need to be aware of these changes.
156 SdfPathSet _didChangeSpecsInternal;
157};
158
162public:
163 PcpLifeboat();
164 ~PcpLifeboat();
165
167 void Retain(const SdfLayerRefPtr& layer);
168
170 void Retain(const PcpLayerStackRefPtr& layerStack);
171
174 const std::set<PcpLayerStackRefPtr>& GetLayerStacks() const;
175
177 void Swap(PcpLifeboat& other);
178
179private:
180 std::set<SdfLayerRefPtr> _layers;
181 std::set<PcpLayerStackRefPtr> _layerStacks;
182};
183
194public:
195 PCP_API PcpChanges();
196 PCP_API ~PcpChanges();
197
205 PCP_API
206 void DidChange(const PcpCache* cache,
207 const SdfLayerChangeListVec& changes);
208
213 PCP_API
214 void DidMaybeFixSublayer(const PcpCache* cache,
215 const SdfLayerHandle& layer,
216 const std::string& assetPath);
217
220 PCP_API
221 void DidMaybeFixAsset(const PcpCache* cache,
222 const PcpSite& site,
223 const SdfLayerHandle& srcLayer,
224 const std::string& assetPath);
225
227 PCP_API
228 void DidMuteLayer(const PcpCache* cache, const std::string& layerId);
229
231 PCP_API
232 void DidUnmuteLayer(const PcpCache* cache, const std::string& layerId);
233
238 PCP_API
239 void DidChangeSignificantly(const PcpCache* cache, const SdfPath& path);
240
246 PCP_API
247 void DidChangeSpecs(const PcpCache* cache, const SdfPath& path,
248 const SdfLayerHandle& changedLayer,
249 const SdfPath& changedPath);
250
253 PCP_API
254 void DidChangeSpecStack(const PcpCache* cache, const SdfPath& path);
255
258 PCP_API
259 void DidChangeTargets(const PcpCache* cache, const SdfPath& path,
260 PcpCacheChanges::TargetType targetType);
261
267 PCP_API
268 void DidChangePaths(const PcpCache* cache,
269 const SdfPath& oldPath, const SdfPath& newPath);
270
272 PCP_API
273 void DidDestroyCache(const PcpCache* cache);
274
279 PCP_API
281
283 PCP_API
284 void Swap(PcpChanges& other);
285
287 PCP_API
288 bool IsEmpty() const;
289
290 typedef std::map<PcpLayerStackPtr, PcpLayerStackChanges> LayerStackChanges;
291 typedef std::map<PcpCache*, PcpCacheChanges> CacheChanges;
292
295 PCP_API
296 const LayerStackChanges& GetLayerStackChanges() const;
297
299 PCP_API
300 const CacheChanges& GetCacheChanges() const;
301
306 PCP_API
307 const PcpLifeboat& GetLifeboat() const;
308
310 PCP_API
311 void Apply() const;
312
313private:
314 // Internal data types for namespace edits from Sd.
315 typedef std::map<SdfPath, SdfPath> _PathEditMap;
316 typedef std::map<PcpCache*, _PathEditMap> _RenameChanges;
317
318 // Returns the PcpLayerStackChanges for the given layer stack.
319 PcpLayerStackChanges& _GetLayerStackChanges(const PcpLayerStackPtr&);
320
321 // Returns the PcpCacheChanges for the given cache.
322 PcpCacheChanges& _GetCacheChanges(const PcpCache* cache);
323
324 // Returns the _PathEditMap for the given cache.
325 _PathEditMap& _GetRenameChanges(const PcpCache* cache);
326
327
328 // Optimize the changes.
329 void _Optimize() const;
330
331 // Optimize the changes.
332 void _Optimize();
333
334 // Optimize the changes for a given cache.
335 void _Optimize(PcpCacheChanges*);
336
337 // Optimize path changes.
338 void _OptimizePathChanges(const PcpCache* cache, PcpCacheChanges* changes,
339 const _PathEditMap* pathChanges);
340
341 // Sublayer change type for _DidChangeSublayer.
342 enum _SublayerChangeType {
343 _SublayerAdded,
344 _SublayerRemoved
345 };
346
347 // Helper function for loading a sublayer of \p layer at \p sublayerPath
348 // for processing changes described by \p sublayerChange.
349 SdfLayerRefPtr _LoadSublayerForChange(const PcpCache* cache,
350 const SdfLayerHandle& layer,
351 const std::string& sublayerPath,
352 _SublayerChangeType changeType) const;
353
354 // Helper function for loading a sublayer at \p sublayerPath
355 // for processing changes described by \p sublayerChange.
356 SdfLayerRefPtr _LoadSublayerForChange(const PcpCache* cache,
357 const std::string& sublayerPath,
358 _SublayerChangeType changeType) const;
359
360 // Propagates changes to \p sublayer specified by \p sublayerChange to
361 // the dependents of that sublayer. This includes all layer stacks
362 // that include the sublayer.
363 void _DidChangeSublayerAndLayerStacks(const PcpCache* cache,
364 const PcpLayerStackPtrVector& stacks,
365 const std::string& sublayerPath,
366 const SdfLayerHandle& sublayer,
367 _SublayerChangeType sublayerChange,
368 std::string* debugSummary);
369
370 // Propagates changes to \p sublayer specified by \p sublayerChange to
371 // the dependents of that sublayer.
372 void _DidChangeSublayer(const PcpCache* cache,
373 const PcpLayerStackPtrVector& layerStacks,
374 const std::string& sublayerPath,
375 const SdfLayerHandle& sublayer,
376 _SublayerChangeType sublayerChange,
377 std::string* debugSummary,
378 bool *significant);
379
380 // Propagates changes due to the addition/removal of the sublayer
381 // at the given \p sublayerPath to/from the parent \p layer.
382 void _DidAddOrRemoveSublayer(const PcpCache* cache,
383 const PcpLayerStackPtrVector& layerStacks,
384 const SdfLayerHandle& layer,
385 const std::string& sublayerPath,
386 _SublayerChangeType sublayerChange,
387 std::string* debugSummary,
388 std::vector<bool> *significant);
389
390 // Mark the layer stack as having changed.
391 void _DidChangeLayerStack(
392 const PcpCache* cache,
393 const PcpLayerStackPtr& layerStack,
394 bool requiresLayerStackChange,
395 bool requiresLayerStackOffsetsChange,
396 bool requiresSignificantChange);
397
398 // Mark the layer stack's relocations as having changed.
399 // Recompute the new relocations, storing the result in the Changes,
400 // so that change-processing can determine which other caches it
401 // needs to invalidate.
402 void _DidChangeLayerStackRelocations(
403 const PcpCache* cache,
404 const PcpLayerStackPtr& layerStack,
405 std::string* debugSummary);
406
407 // Register changes to any prim indexes in \p caches that are affected
408 // by a change to a layer's resolved path used by \p layerStack.
409 void _DidChangeLayerStackResolvedPath(
410 const PcpCache* cache,
411 const PcpLayerStackPtr& layerStack,
412 bool requiresLayerStackChange,
413 std::string* debugSummary);
414
415 // Register changes to layer stacks and prim indexes in \p cache that are
416 // affected by a change to a layer's expression variables used by
417 // \p layerStack.
418 void _DidChangeLayerStackExpressionVariables(
419 const PcpCache* cache,
420 const PcpLayerStackPtr& layerStack,
421 std::string* debugSummary);
422
423 // The spec stack for the prim or property index at \p path must be
424 // recomputed due to a change that affects only the internal representation
425 // of the stack and not its contents.
426 void _DidChangeSpecStackInternal(
427 const PcpCache* cache, const SdfPath& path);
428
429private:
430 LayerStackChanges _layerStackChanges;
431 CacheChanges _cacheChanges;
432 _RenameChanges _renameChanges;
433 mutable PcpLifeboat _lifeboat;
434};
435
436PXR_NAMESPACE_CLOSE_SCOPE
437
438#endif // PXR_USD_PCP_CHANGES_H
Types of changes per cache.
Definition: changes.h:117
std::vector< std::pair< SdfPath, SdfPath > > didChangePath
Must update the path on every namespace object at and below each given path.
Definition: changes.h:143
SdfPathSet didChangePrims
Must rebuild the prim indexes at each path.
Definition: changes.h:134
SdfPathSet didChangeSpecs
Must rebuild the prim/property stacks at each path.
Definition: changes.h:130
SdfPathSet didChangeSignificantly
Must rebuild the indexes at and below each path.
Definition: changes.h:127
bool didMaybeChangeLayers
Layers used in the composition may have changed.
Definition: changes.h:146
std::map< SdfPath, int, SdfPath::FastLessThan > didChangeTargets
Must rebuild the connections/targets at each path.
Definition: changes.h:137
PcpCache is the context required to make requests of the Pcp composition algorithm and cache the resu...
Definition: cache.h:94
Describes Pcp changes.
Definition: changes.h:193
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:54
SdfRelocatesMap newRelocatesTargetToSource
New relocation maps for this layer stack.
Definition: changes.h:80
bool didChangeLayers
Must rebuild the layer tree. Implies didChangeLayerOffsets.
Definition: changes.h:57
bool didChangeExpressionVariables
Must rebuild expression variables.
Definition: changes.h:66
VtDictionary newExpressionVariables
New expression variables for this layer stack.
Definition: changes.h:91
bool didChangeLayerOffsets
Must rebuild the layer offsets.
Definition: changes.h:60
bool didChangeSignificantly
A significant layer stack change means the composed opinions of the layer stack may have changed in a...
Definition: changes.h:73
SdfPathSet pathsAffectedByRelocationChanges
Paths that are affected by the above relocation changes.
Definition: changes.h:88
bool didChangeRelocates
Must rebuild the relocation tables.
Definition: changes.h:63
Represents a stack of layers that contribute opinions to composition.
Definition: layerStack.h:67
Structure used to temporarily retain layers and layerStacks within a code block.
Definition: changes.h:161
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:46
A scene description container that can combine with other such containers to form simple component as...
Definition: layer.h:100
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:290
A map with string keys and VtValue values.
Definition: dictionary.h:60
Standard pointer typedefs.
#define TF_DECLARE_WEAK_AND_REF_PTRS(type)
Define standard weak, ref, and vector pointer types.
Definition: declarePtrs.h:89
Basic Sdf data types.
std::map< SdfPath, SdfPath > SdfRelocatesMap
A map of source SdfPaths to target SdfPaths for relocation.
Definition: types.h:277