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  // Return true if this data handle's node was the most recent node to
168  // create a lock on the stage we may be sharing with many other nodes.
169  bool isMostRecentStageLock() const;
170 
171  // Clear out all mirrored stages completely. They must be rebuilt from
172  // scratch the next time they are asked to mirror a stage.
173  static void clearAllMirroredData();
174 
175 private:
176  HUSD_ConstOverridesPtr currentOverrides() const;
177  HUSD_ConstPostLayersPtr currentPostLayers() const;
178 
179  friend class HUSD_AutoReadLock;
180 
181  PXR_NS::XUSD_DataPtr myData;
182  PXR_NS::XUSD_DataLockPtr myDataLock;
183  HUSD_MirroringType myMirroring;
184  int myNodeId;
185 };
186 
187 // Parent class for read and write locks that permits reading.
189 {
190 public:
192  const HUSD_DataHandle &handle)
193  : myHandle(handle)
194  { }
196  { }
197 
198  bool isStageValid() const;
200  { return myHandle; }
201  virtual PXR_NS::XUSD_ConstDataPtr constData() const = 0;
202 
203 private:
204  const HUSD_DataHandle &myHandle;
205 };
206 
207 // Locks an HUSD_DataHandle for read-only operations.
209 {
210 public:
211  enum HUSD_OverridesUnchangedType { OVERRIDES_UNCHANGED };
212  enum HUSD_RemoveLayerBreaksType { REMOVE_LAYER_BREAKS, KEEP_LAYER_BREAKS };
213 
214  explicit HUSD_AutoReadLock(
215  const HUSD_DataHandle &handle);
216  explicit HUSD_AutoReadLock(
217  const HUSD_DataHandle &handle,
218  HUSD_OverridesUnchangedType);
219  explicit HUSD_AutoReadLock(
220  const HUSD_DataHandle &handle,
222  &overrides,
224  &postlayers,
225  HUSD_RemoveLayerBreaksType
226  lbtype = KEEP_LAYER_BREAKS);
227  ~HUSD_AutoReadLock() override;
228 
230  { return myData; }
231  PXR_NS::XUSD_ConstDataPtr constData() const override;
232 
233 private:
235 };
236 
237 // Locks an HUSD_DataHandle in a way that allows read-only operations on the
238 // data, but write access to the supplied overrides layer.
240 {
241 public:
243  const HUSD_DataHandle &handle,
244  const HUSD_OverridesPtr
245  &overrides);
246  ~HUSD_AutoWriteOverridesLock() override;
247 
248  const PXR_NS::XUSD_DataPtr &data() const
249  { return myData; }
251  { return myOverrides; }
252  PXR_NS::XUSD_ConstDataPtr constData() const override;
253 
254 private:
255  PXR_NS::XUSD_DataPtr myData;
256  HUSD_OverridesPtr myOverrides;
257 };
258 
259 // Locks an HUSD_DataHandle for writing to the active layer in the context
260 // of the current stage.
262 {
263 public:
264  explicit HUSD_AutoWriteLock(
265  const HUSD_DataHandle &handle);
266  ~HUSD_AutoWriteLock() override;
267 
268  const PXR_NS::XUSD_DataPtr &data() const
269  { return myData; }
270  void addLockedStages(const
272  PXR_NS::XUSD_ConstDataPtr constData() const override;
273 
274 private:
275  PXR_NS::XUSD_DataPtr myData;
276 };
277 
278 // Locks an HUSD_DataHandle for writing to the active layer outside the
279 // context of the current stage (which is accessible read-only while editing
280 // this off-stage layer).
281 //
282 // A layer lock can be constructed from an HUSD_AutoWriteLock as well. This
283 // doesn't re-lock the data handle, but instead grabs from the write lock all
284 // the data it needs to implement the interface of this class. If the
285 // ScopedLock flag is passed as a second argument, an SdfChangeBlock is
286 // created for the lifetime of this object. This is only safe if this
287 // object will be destroyed before the next time the WriteLock is used
288 // to edit the stage.
290 {
291 public:
294  NoChangeBlock
295  };
296 
297  explicit HUSD_AutoLayerLock(
298  const HUSD_DataHandle &handle,
299  ChangeBlockTag change_block =
300  ChangeBlock);
301  explicit HUSD_AutoLayerLock(
302  const HUSD_AutoWriteLock &lock,
303  ChangeBlockTag change_block =
304  NoChangeBlock);
305  ~HUSD_AutoLayerLock() override;
306 
308  { return myLayer; }
309  void addLockedGeos(const PXR_NS::
310  XUSD_LockedGeoSet &lockedgeos);
311  void addHeldLayers(const PXR_NS::
312  XUSD_LayerSet &layers);
313  void addReplacements(const PXR_NS::
314  XUSD_LayerSet &replacements);
315  void addLockedStages(const
317  PXR_NS::XUSD_ConstDataPtr constData() const override;
318 
319 private:
320  PXR_NS::XUSD_DataPtr myData;
321  PXR_NS::XUSD_LayerPtr myLayer;
322  bool myOwnsHandleLock;
323 };
324 
325 #endif
326 
UT_IntrusivePtr< HUSD_PostLayers > HUSD_PostLayersPtr
Definition: layer.h:97
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:1432
virtual ~HUSD_AutoAnyLock()
UT_SharedPtr< HUSD_LockedStage > HUSD_LockedStagePtr
LeafData & operator=(const LeafData &)=delete
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