Loading...
Searching...
No Matches
namespaceEditor.h
Go to the documentation of this file.
1//
2// Copyright 2023 Pixar
3//
4// Licensed under the terms set forth in the LICENSE.txt file available at
5// https://openusd.org/license.
6//
7#ifndef PXR_USD_USD_NAMESPACE_EDITOR_H
8#define PXR_USD_USD_NAMESPACE_EDITOR_H
9
11
12#include "pxr/pxr.h"
13#include "pxr/usd/usd/api.h"
14#include "pxr/usd/usd/common.h"
15#include "pxr/usd/usd/stage.h"
18
19
20PXR_NAMESPACE_OPEN_SCOPE
21
28{
29public:
32 struct EditOptions {
33
40 };
41
42 USD_API
43 explicit UsdNamespaceEditor(const UsdStageRefPtr &stage);
44
45 USD_API
47 const UsdStageRefPtr &stage,
48 EditOptions &&editOptions);
49
50 USD_API
52 const UsdStageRefPtr &stage,
53 const EditOptions &editOptions);
54
60 USD_API
62 const SdfPath &path);
63
69 USD_API
71 const SdfPath &path,
72 const SdfPath &newPath);
73
80 USD_API
82 const UsdPrim &prim);
83
91 USD_API
93 const UsdPrim &prim,
94 const TfToken &newName);
95
103 USD_API
105 const UsdPrim &prim,
106 const UsdPrim &newParent);
107
116 USD_API
118 const UsdPrim &prim,
119 const UsdPrim &newParent,
120 const TfToken &newName);
121
127 USD_API
129 const SdfPath &path);
130
137 USD_API
139 const SdfPath &path,
140 const SdfPath &newPath);
141
148 USD_API
150 const UsdProperty &property);
151
159 USD_API
161 const UsdProperty &property,
162 const TfToken &newName);
163
171 USD_API
173 const UsdProperty &property,
174 const UsdPrim &newParent);
175
184 USD_API
186 const UsdProperty &property,
187 const UsdPrim &newParent,
188 const TfToken &newName);
189
197 USD_API
199
206 USD_API
207 bool CanApplyEdits(std::string *whyNot = nullptr) const;
208
209private:
210
211 // The type of edit that an edit description is describing.
212 enum class _EditType {
213 Invalid,
214
215 Delete,
216 Rename,
217 Reparent
218 };
219
220 // Description of an edit added to this namespace editor.
221 struct _EditDescription {
222 // Path to the existing object.
223 SdfPath oldPath;
224 // New path of the object after the edit is performed. An empty path
225 // indicates that the edit operation will delete the object.
226 SdfPath newPath;
227
228 // Type of the edit as determined by the oldPath and the newPath.
229 _EditType editType = _EditType::Invalid;
230
231 // Whether this describes a property edit or, otherwise, a prim edit.
232 bool IsPropertyEdit() const { return oldPath.IsPrimPropertyPath(); }
233 };
234
235 // Struct representing the Sdf layer edits necessary to apply an edit
236 // description to the stage. We need this to gather all the information we
237 // can about what layer edits need to be performed before we start editing
238 // any specs so that we can avoid partial edits when a composed stage level
239 // namespace would fail.
240 struct _ProcessedEdit
241 {
242 // List of errors encountered that would prevent the overall namespace
243 // edit of the composed stage object from being completed successfully.
244 std::vector<std::string> errors;
245
246 // The Sdf batch namespace edit that needs to be applied to each layer
247 // with specs.
249
250 // The list of layers that have specs that need to have the Sdf
251 // namespace edit applied.
252 SdfLayerHandleVector layersToEdit;
253
254 // The list of relocates edits that need to be made to layers in order
255 // to relocate a prim.
257
258 // Layer edits that need to be performed to update connection and
259 // relationship targets of other properties in order to keep them
260 // targeting the same object after applying this processed edit.
261 struct TargetPathListOpEdit {
262 // Property spec to author the new targets value to. Note that we
263 // store the spec handle for the property as the property spec's
264 // path could change if the property is moved or deleted by the
265 // primary namespace edit.
266 SdfPropertySpecHandle propertySpec;
267
268 // Name of the field that holds the path targets for the property
269 // which differs for attributes vs relationships.
270 TfToken fieldName;
271
272 // Updated list op value to set for the property spec.
273 SdfPathListOp newFieldValue;
274 };
275 std::vector<TargetPathListOpEdit> targetPathListOpEdits;
276
277 // List of errors encountered that would prevent connection and
278 // relationship target edits from being performed in response to the
279 // namespace edits.
280 std::vector<std::string> targetPathListOpErrors;
281
282 // Reparent edits may require overs to be created for the new parent if
283 // a layer doesn't have any specs for the parent yet. This specifies the
284 // path of the parent specs to create if need.
285 SdfPath createParentSpecIfNeededPath;
286
287 // Some edits want to remove inert ancestor overs after a prim is
288 // removed from its parent spec in a layer.
289 bool removeInertAncestorOvers = false;
290
291 // Applies this processed edit, performing the individual edits
292 // necessary to each layer that needs to be updated.
293 bool Apply();
294
295 // Returns whether this processed edit can be applied.
296 bool CanApply(std::string *whyNot) const;
297 };
298
299 // Adds an edit description for a prim delete operation.
300 bool _AddPrimDelete(const SdfPath &oldPath);
301
302 // Adds an edit description for a prim rename or reparent operation.
303 bool _AddPrimMove(const SdfPath &oldPath, const SdfPath &newPath);
304
305 // Adds an edit description for a property delete operation.
306 bool _AddPropertyDelete(const SdfPath &oldPath);
307
308 // Adds an edit description for a property rename or reparent operation.
309 bool _AddPropertyMove(const SdfPath &oldPath, const SdfPath &newPath);
310
311 // Clears the current procesed edits.
312 void _ClearProcessedEdits();
313
314 // Processes and caches the layer edits necessary for the current edit
315 // operation if there is no cached processecd edit.
316 void _ProcessEditsIfNeeded() const;
317
318 // Helper class for _ProcessEditsIfNeeded. Defined entirely in
319 // implementation. Declared here for private access to the editor
320 // structures.
321 class _EditProcessor;
322
323 UsdStageRefPtr _stage;
324 EditOptions _editOptions;
325 _EditDescription _editDescription;
326 mutable std::optional<_ProcessedEdit> _processedEdit;
327};
328
329PXR_NAMESPACE_CLOSE_SCOPE
330
331#endif // PXR_USD_USD_NAMESPACE_EDITOR_H
332
std::vector< LayerRelocatesEdit > LayerRelocatesEdits
List of relocates edits to perform on all layers.
A description of an arbitrarily complex namespace edit.
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:274
SDF_API bool IsPrimPropertyPath() const
Returns whether the path identifies a prim's property.
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:71
USD_API bool MovePrimAtPath(const SdfPath &path, const SdfPath &newPath)
Adds an edit operation to move the composed prim at the given path on this namespace editor's stage t...
USD_API bool DeletePrimAtPath(const SdfPath &path)
Adds an edit operation to delete the composed prim at the given path from this namespace editor's sta...
USD_API bool RenameProperty(const UsdProperty &property, const TfToken &newName)
Adds an edit operation to rename the composed property at the path of property on this namespace edit...
USD_API bool ApplyEdits()
Applies all the added namespace edits stored in this to namespace editor to its stage by authoring al...
USD_API bool ReparentProperty(const UsdProperty &property, const UsdPrim &newParent)
Adds an edit operation to reparent the composed property at the path of property on this namespace ed...
USD_API bool DeleteProperty(const UsdProperty &property)
Adds an edit operation to delete the composed property at the path of property from this namespace ed...
USD_API bool ReparentPrim(const UsdPrim &prim, const UsdPrim &newParent)
Adds an edit operation to reparent the composed prim at the path of prim on this namespace editor's s...
USD_API bool MovePropertyAtPath(const SdfPath &path, const SdfPath &newPath)
Adds an edit operation to move the composed property at the given path on this namespace editor's sta...
USD_API bool ReparentProperty(const UsdProperty &property, const UsdPrim &newParent, const TfToken &newName)
Adds an edit operation to reparent the composed property at the path of property on this namespace ed...
USD_API bool ReparentPrim(const UsdPrim &prim, const UsdPrim &newParent, const TfToken &newName)
Adds an edit operation to reparent the composed prim at the path of prim on this namespace editor's s...
USD_API bool CanApplyEdits(std::string *whyNot=nullptr) const
Returns whether all the added namespace edits stored in this to namespace editor can be applied to it...
USD_API bool RenamePrim(const UsdPrim &prim, const TfToken &newName)
Adds an edit operation to rename the composed prim at the path of prim on this namespace editor's sta...
bool allowRelocatesAuthoring
Whether the namespace editor will allow the authoring of relocates in order to perform edits that wou...
USD_API bool DeletePrim(const UsdPrim &prim)
Adds an edit operation to delete the composed prim at the path of prim from this namespace editor's s...
USD_API bool DeletePropertyAtPath(const SdfPath &path)
Adds an edit operation to delete the composed property at the given path from this namespace editor's...
Structure for holding the options for how the namespace editor will behave when trying to perform edi...
UsdPrim is the sole persistent scenegraph object on a UsdStage, and is the embodiment of a "Prim" as ...
Definition: prim.h:117
Base class for UsdAttribute and UsdRelationship scenegraph objects.
Definition: property.h:38
@ Invalid
Invalid or unknown schema kind.