1 //
2 // Copyright 2016 Pixar
3 //
4 // Licensed under the Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 //    names, trademarks, service marks, or product names of the Licensor
11 //    and its affiliates, except as required to comply with Section 4(c) of
12 //    the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 //     http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
24 #ifndef PXR_USD_USD_SPECIALIZES_H
25 #define PXR_USD_USD_SPECIALIZES_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/usd/usd/api.h"
29 #include "pxr/usd/usd/common.h"
30 #include "pxr/usd/usd/prim.h"
31 
32 #include "pxr/usd/sdf/declareHandles.h"
33 #include "pxr/usd/sdf/path.h"
34 
35 PXR_NAMESPACE_OPEN_SCOPE
36 
37 SDF_DECLARE_HANDLES(SdfPrimSpec);
38 
39 /// \class UsdSpecializes
40 ///
41 /// A proxy class for applying listOp edits to the specializes list for a
42 /// prim.
43 ///
44 /// All paths passed to the UsdSpecializes API are expected to be in the
45 /// namespace of the owning prim's stage. Subroot prim specializes paths
46 /// will be translated from this namespace to the namespace of the current
47 /// edit target, if necessary. If a path cannot be translated, a coding error
48 /// will be issued and no changes will be made. Root prim specializes paths
49 /// will not be translated.
50 ///
51 class UsdSpecializes {
52     friend class UsdPrim;
53 
UsdSpecializes(const UsdPrim & prim)54     explicit UsdSpecializes(const UsdPrim& prim) : _prim(prim) {}
55 
56 public:
57 
58     /// Adds a path to the specializes listOp at the current EditTarget,
59     /// in the position specified by \p position.
60     USD_API
61     bool AddSpecialize(const SdfPath &primPath,
62                UsdListPosition position=UsdListPositionBackOfPrependList);
63 
64     /// Removes the specified path from the specializes listOp at the
65     /// current EditTarget.
66     USD_API
67     bool RemoveSpecialize(const SdfPath &primPath);
68 
69     /// Removes the authored specializes listOp edits at the current edit
70     /// target.
71     USD_API
72     bool ClearSpecializes();
73 
74     /// Explicitly set specializes paths, potentially blocking weaker opinions
75     /// that add or remove items, returning true on success, false if the edit
76     /// could not be performed.
77     USD_API
78     bool SetSpecializes(const SdfPathVector& items);
79 
80     /// Return the prim this object is bound to.
GetPrim()81     const UsdPrim &GetPrim() const { return _prim; }
GetPrim()82     UsdPrim GetPrim() { return _prim; }
83 
84     explicit operator bool() { return bool(_prim); }
85 
86     // ---------------------------------------------------------------------- //
87     // Private Methods and Members
88     // ---------------------------------------------------------------------- //
89 private:
90 
91     UsdPrim _prim;
92 };
93 
94 PXR_NAMESPACE_CLOSE_SCOPE
95 
96 #endif //PXR_USD_USD_SPECIALIZES_H
97