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_StringSet.h>
30 #include <pxr/pxr.h>
31 #include <functional>
32 
33 class UT_Color;
34 class UT_StringArray;
35 class HUSD_FindPrims;
37 
41 
46 
47 // Use a SharedPtr instead of an IntrusivePtr for HUSD_LoadMasks because we
48 // want to be able to copy these objects.
51 
53 
54 class XUSD_Data;
57 class XUSD_Layer;
65 template <class T> class TfRefPtr;
66 class SdfLayer;
69 
71 
75 };
76 
77 typedef std::function<UT_StringHolder(const UT_StringRef &oldpath)>
79 
81 {
82 public:
84  mirroring = HUSD_NOT_FOR_MIRRORING);
86  ~HUSD_DataHandle();
87 
88  void reset(int nodeid);
89  const HUSD_DataHandle &operator=(const HUSD_DataHandle &src);
90  void createNewData(
91  const HUSD_LoadMasksPtr &
92  load_masks = HUSD_LoadMasksPtr(),
93  const HUSD_DataHandle *
94  resolver_context_data = nullptr);
95  bool createSoftCopy(const HUSD_DataHandle &src,
96  const HUSD_LoadMasksPtr &load_masks,
97  bool make_new_implicit_layer);
98  bool createCopyWithReplacement(
99  const HUSD_DataHandle &src,
100  const UT_StringRef &frompath,
101  const UT_StringRef &topath,
102  HUSD_MakeNewPathFunc make_new_path,
103  UT_StringSet &replaced_layers);
104  bool flattenLayers();
105  bool flattenStage();
106  bool mirror(const HUSD_DataHandle &src,
107  const HUSD_LoadMasks &load_masks);
108  bool mirrorUpdateRootLayer(
109  const HUSD_MirrorRootLayer &rootlayer);
110 
111  bool hasLayerColorIndex(int &clridx) const;
112  int layerCount() const;
113  int nodeId() const
114  { return myNodeId; }
115  HUSD_LoadMasksPtr loadMasks() const;
116  const std::string &rootLayerIdentifier() const;
117 
119  &overrides,
120  bool remove_layer_break) const;
121  PXR_NS::XUSD_DataPtr writeOverridesLock(const HUSD_OverridesPtr
122  &overrides) const;
123  PXR_NS::XUSD_DataPtr writeLock() const;
125  void release() const;
126 
127 private:
128  HUSD_ConstOverridesPtr currentOverrides() const;
129 
130  friend class HUSD_AutoReadLock;
131 
132  PXR_NS::XUSD_DataPtr myData;
133  PXR_NS::XUSD_DataLockPtr myDataLock;
134  HUSD_MirroringType myMirroring;
135  int myNodeId;
136 };
137 
138 // Parent class for read and write locks that permits reading.
140 {
141 public:
143  const HUSD_DataHandle &handle)
144  : myHandle(handle)
145  { }
147  { }
148 
150  { return myHandle; }
151  virtual PXR_NS::XUSD_ConstDataPtr constData() const = 0;
152 
153 private:
154  const HUSD_DataHandle &myHandle;
155 };
156 
157 // Locks an HUSD_DataHandle for read-only operations.
159 {
160 public:
161  enum HUSD_OverridesUnchangedType { OVERRIDES_UNCHANGED };
162  enum HUSD_RemoveLayerBreaksType { REMOVE_LAYER_BREAKS, KEEP_LAYER_BREAKS };
163 
164  explicit HUSD_AutoReadLock(
165  const HUSD_DataHandle &handle);
166  explicit HUSD_AutoReadLock(
167  const HUSD_DataHandle &handle,
168  HUSD_OverridesUnchangedType);
169  explicit HUSD_AutoReadLock(
170  const HUSD_DataHandle &handle,
171  HUSD_RemoveLayerBreaksType);
172  explicit HUSD_AutoReadLock(
173  const HUSD_DataHandle &handle,
175  &overrides);
176  ~HUSD_AutoReadLock() override;
177 
179  { return myData; }
180  PXR_NS::XUSD_ConstDataPtr constData() const override;
181 
182 private:
184 };
185 
186 // Locks an HUSD_DataHandle in a way that allows read-only operations on the
187 // data, but write access to the supplied overrides layer.
189 {
190 public:
192  const HUSD_DataHandle &handle,
193  const HUSD_OverridesPtr
194  &overrides);
195  ~HUSD_AutoWriteOverridesLock() override;
196 
197  const PXR_NS::XUSD_DataPtr &data() const
198  { return myData; }
200  { return myOverrides; }
201  PXR_NS::XUSD_ConstDataPtr constData() const override;
202 
203 private:
204  PXR_NS::XUSD_DataPtr myData;
205  HUSD_OverridesPtr myOverrides;
206 };
207 
208 // Locks an HUSD_DataHandle for writing to the active layer in the context
209 // of the current stage.
211 {
212 public:
213  explicit HUSD_AutoWriteLock(
214  const HUSD_DataHandle &handle);
215  ~HUSD_AutoWriteLock() override;
216 
217  const PXR_NS::XUSD_DataPtr &data() const
218  { return myData; }
219  void addLockedStages(const
221  PXR_NS::XUSD_ConstDataPtr constData() const override;
222 
223 private:
224  PXR_NS::XUSD_DataPtr myData;
225 };
226 
227 // Locks an HUSD_DataHandle for writing to the active layer outside the
228 // context of the current stage (which is accessible read-only while editing
229 // this off-stage layer).
230 //
231 // A layer lock can be constructed from an HUSD_AutoWriteLock as well. This
232 // doesn't re-lock the data handle, but instead grabs from the write lock all
233 // the data it needs to implement the interface of this class. If the
234 // ScopedLock flag is passed as a second argument, an SdfChangeBlock is
235 // created for the lifetime of this object. This is only safe if this
236 // object will be destroyed before the next time the WriteLock is used
237 // to edit the stage.
239 {
240 public:
241  enum ScopedTag { Scoped };
242 
243  explicit HUSD_AutoLayerLock(
244  const HUSD_DataHandle &handle);
245  explicit HUSD_AutoLayerLock(
246  const HUSD_AutoWriteLock &lock);
247  explicit HUSD_AutoLayerLock(
248  const HUSD_AutoWriteLock &lock,
249  ScopedTag);
250  ~HUSD_AutoLayerLock() override;
251 
253  { return myLayer; }
254  void addTickets(const PXR_NS::
255  XUSD_TicketArray &tickets);
256  void addReplacements(const PXR_NS::
257  XUSD_LayerArray &replacements);
258  void addLockedStages(const
260  PXR_NS::XUSD_ConstDataPtr constData() const override;
261 
262 private:
263  PXR_NS::XUSD_DataPtr myData;
264  PXR_NS::XUSD_LayerPtr myLayer;
265  bool myOwnsHandleLock;
266 };
267 
268 #endif
269 
Definition: layer.h:93
GLenum src
Definition: glew.h:2410
UT_SharedPtr< HUSD_LoadMasks > HUSD_LoadMasksPtr
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
GLboolean reset
Definition: glew.h:4959
const PXR_NS::XUSD_DataPtr & data() const
const PXR_NS::XUSD_LayerPtr & layer() const
UT_Array< XUSD_TicketPtr > XUSD_TicketArray
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
#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:28
GLint GLenum GLsizei GLint GLsizei const void * data
Definition: glew.h:1379
const PXR_NS::XUSD_DataPtr & data() const
UT_IntrusivePtr< const XUSD_Layer > XUSD_ConstLayerPtr
UT_WeakPtr< HUSD_LockedStage > HUSD_LockedStageWeakPtr
virtual PXR_NS::XUSD_ConstDataPtr constData() const =0
GLsizei const GLchar *const * string
Definition: glew.h:1844
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1346
std::weak_ptr< T > UT_WeakPtr
Definition: UT_WeakPtr.h:17
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:83
const PXR_NS::XUSD_ConstDataPtr & data() const
const HUSD_DataHandle & dataHandle() const
TfRefPtr< SdfLayer > SdfLayerRefPtr
UT_Array< SdfLayerRefPtr > XUSD_LayerArray
UT_IntrusivePtr< XUSD_Layer > XUSD_LayerPtr
GLbitfield stages
Definition: glew.h:5939
UT_IntrusivePtr< XUSD_Ticket > XUSD_TicketPtr