All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
stageCache.h
1 //
2 // Copyright 2017 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 _GUSD_STAGECACHE_H_
25 #define _GUSD_STAGECACHE_H_
26 
27 #include <UT/UT_Array.h>
28 #include <UT/UT_Error.h>
29 #include <UT/UT_Set.h>
30 
31 #include "gusd/defaultArray.h"
32 #include "gusd/stageEdit.h"
33 #include "gusd/stageOpts.h"
34 #include "gusd/USD_Utils.h"
35 
36 #include "pxr/pxr.h"
37 #include "pxr/usd/sdf/layer.h"
38 #include "pxr/usd/usd/stage.h"
39 
40 
41 class DEP_MicroNode;
42 class UT_StringHolder;
43 class UT_StringSet;
44 
45 
46 PXR_NAMESPACE_OPEN_SCOPE
47 
48 class GusdUSD_DataCache;
49 class UsdPrim;
50 
54 class GUSD_API GusdStageCache
55 {
56 public:
58 
59  ~GusdStageCache();
60 
61  GusdStageCache(const GusdStageCache&) = delete;
62 
63  GusdStageCache& operator=(const GusdStageCache&) = delete;
64 
65  static GusdStageCache& GetInstance();
66 
71  void AddDataCache(GusdUSD_DataCache& cache);
72 
73  void RemoveDataCache(GusdUSD_DataCache& cache);
75 
102 
104  static void ReloadStages(const UT_Set<UsdStagePtr>& stages);
105 
107  static void ReloadLayers(const UT_Set<SdfLayerHandle>& layers);
108 
109 
110 private:
111  class _MaskedStageCache;
112 
113  class _Impl;
114  _Impl* const _impl;
115 
116  friend class GusdStageCacheReader;
117  friend class GusdStageCacheWriter;
118 };
119 
120 
141 class GUSD_API GusdStageCacheReader
142 {
143 public:
144  using PrimStagePair = std::pair<UsdPrim,UsdStageRefPtr>;
145 
147  GusdStageCacheReader(GusdStageCache& cache=GusdStageCache::GetInstance())
148  : GusdStageCacheReader(cache, false) {}
149 
151 
152  GusdStageCacheReader& operator=(const GusdStageCacheReader&) = delete;
153 
155 
158  Find(const UT_StringRef& path,
160  const GusdStageEditPtr& edit=nullptr) const;
161 
168  FindOrOpen(const UT_StringRef& path,
170  const GusdStageEditPtr& edit=nullptr,
171  UT_ErrorSeverity sev=UT_ERROR_ABORT);
172 
176  DEP_MicroNode*
177  GetStageMicroNode(const UsdStagePtr& stage);
178 
211 
220  PrimStagePair
221  GetPrim(const UT_StringRef& path,
222  const SdfPath& primPath,
223  const GusdStageEditPtr& stageEdit=GusdStageEditPtr(),
225  UT_ErrorSeverity sev=UT_ERROR_ABORT);
226 
240  bool
241  GetPrims(const GusdDefaultArray<UT_StringHolder>& filePaths,
242  const UT_Array<SdfPath>& primPaths,
244  UsdPrim* prims,
246  UT_ErrorSeverity sev=UT_ERROR_ABORT);
247 
257  PrimStagePair
258  GetPrimWithVariants(const UT_StringRef& path,
259  const SdfPath& primPath,
261  UT_ErrorSeverity sev=UT_ERROR_ABORT);
262 
263  PrimStagePair
264  GetPrimWithVariants(const UT_StringRef& path,
265  const UT_StringRef& primPath,
267  UT_ErrorSeverity sev=UT_ERROR_ABORT);
268 
270  PrimStagePair
271  GetPrimWithVariants(const UT_StringRef& path,
272  const SdfPath& primPath,
273  const SdfPath& variants,
275  UT_ErrorSeverity sev=UT_ERROR_ABORT);
276 
277  PrimStagePair
278  GetPrimWithVariants(const UT_StringRef& path,
279  const UT_StringRef& primPath,
280  const UT_StringRef& variants,
282  UT_ErrorSeverity sev=UT_ERROR_ABORT);
284 
285 protected:
286  GusdStageCacheReader(GusdStageCache& cache, bool writer);
287 
288 protected:
289  GusdStageCache& _cache;
290  const bool _writer;
291 };
292 
293 
300 {
301 public:
302  GusdStageCacheWriter(GusdStageCache& cache=GusdStageCache::GetInstance());
303 
305 
306  GusdStageCacheWriter& operator=(const GusdStageCacheWriter&) = delete;
307 
310  void FindStages(const UT_StringSet& paths,
311  UT_Set<UsdStageRefPtr>& stages);
312 
318  void InsertStage(UsdStageRefPtr &stage,
319  const UT_StringRef& path,
320  const GusdStageOpts& opts,
321  const GusdStageEditPtr& edit);
322 
341 
345  void Clear();
346 
349  void Clear(const UT_StringSet& paths);
350 
352  void ReloadStages(const UT_StringSet& paths);
353 
354 };
355 
356 
357 PXR_NAMESPACE_CLOSE_SCOPE
358 
359 
360 #endif /*_GUSD_STAGECACHE_H_*/
static GusdStageOpts LoadAll()
Return options that a configure a stage to be loaded with payloads.
Definition: stageOpts.h:52
Cache for USD stages.
Definition: stageCache.h:54
Options for configuring creation of a new stage.
Definition: stageOpts.h:41
UsdPrim is the sole persistent scenegraph object on a UsdStage, and is the embodiment of a &quot;Prim&quot; as ...
Definition: prim.h:131
Write accessor for a stage cache.
Definition: stageCache.h:299
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:287
Helper for reading from a GusdStageCache.
Definition: stageCache.h:141
Simple array wrapper, providing an array that may either hold a single constant value, or an array of values.
Definition: defaultArray.h:38