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;
36 
40 
45 
46 // Use a SharedPtr instead of an IntrusivePtr for HUSD_LoadMasks because we
47 // want to be able to copy these objects.
50 
52 
53 class XUSD_Data;
56 class XUSD_Layer;
64 template <class T> class TfRefPtr;
65 class SdfLayer;
68 
70 
74 };
75 
76 typedef std::function<UT_StringHolder(const UT_StringRef &oldpath)>
78 
80 {
81 public:
83  mirroring = HUSD_NOT_FOR_MIRRORING);
85  ~HUSD_DataHandle();
86 
87  void reset(int nodeid);
88  const HUSD_DataHandle &operator=(const HUSD_DataHandle &src);
89  void createNewData(
90  const HUSD_LoadMasksPtr &
91  load_masks = HUSD_LoadMasksPtr(),
92  const HUSD_DataHandle *
93  resolver_context_data = nullptr);
94  bool createSoftCopy(const HUSD_DataHandle &src,
95  const HUSD_LoadMasksPtr &load_masks,
96  bool make_new_implicit_layer);
97  bool createCopyWithReplacement(
98  const HUSD_DataHandle &src,
99  const UT_StringRef &frompath,
100  const UT_StringRef &topath,
101  HUSD_MakeNewPathFunc make_new_path,
102  UT_StringSet &replaced_layers);
103  bool flattenLayers();
104  bool flattenStage();
105  bool mirror(const HUSD_DataHandle &src,
106  const HUSD_LoadMasks &load_masks);
107 
108  bool hasLayerColorIndex(int &clridx) const;
109  int layerCount() const;
110  int nodeId() const
111  { return myNodeId; }
112  HUSD_LoadMasksPtr loadMasks() const;
113  const std::string &rootLayerIdentifier() const;
114 
116  &overrides,
117  bool remove_layer_break) const;
118  PXR_NS::XUSD_DataPtr writeOverridesLock(const HUSD_OverridesPtr
119  &overrides) const;
120  PXR_NS::XUSD_DataPtr writeLock() const;
122  void release() const;
123 
124 private:
125  HUSD_ConstOverridesPtr currentOverrides() const;
126 
127  friend class HUSD_AutoReadLock;
128 
129  PXR_NS::XUSD_DataPtr myData;
130  PXR_NS::XUSD_DataLockPtr myDataLock;
131  HUSD_MirroringType myMirroring;
132  int myNodeId;
133 };
134 
135 // Parent class for read and write locks that permits reading.
137 {
138 public:
140  const HUSD_DataHandle &handle)
141  : myHandle(handle)
142  { }
144  { }
145 
147  { return myHandle; }
148  virtual PXR_NS::XUSD_ConstDataPtr constData() const = 0;
149 
150 private:
151  const HUSD_DataHandle &myHandle;
152 };
153 
154 // Locks an HUSD_DataHandle for read-only operations.
156 {
157 public:
158  enum HUSD_OverridesUnchangedType { OVERRIDES_UNCHANGED };
159  enum HUSD_RemoveLayerBreaksType { REMOVE_LAYER_BREAKS };
160 
161  explicit HUSD_AutoReadLock(
162  const HUSD_DataHandle &handle);
163  explicit HUSD_AutoReadLock(
164  const HUSD_DataHandle &handle,
165  HUSD_OverridesUnchangedType);
166  explicit HUSD_AutoReadLock(
167  const HUSD_DataHandle &handle,
168  HUSD_RemoveLayerBreaksType);
169  explicit HUSD_AutoReadLock(
170  const HUSD_DataHandle &handle,
172  &overrides);
173  virtual ~HUSD_AutoReadLock();
174 
176  { return myData; }
177  virtual PXR_NS::XUSD_ConstDataPtr constData() const;
178 
179 private:
181 };
182 
183 // Locks an HUSD_DataHandle in a way that allows read-only operations on the
184 // data, but write access to the supplied overrides layer.
186 {
187 public:
189  const HUSD_DataHandle &handle,
190  const HUSD_OverridesPtr
191  &overrides);
192  virtual ~HUSD_AutoWriteOverridesLock();
193 
194  const PXR_NS::XUSD_DataPtr &data() const
195  { return myData; }
197  { return myOverrides; }
198  virtual PXR_NS::XUSD_ConstDataPtr constData() const;
199 
200 private:
201  PXR_NS::XUSD_DataPtr myData;
202  HUSD_OverridesPtr myOverrides;
203 };
204 
205 // Locks an HUSD_DataHandle for writing to the active layer in the context
206 // of the current stage.
208 {
209 public:
210  explicit HUSD_AutoWriteLock(
211  const HUSD_DataHandle &handle);
212  virtual ~HUSD_AutoWriteLock();
213 
214  const PXR_NS::XUSD_DataPtr &data() const
215  { return myData; }
216  void addLockedStages(const
218  virtual PXR_NS::XUSD_ConstDataPtr constData() const;
219 
220 private:
221  PXR_NS::XUSD_DataPtr myData;
222 };
223 
224 // Locks an HUSD_DataHandle for writing to the active layer outside the
225 // context of the current stage (which is accessible read-only while editing
226 // this off-stage layer).
227 //
228 // A layer lock can be constructed from an HUSD_AutoWriteLock as well. This
229 // doesn't re-lock the data handle, but instead grabs from the write lock all
230 // the data it needs to implement the interface of this class. If the
231 // ScopedLock flag is passed as a second argument, an SdfChangeBlock is
232 // created for the lifetime of this object. This is only safe if this
233 // object will be destroyed before the next time the WriteLock is used
234 // to edit the stage.
236 {
237 public:
238  enum ScopedTag { Scoped };
239 
240  explicit HUSD_AutoLayerLock(
241  const HUSD_DataHandle &handle);
242  explicit HUSD_AutoLayerLock(
243  const HUSD_AutoWriteLock &lock);
244  explicit HUSD_AutoLayerLock(
245  const HUSD_AutoWriteLock &lock,
246  ScopedTag);
247  virtual ~HUSD_AutoLayerLock();
248 
250  { return myLayer; }
251  void addTickets(const PXR_NS::
252  XUSD_TicketArray &tickets);
253  void addReplacements(const PXR_NS::
254  XUSD_LayerArray &replacements);
255  void addLockedStages(const
257  virtual PXR_NS::XUSD_ConstDataPtr constData() const;
258 
259 private:
260  PXR_NS::XUSD_DataPtr myData;
261  PXR_NS::XUSD_LayerPtr myLayer;
262  bool myOwnsHandleLock;
263 };
264 
265 #endif
266 
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:1245
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