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_SharedPtr.h>
27 #include <UT/UT_StringArray.h>
28 #include <UT/UT_StringHolder.h>
29 #include <UT/UT_StringMap.h>
30 #include <UT/UT_StringSet.h>
31 #include <UT/UT_WeakPtr.h>
32 #include <pxr/pxr.h>
33 
34 class UT_Color;
35 class UT_StringArray;
36 class HUSD_FindPrims;
38 
45 
50 
51 // Use a SharedPtr instead of an IntrusivePtr for HUSD_LoadMasks because we
52 // want to be able to copy these objects.
55 
57 
58 class XUSD_Data;
61 class XUSD_Layer;
69 template <class T> class TfRefPtr;
70 class SdfLayer;
73 
75 
80 };
81 
84 
86 {
87 public:
89  mirroring = HUSD_NOT_FOR_MIRRORING);
91  explicit HUSD_DataHandle(void *stage_ptr);
92  explicit HUSD_DataHandle(const UT_StringRef &filepath);
93  ~HUSD_DataHandle();
94 
95  // Test if myData has been set.
96  bool hasData() const;
97  // Compare the resolver context on this data handle with another.
98  bool matchesResolverContext(
99  const HUSD_DataHandle &other) const;
100 
101  void reset(int nodeid);
102  const HUSD_DataHandle &operator=(const HUSD_DataHandle &src);
103  // Create a new, empty stage in our XUSD_Data.
104  void createNewData(
105  const HUSD_LoadMasksPtr &
106  load_masks = HUSD_LoadMasksPtr(),
107  const HUSD_DataHandle *
108  resolver_context_data = nullptr);
109  // Share the stage from the src XUSD_Data object, unless the load_masks
110  // is supplied, in which case we may need to create a new stage with the
111  // specified load masks.
112  bool createSoftCopy(const HUSD_DataHandle &src,
113  const HUSD_LoadMasksPtr &load_masks,
114  bool make_new_implicit_layer);
115  // Create a new stage that is a copy of the src stage, but replacing any
116  // composition of the "frompath" with the "topath". This check works
117  // recursively, which may require performing other layer replacements
118  // as we make modified versions of referencing layers (and layers that
119  // reference those layers, and so on).
120  bool createCopyWithReplacement(
121  const HUSD_DataHandle &src,
122  const UT_StringRef &frompath,
123  const UT_StringRef &topath,
124  HUSD_MakeNewPathFunc make_new_path,
125  UT_StringSet &replaced_layers);
126  // Make a new stage by flattening the layer stack of our current stage.
127  bool flattenLayers();
128  // Make a new stage by flattening our current stage.
129  bool flattenStage();
130 
131  // For an HUSD_FOR_MIRRORING data handle, create a duplicate of the src
132  // data handle's stage and layer stack.
133  bool mirror(const HUSD_DataHandle &src,
134  const HUSD_LoadMasks &load_masks);
135  void clearMirror();
136 
137  // For an HUSD_FOR_MIRRORING data handle, update our stage's root layer
138  // with the information in the HUSD_MirrorRootLayer. This is currently
139  // just a description of the viewport camera.
140  bool mirrorUpdateRootLayer(
141  const HUSD_MirrorRootLayer &rootlayer);
142 
143  bool hasLayerColorIndex(int &clridx) const;
144  int layerCount() const;
145  int nodeId() const
146  { return myNodeId; }
147  HUSD_LoadMasksPtr loadMasks() const;
148  const std::string &rootLayerIdentifier() const;
149 
150  bool isLocked() const;
151  PXR_NS::XUSD_ConstDataPtr readLock(
153  &overrides,
155  &postlayers,
156  bool remove_layer_break) const;
157  PXR_NS::XUSD_DataPtr writeOverridesLock(
158  const HUSD_OverridesPtr
159  &overrides) const;
160  PXR_NS::XUSD_DataPtr writeLock() const;
162  bool create_change_block) const;
163  void release() const;
164 
165 private:
166  HUSD_ConstOverridesPtr currentOverrides() const;
167  HUSD_ConstPostLayersPtr currentPostLayers() const;
168 
169  friend class HUSD_AutoReadLock;
170 
171  PXR_NS::XUSD_DataPtr myData;
172  PXR_NS::XUSD_DataLockPtr myDataLock;
173  HUSD_MirroringType myMirroring;
174  int myNodeId;
175 };
176 
177 // Parent class for read and write locks that permits reading.
179 {
180 public:
182  const HUSD_DataHandle &handle)
183  : myHandle(handle)
184  { }
186  { }
187 
188  bool isStageValid() const;
190  { return myHandle; }
191  virtual PXR_NS::XUSD_ConstDataPtr constData() const = 0;
192 
193 private:
194  const HUSD_DataHandle &myHandle;
195 };
196 
197 // Locks an HUSD_DataHandle for read-only operations.
199 {
200 public:
201  enum HUSD_OverridesUnchangedType { OVERRIDES_UNCHANGED };
202  enum HUSD_RemoveLayerBreaksType { REMOVE_LAYER_BREAKS, KEEP_LAYER_BREAKS };
203 
204  explicit HUSD_AutoReadLock(
205  const HUSD_DataHandle &handle);
206  explicit HUSD_AutoReadLock(
207  const HUSD_DataHandle &handle,
208  HUSD_OverridesUnchangedType);
209  explicit HUSD_AutoReadLock(
210  const HUSD_DataHandle &handle,
212  &overrides,
214  &postlayers,
215  HUSD_RemoveLayerBreaksType
216  lbtype = KEEP_LAYER_BREAKS);
217  ~HUSD_AutoReadLock() override;
218 
220  { return myData; }
221  PXR_NS::XUSD_ConstDataPtr constData() const override;
222 
223 private:
225 };
226 
227 // Locks an HUSD_DataHandle in a way that allows read-only operations on the
228 // data, but write access to the supplied overrides layer.
230 {
231 public:
233  const HUSD_DataHandle &handle,
234  const HUSD_OverridesPtr
235  &overrides);
236  ~HUSD_AutoWriteOverridesLock() override;
237 
238  const PXR_NS::XUSD_DataPtr &data() const
239  { return myData; }
241  { return myOverrides; }
242  PXR_NS::XUSD_ConstDataPtr constData() const override;
243 
244 private:
245  PXR_NS::XUSD_DataPtr myData;
246  HUSD_OverridesPtr myOverrides;
247 };
248 
249 // Locks an HUSD_DataHandle for writing to the active layer in the context
250 // of the current stage.
252 {
253 public:
254  explicit HUSD_AutoWriteLock(
255  const HUSD_DataHandle &handle);
256  ~HUSD_AutoWriteLock() override;
257 
258  const PXR_NS::XUSD_DataPtr &data() const
259  { return myData; }
260  void addLockedStages(const
262  PXR_NS::XUSD_ConstDataPtr constData() const override;
263 
264 private:
265  PXR_NS::XUSD_DataPtr myData;
266 };
267 
268 // Locks an HUSD_DataHandle for writing to the active layer outside the
269 // context of the current stage (which is accessible read-only while editing
270 // this off-stage layer).
271 //
272 // A layer lock can be constructed from an HUSD_AutoWriteLock as well. This
273 // doesn't re-lock the data handle, but instead grabs from the write lock all
274 // the data it needs to implement the interface of this class. If the
275 // ScopedLock flag is passed as a second argument, an SdfChangeBlock is
276 // created for the lifetime of this object. This is only safe if this
277 // object will be destroyed before the next time the WriteLock is used
278 // to edit the stage.
280 {
281 public:
284  NoChangeBlock
285  };
286 
287  explicit HUSD_AutoLayerLock(
288  const HUSD_DataHandle &handle,
289  ChangeBlockTag change_block =
290  ChangeBlock);
291  explicit HUSD_AutoLayerLock(
292  const HUSD_AutoWriteLock &lock,
293  ChangeBlockTag change_block =
294  NoChangeBlock);
295  ~HUSD_AutoLayerLock() override;
296 
298  { return myLayer; }
299  void addLockedGeos(const PXR_NS::
300  XUSD_LockedGeoArray &lockedgeos);
301  void addHeldLayers(const PXR_NS::
302  XUSD_LayerArray &layers);
303  void addReplacements(const PXR_NS::
304  XUSD_LayerArray &replacements);
305  void addLockedStages(const
307  PXR_NS::XUSD_ConstDataPtr constData() const override;
308 
309 private:
310  PXR_NS::XUSD_DataPtr myData;
311  PXR_NS::XUSD_LayerPtr myLayer;
312  bool myOwnsHandleLock;
313 };
314 
315 #endif
316 
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
UT_Array< XUSD_LockedGeoPtr > XUSD_LockedGeoArray
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1441
virtual ~HUSD_AutoAnyLock()
UT_SharedPtr< HUSD_LockedStage > HUSD_LockedStagePtr
UT_Array< HUSD_LockedStagePtr > HUSD_LockedStageArray
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
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
GLenum src
Definition: glcorearb.h:1793