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 addLayer();
138  // Remove one of our source layers.
139  bool removeLayer(const std::string &filepath);
140 
141  // Apply a layer break, which tags all existing layers, and adds a new
142  // empty layer for holding future modification.
143  bool applyLayerBreak();
144 
145  // Store a ticket in with this data to keep alive cooked sop data in the
146  // XUSD_TicketRegistry as long as it might be referenced by our stage.
147  void addTicket(const XUSD_TicketPtr &ticket);
148  void addTickets(const XUSD_TicketArray &tickets);
149  const XUSD_TicketArray &tickets() const;
150 
151  // Store pointers to arrays that were created automatically as part of a
152  // process of replacing a layer on disk with an anonymous layer.
153  void addReplacements(
154  const XUSD_LayerArray &replacements);
155  const XUSD_LayerArray &replacements() const;
156 
157  // Store a locked stage with this data to keep alive cooked lop data in the
158  // HUSD_LockedStageRegistry as long as it might be referenced by our stage.
159  void addLockedStage(
160  const HUSD_LockedStagePtr &stage);
161  void addLockedStages(
163  const HUSD_LockedStageArray &lockedStages() const;
164 
165 private:
166  void reset();
167  void createNewData(const HUSD_LoadMasksPtr &load_masks,
168  int resolver_context_nodeid,
169  const UsdStageWeakPtr &resolver_context_stage,
170  const ArResolverContext *resolver_context);
171  void createHardCopy(const XUSD_Data &src);
172  void createSoftCopy(const XUSD_Data &src,
173  const HUSD_LoadMasksPtr &load_masks,
174  bool make_new_implicit_layer);
175  void createCopyWithReplacement(
176  const XUSD_Data &src,
177  const UT_StringRef &frompath,
178  const UT_StringRef &topath,
179  int nodeid,
180  HUSD_MakeNewPathFunc make_new_path,
181  UT_StringSet &replaced_layers);
182 
183  // Return the resolver context for our stage. Note this this method does
184  // not require that the stage be locked, becaue it is unchanging data set
185  // on the stage when it was created.
186  ArResolverContext resolverContext() const;
187 
188  // Return a layer created by flattening all source layers up to the
189  // strongest layer excluded by a Layer Break node.
190  void flattenLayers(const XUSD_Data &src,
191  int creator_node_id);
192  // Return a layer created by flattening the stage composed of all source
193  // layers up to the strongest layer excluded by a Layer Break node.
194  void flattenStage(const XUSD_Data &src,
195  int creator_node_id);
196  // Utility method used by the two flatten methods above to separate all
197  // layers preceding a layer break point. Optionally creates a warning if
198  // a layer break is found.
199  UsdStageRefPtr getOrCreateStageForFlattening(
200  HUSD_StripLayerResponse response,
201  UsdStage::InitialLoadSet loadset) const;
202 
203  void mirror(const XUSD_Data &src,
204  const HUSD_LoadMasks &load_masks);
205 
206  void afterLock(bool for_write,
208  &read_overrides =
210  const HUSD_OverridesPtr
211  &write_overrides =
213  bool remove_layer_breaks = false);
214  XUSD_LayerPtr editActiveSourceLayer();
215  void createInitialPlaceholderSublayers();
216  void afterRelease();
217 
218  static void exitCallback(void *);
219 
220  UsdStageRefPtr myStage;
221  UT_SharedPtr<UT_StringArray> myStageLayerAssignments;
222  UT_SharedPtr<XUSD_LayerArray> myStageLayers;
223  UT_SharedPtr<int> myStageLayerCount;
224  UT_SharedPtr<XUSD_OverridesInfo> myOverridesInfo;
225  XUSD_LayerAtPathArray mySourceLayers;
226  HUSD_LoadMasksPtr myLoadMasks;
227  XUSD_DataLockPtr myDataLock;
228  XUSD_TicketArray myTicketArray;
229  XUSD_LayerArray myReplacementLayerArray;
230  HUSD_LockedStageArray myLockedStages;
231  HUSD_MirroringType myMirroring;
232  UsdStageLoadRules myMirrorLoadRules;
233  bool myMirrorLoadRulesChanged;
234  int myActiveLayerIndex;
235  bool myOwnsActiveLayer;
236 
237  friend class ::HUSD_DataHandle;
238 };
239 
240 class HUSD_API XUSD_Layer : public UT_IntrusiveRefCounter<XUSD_Layer>
241 {
242 public:
244  bool create_change_block)
245  : myLayer(layer),
246  myChangeBlock(nullptr)
247  {
248  if (create_change_block)
249  myChangeBlock.reset(
250  new SdfChangeBlock());
251  }
253  { }
254 
255  const SdfLayerRefPtr &layer() const
256  { return myLayer; }
257 
258 private:
259  SdfLayerRefPtr myLayer;
260  UT_UniquePtr<SdfChangeBlock> myChangeBlock;
261 };
262 
264 
265 #endif
266 
std::string myIdentifier
Definition: XUSD_Data.h:63
const SdfLayerRefPtr & layer() const
Definition: XUSD_Data.h:255
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:243
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.
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:57
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:63
HUSD_StripLayerResponse
Definition: HUSD_Utils.h:74
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