HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
HUSD_DataHandle.h
Go to the documentation of this file.
1 /*
2  * Copyright 2019 Side Effects Software Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17 
18 #ifndef __HUSD_DataHandle_h__
19 #define __HUSD_DataHandle_h__
20 
21 #include "HUSD_API.h"
22 #include <UT/UT_Assert.h>
23 #include <UT/UT_Function.h>
24 #include <UT/UT_IntrusivePtr.h>
25 #include <UT/UT_NonCopyable.h>
26 #include <UT/UT_Set.h>
27 #include <UT/UT_SharedPtr.h>
28 #include <UT/UT_StringArray.h>
29 #include <UT/UT_StringHolder.h>
30 #include <UT/UT_StringMap.h>
31 #include <UT/UT_StringSet.h>
32 #include <UT/UT_WeakPtr.h>
33 #include <pxr/pxr.h>
34 
35 class UT_Color;
36 class UT_StringArray;
37 class HUSD_FindPrims;
39 
46 
51 
52 // Use a SharedPtr instead of an IntrusivePtr for HUSD_LoadMasks because we
53 // want to be able to copy these objects.
56 
58 
59 class XUSD_Data;
62 class XUSD_Layer;
70 template <class T> class TfRefPtr;
71 class SdfLayer;
75 
77 
82 };
83 
86 
88 {
89 public:
91  mirroring = HUSD_NOT_FOR_MIRRORING);
93  explicit HUSD_DataHandle(void *stage_ptr);
94  explicit HUSD_DataHandle(const UT_StringRef &filepath);
95  ~HUSD_DataHandle();
96 
97  // Test if myData has been set.
98  bool hasData() const;
99  // Compare the resolver context on this data handle with another.
100  bool matchesResolverContext(
101  const HUSD_DataHandle &other) const;
102 
103  void reset(int nodeid);
104  const HUSD_DataHandle &operator=(const HUSD_DataHandle &src);
105  // Create a new, empty stage in our XUSD_Data.
106  void createNewData(
107  const HUSD_LoadMasksPtr &
108  load_masks = HUSD_LoadMasksPtr(),
109  const HUSD_DataHandle *
110  resolver_context_data = nullptr);
111  // Share the stage from the src XUSD_Data object, unless the load_masks
112  // is supplied, in which case we may need to create a new stage with the
113  // specified load masks.
114  bool createSoftCopy(const HUSD_DataHandle &src,
115  const HUSD_LoadMasksPtr &load_masks,
116  bool make_new_implicit_layer);
117  // Create a new stage that is a copy of the src stage, but replacing any
118  // composition of the "frompath" with the "topath". This check works
119  // recursively, which may require performing other layer replacements
120  // as we make modified versions of referencing layers (and layers that
121  // reference those layers, and so on).
122  bool createCopyWithReplacement(
123  const HUSD_DataHandle &src,
124  const UT_StringRef &frompath,
125  const UT_StringRef &topath,
126  HUSD_MakeNewPathFunc make_new_path,
127  UT_StringSet &replaced_layers);
128  // Make a new stage by flattening the layer stack of our current stage.
129  bool flattenLayers();
130  // Make a new stage by flattening our current stage.
131  bool flattenStage();
132 
133  // For an HUSD_FOR_MIRRORING data handle, create a duplicate of the src
134  // data handle's stage and layer stack.
135  bool mirror(const HUSD_DataHandle &src,
136  const HUSD_LoadMasks &load_masks);
137  void clearMirror();
138 
139  // For an HUSD_FOR_MIRRORING data handle, update our stage's root layer
140  // with the information in the HUSD_MirrorRootLayer. This is currently
141  // just a description of the viewport camera.
142  bool mirrorUpdateRootLayer(
143  const HUSD_MirrorRootLayer &rootlayer);
144 
145  bool hasLayerColorIndex(int &clridx) const;
146  int layerCount() const;
147  int nodeId() const
148  { return myNodeId; }
149  HUSD_LoadMasksPtr loadMasks() const;
150  const std::string &rootLayerIdentifier() const;
151 
152  bool isLocked() const;
153  PXR_NS::XUSD_ConstDataPtr readLock(
155  &overrides,
157  &postlayers,
158  bool remove_layer_break) const;
159  PXR_NS::XUSD_DataPtr writeOverridesLock(
160  const HUSD_OverridesPtr
161  &overrides) const;
162  PXR_NS::XUSD_DataPtr writeLock() const;
164  bool create_change_block) const;
165  void release() const;
166 
167  // Clear out all mirrored stages completely. They must be rebuilt from
168  // scratch the next time they are asked to mirror a stage.
169  static void clearAllMirroredData();
170 
171 private:
172  HUSD_ConstOverridesPtr currentOverrides() const;
173  HUSD_ConstPostLayersPtr currentPostLayers() const;
174 
175  friend class HUSD_AutoReadLock;
176 
177  PXR_NS::XUSD_DataPtr myData;
178  PXR_NS::XUSD_DataLockPtr myDataLock;
179  HUSD_MirroringType myMirroring;
180  int myNodeId;
181 };
182 
183 // Parent class for read and write locks that permits reading.
185 {
186 public:
188  const HUSD_DataHandle &handle)
189  : myHandle(handle)
190  { }
192  { }
193 
194  bool isStageValid() const;
196  { return myHandle; }
197  virtual PXR_NS::XUSD_ConstDataPtr constData() const = 0;
198 
199 private:
200  const HUSD_DataHandle &myHandle;
201 };
202 
203 // Locks an HUSD_DataHandle for read-only operations.
205 {
206 public:
207  enum HUSD_OverridesUnchangedType { OVERRIDES_UNCHANGED };
208  enum HUSD_RemoveLayerBreaksType { REMOVE_LAYER_BREAKS, KEEP_LAYER_BREAKS };
209 
210  explicit HUSD_AutoReadLock(
211  const HUSD_DataHandle &handle);
212  explicit HUSD_AutoReadLock(
213  const HUSD_DataHandle &handle,
214  HUSD_OverridesUnchangedType);
215  explicit HUSD_AutoReadLock(
216  const HUSD_DataHandle &handle,
218  &overrides,
220  &postlayers,
221  HUSD_RemoveLayerBreaksType
222  lbtype = KEEP_LAYER_BREAKS);
223  ~HUSD_AutoReadLock() override;
224 
226  { return myData; }
227  PXR_NS::XUSD_ConstDataPtr constData() const override;
228 
229 private:
231 };
232 
233 // Locks an HUSD_DataHandle in a way that allows read-only operations on the
234 // data, but write access to the supplied overrides layer.
236 {
237 public:
239  const HUSD_DataHandle &handle,
240  const HUSD_OverridesPtr
241  &overrides);
242  ~HUSD_AutoWriteOverridesLock() override;
243 
244  const PXR_NS::XUSD_DataPtr &data() const
245  { return myData; }
247  { return myOverrides; }
248  PXR_NS::XUSD_ConstDataPtr constData() const override;
249 
250 private:
251  PXR_NS::XUSD_DataPtr myData;
252  HUSD_OverridesPtr myOverrides;
253 };
254 
255 // Locks an HUSD_DataHandle for writing to the active layer in the context
256 // of the current stage.
258 {
259 public:
260  explicit HUSD_AutoWriteLock(
261  const HUSD_DataHandle &handle);
262  ~HUSD_AutoWriteLock() override;
263 
264  const PXR_NS::XUSD_DataPtr &data() const
265  { return myData; }
266  void addLockedStages(const
268  PXR_NS::XUSD_ConstDataPtr constData() const override;
269 
270 private:
271  PXR_NS::XUSD_DataPtr myData;
272 };
273 
274 // Locks an HUSD_DataHandle for writing to the active layer outside the
275 // context of the current stage (which is accessible read-only while editing
276 // this off-stage layer).
277 //
278 // A layer lock can be constructed from an HUSD_AutoWriteLock as well. This
279 // doesn't re-lock the data handle, but instead grabs from the write lock all
280 // the data it needs to implement the interface of this class. If the
281 // ScopedLock flag is passed as a second argument, an SdfChangeBlock is
282 // created for the lifetime of this object. This is only safe if this
283 // object will be destroyed before the next time the WriteLock is used
284 // to edit the stage.
286 {
287 public:
290  NoChangeBlock
291  };
292 
293  explicit HUSD_AutoLayerLock(
294  const HUSD_DataHandle &handle,
295  ChangeBlockTag change_block =
296  ChangeBlock);
297  explicit HUSD_AutoLayerLock(
298  const HUSD_AutoWriteLock &lock,
299  ChangeBlockTag change_block =
300  NoChangeBlock);
301  ~HUSD_AutoLayerLock() override;
302 
304  { return myLayer; }
305  void addLockedGeos(const PXR_NS::
306  XUSD_LockedGeoSet &lockedgeos);
307  void addHeldLayers(const PXR_NS::
308  XUSD_LayerSet &layers);
309  void addReplacements(const PXR_NS::
310  XUSD_LayerSet &replacements);
311  void addLockedStages(const
313  PXR_NS::XUSD_ConstDataPtr constData() const override;
314 
315 private:
316  PXR_NS::XUSD_DataPtr myData;
317  PXR_NS::XUSD_LayerPtr myLayer;
318  bool myOwnsHandleLock;
319 };
320 
321 #endif
322 
UT_IntrusivePtr< HUSD_PostLayers > HUSD_PostLayersPtr
Definition: layer.h:94
UT_SharedPtr< HUSD_LoadMasks > HUSD_LoadMasksPtr
GLbitfield stages
Definition: glcorearb.h:1931
HUSD_MirroringType
UT_IntrusivePtr< XUSD_DataLock > XUSD_DataLockPtr
GLsizei const GLchar *const * string
Definition: glcorearb.h:814
UT_IntrusivePtr< const HUSD_Overrides > HUSD_ConstOverridesPtr
#define HUSD_API
Definition: HUSD_API.h:32
UT_IntrusivePtr< XUSD_Data > XUSD_DataPtr
const PXR_NS::XUSD_DataPtr & data() const
UT_IntrusivePtr< XUSD_LockedGeo > XUSD_LockedGeoPtr
UT_IntrusivePtr< const HUSD_PostLayers > HUSD_ConstPostLayersPtr
const PXR_NS::XUSD_LayerPtr & layer() const
UT_IntrusivePtr< HUSD_Overrides > HUSD_OverridesPtr
const HUSD_OverridesPtr & overrides() const
UT_IntrusivePtr< const XUSD_Data > XUSD_ConstDataPtr
#define PXR_NS
Definition: pxr.h:71
int nodeId() const
GLboolean reset
Definition: glad.h:5138
std::shared_ptr< T > UT_SharedPtr
Wrapper around std::shared_ptr.
Definition: UT_SharedPtr.h:36
const PXR_NS::XUSD_DataPtr & data() const
UT_IntrusivePtr< const XUSD_Layer > XUSD_ConstLayerPtr
UT_WeakPtr< HUSD_LockedStage > HUSD_LockedStageWeakPtr
std::function< T > UT_Function
Definition: UT_Function.h:37
virtual PXR_NS::XUSD_ConstDataPtr constData() const =0
UT_Function< UT_StringHolder(const UT_StringRef &oldpath)> HUSD_MakeNewPathFunc
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1441
virtual ~HUSD_AutoAnyLock()
UT_SharedPtr< HUSD_LockedStage > HUSD_LockedStagePtr
HUSD_AutoAnyLock(const HUSD_DataHandle &handle)
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
const PXR_NS::XUSD_ConstDataPtr & data() const
const HUSD_DataHandle & dataHandle() const
UT_Set< XUSD_LockedGeoPtr > XUSD_LockedGeoSet
UT_Set< HUSD_LockedStagePtr > HUSD_LockedStageSet
TfRefPtr< SdfLayer > SdfLayerRefPtr
UT_Array< SdfLayerRefPtr > XUSD_LayerArray
std::weak_ptr< T > UT_WeakPtr
Definition: UT_SharedPtr.h:49
UT_IntrusivePtr< XUSD_Layer > XUSD_LayerPtr
Definition: format.h:895
UT_Set< SdfLayerRefPtr > XUSD_LayerSet
GLenum src
Definition: glcorearb.h:1793