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_Ticket.h"
27 #include <UT/UT_Color.h>
28 #include <UT/UT_StringArray.h>
29 #include <UT/UT_StringHolder.h>
30 #include <UT/UT_StringSet.h>
31 #include <UT/UT_IntrusivePtr.h>
32 #include <UT/UT_SharedPtr.h>
33 #include <UT/UT_UniquePtr.h>
34 #include <pxr/usd/usd/stage.h>
37 #include <pxr/usd/sdf/path.h>
38 
40 
42 {
45 };
46 
48 {
49 public:
51  explicit XUSD_LayerAtPath(const SdfLayerRefPtr &layer,
53  int layer_badge_index = 0);
54  explicit XUSD_LayerAtPath(const SdfLayerRefPtr &layer,
55  const std::string &filepath,
57  int layer_badge_index = 0);
58 
59  bool hasLayerColorIndex(int &clridx) const;
60  bool isLayerAnonymous() const;
61 
68 };
69 
71 {
72 public:
73  XUSD_OverridesInfo(const UsdStageRefPtr &stage);
75 
76  bool isEmpty() const
77  { return !myReadOverrides && !myWriteOverrides; }
78 
83 };
84 
86 
87 class HUSD_API XUSD_Data : public UT_IntrusiveRefCounter<XUSD_Data>,
88  public UT_NonCopyable
89 {
90 public:
91  XUSD_Data(HUSD_MirroringType mirroring);
92  ~XUSD_Data();
93 
94  // Return true if our stage value is set and has a valid root prim.
95  bool isStageValid() const;
96  // Returns our stage. Should only be accessed when this data is locked.
97  UsdStageRefPtr stage() const;
98  // Returns the active layer on our composed stage.
99  SdfLayerRefPtr activeLayer() const;
100  // Return the on-stage identifiers of any layers that are marked in the
101  // source layers array to be removed due to a layer break.
102  std::set<std::string> getStageLayersToRemoveFromLayerBreak() const;
103  // Creates a layer by flattening all our source layers together. Also
104  // strips out any layers tagged by a Layer Break LOP.
105  SdfLayerRefPtr createFlattenedLayer(
106  HUSD_StripLayerResponse response) const;
107  // Creates a layer by flattening a stage consisting of our source layers
108  // after stripping out any layers tagged by a Layer Break LOP.
109  SdfLayerRefPtr createFlattenedStage(
110  HUSD_StripLayerResponse response) const;
111 
112  // Return the array of source layers that are combined to make our stage.
113  const XUSD_LayerAtPathArray &sourceLayers() const;
114  // Return the current session layer overrides set on our stage.
115  const HUSD_ConstOverridesPtr&overrides() const;
116  // Return a specific session layer object on our stage.
117  const SdfLayerRefPtr &sessionLayer(HUSD_OverridesLayerId id) const;
118  // Return the current load masks set on our stge.
119  const HUSD_LoadMasksPtr &loadMasks() const;
120  // Return the identifier of our stage's root layer. This can be used as
121  // a quick check as to whether we have create a brand new stage.
122  const std::string &rootLayerIdentifier() const;
123 
124  // Add a layer using a file path, layer pointer, or an empty layer.
125  // Files and layer pointers can be inserted at any position in the
126  // sublayer list (0 is strongest, -1 is weakest). The layer op value
127  // indicates whether the layer should be editable, which implies that
128  // it must be added to the strongest position (the only place where a
129  // layer can be edited).
130  bool addLayer(const std::string &filepath,
131  const SdfLayerOffset &offset,
132  int position,
133  XUSD_AddLayerOp add_layer_op);
134  bool addLayer(const XUSD_LayerAtPath &layer,
135  int position,
136  XUSD_AddLayerOp add_layer_op);
137  bool addLayers(const XUSD_LayerAtPathArray &layers);
138  bool addLayer();
139  // Remove one of our source layers.
140  bool removeLayer(const std::string &filepath);
141 
142  // Apply a layer break, which tags all existing layers, and adds a new
143  // empty layer for holding future modification.
144  bool applyLayerBreak();
145 
146  // Store a ticket in with this data to keep alive cooked sop data in the
147  // XUSD_TicketRegistry as long as it might be referenced by our stage.
148  void addTicket(const XUSD_TicketPtr &ticket);
149  void addTickets(const XUSD_TicketArray &tickets);
150  const XUSD_TicketArray &tickets() const;
151 
152  // Store pointers to arrays that were created automatically as part of a
153  // process of replacing a layer on disk with an anonymous layer.
154  void addReplacements(
155  const XUSD_LayerArray &replacements);
156  const XUSD_LayerArray &replacements() const;
157 
158  // Store a locked stage with this data to keep alive cooked lop data in the
159  // HUSD_LockedStageRegistry as long as it might be referenced by our stage.
160  void addLockedStage(
161  const HUSD_LockedStagePtr &stage);
162  void addLockedStages(
164  const HUSD_LockedStageArray &lockedStages() const;
165 
166 private:
167  void reset();
168  void createNewData(const HUSD_LoadMasksPtr &load_masks,
169  int resolver_context_nodeid,
170  const UsdStageWeakPtr &resolver_context_stage,
171  const ArResolverContext *resolver_context);
172  void createHardCopy(const XUSD_Data &src);
173  void createSoftCopy(const XUSD_Data &src,
174  const HUSD_LoadMasksPtr &load_masks,
175  bool make_new_implicit_layer);
176  void createCopyWithReplacement(
177  const XUSD_Data &src,
178  const UT_StringRef &frompath,
179  const UT_StringRef &topath,
180  int nodeid,
181  HUSD_MakeNewPathFunc make_new_path,
182  UT_StringSet &replaced_layers);
183 
184  // Return the resolver context for our stage. Note this this method does
185  // not require that the stage be locked, becaue it is unchanging data set
186  // on the stage when it was created.
187  ArResolverContext resolverContext() const;
188 
189  // Return a layer created by flattening all source layers up to the
190  // strongest layer excluded by a Layer Break node.
191  void flattenLayers(const XUSD_Data &src,
192  int creator_node_id);
193  // Return a layer created by flattening the stage composed of all source
194  // layers up to the strongest layer excluded by a Layer Break node.
195  void flattenStage(const XUSD_Data &src,
196  int creator_node_id);
197  // Utility method used by the two flatten methods above to separate all
198  // layers preceding a layer break point. Optionally creates a warning if
199  // a layer break is found.
200  UsdStageRefPtr getOrCreateStageForFlattening(
201  HUSD_StripLayerResponse response,
202  UsdStage::InitialLoadSet loadset) const;
203 
204  void mirror(const XUSD_Data &src,
205  const HUSD_LoadMasks &load_masks);
206 
207  void afterLock(bool for_write,
209  &read_overrides =
211  const HUSD_OverridesPtr
212  &write_overrides =
214  bool remove_layer_breaks = false);
215  XUSD_LayerPtr editActiveSourceLayer();
216  void createInitialPlaceholderSublayers();
217  void afterRelease();
218 
219  static void exitCallback(void *);
220 
221  UsdStageRefPtr myStage;
222  UT_SharedPtr<UT_StringArray> myStageLayerAssignments;
223  UT_SharedPtr<XUSD_LayerArray> myStageLayers;
224  UT_SharedPtr<int> myStageLayerCount;
225  UT_SharedPtr<XUSD_OverridesInfo> myOverridesInfo;
226  XUSD_LayerAtPathArray mySourceLayers;
227  HUSD_LoadMasksPtr myLoadMasks;
228  XUSD_DataLockPtr myDataLock;
229  XUSD_TicketArray myTicketArray;
230  XUSD_LayerArray myReplacementLayerArray;
231  HUSD_LockedStageArray myLockedStages;
232  HUSD_MirroringType myMirroring;
233  UsdStageLoadRules myMirrorLoadRules;
234  bool myMirrorLoadRulesChanged;
235  int myActiveLayerIndex;
236  bool myOwnsActiveLayer;
237 
238  friend class ::HUSD_DataHandle;
239 };
240 
241 class HUSD_API XUSD_Layer : public UT_IntrusiveRefCounter<XUSD_Layer>
242 {
243 public:
245  bool create_change_block)
246  : myLayer(layer),
247  myChangeBlock(nullptr)
248  {
249  if (create_change_block)
250  myChangeBlock.reset(
251  new SdfChangeBlock());
252  }
254  { }
255 
256  const SdfLayerRefPtr &layer() const
257  { return myLayer; }
258 
259 private:
260  SdfLayerRefPtr myLayer;
261  UT_UniquePtr<SdfChangeBlock> myChangeBlock;
262 };
263 
265 
266 #endif
267 
std::string myIdentifier
Definition: XUSD_Data.h:63
const SdfLayerRefPtr & layer() const
Definition: XUSD_Data.h:256
GLenum src
Definition: glew.h:2410
SdfLayerOffset myOffset
Definition: XUSD_Data.h:64
UT_SharedPtr< HUSD_LoadMasks > HUSD_LoadMasksPtr
HUSD_MirroringType
HUSD_OverridesPtr myWriteOverrides
Definition: XUSD_Data.h:80
UT_IntrusivePtr< const HUSD_Overrides > HUSD_ConstOverridesPtr
#define HUSD_API
Definition: HUSD_API.h:32
XUSD_Layer(const SdfLayerRefPtr &layer, bool create_change_block)
Definition: XUSD_Data.h:244
bool isEmpty() const
Definition: XUSD_Data.h:76
InitialLoadSet
Definition: stage.h:155
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:67
bool isLayerAnonymous() const
std::function< UT_StringHolder(const UT_StringRef &oldpath)> HUSD_MakeNewPathFunc
HUSD_OverridesLayerId
Definition: HUSD_Utils.h:58
HUSD_ConstOverridesPtr myReadOverrides
Definition: XUSD_Data.h:79
std::shared_ptr< T > UT_SharedPtr
Wrapper around std::shared_ptr.
Definition: UT_SharedPtr.h:28
int64 exint
Definition: SYS_Types.h:120
#define HUSD_OVERRIDES_NUM_LAYERS
Definition: HUSD_Utils.h:64
HUSD_StripLayerResponse
Definition: HUSD_Utils.h:75
exint myOverridesVersionId
Definition: XUSD_Data.h:82
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:1245
UT_Array< XUSD_LayerAtPath > XUSD_LayerAtPathArray
Definition: XUSD_Data.h:85
XUSD_AddLayerOp
Definition: XUSD_Data.h:41
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:81
SdfLayerRefPtr myLayer
Definition: XUSD_Data.h:62
bool myRemoveWithLayerBreak
Definition: XUSD_Data.h:66
XUSD_OverridesInfo(const UsdStageRefPtr &stage)
int myLayerColorIndex
Definition: XUSD_Data.h:65
GLbitfield stages
Definition: glew.h:5939
GLintptr offset
Definition: glew.h:1682