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  bool create_change_block) const;
126  void release() const;
127 
128 private:
129  HUSD_ConstOverridesPtr currentOverrides() const;
130 
131  friend class HUSD_AutoReadLock;
132 
133  PXR_NS::XUSD_DataPtr myData;
134  PXR_NS::XUSD_DataLockPtr myDataLock;
135  HUSD_MirroringType myMirroring;
136  int myNodeId;
137 };
138 
139 // Parent class for read and write locks that permits reading.
141 {
142 public:
144  const HUSD_DataHandle &handle)
145  : myHandle(handle)
146  { }
148  { }
149 
151  { return myHandle; }
152  virtual PXR_NS::XUSD_ConstDataPtr constData() const = 0;
153 
154 private:
155  const HUSD_DataHandle &myHandle;
156 };
157 
158 // Locks an HUSD_DataHandle for read-only operations.
160 {
161 public:
162  enum HUSD_OverridesUnchangedType { OVERRIDES_UNCHANGED };
163  enum HUSD_RemoveLayerBreaksType { REMOVE_LAYER_BREAKS, KEEP_LAYER_BREAKS };
164 
165  explicit HUSD_AutoReadLock(
166  const HUSD_DataHandle &handle);
167  explicit HUSD_AutoReadLock(
168  const HUSD_DataHandle &handle,
169  HUSD_OverridesUnchangedType);
170  explicit HUSD_AutoReadLock(
171  const HUSD_DataHandle &handle,
172  HUSD_RemoveLayerBreaksType);
173  explicit HUSD_AutoReadLock(
174  const HUSD_DataHandle &handle,
176  &overrides);
177  ~HUSD_AutoReadLock() override;
178 
180  { return myData; }
181  PXR_NS::XUSD_ConstDataPtr constData() const override;
182 
183 private:
185 };
186 
187 // Locks an HUSD_DataHandle in a way that allows read-only operations on the
188 // data, but write access to the supplied overrides layer.
190 {
191 public:
193  const HUSD_DataHandle &handle,
194  const HUSD_OverridesPtr
195  &overrides);
196  ~HUSD_AutoWriteOverridesLock() override;
197 
198  const PXR_NS::XUSD_DataPtr &data() const
199  { return myData; }
201  { return myOverrides; }
202  PXR_NS::XUSD_ConstDataPtr constData() const override;
203 
204 private:
205  PXR_NS::XUSD_DataPtr myData;
206  HUSD_OverridesPtr myOverrides;
207 };
208 
209 // Locks an HUSD_DataHandle for writing to the active layer in the context
210 // of the current stage.
212 {
213 public:
214  explicit HUSD_AutoWriteLock(
215  const HUSD_DataHandle &handle);
216  ~HUSD_AutoWriteLock() override;
217 
218  const PXR_NS::XUSD_DataPtr &data() const
219  { return myData; }
220  void addLockedStages(const
222  PXR_NS::XUSD_ConstDataPtr constData() const override;
223 
224 private:
225  PXR_NS::XUSD_DataPtr myData;
226 };
227 
228 // Locks an HUSD_DataHandle for writing to the active layer outside the
229 // context of the current stage (which is accessible read-only while editing
230 // this off-stage layer).
231 //
232 // A layer lock can be constructed from an HUSD_AutoWriteLock as well. This
233 // doesn't re-lock the data handle, but instead grabs from the write lock all
234 // the data it needs to implement the interface of this class. If the
235 // ScopedLock flag is passed as a second argument, an SdfChangeBlock is
236 // created for the lifetime of this object. This is only safe if this
237 // object will be destroyed before the next time the WriteLock is used
238 // to edit the stage.
240 {
241 public:
242  enum ScopedTag { Scoped };
243  enum NotScopedTag { NotScoped };
244 
245  explicit HUSD_AutoLayerLock(
246  const HUSD_DataHandle &handle);
247  explicit HUSD_AutoLayerLock(
248  const HUSD_DataHandle &handle,
249  NotScopedTag);
250  explicit HUSD_AutoLayerLock(
251  const HUSD_AutoWriteLock &lock);
252  explicit HUSD_AutoLayerLock(
253  const HUSD_AutoWriteLock &lock,
254  ScopedTag);
255  ~HUSD_AutoLayerLock() override;
256 
258  { return myLayer; }
259  void addTickets(const PXR_NS::
260  XUSD_TicketArray &tickets);
261  void addReplacements(const PXR_NS::
262  XUSD_LayerArray &replacements);
263  void addLockedStages(const
265  PXR_NS::XUSD_ConstDataPtr constData() const override;
266 
267 private:
268  PXR_NS::XUSD_DataPtr myData;
269  PXR_NS::XUSD_LayerPtr myLayer;
270  bool myOwnsHandleLock;
271 };
272 
273 #endif
274 
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:91
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