HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
XUSD_Data.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_Data_h__
19 #define __HUSD_Data_h__
20 
21 #include "HUSD_API.h"
22 #include "HUSD_DataHandle.h"
23 #include "XUSD_DataLock.h"
24 #include "HUSD_Overrides.h"
25 #include "XUSD_PathSet.h"
26 #include "XUSD_RootLayerData.h"
27 #include "XUSD_Ticket.h"
28 #include <UT/UT_Color.h>
29 #include <UT/UT_StringArray.h>
30 #include <UT/UT_StringHolder.h>
31 #include <UT/UT_StringSet.h>
32 #include <UT/UT_IntrusivePtr.h>
33 #include <UT/UT_SharedPtr.h>
34 #include <UT/UT_UniquePtr.h>
35 #include <pxr/usd/usd/stage.h>
38 #include <pxr/usd/sdf/path.h>
39 
41 
43 {
49 };
50 
52 {
53 public:
55  explicit XUSD_LayerAtPath(const SdfLayerRefPtr &layer,
57  int layer_badge_index = 0);
58  explicit XUSD_LayerAtPath(const SdfLayerRefPtr &layer,
59  const std::string &filepath,
61  int layer_badge_index = 0);
62 
63  bool hasLayerColorIndex(int &clridx) const;
64  bool isLayerAnonymous() const;
65 
72 };
73 
75 {
76 public:
77  XUSD_OverridesInfo(const UsdStageRefPtr &stage);
79 
80  bool isEmpty() const
81  { return !myReadOverrides && !myWriteOverrides; }
82 
87 };
88 
90 
91 class HUSD_API XUSD_Data : public UT_IntrusiveRefCounter<XUSD_Data>,
92  public UT_NonCopyable
93 {
94 public:
95  XUSD_Data(HUSD_MirroringType mirroring);
96  ~XUSD_Data();
97 
98  // Return true if our stage value is set and has a valid root prim.
99  bool isStageValid() const;
100  // Returns our stage. Should only be accessed when this data is locked.
101  UsdStageRefPtr stage() const;
102  // Returns the active layer on our composed stage.
103  SdfLayerRefPtr activeLayer() const;
104  // Return the on-stage identifiers of any layers that are marked in the
105  // source layers array to be removed due to a layer break.
106  std::set<std::string> getStageLayersToRemoveFromLayerBreak() const;
107  // Creates a layer by flattening all our source layers together. Also
108  // strips out any layers tagged by a Layer Break LOP.
109  SdfLayerRefPtr createFlattenedLayer(
110  HUSD_StripLayerResponse response) const;
111  // Creates a layer by flattening a stage consisting of our source layers
112  // after stripping out any layers tagged by a Layer Break LOP.
113  SdfLayerRefPtr createFlattenedStage(
114  HUSD_StripLayerResponse response) const;
115 
116  // Return the array of source layers that are combined to make our stage.
117  const XUSD_LayerAtPathArray &sourceLayers() const;
118  // Return the current session layer overrides set on our stage.
119  const HUSD_ConstOverridesPtr&overrides() const;
120  // Return a specific session layer object on our stage.
121  const SdfLayerRefPtr &sessionLayer(HUSD_OverridesLayerId id) const;
122  // Return the current load masks set on our stge.
123  const HUSD_LoadMasksPtr &loadMasks() const;
124  // Return the identifier of our stage's root layer. This can be used as
125  // a quick check as to whether we have create a brand new stage.
126  const std::string &rootLayerIdentifier() const;
127 
128  // Add a layer using a file path, layer pointer, or an empty layer.
129  // Files and layer pointers can be inserted at any position in the
130  // sublayer list (0 is strongest, -1 is weakest). The layer op value
131  // indicates whether the layer should be editable, which implies that
132  // it must be added to the strongest position (the only place where a
133  // layer can be edited).
134  bool addLayer(const std::string &filepath,
135  const SdfLayerOffset &offset,
136  int position,
137  XUSD_AddLayerOp add_layer_op,
138  bool copy_root_prim_metadata);
139  bool addLayer(const XUSD_LayerAtPath &layer,
140  int position,
141  XUSD_AddLayerOp add_layer_op,
142  bool copy_root_prim_metadata);
143  // Methods for adding a bunch of layers to our stage in one call. These
144  // methods only unlock and re-lock the data once (meaning only a single
145  // recomposition is required). The resulting behavior of this call is the
146  // same as calling addLayer on each individual layer in order.
147  bool addLayers(
148  const std::vector<std::string> &paths,
149  const std::vector<bool> &above_breaks,
151  int position,
152  XUSD_AddLayerOp add_layer_op,
153  bool copy_root_prim_metadata);
154  bool addLayers(
155  const std::vector<std::string> &paths,
156  const SdfLayerOffsetVector &offsets,
157  int position,
158  XUSD_AddLayerOp add_layer_op,
159  bool copy_root_prim_metadata);
160  bool addLayers(const XUSD_LayerAtPathArray &layers,
161  int position,
162  XUSD_AddLayerOp add_layer_op,
163  bool copy_root_prim_metadata);
164  // Add a single new empty layer.
165  bool addLayer();
166 
167  // Remove one or more of our source layers.
168  bool removeLayers(
169  const std::set<std::string> &filepaths);
170 
171  // Apply a layer break, which tags all existing layers, and adds a new
172  // empty layer for holding future modification.
173  bool applyLayerBreak();
174 
175  // Set a piece of metadata on the root prim of the root layer of the
176  // stage. Also record this change to myRootLayerData so that we can
177  // restore this metadata value if we lock this stage to another state
178  // then return to this state.
179  void setStageRootPrimMetadata(const TfToken &field,
180  const VtValue &value);
181  void setStageRootLayerData(
183  &rootlayerdata);
184  void setStageRootLayerData(
185  const SdfLayerRefPtr &layer);
186 
187  // Store a ticket in with this data to keep alive cooked sop data in the
188  // XUSD_TicketRegistry as long as it might be referenced by our stage.
189  void addTicket(const XUSD_TicketPtr &ticket);
190  void addTickets(const XUSD_TicketArray &tickets);
191  const XUSD_TicketArray &tickets() const;
192 
193  // Store pointers to arrays that were created automatically as part of a
194  // process of replacing a layer on disk with an anonymous layer.
195  void addReplacements(
196  const XUSD_LayerArray &replacements);
197  const XUSD_LayerArray &replacements() const;
198 
199  // Store a locked stage with this data to keep alive cooked lop data in the
200  // HUSD_LockedStageRegistry as long as it might be referenced by our stage.
201  void addLockedStage(
202  const HUSD_LockedStagePtr &stage);
203  void addLockedStages(
205  const HUSD_LockedStageArray &lockedStages() const;
206 
207 private:
208  void reset();
209  void createNewData(const HUSD_LoadMasksPtr &load_masks,
210  int resolver_context_nodeid,
211  const UsdStageWeakPtr &resolver_context_stage,
212  const ArResolverContext *resolver_context);
213  void createHardCopy(const XUSD_Data &src);
214  void createSoftCopy(const XUSD_Data &src,
215  const HUSD_LoadMasksPtr &load_masks,
216  bool make_new_implicit_layer);
217  void createCopyWithReplacement(
218  const XUSD_Data &src,
219  const UT_StringRef &frompath,
220  const UT_StringRef &topath,
221  int nodeid,
222  HUSD_MakeNewPathFunc make_new_path,
223  UT_StringSet &replaced_layers);
224 
225  // Return the resolver context for our stage. Note this this method does
226  // not require that the stage be locked, becaue it is unchanging data set
227  // on the stage when it was created.
228  ArResolverContext resolverContext() const;
229 
230  // Return a layer created by flattening all source layers up to the
231  // strongest layer excluded by a Layer Break node.
232  void flattenLayers(const XUSD_Data &src,
233  int creator_node_id);
234  // Return a layer created by flattening the stage composed of all source
235  // layers up to the strongest layer excluded by a Layer Break node.
236  void flattenStage(const XUSD_Data &src,
237  int creator_node_id);
238  // Utility method used by the two flatten methods above to separate all
239  // layers preceding a layer break point. Optionally creates a warning if
240  // a layer break is found.
241  UsdStageRefPtr getOrCreateStageForFlattening(
242  HUSD_StripLayerResponse response,
243  UsdStage::InitialLoadSet loadset) const;
244 
245  void mirror(const XUSD_Data &src,
246  const HUSD_LoadMasks &load_masks);
247  bool mirrorUpdateRootLayer(
248  const HUSD_MirrorRootLayer &rootlayer);
249 
250  void afterLock(bool for_write,
252  &read_overrides =
254  const HUSD_OverridesPtr
255  &write_overrides =
257  bool remove_layer_breaks = false);
258  XUSD_LayerPtr editActiveSourceLayer();
259  void createInitialPlaceholderSublayers();
260  void afterRelease();
261 
262  static void exitCallback(void *);
263 
264  UsdStageRefPtr myStage;
265  UT_SharedPtr<UT_StringArray> myStageLayerAssignments;
266  UT_SharedPtr<XUSD_LayerArray> myStageLayers;
267  UT_SharedPtr<int> myStageLayerCount;
268  UT_SharedPtr<XUSD_OverridesInfo> myOverridesInfo;
269  UT_SharedPtr<XUSD_RootLayerData> myRootLayerData;
270  XUSD_LayerAtPathArray mySourceLayers;
271  HUSD_LoadMasksPtr myLoadMasks;
272  XUSD_DataLockPtr myDataLock;
273  XUSD_TicketArray myTicketArray;
274  XUSD_LayerArray myReplacementLayerArray;
275  HUSD_LockedStageArray myLockedStages;
276  HUSD_MirroringType myMirroring;
277  UsdStageLoadRules myMirrorLoadRules;
278  bool myMirrorLoadRulesChanged;
279  int myActiveLayerIndex;
280  bool myOwnsActiveLayer;
281 
282  friend class ::HUSD_DataHandle;
283 };
284 
285 class HUSD_API XUSD_Layer : public UT_IntrusiveRefCounter<XUSD_Layer>
286 {
287 public:
289  bool create_change_block)
290  : myLayer(layer),
291  myChangeBlock(nullptr)
292  {
293  if (create_change_block)
294  myChangeBlock.reset(
295  new SdfChangeBlock());
296  }
298  { }
299 
300  const SdfLayerRefPtr &layer() const
301  { return myLayer; }
302 
303 private:
304  SdfLayerRefPtr myLayer;
305  UT_UniquePtr<SdfChangeBlock> myChangeBlock;
306 };
307 
309 
310 #endif
311 
std::string myIdentifier
Definition: XUSD_Data.h:67
const SdfLayerRefPtr & layer() const
Definition: XUSD_Data.h:300
GLenum src
Definition: glew.h:2410
SdfLayerOffset myOffset
Definition: XUSD_Data.h:68
UT_SharedPtr< HUSD_LoadMasks > HUSD_LoadMasksPtr
HUSD_MirroringType
HUSD_OverridesPtr myWriteOverrides
Definition: XUSD_Data.h:84
GLuint GLsizei const GLuint const GLintptr * offsets
Definition: glew.h:4117
UT_IntrusivePtr< const HUSD_Overrides > HUSD_ConstOverridesPtr
int64 exint
Definition: SYS_Types.h:125
#define HUSD_API
Definition: HUSD_API.h:32
XUSD_Layer(const SdfLayerRefPtr &layer, bool create_change_block)
Definition: XUSD_Data.h:288
bool isEmpty() const
Definition: XUSD_Data.h:80
InitialLoadSet
Definition: stage.h:156
GLboolean reset
Definition: glew.h:4959
A reference counter base class for use with UT_IntrusivePtr.
GLenum GLsizei GLsizei GLsizei GLsizei layers
Definition: glew.h:2864
UT_IntrusivePtr< HUSD_Overrides > HUSD_OverridesPtr
bool myLayerIsMissingFile
Definition: XUSD_Data.h:71
bool isLayerAnonymous() const
std::function< UT_StringHolder(const UT_StringRef &oldpath)> HUSD_MakeNewPathFunc
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:33
HUSD_OverridesLayerId
Definition: HUSD_Utils.h:59
std::vector< SdfLayerOffset > SdfLayerOffsetVector
Definition: layerOffset.h:155
Definition: token.h:87
HUSD_ConstOverridesPtr myReadOverrides
Definition: XUSD_Data.h:83
std::shared_ptr< T > UT_SharedPtr
Wrapper around std::shared_ptr.
Definition: UT_SharedPtr.h:28
#define HUSD_OVERRIDES_NUM_LAYERS
Definition: HUSD_Utils.h:65
HUSD_StripLayerResponse
Definition: HUSD_Utils.h:75
exint myOverridesVersionId
Definition: XUSD_Data.h:86
bool hasLayerColorIndex(int &clridx) const
UsdStagePtr UsdStageWeakPtr
Definition: common.h:55
GLsizei const GLchar *const * string
Definition: glew.h:1844
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1346
UT_Array< XUSD_LayerAtPath > XUSD_LayerAtPathArray
Definition: XUSD_Data.h:89
XUSD_AddLayerOp
Definition: XUSD_Data.h:42
UT_SharedPtr< HUSD_LockedStage > HUSD_LockedStagePtr
GLint GLboolean GLint layer
Definition: glew.h:3601
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:83
SdfLayerRefPtr mySessionLayers[HUSD_OVERRIDES_NUM_LAYERS]
Definition: XUSD_Data.h:85
SdfLayerRefPtr myLayer
Definition: XUSD_Data.h:66
bool myRemoveWithLayerBreak
Definition: XUSD_Data.h:70
XUSD_OverridesInfo(const UsdStageRefPtr &stage)
GLsizei const GLfloat * value
Definition: glew.h:1849
Definition: value.h:174
int myLayerColorIndex
Definition: XUSD_Data.h:69
GLbitfield stages
Definition: glew.h:5939
GLenum const void * paths
Definition: glew.h:13589
GLintptr offset
Definition: glew.h:1682