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 private:
168  HUSD_ConstOverridesPtr currentOverrides() const;
169  HUSD_ConstPostLayersPtr currentPostLayers() const;
170 
171  friend class HUSD_AutoReadLock;
172 
173  PXR_NS::XUSD_DataPtr myData;
174  PXR_NS::XUSD_DataLockPtr myDataLock;
175  HUSD_MirroringType myMirroring;
176  int myNodeId;
177 };
178 
179 // Parent class for read and write locks that permits reading.
181 {
182 public:
184  const HUSD_DataHandle &handle)
185  : myHandle(handle)
186  { }
188  { }
189 
190  bool isStageValid() const;
192  { return myHandle; }
193  virtual PXR_NS::XUSD_ConstDataPtr constData() const = 0;
194 
195 private:
196  const HUSD_DataHandle &myHandle;
197 };
198 
199 // Locks an HUSD_DataHandle for read-only operations.
201 {
202 public:
203  enum HUSD_OverridesUnchangedType { OVERRIDES_UNCHANGED };
204  enum HUSD_RemoveLayerBreaksType { REMOVE_LAYER_BREAKS, KEEP_LAYER_BREAKS };
205 
206  explicit HUSD_AutoReadLock(
207  const HUSD_DataHandle &handle);
208  explicit HUSD_AutoReadLock(
209  const HUSD_DataHandle &handle,
210  HUSD_OverridesUnchangedType);
211  explicit HUSD_AutoReadLock(
212  const HUSD_DataHandle &handle,
214  &overrides,
216  &postlayers,
217  HUSD_RemoveLayerBreaksType
218  lbtype = KEEP_LAYER_BREAKS);
219  ~HUSD_AutoReadLock() override;
220 
222  { return myData; }
223  PXR_NS::XUSD_ConstDataPtr constData() const override;
224 
225 private:
227 };
228 
229 // Locks an HUSD_DataHandle in a way that allows read-only operations on the
230 // data, but write access to the supplied overrides layer.
232 {
233 public:
235  const HUSD_DataHandle &handle,
236  const HUSD_OverridesPtr
237  &overrides);
238  ~HUSD_AutoWriteOverridesLock() override;
239 
240  const PXR_NS::XUSD_DataPtr &data() const
241  { return myData; }
243  { return myOverrides; }
244  PXR_NS::XUSD_ConstDataPtr constData() const override;
245 
246 private:
247  PXR_NS::XUSD_DataPtr myData;
248  HUSD_OverridesPtr myOverrides;
249 };
250 
251 // Locks an HUSD_DataHandle for writing to the active layer in the context
252 // of the current stage.
254 {
255 public:
256  explicit HUSD_AutoWriteLock(
257  const HUSD_DataHandle &handle);
258  ~HUSD_AutoWriteLock() override;
259 
260  const PXR_NS::XUSD_DataPtr &data() const
261  { return myData; }
262  void addLockedStages(const
264  PXR_NS::XUSD_ConstDataPtr constData() const override;
265 
266 private:
267  PXR_NS::XUSD_DataPtr myData;
268 };
269 
270 // Locks an HUSD_DataHandle for writing to the active layer outside the
271 // context of the current stage (which is accessible read-only while editing
272 // this off-stage layer).
273 //
274 // A layer lock can be constructed from an HUSD_AutoWriteLock as well. This
275 // doesn't re-lock the data handle, but instead grabs from the write lock all
276 // the data it needs to implement the interface of this class. If the
277 // ScopedLock flag is passed as a second argument, an SdfChangeBlock is
278 // created for the lifetime of this object. This is only safe if this
279 // object will be destroyed before the next time the WriteLock is used
280 // to edit the stage.
282 {
283 public:
286  NoChangeBlock
287  };
288 
289  explicit HUSD_AutoLayerLock(
290  const HUSD_DataHandle &handle,
291  ChangeBlockTag change_block =
292  ChangeBlock);
293  explicit HUSD_AutoLayerLock(
294  const HUSD_AutoWriteLock &lock,
295  ChangeBlockTag change_block =
296  NoChangeBlock);
297  ~HUSD_AutoLayerLock() override;
298 
300  { return myLayer; }
301  void addLockedGeos(const PXR_NS::
302  XUSD_LockedGeoSet &lockedgeos);
303  void addHeldLayers(const PXR_NS::
304  XUSD_LayerSet &layers);
305  void addReplacements(const PXR_NS::
306  XUSD_LayerSet &replacements);
307  void addLockedStages(const
309  PXR_NS::XUSD_ConstDataPtr constData() const override;
310 
311 private:
312  PXR_NS::XUSD_DataPtr myData;
313  PXR_NS::XUSD_LayerPtr myLayer;
314  bool myOwnsHandleLock;
315 };
316 
317 #endif
318 
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