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_IntrusivePtr.h>
24 #include <UT/UT_NonCopyable.h>
25 #include <UT/UT_SharedPtr.h>
26 #include <UT/UT_WeakPtr.h>
27 #include <UT/UT_StringHolder.h>
28 #include <UT/UT_StringArray.h>
29 #include <UT/UT_StringMap.h>
30 #include <UT/UT_StringSet.h>
31 #include <pxr/pxr.h>
32 #include <functional>
33 
34 class UT_Color;
35 class UT_StringArray;
36 class HUSD_FindPrims;
38 
45 
50 
53 
54 // Use a SharedPtr instead of an IntrusivePtr for HUSD_LoadMasks because we
55 // want to be able to copy these objects.
58 
60 
61 class XUSD_Data;
64 class XUSD_Layer;
72 template <class T> class TfRefPtr;
73 class SdfLayer;
76 
78 
82 };
83 
84 typedef std::function<UT_StringHolder(const UT_StringRef &oldpath)>
86 
88 {
89 public:
91  mirroring = HUSD_NOT_FOR_MIRRORING);
93  ~HUSD_DataHandle();
94 
95  void reset(int nodeid);
96  const HUSD_DataHandle &operator=(const HUSD_DataHandle &src);
97  void createNewData(
98  const HUSD_LoadMasksPtr &
99  load_masks = HUSD_LoadMasksPtr(),
100  const HUSD_DataHandle *
101  resolver_context_data = nullptr);
102  bool createSoftCopy(const HUSD_DataHandle &src,
103  const HUSD_LoadMasksPtr &load_masks,
104  bool make_new_implicit_layer);
105  bool createCopyWithReplacement(
106  const HUSD_DataHandle &src,
107  const UT_StringRef &frompath,
108  const UT_StringRef &topath,
109  HUSD_MakeNewPathFunc make_new_path,
110  UT_StringSet &replaced_layers);
111  bool flattenLayers();
112  bool flattenStage();
113  bool mirror(const HUSD_DataHandle &src,
114  const HUSD_LoadMasks &load_masks);
115  bool mirrorUpdateRootLayer(
116  const HUSD_MirrorRootLayer &rootlayer);
117 
118  bool hasLayerColorIndex(int &clridx) const;
119  int layerCount() const;
120  int nodeId() const
121  { return myNodeId; }
122  HUSD_LoadMasksPtr loadMasks() const;
123  const std::string &rootLayerIdentifier() const;
124 
125  PXR_NS::XUSD_ConstDataPtr readLock(
127  &overrides,
129  &postlayers,
130  bool remove_layer_break) const;
131  PXR_NS::XUSD_DataPtr writeOverridesLock(
132  const HUSD_OverridesPtr
133  &overrides) const;
134  PXR_NS::XUSD_DataPtr writeLock() const;
136  bool create_change_block) const;
137  void release() const;
138 
139 private:
140  HUSD_ConstOverridesPtr currentOverrides() const;
141  HUSD_ConstPostLayersPtr currentPostLayers() const;
142 
143  friend class HUSD_AutoReadLock;
144 
145  PXR_NS::XUSD_DataPtr myData;
146  PXR_NS::XUSD_DataLockPtr myDataLock;
147  HUSD_MirroringType myMirroring;
148  int myNodeId;
149 };
150 
151 // Parent class for read and write locks that permits reading.
153 {
154 public:
156  const HUSD_DataHandle &handle)
157  : myHandle(handle)
158  { }
160  { }
161 
163  { return myHandle; }
164  virtual PXR_NS::XUSD_ConstDataPtr constData() const = 0;
165 
166 private:
167  const HUSD_DataHandle &myHandle;
168 };
169 
170 // Locks an HUSD_DataHandle for read-only operations.
172 {
173 public:
174  enum HUSD_OverridesUnchangedType { OVERRIDES_UNCHANGED };
175  enum HUSD_RemoveLayerBreaksType { REMOVE_LAYER_BREAKS, KEEP_LAYER_BREAKS };
176 
177  explicit HUSD_AutoReadLock(
178  const HUSD_DataHandle &handle);
179  explicit HUSD_AutoReadLock(
180  const HUSD_DataHandle &handle,
181  HUSD_OverridesUnchangedType);
182  explicit HUSD_AutoReadLock(
183  const HUSD_DataHandle &handle,
185  &overrides,
187  &postlayers,
188  HUSD_RemoveLayerBreaksType
189  lbtype = KEEP_LAYER_BREAKS);
190  ~HUSD_AutoReadLock() override;
191 
193  { return myData; }
194  PXR_NS::XUSD_ConstDataPtr constData() const override;
195 
196 private:
198 };
199 
200 // Locks an HUSD_DataHandle in a way that allows read-only operations on the
201 // data, but write access to the supplied overrides layer.
203 {
204 public:
206  const HUSD_DataHandle &handle,
207  const HUSD_OverridesPtr
208  &overrides);
209  ~HUSD_AutoWriteOverridesLock() override;
210 
211  const PXR_NS::XUSD_DataPtr &data() const
212  { return myData; }
214  { return myOverrides; }
215  PXR_NS::XUSD_ConstDataPtr constData() const override;
216 
217 private:
218  PXR_NS::XUSD_DataPtr myData;
219  HUSD_OverridesPtr myOverrides;
220 };
221 
222 // Locks an HUSD_DataHandle for writing to the active layer in the context
223 // of the current stage.
225 {
226 public:
227  explicit HUSD_AutoWriteLock(
228  const HUSD_DataHandle &handle);
229  ~HUSD_AutoWriteLock() override;
230 
231  const PXR_NS::XUSD_DataPtr &data() const
232  { return myData; }
233  void addLockedStages(const
235  PXR_NS::XUSD_ConstDataPtr constData() const override;
236 
237 private:
238  PXR_NS::XUSD_DataPtr myData;
239 };
240 
241 // Locks an HUSD_DataHandle for writing to the active layer outside the
242 // context of the current stage (which is accessible read-only while editing
243 // this off-stage layer).
244 //
245 // A layer lock can be constructed from an HUSD_AutoWriteLock as well. This
246 // doesn't re-lock the data handle, but instead grabs from the write lock all
247 // the data it needs to implement the interface of this class. If the
248 // ScopedLock flag is passed as a second argument, an SdfChangeBlock is
249 // created for the lifetime of this object. This is only safe if this
250 // object will be destroyed before the next time the WriteLock is used
251 // to edit the stage.
253 {
254 public:
257  NoChangeBlock
258  };
259 
260  explicit HUSD_AutoLayerLock(
261  const HUSD_DataHandle &handle,
262  ChangeBlockTag change_block =
263  ChangeBlock);
264  explicit HUSD_AutoLayerLock(
265  const HUSD_AutoWriteLock &lock,
266  ChangeBlockTag change_block =
267  NoChangeBlock);
268  ~HUSD_AutoLayerLock() override;
269 
271  { return myLayer; }
272  void addLockedGeos(const PXR_NS::
273  XUSD_LockedGeoArray &lockedgeos);
274  void addReplacements(const PXR_NS::
275  XUSD_LayerArray &replacements);
276  void addLockedStages(const
278  PXR_NS::XUSD_ConstDataPtr constData() const override;
279 
280 private:
281  PXR_NS::XUSD_DataPtr myData;
282  PXR_NS::XUSD_LayerPtr myLayer;
283  bool myOwnsHandleLock;
284 };
285 
286 #endif
287 
UT_IntrusivePtr< HUSD_PostLayers > HUSD_PostLayersPtr
Definition: layer.h:96
UT_SharedPtr< HUSD_LoadMasks > HUSD_LoadMasksPtr
GLbitfield stages
Definition: glcorearb.h:1930
HUSD_MirroringType
UT_IntrusivePtr< XUSD_DataLock > XUSD_DataLockPtr
UT_IntrusivePtr< const HUSD_Overrides > HUSD_ConstOverridesPtr
#define HUSD_API
Definition: HUSD_API.h:32
UT_IntrusivePtr< XUSD_Data > XUSD_DataPtr
GLenum src
Definition: glcorearb.h:1792
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
std::function< UT_StringHolder(const UT_StringRef &oldpath)> HUSD_MakeNewPathFunc
const HUSD_OverridesPtr & overrides() const
UT_IntrusivePtr< const XUSD_Data > XUSD_ConstDataPtr
UT_StringMap< HUSD_DataHandle > HUSD_DataHandleMap
#define PXR_NS
Definition: pxr.h:71
int nodeId() const
std::shared_ptr< T > UT_SharedPtr
Wrapper around std::shared_ptr.
Definition: UT_SharedPtr.h:30
GLsizei const GLchar *const * string
Definition: glcorearb.h:813
const PXR_NS::XUSD_DataPtr & data() const
GLboolean reset
Definition: glew.h:4989
UT_IntrusivePtr< const XUSD_Layer > XUSD_ConstLayerPtr
UT_WeakPtr< HUSD_LockedStage > HUSD_LockedStageWeakPtr
virtual PXR_NS::XUSD_ConstDataPtr constData() const =0
GLboolean * data
Definition: glcorearb.h:130
UT_Array< XUSD_LockedGeoPtr > XUSD_LockedGeoArray
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1375
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:43
UT_IntrusivePtr< XUSD_Layer > XUSD_LayerPtr